4 Commits
Author SHA1 Message Date
anorandClaude Opus 4.6 12d28d6617 refactor: exchange as source of truth вместо DB-first reconcile
Бот теперь спрашивает биржу "что открыто?" перед каждым решением.
DB → журнал для trailing state, а не source of truth.

- _get_exchange_position: получает позицию с биржи (futures/spot/paper)
- _adopt_orphan: биржа имеет, DB нет → создаёт запись (только futures)
- _close_phantom: DB имеет, биржа нет → закрывает с Bybit PnL
- _sync_position_size: синхронизирует size при расхождении >2%
- _inline_reconcile: оркестрирует три предыдущие функции
- run_cycle/update_stops: exchange-first → inline reconcile → решения
- Удалён reconcile_positions (логика встроена в основной flow)
- 8 новых тестов, все 55 проходят

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-15 18:21:44 +10:00
anorandClaude Opus 4.6 91234187ff fix: utcnow() naive/aware crash + перепись тестов на интеграционные
- executor.py: utcnow() → now(utc) + ensure entry_dt is aware
  (предотвращает TypeError при aware created_at)
- test_executor.py: все тесты переписаны — вызывают реальные
  _check_signal, _check_position, run_cycle с мокнутой моделью/биржей
  Раньше тесты проверяли арифметику в изоляции (assert 0 < 3)
- 21 интеграционный тест включая regression на cooldown 1h

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-15 04:22:02 +10:00
anorandClaude Opus 4.6 59eadc9f9c test: cooldown regression — 1h TF не застревает на 24ч + legacy date format
Старые тесты тестировали формулу days*24//tf_hours, повторяя баг.
Новые тесты используют hours-based логику (как prod) и проверяют:
- 4h после стопа на 1h TF = 4 candles >= cooldown 3 (regression)
- legacy date string "2026-03-13" парсится без ошибок

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-15 04:09:58 +10:00
anorandClaude Opus 4.6 db17365bbb feat: тесты (71) + backtest long-only для честных спот-результатов
- tests/test_core.py: 50 тестов (risk, state, reconciliation)
- tests/test_executor.py: 21 тест (SHORT skip, cooldown, CB, reconcile, update_stops, balance sync)
- backtest_prod.py: LONG_ONLY=True по умолчанию (шорты на споте невозможны), NEAR cd=3

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-13 21:50:05 +10:00