/** * Strategy interface for Bot Engine v2. * All trading strategies implement this interface. */ import type { ExchangeAdapter, ExchangeKline } from "../exchanges/index.js"; import type { MarketSnapshot } from "./conditions.js"; export interface EnrichedSnapshot extends MarketSnapshot { klines: ExchangeKline[]; orderbook: { bids: [string, string][]; asks: [string, string][]; }; openInterest: string; } export type StrategyAction = { type: "place_order"; side: "buy" | "sell"; price: string; size: string; orderType: "limit" | "market"; reduceOnly?: boolean; tif?: string; } | { type: "cancel_order"; orderId: string; } | { type: "cancel_all"; } | { type: "edit_order"; orderId: string; price: string; size: string; } | { type: "set_leverage"; leverage: number; marginMode?: "cross" | "isolated"; } | { type: "noop"; }; export interface StrategyContext { adapter: ExchangeAdapter; symbol: string; config: Record; state: Map; tick: number; log: (msg: string) => void; } export interface ParamDef { name: string; type: "number" | "string" | "boolean"; required: boolean; default?: unknown; description: string; } export interface Strategy { readonly name: string; describe(): { description: string; params: ParamDef[]; }; init(ctx: StrategyContext, snapshot: EnrichedSnapshot): Promise; onTick(ctx: StrategyContext, snapshot: EnrichedSnapshot): Promise; onStop(ctx: StrategyContext): Promise; }