When WF filter blocks a ticker, automatically start a virtual (shadow)
position with the same trailing/time stop logic. After WF_SHADOW_WINS
consecutive shadow wins, reset WF history to re-enable real trading.
- trader.py: add _shadow_positions, _shadow_cons_wins state;
_shadow_enter(), get_shadow_positions(), update_shadow_peak(),
close_shadow() functions; trigger shadow entry on WF block in buy()
- monitor.py: add _check_shadow_position() with ATR trailing + time stop;
check shadow positions every 10s in run_monitor()
- Env: WF_SHADOW_WINS=2 (2 consecutive wins to rehabilitate)
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
After sell_market_order, query Upbit /v1/order API to get actual
trade fills. If split across multiple fills, compute weighted average
price and use actual paid_fee instead of estimate.
Falls back to get_current_price if order query fails.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Each buy generates a UUID trade_id stored in positions table.
Each sell links via same trade_id in trade_results, enabling
round-trip grouping of buy→sell pairs.
Additional fields saved per trade:
- fee_krw: commission amount (0.05% each side)
- krw_profit: net KRW profit/loss after fees
- buy_price / sell_price: exact prices
- invested_krw: capital deployed
- sell_reason: trailing stop / time stop / etc.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- strategy: replace daily volume check with 60-min candle volume
(daily volume at 5am is tiny -> BTC/ETH never matched; now uses
last 1h candle vs previous 23h avg × 2)
- trader: log actual KRW net profit and fee on every sell
- trader: skip re-entry +1% block when last trade was a win
(allow re-entry on new trend signal even below last sell price)
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- price_db: add sell_prices table (ensure/upsert/load/delete)
- trader: restore _last_sell_prices from DB on startup so re-entry
block survives restarts; persist each sell price immediately
- market: retry chunk requests up to 3 times with backoff on 429
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Add trade_results table to Oracle DB for persistent trade history
- Record win/loss after each sell with pnl_pct
- Load last N trades per ticker from DB on startup (survives restarts)
- Block buy() when recent win rate (last 5 trades) < 40% threshold
- Configurable via WF_WINDOW and WF_MIN_WIN_RATE env vars
- Backtest showed improvement from -7.5% to +37.4% cumulative return
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- restore_positions(): read Upbit balances on startup to prevent
double-buying after restart
- notify.py: read TOKEN/CHAT_ID inside _send() to avoid empty values
when module is imported before load_dotenv()
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- notify.py: buy/sell/error alerts via upbit_trading_jm_bot
- STOP_LOSS_PCT: trailing stop configurable via .env (default -5%)
- notify_buy/notify_sell called on every trade execution
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Sell position if held for TIME_STOP_HOURS (default 24h) with less than
TIME_STOP_MIN_GAIN_PCT (default +3%) gain. Frees up capital for
fresh momentum opportunities.
Priority: trailing stop (-10%) checked first, then time stop.
Both thresholds configurable via .env.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Strategy C: volatility breakout (Larry Williams K=0.5) AND momentum
(MA20 + 2x volume surge) must both trigger for a buy signal.
Hard rules:
- Trailing stop: sell when price drops -10% from peak
- Max budget: 1,000,000 KRW total, up to 3 positions (333,333 KRW each)
- Scan top 20 KRW tickers by 24h trading volume every 60s
- Monitor positions every 10s
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>