fix: flash trades — entry+exit в одном цикле replay

Replay approach: run_day() возвращает trade уже закрытым (session-end
на последней свече). Раньше executor пропускал такие trades. Теперь
исполняет entry+exit в одном цикле.

Добавлен test_live.py — интеграционный тест на кэшированных 5m данных:
OR computation, strategy signals, incremental simulation.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
anor
2026-03-13 17:13:35 +10:00
co-authored by Claude Opus 4.6
parent 70a855c588
commit efc728cfe7
2 changed files with 220 additions and 1 deletions
+12 -1
View File
@@ -182,8 +182,19 @@ def run_cycle(conn: sqlite3.Connection, cfg: Config) -> list[str]:
key = _trade_key(t)
if key in db_keys or key in _session.last_trade_ids:
continue
if t.exit_price > 0:
# Already closed in strategy — skip (historical trade)
# "Flash trade": entered and exited within this cycle's candle window.
# Execute both entry and exit on exchange.
_execute_entry(conn, cfg, t, get_equity(conn), logs)
_session.last_trade_ids.add(key)
# Now close the just-opened position
new_positions = get_open_positions(conn)
for pos in new_positions:
pos_key = f"{pos['direction']}_{pos['entry_price']:.2f}_{pos['stop_price']:.2f}"
if pos_key == key:
_execute_exit(conn, cfg, pos, t.exit_price, t.result, logs)
break
continue
# New active trade → execute entry (re-read equity for fresh value)