import type { OrderBookId } from "../../shared"; import type { OrderBook } from "./wire"; import { type BookAggregation } from "./aggregation"; /** * The `book_update` stream is snapshot-only: every data frame carries the * full top-20 levels per side and replaces the previous book wholesale. * Equal and older revisions are discarded within one generation. * Consumers holding multiple aggregation views of one orderbook on the same * connection key their `OrderbookState` instances by * `(orderbook_id, aggregation)` using * `aggregationFromFrame(book.n_sig_figs, book.mantissa)`. */ export type OrderbookApplyResult = { kind: "applied"; } | { kind: "discarded_stale"; } | { kind: "subscription_mismatch"; } | { kind: "refresh_required"; reason: OrderbookRefreshReason; }; export type OrderbookRefreshReason = /** * The backend explicitly requested a resync: unsubscribe and re-subscribe * with the same parameters (including aggregation) to receive a fresh * snapshot. */ { kind: "server_resync"; }; export declare class OrderbookState { readonly orderbookId: OrderBookId; readonly aggregation: BookAggregation; /** * Last accepted engine depth revision. Forward gaps are expected. */ seq: bigint; private lastSeq; bidsTruncated: boolean; asksTruncated: boolean; private readonly bidsMap; private readonly asksMap; private cachedBestBid; private cachedBestAsk; constructor(orderbookId: OrderBookId, aggregation?: BookAggregation); /** * Apply a full snapshot when its revision is newer in this generation. * * `resync` frames take precedence and leave the book untouched — the * caller must re-subscribe with the same parameters. Every other data * accepted frame replaces the book wholesale. Revision gaps are normal. */ apply(book: OrderBook): OrderbookApplyResult; bids(): ReadonlyMap; asks(): ReadonlyMap; bestBid(): string | undefined; bestAsk(): string | undefined; midPrice(): string | undefined; spread(): string | undefined; isEmpty(): boolean; /** Reset the revision gate for reconnect/resubscribe without hiding levels. */ beginGeneration(): void; clear(): void; } //# sourceMappingURL=state.d.ts.map