fix: address critical code review issues (PnL double recording, sync HTTP, race conditions)

- fix(bot): prevent PnL double recording in _close_and_reenter using asyncio.Event
- fix(bot): prevent SYNC detection PnL duplication with _close_handled_by_sync flag
- fix(notifier): move sync HTTP call to background thread via run_in_executor
- fix(risk_manager): make is_trading_allowed async with lock for thread safety
- fix(exchange): cache exchange info at class level (1 API call for all symbols)
- fix(exchange): use `is not None` instead of truthy check for price/stop_price
- refactor(backtester): extract _calc_trade_stats to eliminate code duplication
- fix(ml_features): apply rolling z-score to OI/funding rate in serving (train-serve skew)
- fix(bot): use config.correlation_symbols instead of hardcoded BTCUSDT/ETHUSDT
- fix(bot): expand OI/funding history deque to 96 for z-score window
- cleanup(config): remove unused stop_loss_pct, take_profit_pct, trailing_stop_pct fields

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
21in7
2026-03-19 23:03:52 +09:00
parent 24ed7ddec0
commit 181f82d3c0
9 changed files with 189 additions and 182 deletions

View File

@@ -15,18 +15,20 @@ def config():
return Config()
def test_max_drawdown_check(config):
@pytest.mark.asyncio
async def test_max_drawdown_check(config):
rm = RiskManager(config, max_daily_loss_pct=0.05)
rm.daily_pnl = -60.0
rm.initial_balance = 1000.0
assert rm.is_trading_allowed() is False
assert await rm.is_trading_allowed() is False
def test_trading_allowed_normal(config):
@pytest.mark.asyncio
async def test_trading_allowed_normal(config):
rm = RiskManager(config, max_daily_loss_pct=0.05)
rm.daily_pnl = -10.0
rm.initial_balance = 1000.0
assert rm.is_trading_allowed() is True
assert await rm.is_trading_allowed() is True
@pytest.mark.asyncio