import { IncomingPriceEvent } from './lib/types/events.js'; import { EngineOrder } from './lib/types/order.js'; import { EnginePositionSide, EngineSimplePosition } from './lib/types/position.js'; /** * This abstraction layer is a state cache for account state (so we know what changed when an event comes in). * * Since it's mostly a cache of information also available on the exchange (via a REST API call), none of it needs to be persisted. * * EXCEPT the following, which cannot be derived from the exchange: * - accountPositionMetadata - an object representing information about a position, per symbol * * This "accountPositionMetadata" can be any additional info to store about this symbol's position(s). A good place to store custom info. */ export declare class AccountStateStore> { private isPendingPersistPositionMetadata; private accountLeverageState; private accountPositionState; private accountPositionMetadata; private accountOrders; private accountOtherState; dumpLogState(): void; /** * Pass a price update event to recalculate price-sensitive position state (such as UPNL) */ processPriceEvent(event: IncomingPriceEvent): void; /** * Return some loggable summary state. Takes the last seen price event into account, when looking at position upnl. * * Don't rely on this too much, it's a rushed implementation */ getSessionSummary(startingBalance: number): { activePositions: { leverage: number | undefined; symbol: string; timestampMs: number; positionSide: EnginePositionSide; orderPositionSide: import("./index.js").EngineOrderPositionSide; positionPrice: number; assetQty: number; value: number; valueUpnl: number; marginValue: number; liquidationPrice: number; stopLossPrice: number | undefined; takeProfitPrice: number | undefined; }[]; activePositionUpnlSum: number; account: { quoteBalanceState: { startedWith: number; now: number; quoteMarginLockedSum: number; nowInclLocked: number; nowIfEverythingClosedAtMarket: number; }; pnlState: { realisedPnl: number; unrealisedPnl: number; }; }; }; /** * Utility method to check if metadata was recently changed (and hasn't been persisted yet) */ isPendingPersist(): boolean; /** * Internally mark that metadata recently changed (and should be persisted) * * After you've persisted it somewhere, you should set this back to "false". */ setIsPendingPersist(value: boolean): void; setWalletBalance(bal: number): void; getWalletBalance(): number; /** * Overwrites "previous balance" with current balance. Can be used to track balance changes before/after events */ storePreviousBalance(): void; getPreviousBalance(): number; getAllPositions(): EngineSimplePosition[]; /** * Recalculate and return counters for the total number of positions opened (hedged positions count as 2) * @returns */ getTotalActivePositions(): { total: number; totalHedged: number; }; /** * @returns a cached count on the total number of positions that have both a long and a short open */ getTotalHedgedPositions(): number; isSymbolSideInPosition(symbol: string, positionSide: EnginePositionSide): boolean; /** Returns true if any side has a position for this symbol */ isSymbolInAnyPosition(symbol: string): boolean; isDualPositionMode(): boolean; setSymbolLeverage(symbol: string, leverage: number): void; getSymbolLeverage(symbol: string): number | undefined; getSymbolLeverageCache(): Record; private assertInitialStateActivePosition; getActivePosition(symbol: string, side: EnginePositionSide): EngineSimplePosition | undefined; setActivePosition(symbol: string, side: EnginePositionSide, newState: EngineSimplePosition): void; deleteActivePosition(symbol: string, side: EnginePositionSide): void; /** Overwrite the full metadata store. This should be keyed by symbol! */ setAllSymbolMetadata(data: typeof this.accountPositionMetadata): void; /** Return position metadata for all symbols */ getAllSymbolMetadata(): typeof this.accountPositionMetadata; /** Return a list of symbols with any metadata stored */ getSymbolsWithMetadata(): string[]; /** Return metadata for one symbol */ getSymbolMetadata(symbol: string): TEnginePositionMetadata | undefined; /** Overwrite the full state for a symbol's metadata */ setSymbolMetadata(symbol: string, data: TEnginePositionMetadata): TEnginePositionMetadata; deletePositionMetadata(symbol: string): void; /** * Set one value in this symbol's metadata state. * * Warning: make sure to set initial metadata (via setSymbolMetadata()) before trying to use this, or it will throw an error! */ setSymbolMetadataValue(symbol: string, key: TMetadataKey, newValue: TEnginePositionMetadata[TMetadataKey]): TEnginePositionMetadata; /** * Get all orders */ getOrders(): EngineOrder[]; /** * Get all active orders */ getActiveOrders(): EngineOrder[]; /** * Get orders for a specific symbol */ getOrdersForSymbol(symbol: string): EngineOrder[]; /** * Get orders for a specific symbol and side */ getOrdersForSymbolSide(symbol: string, side: 'BUY' | 'SELL'): EngineOrder[]; /** * Get a specific order by ID */ getOrder(orderId: string): EngineOrder | undefined; /** * Upsert an active order into the state store * Main entry point for order state updates * Only keeps active and partially filled orders in state * Deletes orders if they are not longer active(cancelled, filled, expired, etc) */ upsertActiveOrder(order: EngineOrder): void; /** * Remove an order from tracking */ deleteOrder(orderId: string): void; /** * Clear all orders */ clearAllOrders(): void; /** * Get orders by status */ getOrdersByStatus(status: EngineOrder['status']): EngineOrder[]; /** * Get orders by type */ getOrdersByType(orderType: EngineOrder['orderType']): EngineOrder[]; /** * Get all orders sorted by orderId * @param ascending - true for ascending order, false for descending */ getOrdersSortedById(ascending?: boolean): EngineOrder[]; /** * Get all orders sorted by symbol * @param ascending - true for ascending order, false for descending */ getOrdersSortedBySymbol(ascending?: boolean): EngineOrder[]; /** * Get all orders sorted by price * @param ascending - true for ascending order, false for descending */ getOrdersSortedByPrice(ascending?: boolean): EngineOrder[]; /** * Get orders for a specific symbol sorted by price * @param symbol - The symbol to filter orders for * @param ascending - true for ascending order, false for descending */ getOrdersForSymbolSortedByPrice(symbol: string, ascending?: boolean): EngineOrder[]; /** * Get orders for a specific symbol and side sorted by price * @param symbol - The symbol to filter orders for * @param side - The side to filter orders for (BUY/SELL) * @param ascending - true for ascending order, false for descending */ getOrdersForSymbolSideSortedByPrice(symbol: string, side: 'BUY' | 'SELL', ascending?: boolean): EngineOrder[]; /** * Get orders sorted by timestamp * @param ascending - true for ascending order (oldest first), false for descending (newest first) */ getOrdersSortedByTimestamp(ascending?: boolean): EngineOrder[]; }