feat(backtest): implement tick-by-tick fill loop with JSONL output#62
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (8)
📝 WalkthroughWalkthroughJSON structured logging is integrated into the backtesting framework. Changes
Sequence Diagram: BacktestEngine Main Loop with Fill ProcessingsequenceDiagram
participant Engine as BacktestEngine
participant Strategy as BasicMarketMaker
participant Logger as JsonLogger
participant Analyzer as TradeAnalyzer
loop Per Market Data Point
Engine->>Engine: Record market data snapshot<br/>(m_lastData)
Engine->>Strategy: getPendingOrders()
Strategy-->>Engine: pending orders
alt Orders exist
Engine->>Engine: Validate & fill orders<br/>against m_lastData bid/ask<br/>apply slippage & fees<br/>update cost basis & position
Engine->>Analyzer: recordTrade()
Engine->>Strategy: onBacktestFill(side,<br/>price, qty, timestamp)
Strategy->>Strategy: Update m_position & m_pnl
alt JSON logging enabled
Engine->>Logger: log(fill entry)
end
end
Engine->>Strategy: updateMarketData(dataPoint)
Strategy->>Strategy: generateBacktestQuotes()
end
Engine->>Engine: emitFinalStrategyMetrics()
alt JSON logging enabled
Engine->>Logger: log(strategy_metrics)
end
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Poem
🚥 Pre-merge checks | ✅ 1 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (1 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
# [1.8.0](v1.7.1...v1.8.0) (2026-04-19) ### Features * **backtest:** implement tick-by-tick fill loop with JSONL output ([#62](#62)) ([9fb74d6](9fb74d6))
|
🎉 This PR is included in version 1.8.0 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
Summary
BacktestEngine::processMarketData/processStrategyOrdersfrom stubs into a working fill loop: the strategy sees each tick, quotes, and fills are matched against the next tick's bid/ask.order_filledper fill,strategy_metricsonce at the end.StopBacktestTest.Fill mechanics
tradingFee, cost-basis P&L via weighted-average accountingmaxPositionenforced per fill; insufficient-balance buys rejectedm_stateMutexwhile mutatingStrategy API (
BasicMarketMaker)updateMarketData(MarketDataPoint), synchronous tick feed for backtestgetPendingOrders()drain quotesonBacktestFill(side, price, qty, ts)atomic position update (CAS)JSONL
JsonLogger::log(json)writes raw top-level entries (existing helpers wrap undertrading_event, which doesn't match the runner's expected shape)nullSummary by CodeRabbit
Release Notes
New Features
Bug Fixes