import type { AuxSeriesKind, Bar, MaValues, OiOhlc, ParamValue, PendingOrder, Position, PositionOptions, Strategy, TradingEnv } from "../types"; import type { EntryOrderFilledArgs, EntryOrderPartiallyFilledArgs, LiveEntryOrderState, LivePositionState, LiveRunnerSnapshot, LiveStrategyRunnerOptions, ProtectiveOrderFilledArgs } from "./types"; /** * Drives ONE strategy instance (= one symbol+direction) against a live exchange through a * LiveExecutionPort. The strategy sees the exact same TradingEnv contract as in the backtest player; * the runner translates its synchronous calls into a desired order/position state and syncs that * state to the exchange after every bar / fill handler ("desired-state sync"). * * Aggregation: the strategy holds N small positions (one per limit fill, mirroring the backtest * runtime), while the exchange holds ONE netted position. Protective orders (stop-loss / * take-profit) therefore sync as ONE logical order covering the total size — physically a SET of * exchange orders when the size exceeds the per-order cap (the port owns the splitting; the runner * tracks the piece id list). The strategy is expected to keep one uniform protective price across * its positions (the last set price wins, same for the optional exit-reason code). * * Take-profit fills mirror the backtest runtime semantics: they do NOT produce onOrderFill — the * strategy reconciles its position list via getPosition/getPositionList on the next bar. * * Catch-up mode replays history through the strategy WITHOUT touching the exchange; completing it * syncs only the final desired state (used for manual late entries and restart recovery). */ export declare class LiveStrategyRunner implements TradingEnv { private readonly strategy; private readonly port; private readonly params; private readonly rawConfig; private readonly onEvent?; private readonly balanceProvider?; private readonly historyLimit; private readonly oiProvider; private barHistory; private currentBar; private currentMaValues; private currentBarIndex; private oiHistory; private currentOiBar; /** 24h quote volume of the current bar, supplied per bar by the host (the exchange feed knows it). */ private currentVolume24hUsd; private desiredMarketEntry; private entryOrderList; private cancelRequestList; private positionList; private desiredStopLossPrice; private desiredTakeProfitPrice; private desiredStopLossReason; private desiredTakeProfitReason; private stopLossExchangeOrderIdList; private takeProfitExchangeOrderIdList; private lastSyncedStopLoss; private lastSyncedTakeProfit; private isProtectiveSyncHeld; private pendingCloseAmountUsd; private pendingCloseContracts; private nextLocalOrderNumber; private nextLocalPositionNumber; private isCatchUpActive; private isInitialized; private isSyncRunning; private isSyncRerunRequested; constructor(strategy: Strategy, options: LiveStrategyRunnerOptions); feedClosedBar(bar: Bar, maValues?: MaValues, oiBar?: OiOhlc, volume24hUsd?: number): Promise; catchUpBar(bar: Bar, maValues?: MaValues, oiBar?: OiOhlc, volume24hUsd?: number): void; private advanceBar; sendCommand(command: Record): Promise; startCatchUp(): void; completeCatchUp(): Promise; isInCatchUp(): boolean; handleEntryOrderFilled(args: EntryOrderFilledArgs): Promise; handleEntryOrderPartiallyFilled(args: EntryOrderPartiallyFilledArgs): Promise; private bookEntryFill; /** The host must call this only when the protective exit is COMPLETE — every stop piece is * terminal and the exchange position is confirmed flat. The whole book clears; the price is the * volume-weighted average across the pieces. */ handleStopLossFilled(args: ProtectiveOrderFilledArgs): Promise; handleEntryOrderCanceled(args: EntryOrderFilledArgs): void; handleTakeProfitFilled(_args: ProtectiveOrderFilledArgs): Promise; handleExternalPositionClose(): Promise; getSnapshot(): LiveRunnerSnapshot; restoreSnapshot(snapshot: LiveRunnerSnapshot): void; getEntryOrderStateList(): LiveEntryOrderState[]; getPositionStateList(): LivePositionState[]; getStopLossExchangeOrderIdList(): string[]; getTakeProfitExchangeOrderIdList(): string[]; getDesiredStopLossReason(): string | null; getDesiredTakeProfitReason(): string | null; /** Drop the synced markers so the next sync re-places both protective order sets at the current * desired values — the host's escape hatch when it detects the exchange lost part of the set. */ invalidateProtectiveSync(): void; /** Invalidate AND re-sync the protective sets right away. The host's coverage watchdog uses this * so a detected deficit heals on the watchdog cadence (seconds) instead of waiting for the next * bar to trigger a sync — an unprotected remainder must live as briefly as possible. */ resyncProtectiveOrders(): Promise; /** While held, protective REPLACE placements are frozen (a protective exit is being finalized — * re-placing mid-exit would fight the fills). Cancels still run: finalizing a stop must still be * able to cancel the orphaned take-profit set, and vice versa. */ setProtectiveSyncHold(isHeld: boolean): void; openLong(sizeUsd: number, _options?: PositionOptions): void; openShort(sizeUsd: number, _options?: PositionOptions): void; closeLong(): void; closeShort(): void; placeLimitOrder(side: "buy" | "sell", price: number, amountUsd: number): string; cancelOrder(orderId: string): boolean; cancelAllOrders(): void; modifyOrderPrice(orderId: string, newPrice: number): boolean; getPendingOrderList(): PendingOrder[]; getPosition(positionId?: string): Position | null; getPositionList(): Position[]; closePosition(positionId?: string, _exitReason?: string): void; closeAllPositions(exitReason?: string): void; setStopLoss(positionIdOrPrice: string | number, price?: number, reason?: string): void; setTakeProfit(positionId: string, price: number, reason?: string): void; setPositionTag(positionId: string, tag: string): void; setPositionDisplay(_positionId: string, _data: Record): void; getBalance(): number; getBarIndex(): number; getCurrentBar(): Bar; getHistory(count: number, resolution?: string): Bar[]; getOiClose(_resolution?: string): number | null; /** 24h quote volume of the current bar, as handed in by the host (see feedClosedBar). Null when the * host does not supply it — a strategy that gates on liquidity must then decide what that means. */ getVolume24h(_resolution?: string): number | null; getOiOhlc(_resolution?: string): OiOhlc | null; getOiOhlcHistory(count: number, _resolution?: string): Array; getLiqLongUsd(_resolution?: string): number | null; getLiqShortUsd(_resolution?: string): number | null; getLongShortRatio(_resolution?: string): number | null; getCurrentFundingRate(): number | null; getRecentFundingRates(_count: number): number[]; getAuxHistory(series: AuxSeriesKind, count: number, _resolution?: string): Array; getMaValues(_resolution: string): MaValues; getParam(key: string, defaultValue: T): T; getConfig(): Record; emitEvent(type: string, data: Record): void; private ensureInitialized; private toPositionView; private updateRunningBest; private getTotalContracts; private getTotalAmountUsd; private sync; private executeSync; private applyEntryPlacementResult; private finishExecuteSync; private requireMarketEntrySupport; private executeMarketEntry; private syncProtectiveOrders; private isProtectiveOrderSynced; } //# sourceMappingURL=live-strategy-runner.d.ts.map