InputApi
InputApi
Exposed as api.input inside setup(), this declares the tunable inputs of your strategy. Each method — int, float, bool, and enum — returns the resolved value to use immediately, while the declaration drives the strategy manifest and the UI sliders shown to users. Numeric inputs accept optional min, max, and step bounds.
Signature
export interface InputApi { int(name: string, def: number, opts?: { min?: number; max?: number; step?: number }): number; float(name: string, def: number, opts?: { min?: number; max?: number; step?: number }): number; bool(name: string, def: boolean): boolean; enum<T extends string>(name: string, def: T, options: readonly T[]): T;}Example
import { defineStrategy } from '@nexpips/sdk-trading';
/** * Recette cookbook : achat market avec stop-loss ATR et take-profit en R:R 1:2. */export default defineStrategy({ symbol: 'EURUSD', timeframe: 'H1', risk: { maxRiskPercentPerTrade: 1, maxOpenPositions: 1, maxDailyLossPercent: 5, }, setup: (api) => { const riskPercent = api.input.float('riskPercent', 1, { min: 0.1, max: 2, step: 0.1 });
return { onBar(ctx) { if (!ctx.position.isFlat) return; if (ctx.position.hasPendingOrder) return;
ctx.order.marketBuy({ riskPercent, stopLoss: { type: 'atr', period: 14, multiple: 2 }, takeProfit: { type: 'rr', value: 2 }, }); }, }; },});Declaring inputs that drive the strategy's risk/reward.