Skip to main content

Strategy Execution Context (input.execution)

Every strategy evaluation now receives a guaranteed input.execution object injected by the runtime. It cannot be removed or overridden by strategy parameters or AI-generated configuration.

What's in input.execution​

input.execution.market.pipSize          // e.g. 0.0001 for EURUSD, null for crypto
input.execution.market.previousClose // close of the candle before current, or null

input.execution.costs.spreadPips // round-trip spread in pips (0 if disabled)
input.execution.costs.slippagePips // round-trip slippage in pips (0 if disabled)
input.execution.costs.commission // { type, perLotCost?, lotSize?, ... }
input.execution.costs.fees // { type, percentNotional?, perTradeCost? }

input.execution.bot.id // bot DB id (null in backtest)
input.execution.bot.name // bot display name (null in backtest)
input.execution.bot.symbol // e.g. 'EURUSD'
input.execution.bot.assetClass // 'forex' | 'crypto' | 'stock'
input.execution.bot.exchange // broker/exchange identifier
input.execution.bot.isPaper // paper trading mode
input.execution.bot.allocatedBalance // budget in account currency (null if not set)
input.execution.bot.currentBalance // available balance (null if not tracked)
input.execution.bot.status // 'active' | 'paused' | 'stopped' | null in backtest

input.execution.schedule.allowed // true if trading is permitted now
input.execution.schedule.reason // why blocked, or null

Net-profit decision pattern​

const pip = input.execution.market.pipSize ?? 0.0001;
const roundTripCostPips = input.execution.costs.spreadPips + input.execution.costs.slippagePips;
const grossPips = (exitPrice - entryPrice) / pip;
if (grossPips - roundTripCostPips <= 0) {
return { action: 'HOLD', reason: 'No net edge after costs', checks: [] };
}

Files changed​

  • services/backend/src/lib/backtest-engine/types.ts — new StrategyExecution* interfaces + execution field on StrategyExecutionInput
  • services/backend/src/lib/backtest-engine/runner.ts — populates execution in buildStrategyExecutionInput; exports resolveCommissionModel and resolveFeeModel
  • services/backend/src/routes/bots/bot-runner.ts — buildBotExecution helper; populates execution in evaluateStrategy and buildFastExitInput
  • services/backend/src/lib/strategy-validator.ts — adds safe-default execution to contract validation input
  • docs/strategies/authoring-guide.md (+ .es.md, .hu.md) — documents the new field