Commit Graph
7 Commits
Author SHA1 Message Date
anorandClaude Opus 4.6 377d682c0f feat: Bybit exchange emulator + per-coin 1h оптимизация (+$862, 17/17 profitable)
Новый пакет `emulator/`:
- BybitEmulator: drop-in ccxt.bybit mock (13 методов, duck typing)
- FillModel: реалистичные косты (spread 0.03%, slippage 0.2%, funding 0.01%)
- MatchingEngine: bar-by-bar stops по high/low, funding каждые 8h
- AccountState: позиции, ордера, баланс, PnL
- runner.py: standalone backtest с True ATR и per-coin параметрами
- integration.py: прогон реального run_cycle() через эмулятор

Исправления:
- FuturesExecutor: dependency injection (exchange= параметр)
- optimize-windows: добавлены realistic costs (spread, slippage), true ATR,
  убран longs-only фильтр
- compute_atr (close-only) даёт стопы в 2.5x теснее True ATR — задокументировано

Per-coin оптимизация 1h (data/1h_optimal_params.json):
- 17/17 монет прибыльны, total +$862, ROI 86% за 17 мес
- Паттерн: shift 42-48, SM 4.0-6.0, K 2-5

146 тестов проходят.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-17 00:48:50 +10:00
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 bcf3c2a4ec fix: safety stop как SL на позиции (set_trading_stop) вместо отдельного ордера
- place_safety_stop теперь использует set_trading_stop — SL привязан
  к позиции, переживает рестарт бота, не осиротеет
- Не нужен cancel_order для futures — set_trading_stop перезаписывает
- Для spot оставлен старый подход (отдельный conditional order)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-15 04:48:57 +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 0b2602600e feat: futures long+short 1x 1h — FuturesExecutor, routing, time_exit в барах
- Новый FuturesExecutor (ccxt bybit linear): open_long/short, close_position,
  place_safety_stop с side, ensure_leverage (cached)
- Config: market_type, retrain_enabled, is_futures(), commission_for()
- Executor: routing spot/futures, SHORT разрешён для futures,
  time_exit в барах (не днях), commission по типу рынка
- Notify: USDT balance, skip futures в coin positions, dynamic timeframe
- Config.yaml: UNI+ATOM+SUI futures 1h, mode=paper
- 26 новых тестов (всего 97)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-15 03:55:17 +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