IExchange

Exchange interface implemented by ClientExchange. Provides candle data access and VWAP calculation.

getCandles: (symbol: string, interval: CandleInterval, limit: number) => Promise<ICandleData[]>

Fetch historical candles backwards from execution context time.

getNextCandles: (symbol: string, interval: CandleInterval, limit: number) => Promise<ICandleData[]>

Fetch future candles forward from execution context time (for backtest).

formatQuantity: (symbol: string, quantity: number) => Promise<string>

Format quantity for exchange precision.

formatPrice: (symbol: string, price: number) => Promise<string>

Format price for exchange precision.

getAveragePrice: (symbol: string) => Promise<number>

Calculate VWAP from last 5 1-minute candles.

Formula: VWAP = Σ(Typical Price × Volume) / Σ(Volume) where Typical Price = (High + Low + Close) / 3

getOrderBook: (symbol: string, depth?: number) => Promise<IOrderBookData>

Fetch order book for a trading pair.

getAggregatedTrades: (symbol: string, limit?: number) => Promise<IAggregatedTradeData[]>

Fetch aggregated trades for a trading pair.

getRawCandles: (symbol: string, interval: CandleInterval, limit?: number, sDate?: number, eDate?: number) => Promise<ICandleData[]>

Fetch raw candles with flexible date/limit parameters.

All modes respect execution context and prevent look-ahead bias.

Parameter combinations:

  1. sDate + eDate + limit: fetches with explicit parameters, validates eDate <= when
  2. sDate + eDate: calculates limit from date range, validates eDate <= when
  3. eDate + limit: calculates sDate backward, validates eDate <= when
  4. sDate + limit: fetches forward, validates calculated endTimestamp <= when
  5. Only limit: uses execution.context.when as reference (backward)