@0xarchive/sdk 0.6.2 → 0.6.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -127,6 +127,62 @@ const history = await client.lighter.orderbook.history('BTC', {
127
127
 
128
128
  **Note:** The `granularity` parameter is ignored for Hyperliquid orderbook history.
129
129
 
130
+ #### Orderbook Reconstruction (Enterprise Tier)
131
+
132
+ For tick-level data, the SDK provides client-side orderbook reconstruction. This efficiently reconstructs full orderbook state from a checkpoint and incremental deltas.
133
+
134
+ ```typescript
135
+ import { OrderBookReconstructor } from '@0xarchive/sdk';
136
+
137
+ // Option 1: Get fully reconstructed snapshots (simplest)
138
+ const snapshots = await client.lighter.orderbook.historyReconstructed('BTC', {
139
+ start: Date.now() - 3600000,
140
+ end: Date.now()
141
+ });
142
+
143
+ for (const ob of snapshots) {
144
+ console.log(`${ob.timestamp}: bid=${ob.bids[0]?.px} ask=${ob.asks[0]?.px}`);
145
+ }
146
+
147
+ // Option 2: Get raw tick data for custom reconstruction
148
+ const tickData = await client.lighter.orderbook.historyTick('BTC', {
149
+ start: Date.now() - 3600000,
150
+ end: Date.now()
151
+ });
152
+
153
+ console.log(`Checkpoint: ${tickData.checkpoint.bids.length} bids`);
154
+ console.log(`Deltas: ${tickData.deltas.length} updates`);
155
+
156
+ // Option 3: Memory-efficient iteration (for large datasets)
157
+ const reconstructor = client.lighter.orderbook.createReconstructor();
158
+ for (const snapshot of reconstructor.iterate(tickData.checkpoint, tickData.deltas)) {
159
+ // Process each snapshot without loading all into memory
160
+ if (someCondition(snapshot)) break; // Early exit if needed
161
+ }
162
+
163
+ // Option 4: Get only final state (most efficient)
164
+ const final = reconstructor.reconstructFinal(tickData.checkpoint, tickData.deltas);
165
+
166
+ // Check for sequence gaps
167
+ const gaps = OrderBookReconstructor.detectGaps(tickData.deltas);
168
+ if (gaps.length > 0) {
169
+ console.warn('Sequence gaps detected:', gaps);
170
+ }
171
+ ```
172
+
173
+ **Methods:**
174
+ | Method | Description |
175
+ |--------|-------------|
176
+ | `historyTick(coin, params)` | Get raw checkpoint + deltas for custom reconstruction |
177
+ | `historyReconstructed(coin, params, options)` | Get fully reconstructed snapshots |
178
+ | `createReconstructor()` | Create a reconstructor instance for manual control |
179
+
180
+ **ReconstructOptions:**
181
+ | Option | Default | Description |
182
+ |--------|---------|-------------|
183
+ | `depth` | all | Maximum price levels in output |
184
+ | `emitAll` | `true` | If `false`, only return final state |
185
+
130
186
  ### Trades
131
187
 
132
188
  The trades API uses cursor-based pagination for efficient retrieval of large datasets.
@@ -663,7 +719,16 @@ import type {
663
719
  WsOptions,
664
720
  WsChannel,
665
721
  WsConnectionState,
722
+ // Orderbook reconstruction (Enterprise)
723
+ OrderbookDelta,
724
+ TickData,
725
+ ReconstructedOrderBook,
726
+ ReconstructOptions,
727
+ TickHistoryParams,
666
728
  } from '@0xarchive/sdk';
729
+
730
+ // Import reconstructor class
731
+ import { OrderBookReconstructor } from '@0xarchive/sdk';
667
732
  ```
668
733
 
669
734
  ## Runtime Validation
package/dist/index.d.mts CHANGED
@@ -890,6 +890,154 @@ declare class HttpClient {
890
890
  get<T>(path: string, params?: Record<string, unknown>, schema?: z.ZodType<T>): Promise<T>;
891
891
  }
892
892
 
893
+ /**
894
+ * Orderbook Reconstructor for tick-level delta data.
895
+ *
896
+ * Efficiently reconstructs full orderbook state from checkpoint + deltas.
897
+ * All reconstruction happens client-side for optimal server performance.
898
+ *
899
+ * @example
900
+ * ```typescript
901
+ * // Get raw tick data
902
+ * const tickData = await client.lighter.orderbook.historyTick('BTC', { start, end });
903
+ *
904
+ * // Reconstruct to get snapshots at each delta
905
+ * const reconstructor = new OrderBookReconstructor();
906
+ * const snapshots = reconstructor.reconstructAll(tickData.checkpoint, tickData.deltas);
907
+ *
908
+ * // Or iterate efficiently (memory-friendly for large datasets)
909
+ * for (const snapshot of reconstructor.iterate(tickData.checkpoint, tickData.deltas)) {
910
+ * console.log(snapshot.timestamp, snapshot.bids[0], snapshot.asks[0]);
911
+ * }
912
+ * ```
913
+ */
914
+
915
+ /**
916
+ * Reconstructed orderbook snapshot with timestamp
917
+ */
918
+ interface ReconstructedOrderBook extends OrderBook {
919
+ /** Sequence number of the last applied delta */
920
+ sequence?: number;
921
+ }
922
+ /**
923
+ * Raw tick data from the API (checkpoint + deltas)
924
+ */
925
+ interface TickData {
926
+ /** Initial orderbook state */
927
+ checkpoint: OrderBook;
928
+ /** Incremental changes to apply */
929
+ deltas: OrderbookDelta[];
930
+ }
931
+ /**
932
+ * Options for reconstruction
933
+ */
934
+ interface ReconstructOptions {
935
+ /** Maximum depth (price levels) to include in output. Default: all levels */
936
+ depth?: number;
937
+ /** If true, yield a snapshot after every delta. If false, only return final state. Default: true */
938
+ emitAll?: boolean;
939
+ }
940
+ /**
941
+ * Orderbook Reconstructor
942
+ *
943
+ * Maintains orderbook state and efficiently applies delta updates.
944
+ * Uses sorted arrays with binary search for O(log n) insertions.
945
+ *
946
+ * Thread-safe for single-threaded JavaScript; for worker threads,
947
+ * create a separate instance per thread.
948
+ */
949
+ declare class OrderBookReconstructor {
950
+ private bids;
951
+ private asks;
952
+ private coin;
953
+ private lastTimestamp;
954
+ private lastSequence;
955
+ /**
956
+ * Initialize or reset the reconstructor with a checkpoint
957
+ */
958
+ initialize(checkpoint: OrderBook): void;
959
+ /**
960
+ * Apply a single delta to the current state
961
+ */
962
+ applyDelta(delta: OrderbookDelta): void;
963
+ /**
964
+ * Get the current orderbook state as a snapshot
965
+ */
966
+ getSnapshot(depth?: number): ReconstructedOrderBook;
967
+ /**
968
+ * Convert internal level to API format
969
+ */
970
+ private toLevel;
971
+ /**
972
+ * Reconstruct all orderbook states from checkpoint + deltas.
973
+ * Returns an array of snapshots, one after each delta.
974
+ *
975
+ * For large datasets, prefer `iterate()` to avoid memory issues.
976
+ *
977
+ * @param checkpoint - Initial orderbook state
978
+ * @param deltas - Array of delta updates
979
+ * @param options - Reconstruction options
980
+ * @returns Array of reconstructed orderbook snapshots
981
+ */
982
+ reconstructAll(checkpoint: OrderBook, deltas: OrderbookDelta[], options?: ReconstructOptions): ReconstructedOrderBook[];
983
+ /**
984
+ * Iterate over reconstructed orderbook states (memory-efficient).
985
+ * Yields a snapshot after each delta is applied.
986
+ *
987
+ * @param checkpoint - Initial orderbook state
988
+ * @param deltas - Array of delta updates
989
+ * @param options - Reconstruction options
990
+ * @yields Reconstructed orderbook snapshots
991
+ */
992
+ iterate(checkpoint: OrderBook, deltas: OrderbookDelta[], options?: ReconstructOptions): Generator<ReconstructedOrderBook>;
993
+ /**
994
+ * Get the final reconstructed state without intermediate snapshots.
995
+ * Most efficient when you only need the end result.
996
+ *
997
+ * @param checkpoint - Initial orderbook state
998
+ * @param deltas - Array of delta updates
999
+ * @param depth - Maximum price levels to include
1000
+ * @returns Final orderbook state after all deltas applied
1001
+ */
1002
+ reconstructFinal(checkpoint: OrderBook, deltas: OrderbookDelta[], depth?: number): ReconstructedOrderBook;
1003
+ /**
1004
+ * Check for sequence gaps in deltas.
1005
+ * Returns array of missing sequence numbers.
1006
+ *
1007
+ * @param deltas - Array of delta updates
1008
+ * @returns Array of [expectedSeq, actualSeq] tuples where gaps exist
1009
+ */
1010
+ static detectGaps(deltas: OrderbookDelta[]): Array<[number, number]>;
1011
+ }
1012
+ /**
1013
+ * Convenience function for one-shot reconstruction.
1014
+ * Creates a new reconstructor, processes data, and returns snapshots.
1015
+ *
1016
+ * @param tickData - Checkpoint and deltas from API
1017
+ * @param options - Reconstruction options
1018
+ * @returns Array of reconstructed orderbook snapshots
1019
+ */
1020
+ declare function reconstructOrderBook(tickData: TickData, options?: ReconstructOptions): ReconstructedOrderBook[];
1021
+ /**
1022
+ * Convenience function to get final orderbook state.
1023
+ *
1024
+ * @param tickData - Checkpoint and deltas from API
1025
+ * @param depth - Maximum price levels
1026
+ * @returns Final orderbook state
1027
+ */
1028
+ declare function reconstructFinal(tickData: TickData, depth?: number): ReconstructedOrderBook;
1029
+
1030
+ /**
1031
+ * Parameters for tick-level orderbook history (Enterprise tier only)
1032
+ */
1033
+ interface TickHistoryParams {
1034
+ /** Start timestamp (Unix ms or ISO string) - REQUIRED */
1035
+ start: number | string;
1036
+ /** End timestamp (Unix ms or ISO string) - REQUIRED */
1037
+ end: number | string;
1038
+ /** Number of price levels in checkpoint (default: all) */
1039
+ depth?: number;
1040
+ }
893
1041
  /**
894
1042
  * Order book API resource
895
1043
  *
@@ -910,6 +1058,18 @@ declare class HttpClient {
910
1058
  * end: Date.now(),
911
1059
  * limit: 100
912
1060
  * });
1061
+ *
1062
+ * // Enterprise: Get tick-level data with reconstruction
1063
+ * const snapshots = await client.lighter.orderbook.historyReconstructed('BTC', {
1064
+ * start: Date.now() - 3600000,
1065
+ * end: Date.now()
1066
+ * });
1067
+ *
1068
+ * // Enterprise: Get raw tick data for custom reconstruction
1069
+ * const tickData = await client.lighter.orderbook.historyTick('BTC', {
1070
+ * start: Date.now() - 3600000,
1071
+ * end: Date.now()
1072
+ * });
913
1073
  * ```
914
1074
  */
915
1075
  declare class OrderBookResource {
@@ -952,6 +1112,97 @@ declare class OrderBookResource {
952
1112
  * ```
953
1113
  */
954
1114
  history(coin: string, params: OrderBookHistoryParams): Promise<CursorResponse<OrderBook[]>>;
1115
+ /**
1116
+ * Get raw tick-level orderbook data (Enterprise tier only).
1117
+ *
1118
+ * Returns a checkpoint (full orderbook state) and array of deltas.
1119
+ * Use this when you want to implement custom reconstruction logic
1120
+ * (e.g., in Rust for maximum performance).
1121
+ *
1122
+ * For automatic reconstruction, use `historyReconstructed()` instead.
1123
+ *
1124
+ * @param coin - The coin symbol (e.g., 'BTC', 'ETH')
1125
+ * @param params - Time range parameters
1126
+ * @returns Tick data with checkpoint and deltas
1127
+ *
1128
+ * @example
1129
+ * ```typescript
1130
+ * const tickData = await client.lighter.orderbook.historyTick('BTC', {
1131
+ * start: Date.now() - 3600000,
1132
+ * end: Date.now()
1133
+ * });
1134
+ *
1135
+ * console.log('Checkpoint:', tickData.checkpoint);
1136
+ * console.log('Deltas:', tickData.deltas.length);
1137
+ *
1138
+ * // Implement your own reconstruction...
1139
+ * for (const delta of tickData.deltas) {
1140
+ * // delta: { timestamp, side, price, size, sequence }
1141
+ * }
1142
+ * ```
1143
+ */
1144
+ historyTick(coin: string, params: TickHistoryParams): Promise<TickData>;
1145
+ /**
1146
+ * Get reconstructed tick-level orderbook history (Enterprise tier only).
1147
+ *
1148
+ * Fetches raw tick data and reconstructs full orderbook state at each delta.
1149
+ * All reconstruction happens client-side for optimal server performance.
1150
+ *
1151
+ * For large time ranges, consider using `historyTick()` with the
1152
+ * `OrderBookReconstructor.iterate()` method for memory efficiency.
1153
+ *
1154
+ * @param coin - The coin symbol (e.g., 'BTC', 'ETH')
1155
+ * @param params - Time range parameters
1156
+ * @param options - Reconstruction options
1157
+ * @returns Array of reconstructed orderbook snapshots
1158
+ *
1159
+ * @example
1160
+ * ```typescript
1161
+ * // Get all snapshots
1162
+ * const snapshots = await client.lighter.orderbook.historyReconstructed('BTC', {
1163
+ * start: Date.now() - 3600000,
1164
+ * end: Date.now()
1165
+ * });
1166
+ *
1167
+ * for (const ob of snapshots) {
1168
+ * console.log(ob.timestamp, 'Best bid:', ob.bids[0]?.px, 'Best ask:', ob.asks[0]?.px);
1169
+ * }
1170
+ *
1171
+ * // Get only final state
1172
+ * const [final] = await client.lighter.orderbook.historyReconstructed('BTC',
1173
+ * { start, end },
1174
+ * { emitAll: false }
1175
+ * );
1176
+ * ```
1177
+ */
1178
+ historyReconstructed(coin: string, params: TickHistoryParams, options?: ReconstructOptions): Promise<ReconstructedOrderBook[]>;
1179
+ /**
1180
+ * Create a reconstructor for streaming tick-level data.
1181
+ *
1182
+ * Returns an OrderBookReconstructor instance that you can use
1183
+ * to process tick data incrementally or with custom logic.
1184
+ *
1185
+ * @returns A new OrderBookReconstructor instance
1186
+ *
1187
+ * @example
1188
+ * ```typescript
1189
+ * const reconstructor = client.lighter.orderbook.createReconstructor();
1190
+ * const tickData = await client.lighter.orderbook.historyTick('BTC', { start, end });
1191
+ *
1192
+ * // Memory-efficient iteration
1193
+ * for (const snapshot of reconstructor.iterate(tickData.checkpoint, tickData.deltas)) {
1194
+ * // Process each snapshot
1195
+ * if (someCondition(snapshot)) break; // Early exit if needed
1196
+ * }
1197
+ *
1198
+ * // Check for gaps
1199
+ * const gaps = OrderBookReconstructor.detectGaps(tickData.deltas);
1200
+ * if (gaps.length > 0) {
1201
+ * console.warn('Sequence gaps detected:', gaps);
1202
+ * }
1203
+ * ```
1204
+ */
1205
+ createReconstructor(): OrderBookReconstructor;
955
1206
  }
956
1207
 
957
1208
  /**
@@ -3713,4 +3964,4 @@ type ValidatedCandle = z.infer<typeof CandleSchema>;
3713
3964
  type ValidatedLiquidation = z.infer<typeof LiquidationSchema>;
3714
3965
  type ValidatedWsServerMessage = z.infer<typeof WsServerMessageSchema>;
3715
3966
 
3716
- export { type ApiError, type ApiMeta, ApiMetaSchema, type ApiResponse, ApiResponseSchema, type Candle, CandleArrayResponseSchema, type CandleHistoryParams, type CandleInterval, CandleIntervalSchema, CandleSchema, type ClientOptions, type CompletenessMetrics, type CoverageGap, type CoverageResponse, type CursorResponse, type DataFreshness, type DataTypeCoverage, type DataTypeStatus, type ExchangeCoverage, type ExchangeLatency, type ExchangeStatus, type FundingRate, FundingRateArrayResponseSchema, FundingRateResponseSchema, FundingRateSchema, type GetOrderBookParams, type GetTradesCursorParams, HyperliquidClient, type Incident, type IncidentSeverityValue, type IncidentStatusValue, type IncidentsResponse, type Instrument, InstrumentArrayResponseSchema, InstrumentResponseSchema, InstrumentSchema, type InstrumentType, InstrumentTypeSchema, type LatencyResponse, LighterClient, type LighterGranularity, type LighterInstrument, type Liquidation, LiquidationArrayResponseSchema, type LiquidationHistoryParams, LiquidationSchema, LiquidationSideSchema, type LiquidationsByUserParams, type ListIncidentsParams, type OpenInterest, OpenInterestArrayResponseSchema, OpenInterestResponseSchema, OpenInterestSchema, type OrderBook, OrderBookArrayResponseSchema, type OrderBookHistoryParams, OrderBookResponseSchema, OrderBookSchema, OxArchive, OxArchiveError, OxArchiveWs, type Pagination, type PriceLevel, PriceLevelSchema, type RestApiLatency, type SlaActual, type SlaParams, type SlaResponse, type SlaTargets, type StatusResponse, type SymbolCoverageResponse, type SymbolDataTypeCoverage, type SystemStatusValue, type Timestamp, type TimestampedRecord, TimestampedRecordSchema, type Trade, TradeArrayResponseSchema, type TradeDirection, TradeDirectionSchema, TradeSchema, type TradeSide, TradeSideSchema, type ValidatedApiMeta, type ValidatedCandle, type ValidatedFundingRate, type ValidatedInstrument, type ValidatedLiquidation, type ValidatedOpenInterest, type ValidatedOrderBook, type ValidatedPriceLevel, type ValidatedTrade, type ValidatedWsServerMessage, type WebSocketLatency, type WsChannel, WsChannelSchema, type WsClientMessage, type WsConnectionState, WsConnectionStateSchema, type WsData, WsDataSchema, type WsError, WsErrorSchema, type WsEventHandlers, type WsHistoricalBatch, WsHistoricalBatchSchema, type WsHistoricalData, WsHistoricalDataSchema, type WsOptions, type WsPing, type WsPong, WsPongSchema, type WsReplay, type WsReplayCompleted, WsReplayCompletedSchema, type WsReplayPause, type WsReplayPaused, WsReplayPausedSchema, type WsReplayResume, type WsReplayResumed, WsReplayResumedSchema, type WsReplaySeek, type WsReplayStarted, WsReplayStartedSchema, type WsReplayStop, type WsReplayStopped, WsReplayStoppedSchema, type WsServerMessage, WsServerMessageSchema, type WsStream, type WsStreamCompleted, WsStreamCompletedSchema, type WsStreamProgress, WsStreamProgressSchema, type WsStreamStarted, WsStreamStartedSchema, type WsStreamStop, type WsStreamStopped, WsStreamStoppedSchema, type WsSubscribe, type WsSubscribed, WsSubscribedSchema, type WsUnsubscribe, type WsUnsubscribed, WsUnsubscribedSchema, OxArchive as default };
3967
+ export { type ApiError, type ApiMeta, ApiMetaSchema, type ApiResponse, ApiResponseSchema, type Candle, CandleArrayResponseSchema, type CandleHistoryParams, type CandleInterval, CandleIntervalSchema, CandleSchema, type ClientOptions, type CompletenessMetrics, type CoverageGap, type CoverageResponse, type CursorResponse, type DataFreshness, type DataTypeCoverage, type DataTypeStatus, type ExchangeCoverage, type ExchangeLatency, type ExchangeStatus, type FundingRate, FundingRateArrayResponseSchema, FundingRateResponseSchema, FundingRateSchema, type GetOrderBookParams, type GetTradesCursorParams, HyperliquidClient, type Incident, type IncidentSeverityValue, type IncidentStatusValue, type IncidentsResponse, type Instrument, InstrumentArrayResponseSchema, InstrumentResponseSchema, InstrumentSchema, type InstrumentType, InstrumentTypeSchema, type LatencyResponse, LighterClient, type LighterGranularity, type LighterInstrument, type Liquidation, LiquidationArrayResponseSchema, type LiquidationHistoryParams, LiquidationSchema, LiquidationSideSchema, type LiquidationsByUserParams, type ListIncidentsParams, type OpenInterest, OpenInterestArrayResponseSchema, OpenInterestResponseSchema, OpenInterestSchema, type OrderBook, OrderBookArrayResponseSchema, type OrderBookHistoryParams, OrderBookReconstructor, OrderBookResponseSchema, OrderBookSchema, type OrderbookDelta, OxArchive, OxArchiveError, OxArchiveWs, type Pagination, type PriceLevel, PriceLevelSchema, type ReconstructOptions, type ReconstructedOrderBook, type RestApiLatency, type SlaActual, type SlaParams, type SlaResponse, type SlaTargets, type StatusResponse, type SymbolCoverageResponse, type SymbolDataTypeCoverage, type SystemStatusValue, type TickData, type TickHistoryParams, type Timestamp, type TimestampedRecord, TimestampedRecordSchema, type Trade, TradeArrayResponseSchema, type TradeDirection, TradeDirectionSchema, TradeSchema, type TradeSide, TradeSideSchema, type ValidatedApiMeta, type ValidatedCandle, type ValidatedFundingRate, type ValidatedInstrument, type ValidatedLiquidation, type ValidatedOpenInterest, type ValidatedOrderBook, type ValidatedPriceLevel, type ValidatedTrade, type ValidatedWsServerMessage, type WebSocketLatency, type WsChannel, WsChannelSchema, type WsClientMessage, type WsConnectionState, WsConnectionStateSchema, type WsData, WsDataSchema, type WsError, WsErrorSchema, type WsEventHandlers, type WsHistoricalBatch, WsHistoricalBatchSchema, type WsHistoricalData, WsHistoricalDataSchema, type WsHistoricalTickData, type WsOptions, type WsPing, type WsPong, WsPongSchema, type WsReplay, type WsReplayCompleted, WsReplayCompletedSchema, type WsReplayPause, type WsReplayPaused, WsReplayPausedSchema, type WsReplayResume, type WsReplayResumed, WsReplayResumedSchema, type WsReplaySeek, type WsReplayStarted, WsReplayStartedSchema, type WsReplayStop, type WsReplayStopped, WsReplayStoppedSchema, type WsServerMessage, WsServerMessageSchema, type WsStream, type WsStreamCompleted, WsStreamCompletedSchema, type WsStreamProgress, WsStreamProgressSchema, type WsStreamStarted, WsStreamStartedSchema, type WsStreamStop, type WsStreamStopped, WsStreamStoppedSchema, type WsSubscribe, type WsSubscribed, WsSubscribedSchema, type WsUnsubscribe, type WsUnsubscribed, WsUnsubscribedSchema, OxArchive as default, reconstructFinal, reconstructOrderBook };
package/dist/index.d.ts CHANGED
@@ -890,6 +890,154 @@ declare class HttpClient {
890
890
  get<T>(path: string, params?: Record<string, unknown>, schema?: z.ZodType<T>): Promise<T>;
891
891
  }
892
892
 
893
+ /**
894
+ * Orderbook Reconstructor for tick-level delta data.
895
+ *
896
+ * Efficiently reconstructs full orderbook state from checkpoint + deltas.
897
+ * All reconstruction happens client-side for optimal server performance.
898
+ *
899
+ * @example
900
+ * ```typescript
901
+ * // Get raw tick data
902
+ * const tickData = await client.lighter.orderbook.historyTick('BTC', { start, end });
903
+ *
904
+ * // Reconstruct to get snapshots at each delta
905
+ * const reconstructor = new OrderBookReconstructor();
906
+ * const snapshots = reconstructor.reconstructAll(tickData.checkpoint, tickData.deltas);
907
+ *
908
+ * // Or iterate efficiently (memory-friendly for large datasets)
909
+ * for (const snapshot of reconstructor.iterate(tickData.checkpoint, tickData.deltas)) {
910
+ * console.log(snapshot.timestamp, snapshot.bids[0], snapshot.asks[0]);
911
+ * }
912
+ * ```
913
+ */
914
+
915
+ /**
916
+ * Reconstructed orderbook snapshot with timestamp
917
+ */
918
+ interface ReconstructedOrderBook extends OrderBook {
919
+ /** Sequence number of the last applied delta */
920
+ sequence?: number;
921
+ }
922
+ /**
923
+ * Raw tick data from the API (checkpoint + deltas)
924
+ */
925
+ interface TickData {
926
+ /** Initial orderbook state */
927
+ checkpoint: OrderBook;
928
+ /** Incremental changes to apply */
929
+ deltas: OrderbookDelta[];
930
+ }
931
+ /**
932
+ * Options for reconstruction
933
+ */
934
+ interface ReconstructOptions {
935
+ /** Maximum depth (price levels) to include in output. Default: all levels */
936
+ depth?: number;
937
+ /** If true, yield a snapshot after every delta. If false, only return final state. Default: true */
938
+ emitAll?: boolean;
939
+ }
940
+ /**
941
+ * Orderbook Reconstructor
942
+ *
943
+ * Maintains orderbook state and efficiently applies delta updates.
944
+ * Uses sorted arrays with binary search for O(log n) insertions.
945
+ *
946
+ * Thread-safe for single-threaded JavaScript; for worker threads,
947
+ * create a separate instance per thread.
948
+ */
949
+ declare class OrderBookReconstructor {
950
+ private bids;
951
+ private asks;
952
+ private coin;
953
+ private lastTimestamp;
954
+ private lastSequence;
955
+ /**
956
+ * Initialize or reset the reconstructor with a checkpoint
957
+ */
958
+ initialize(checkpoint: OrderBook): void;
959
+ /**
960
+ * Apply a single delta to the current state
961
+ */
962
+ applyDelta(delta: OrderbookDelta): void;
963
+ /**
964
+ * Get the current orderbook state as a snapshot
965
+ */
966
+ getSnapshot(depth?: number): ReconstructedOrderBook;
967
+ /**
968
+ * Convert internal level to API format
969
+ */
970
+ private toLevel;
971
+ /**
972
+ * Reconstruct all orderbook states from checkpoint + deltas.
973
+ * Returns an array of snapshots, one after each delta.
974
+ *
975
+ * For large datasets, prefer `iterate()` to avoid memory issues.
976
+ *
977
+ * @param checkpoint - Initial orderbook state
978
+ * @param deltas - Array of delta updates
979
+ * @param options - Reconstruction options
980
+ * @returns Array of reconstructed orderbook snapshots
981
+ */
982
+ reconstructAll(checkpoint: OrderBook, deltas: OrderbookDelta[], options?: ReconstructOptions): ReconstructedOrderBook[];
983
+ /**
984
+ * Iterate over reconstructed orderbook states (memory-efficient).
985
+ * Yields a snapshot after each delta is applied.
986
+ *
987
+ * @param checkpoint - Initial orderbook state
988
+ * @param deltas - Array of delta updates
989
+ * @param options - Reconstruction options
990
+ * @yields Reconstructed orderbook snapshots
991
+ */
992
+ iterate(checkpoint: OrderBook, deltas: OrderbookDelta[], options?: ReconstructOptions): Generator<ReconstructedOrderBook>;
993
+ /**
994
+ * Get the final reconstructed state without intermediate snapshots.
995
+ * Most efficient when you only need the end result.
996
+ *
997
+ * @param checkpoint - Initial orderbook state
998
+ * @param deltas - Array of delta updates
999
+ * @param depth - Maximum price levels to include
1000
+ * @returns Final orderbook state after all deltas applied
1001
+ */
1002
+ reconstructFinal(checkpoint: OrderBook, deltas: OrderbookDelta[], depth?: number): ReconstructedOrderBook;
1003
+ /**
1004
+ * Check for sequence gaps in deltas.
1005
+ * Returns array of missing sequence numbers.
1006
+ *
1007
+ * @param deltas - Array of delta updates
1008
+ * @returns Array of [expectedSeq, actualSeq] tuples where gaps exist
1009
+ */
1010
+ static detectGaps(deltas: OrderbookDelta[]): Array<[number, number]>;
1011
+ }
1012
+ /**
1013
+ * Convenience function for one-shot reconstruction.
1014
+ * Creates a new reconstructor, processes data, and returns snapshots.
1015
+ *
1016
+ * @param tickData - Checkpoint and deltas from API
1017
+ * @param options - Reconstruction options
1018
+ * @returns Array of reconstructed orderbook snapshots
1019
+ */
1020
+ declare function reconstructOrderBook(tickData: TickData, options?: ReconstructOptions): ReconstructedOrderBook[];
1021
+ /**
1022
+ * Convenience function to get final orderbook state.
1023
+ *
1024
+ * @param tickData - Checkpoint and deltas from API
1025
+ * @param depth - Maximum price levels
1026
+ * @returns Final orderbook state
1027
+ */
1028
+ declare function reconstructFinal(tickData: TickData, depth?: number): ReconstructedOrderBook;
1029
+
1030
+ /**
1031
+ * Parameters for tick-level orderbook history (Enterprise tier only)
1032
+ */
1033
+ interface TickHistoryParams {
1034
+ /** Start timestamp (Unix ms or ISO string) - REQUIRED */
1035
+ start: number | string;
1036
+ /** End timestamp (Unix ms or ISO string) - REQUIRED */
1037
+ end: number | string;
1038
+ /** Number of price levels in checkpoint (default: all) */
1039
+ depth?: number;
1040
+ }
893
1041
  /**
894
1042
  * Order book API resource
895
1043
  *
@@ -910,6 +1058,18 @@ declare class HttpClient {
910
1058
  * end: Date.now(),
911
1059
  * limit: 100
912
1060
  * });
1061
+ *
1062
+ * // Enterprise: Get tick-level data with reconstruction
1063
+ * const snapshots = await client.lighter.orderbook.historyReconstructed('BTC', {
1064
+ * start: Date.now() - 3600000,
1065
+ * end: Date.now()
1066
+ * });
1067
+ *
1068
+ * // Enterprise: Get raw tick data for custom reconstruction
1069
+ * const tickData = await client.lighter.orderbook.historyTick('BTC', {
1070
+ * start: Date.now() - 3600000,
1071
+ * end: Date.now()
1072
+ * });
913
1073
  * ```
914
1074
  */
915
1075
  declare class OrderBookResource {
@@ -952,6 +1112,97 @@ declare class OrderBookResource {
952
1112
  * ```
953
1113
  */
954
1114
  history(coin: string, params: OrderBookHistoryParams): Promise<CursorResponse<OrderBook[]>>;
1115
+ /**
1116
+ * Get raw tick-level orderbook data (Enterprise tier only).
1117
+ *
1118
+ * Returns a checkpoint (full orderbook state) and array of deltas.
1119
+ * Use this when you want to implement custom reconstruction logic
1120
+ * (e.g., in Rust for maximum performance).
1121
+ *
1122
+ * For automatic reconstruction, use `historyReconstructed()` instead.
1123
+ *
1124
+ * @param coin - The coin symbol (e.g., 'BTC', 'ETH')
1125
+ * @param params - Time range parameters
1126
+ * @returns Tick data with checkpoint and deltas
1127
+ *
1128
+ * @example
1129
+ * ```typescript
1130
+ * const tickData = await client.lighter.orderbook.historyTick('BTC', {
1131
+ * start: Date.now() - 3600000,
1132
+ * end: Date.now()
1133
+ * });
1134
+ *
1135
+ * console.log('Checkpoint:', tickData.checkpoint);
1136
+ * console.log('Deltas:', tickData.deltas.length);
1137
+ *
1138
+ * // Implement your own reconstruction...
1139
+ * for (const delta of tickData.deltas) {
1140
+ * // delta: { timestamp, side, price, size, sequence }
1141
+ * }
1142
+ * ```
1143
+ */
1144
+ historyTick(coin: string, params: TickHistoryParams): Promise<TickData>;
1145
+ /**
1146
+ * Get reconstructed tick-level orderbook history (Enterprise tier only).
1147
+ *
1148
+ * Fetches raw tick data and reconstructs full orderbook state at each delta.
1149
+ * All reconstruction happens client-side for optimal server performance.
1150
+ *
1151
+ * For large time ranges, consider using `historyTick()` with the
1152
+ * `OrderBookReconstructor.iterate()` method for memory efficiency.
1153
+ *
1154
+ * @param coin - The coin symbol (e.g., 'BTC', 'ETH')
1155
+ * @param params - Time range parameters
1156
+ * @param options - Reconstruction options
1157
+ * @returns Array of reconstructed orderbook snapshots
1158
+ *
1159
+ * @example
1160
+ * ```typescript
1161
+ * // Get all snapshots
1162
+ * const snapshots = await client.lighter.orderbook.historyReconstructed('BTC', {
1163
+ * start: Date.now() - 3600000,
1164
+ * end: Date.now()
1165
+ * });
1166
+ *
1167
+ * for (const ob of snapshots) {
1168
+ * console.log(ob.timestamp, 'Best bid:', ob.bids[0]?.px, 'Best ask:', ob.asks[0]?.px);
1169
+ * }
1170
+ *
1171
+ * // Get only final state
1172
+ * const [final] = await client.lighter.orderbook.historyReconstructed('BTC',
1173
+ * { start, end },
1174
+ * { emitAll: false }
1175
+ * );
1176
+ * ```
1177
+ */
1178
+ historyReconstructed(coin: string, params: TickHistoryParams, options?: ReconstructOptions): Promise<ReconstructedOrderBook[]>;
1179
+ /**
1180
+ * Create a reconstructor for streaming tick-level data.
1181
+ *
1182
+ * Returns an OrderBookReconstructor instance that you can use
1183
+ * to process tick data incrementally or with custom logic.
1184
+ *
1185
+ * @returns A new OrderBookReconstructor instance
1186
+ *
1187
+ * @example
1188
+ * ```typescript
1189
+ * const reconstructor = client.lighter.orderbook.createReconstructor();
1190
+ * const tickData = await client.lighter.orderbook.historyTick('BTC', { start, end });
1191
+ *
1192
+ * // Memory-efficient iteration
1193
+ * for (const snapshot of reconstructor.iterate(tickData.checkpoint, tickData.deltas)) {
1194
+ * // Process each snapshot
1195
+ * if (someCondition(snapshot)) break; // Early exit if needed
1196
+ * }
1197
+ *
1198
+ * // Check for gaps
1199
+ * const gaps = OrderBookReconstructor.detectGaps(tickData.deltas);
1200
+ * if (gaps.length > 0) {
1201
+ * console.warn('Sequence gaps detected:', gaps);
1202
+ * }
1203
+ * ```
1204
+ */
1205
+ createReconstructor(): OrderBookReconstructor;
955
1206
  }
956
1207
 
957
1208
  /**
@@ -3713,4 +3964,4 @@ type ValidatedCandle = z.infer<typeof CandleSchema>;
3713
3964
  type ValidatedLiquidation = z.infer<typeof LiquidationSchema>;
3714
3965
  type ValidatedWsServerMessage = z.infer<typeof WsServerMessageSchema>;
3715
3966
 
3716
- export { type ApiError, type ApiMeta, ApiMetaSchema, type ApiResponse, ApiResponseSchema, type Candle, CandleArrayResponseSchema, type CandleHistoryParams, type CandleInterval, CandleIntervalSchema, CandleSchema, type ClientOptions, type CompletenessMetrics, type CoverageGap, type CoverageResponse, type CursorResponse, type DataFreshness, type DataTypeCoverage, type DataTypeStatus, type ExchangeCoverage, type ExchangeLatency, type ExchangeStatus, type FundingRate, FundingRateArrayResponseSchema, FundingRateResponseSchema, FundingRateSchema, type GetOrderBookParams, type GetTradesCursorParams, HyperliquidClient, type Incident, type IncidentSeverityValue, type IncidentStatusValue, type IncidentsResponse, type Instrument, InstrumentArrayResponseSchema, InstrumentResponseSchema, InstrumentSchema, type InstrumentType, InstrumentTypeSchema, type LatencyResponse, LighterClient, type LighterGranularity, type LighterInstrument, type Liquidation, LiquidationArrayResponseSchema, type LiquidationHistoryParams, LiquidationSchema, LiquidationSideSchema, type LiquidationsByUserParams, type ListIncidentsParams, type OpenInterest, OpenInterestArrayResponseSchema, OpenInterestResponseSchema, OpenInterestSchema, type OrderBook, OrderBookArrayResponseSchema, type OrderBookHistoryParams, OrderBookResponseSchema, OrderBookSchema, OxArchive, OxArchiveError, OxArchiveWs, type Pagination, type PriceLevel, PriceLevelSchema, type RestApiLatency, type SlaActual, type SlaParams, type SlaResponse, type SlaTargets, type StatusResponse, type SymbolCoverageResponse, type SymbolDataTypeCoverage, type SystemStatusValue, type Timestamp, type TimestampedRecord, TimestampedRecordSchema, type Trade, TradeArrayResponseSchema, type TradeDirection, TradeDirectionSchema, TradeSchema, type TradeSide, TradeSideSchema, type ValidatedApiMeta, type ValidatedCandle, type ValidatedFundingRate, type ValidatedInstrument, type ValidatedLiquidation, type ValidatedOpenInterest, type ValidatedOrderBook, type ValidatedPriceLevel, type ValidatedTrade, type ValidatedWsServerMessage, type WebSocketLatency, type WsChannel, WsChannelSchema, type WsClientMessage, type WsConnectionState, WsConnectionStateSchema, type WsData, WsDataSchema, type WsError, WsErrorSchema, type WsEventHandlers, type WsHistoricalBatch, WsHistoricalBatchSchema, type WsHistoricalData, WsHistoricalDataSchema, type WsOptions, type WsPing, type WsPong, WsPongSchema, type WsReplay, type WsReplayCompleted, WsReplayCompletedSchema, type WsReplayPause, type WsReplayPaused, WsReplayPausedSchema, type WsReplayResume, type WsReplayResumed, WsReplayResumedSchema, type WsReplaySeek, type WsReplayStarted, WsReplayStartedSchema, type WsReplayStop, type WsReplayStopped, WsReplayStoppedSchema, type WsServerMessage, WsServerMessageSchema, type WsStream, type WsStreamCompleted, WsStreamCompletedSchema, type WsStreamProgress, WsStreamProgressSchema, type WsStreamStarted, WsStreamStartedSchema, type WsStreamStop, type WsStreamStopped, WsStreamStoppedSchema, type WsSubscribe, type WsSubscribed, WsSubscribedSchema, type WsUnsubscribe, type WsUnsubscribed, WsUnsubscribedSchema, OxArchive as default };
3967
+ export { type ApiError, type ApiMeta, ApiMetaSchema, type ApiResponse, ApiResponseSchema, type Candle, CandleArrayResponseSchema, type CandleHistoryParams, type CandleInterval, CandleIntervalSchema, CandleSchema, type ClientOptions, type CompletenessMetrics, type CoverageGap, type CoverageResponse, type CursorResponse, type DataFreshness, type DataTypeCoverage, type DataTypeStatus, type ExchangeCoverage, type ExchangeLatency, type ExchangeStatus, type FundingRate, FundingRateArrayResponseSchema, FundingRateResponseSchema, FundingRateSchema, type GetOrderBookParams, type GetTradesCursorParams, HyperliquidClient, type Incident, type IncidentSeverityValue, type IncidentStatusValue, type IncidentsResponse, type Instrument, InstrumentArrayResponseSchema, InstrumentResponseSchema, InstrumentSchema, type InstrumentType, InstrumentTypeSchema, type LatencyResponse, LighterClient, type LighterGranularity, type LighterInstrument, type Liquidation, LiquidationArrayResponseSchema, type LiquidationHistoryParams, LiquidationSchema, LiquidationSideSchema, type LiquidationsByUserParams, type ListIncidentsParams, type OpenInterest, OpenInterestArrayResponseSchema, OpenInterestResponseSchema, OpenInterestSchema, type OrderBook, OrderBookArrayResponseSchema, type OrderBookHistoryParams, OrderBookReconstructor, OrderBookResponseSchema, OrderBookSchema, type OrderbookDelta, OxArchive, OxArchiveError, OxArchiveWs, type Pagination, type PriceLevel, PriceLevelSchema, type ReconstructOptions, type ReconstructedOrderBook, type RestApiLatency, type SlaActual, type SlaParams, type SlaResponse, type SlaTargets, type StatusResponse, type SymbolCoverageResponse, type SymbolDataTypeCoverage, type SystemStatusValue, type TickData, type TickHistoryParams, type Timestamp, type TimestampedRecord, TimestampedRecordSchema, type Trade, TradeArrayResponseSchema, type TradeDirection, TradeDirectionSchema, TradeSchema, type TradeSide, TradeSideSchema, type ValidatedApiMeta, type ValidatedCandle, type ValidatedFundingRate, type ValidatedInstrument, type ValidatedLiquidation, type ValidatedOpenInterest, type ValidatedOrderBook, type ValidatedPriceLevel, type ValidatedTrade, type ValidatedWsServerMessage, type WebSocketLatency, type WsChannel, WsChannelSchema, type WsClientMessage, type WsConnectionState, WsConnectionStateSchema, type WsData, WsDataSchema, type WsError, WsErrorSchema, type WsEventHandlers, type WsHistoricalBatch, WsHistoricalBatchSchema, type WsHistoricalData, WsHistoricalDataSchema, type WsHistoricalTickData, type WsOptions, type WsPing, type WsPong, WsPongSchema, type WsReplay, type WsReplayCompleted, WsReplayCompletedSchema, type WsReplayPause, type WsReplayPaused, WsReplayPausedSchema, type WsReplayResume, type WsReplayResumed, WsReplayResumedSchema, type WsReplaySeek, type WsReplayStarted, WsReplayStartedSchema, type WsReplayStop, type WsReplayStopped, WsReplayStoppedSchema, type WsServerMessage, WsServerMessageSchema, type WsStream, type WsStreamCompleted, WsStreamCompletedSchema, type WsStreamProgress, WsStreamProgressSchema, type WsStreamStarted, WsStreamStartedSchema, type WsStreamStop, type WsStreamStopped, WsStreamStoppedSchema, type WsSubscribe, type WsSubscribed, WsSubscribedSchema, type WsUnsubscribe, type WsUnsubscribed, WsUnsubscribedSchema, OxArchive as default, reconstructFinal, reconstructOrderBook };