execution-context test suite
Added services/backend/tests/execution-context.test.ts — 23 tests verifying that input.execution is correctly populated in both the backtest runner and the live bot runner.
What is tested
Backtest (13 tests)
execution.market.pipSize=0.0001for EURUSDexecution.market.lotSize/minLotSize/lotStepcorrect for forex (100_000 / 0.01 / 0.01)execution.market.previousClosematches the candle immediately before the current one (null at index 0)execution.clockfields for a known London session candle (Tuesday 09:05 UTC):dayOfWeek=2,isLondonSession=true,isNewYorkSession=falseexecution.clock.isNewYorkSessiontrue during 14:00 UTC; London+NY overlap verifiedexecution.clock.isWeekend=trueon Saturday; session flags all falseexecution.bot.id/name/statusare null in backtest context;symbolandisPaper=falsecorrectexecution.schedule.upcomingEventsis empty array;allowed=true,reason=nullexecution.costs.spreadPips/slippagePipsreflectassumedSpreadPips/assumedSlippagePipsparameters; commission type forwardedsession.dailyTradeCountincrements from 0 → 1 after the first trade closessession.consecutiveWins/consecutiveLossesare non-negative integers throughoutportfolio.cashequalsinitialBalancebefore any trades;equityequalscashwith no open position- Real ClickHouse EURUSD 4h fixture: pipSize, lotSize, bot nulls, empty events, clock hour/dayOfWeek
Live bot runner (10 tests)
execution.market.pipSize/lotSize/minLotSize/lotStepcorrect for EURUSD via bundled strategy metadataexecution.market.previousClose= second-to-last candle's closeexecution.clock.evaluatedAtis a valid ISO string; all session flags are booleans; dayOfWeek in 1–7execution.bot.id/name/symbol/status/isPapermatch theBotRowvaluesexecution.session.allTimeTrades/allTimePnl/allTimeWinRateread frombot.total_trades/total_profit/win_rateexecution.schedule.allowedis booleanexecution.costs.commission.type='per_lot'whencommissionModelparameter is setexecution.costs.spreadPips/slippagePipsfromassumedSpreadPips/assumedSlippagePipsparametersportfolio.cash=bot.current_balance(not hardcoded 0)
Approach
- Backtest tests use a native
StrategyDefinitionthat capturesStrategyExecutionInputvia a closure — no QuickJS overhead, direct field access. - Live bot tests use a bundled
entry.jsthat returnsinput.execution.*fields inmetadatafor assertion viaevaluateBotWithCandles(). - Synthetic candles are pinned to known UTC timestamps so session flag assertions are deterministic.
- One test uses real ClickHouse EURUSD data from
tests/fixtures/strategy-real-data/eurusd-clickhouse-smoke.json.