Skip to main content

Strategy Execution Context v2

What changed​

Extended StrategyExecution (the input.execution object injected into every strategy evaluation) with 6 new runtime inputs:

1. input.execution.market.lotSize / minLotSize / lotStep​

Contract specs for the symbol. Forex: lotSize=100000, minLotSize=0.01, lotStep=0.01. BTC/ETH: minLotSize=0.001. Stocks: whole shares.

2. input.execution.schedule.upcomingEvents​

Array of StrategyExecutionUpcomingEvent objects — economic calendar blackout events in the next 24 hours. Empty array in backtests.

3. input.execution.clock​

Server/candle time context with UTC hour/minute, day-of-week, weekend flag, and four session flags (London, New York, Tokyo, Pacific).

4. input.execution.session​

Per-bot performance counters: dailyTradeCount, dailyPnl, allTimeTrades, allTimePnl, allTimeWinRate, consecutiveLosses, consecutiveWins.

5. portfolio.openPosition.accruedSwap​

New field on StrategyPositionState. Always 0 in backtests and live (not yet tracked from broker).

Files changed​

  • services/backend/src/lib/backtest-engine/types.ts — new interfaces + extended existing ones
  • services/backend/src/lib/pip-utils.ts — added getSymbolContractSpecs
  • services/backend/src/lib/economic-calendar.ts — added fetchUpcomingEventsForStrategy
  • services/backend/src/lib/backtest-engine/runner.ts — wired new fields into backtest evaluations
  • services/backend/src/routes/bots/bot-runner.ts — wired new fields into live bot evaluations
  • services/backend/src/lib/strategy-validator.ts — updated validator execution fixture
  • docs/strategies/authoring-guide.md + .es.md + .hu.md — updated input.execution shape docs