UNPKG

orderbooks

Version:

In-memory state stores and handlers for caching multiple exchange:symbol orderbook states

54 lines (53 loc) 2.65 kB
import { OrderBook, OrderBookOptions } from './OrderBook'; import { OrderBookLevelState } from './OrderBookLevel'; /** * Store for multi-symbol orderbooks, grouped into one book (OrderBook) per symbol * * `ExtraStateType` is optional extra state you may want to store with each orderbook level, completely optional. Inject a union type if desired. * @class OrderBooksStore */ export declare class OrderBooksStore<ExtraStateType = unknown> { books: Record<string, OrderBook<ExtraStateType>>; traceLog: boolean; shouldCheckTimestamp: boolean; maxDepth: number; constructor(options?: OrderBookOptions); /** * Get the current orderbook store for a symbol. Automatically initialised (empty), if none exists yet. * @param {string} symbol * @returns {OrderBook} created for symbol if not already tracked */ getBook(symbol: string): OrderBook<ExtraStateType>; /** * @public Store/replace existing orderbook state in-memory * * @param {string} symbol * @param {Array} data current orderbook snapshot represented as array, where each child element is a level in the orderbook * @param {number} timestamp * @returns {OrderBook} store instance that handled this event */ handleSnapshot(symbol: string, data: OrderBookLevelState[], timestamp?: number): OrderBook<ExtraStateType>; /** * @public Update existing orderbook state in-memory * * @param {string} symbol * @param {Array} deleteLevels - array with levels to delete * @param {Array} updateLevels - array with levels to update * @param {Array} insertLevels - array with levels to insert * @param {number} timestamp * @returns {OrderBook} store instance that handled this event */ handleDelta(symbol: string, deleteLevels: OrderBookLevelState[] | undefined, updateLevels: OrderBookLevelState[] | undefined, insertLevels: OrderBookLevelState[] | undefined, timestamp?: number): OrderBook<ExtraStateType>; /** * Calculate expected slippage for a market order of a given size for a specific symbol * @param {string} symbol - The trading symbol * @param {number} orderSize - The size of the order in base units * @param {string} side - 'Buy' or 'Sell' side of the order * @returns {{ executionPrice: number, slippagePercent: number, slippageBasisPoints: number } | null} - The expected execution price and slippage */ getEstimatedSlippage(symbol: string, baseOrderSize: number, side: 'Buy' | 'Sell'): { executionPrice: number; slippagePercent: number; slippageBasisPoints: number; } | null; }