Exchange configuration object
Exchange schema registered via addExchange(). Defines candle data source and formatting logic.
Optionalcallbacks?: Partial<IExchangeCallbacks>Optional lifecycle event callbacks (onCandleData)
Unique exchange identifier for registration
OptionalformatPrice?: (symbol: string, price: number, backtest: boolean) => Promise<string>Format price according to exchange precision rules.
Optional. If not provided, defaults to Bitcoin precision on Binance (2 decimal places).
OptionalformatQuantity?: (symbol: string, quantity: number, backtest: boolean) => Promise<string>Format quantity according to exchange precision rules.
Optional. If not provided, defaults to Bitcoin precision on Binance (8 decimal places).
OptionalgetAggregatedTrades?: (Fetch aggregated trades for a trading pair. Optional. If not provided, throws an error when called.
// Backtest implementation: returns historical aggregated trades for the time range
const backtestAggregatedTrades = async (symbol: string, from: Date, to: Date, backtest: boolean) => {
if (backtest) {
return await database.getAggregatedTrades(symbol, from, to);
}
return await exchange.fetchAggregatedTrades(symbol);
};
// Live implementation: ignores from/to when not in backtest mode
const liveAggregatedTrades = async (symbol: string, _from: Date, _to: Date, backtest: boolean) => {
return await exchange.fetchAggregatedTrades(symbol);
};
Fetch candles from data source (API or database).
OptionalgetOrderBook?: (Fetch order book for a trading pair.
Optional. If not provided, throws an error when called.
// Backtest implementation: returns historical order book for the time range
const backtestOrderBook = async (symbol: string, depth: number, from: Date, to: Date, backtest: boolean) => {
if (backtest) {
return await database.getOrderBookSnapshot(symbol, depth, from, to);
}
return await exchange.fetchOrderBook(symbol, depth);
};
// Live implementation: ignores from/to when not in backtest mode
const liveOrderBook = async (symbol: string, depth: number, _from: Date, _to: Date, backtest: boolean) => {
return await exchange.fetchOrderBook(symbol, depth);
};
Optionalnote?: stringOptional developer note for documentation
addExchange({
exchangeName: "binance",
getCandles: async (symbol, interval, since, limit) => {
// Fetch from Binance API or database
return [{
timestamp: Date.now(),
open: 50000,
high: 51000,
low: 49000,
close: 50500,
volume: 1000,
}];
},
formatPrice: async (symbol, price) => price.toFixed(2),
formatQuantity: async (symbol, quantity) => quantity.toFixed(8),
});
Registers an exchange data source in the framework.
The exchange provides: