@0xarchive/sdk 0.4.3 → 0.4.5

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
@@ -77,6 +77,19 @@ const history = await client.hyperliquid.orderbook.history('BTC', {
77
77
  });
78
78
  ```
79
79
 
80
+ #### Orderbook Depth Limits
81
+
82
+ The `depth` parameter controls how many price levels are returned per side. Tier-based limits apply:
83
+
84
+ | Tier | Max Depth |
85
+ |------|-----------|
86
+ | Free | 20 |
87
+ | Build | 50 |
88
+ | Pro | 100 |
89
+ | Enterprise | Full Depth |
90
+
91
+ **Note:** Hyperliquid source data only contains 20 levels. Higher limits apply to Lighter.xyz data.
92
+
80
93
  #### Lighter Orderbook Granularity
81
94
 
82
95
  Lighter.xyz orderbook history supports a `granularity` parameter for different data resolutions. Tier restrictions apply.
@@ -292,6 +305,20 @@ ws.replay('orderbook', 'BTC', {
292
305
  speed: 10 // Optional, defaults to 1x
293
306
  });
294
307
 
308
+ // Lighter.xyz replay with granularity (tier restrictions apply)
309
+ ws.replay('orderbook', 'BTC', {
310
+ start: Date.now() - 86400000,
311
+ speed: 10,
312
+ granularity: '10s' // Options: 'checkpoint', '30s', '10s', '1s', 'tick'
313
+ });
314
+
315
+ // Handle tick-level data (granularity='tick', Enterprise tier)
316
+ ws.onHistoricalTickData((coin, checkpoint, deltas) => {
317
+ console.log(`Checkpoint: ${checkpoint.bids.length} bids`);
318
+ console.log(`Deltas: ${deltas.length} updates`);
319
+ // Apply deltas to checkpoint to reconstruct orderbook at any point
320
+ });
321
+
295
322
  // Control playback
296
323
  ws.replayPause();
297
324
  ws.replayResume();
@@ -329,6 +356,13 @@ ws.stream('orderbook', 'ETH', {
329
356
  batchSize: 1000 // Optional, defaults to 1000
330
357
  });
331
358
 
359
+ // Lighter.xyz stream with granularity (tier restrictions apply)
360
+ ws.stream('orderbook', 'BTC', {
361
+ start: Date.now() - 3600000,
362
+ end: Date.now(),
363
+ granularity: '10s' // Options: 'checkpoint', '30s', '10s', '1s', 'tick'
364
+ });
365
+
332
366
  // Stop if needed
333
367
  ws.streamStop();
334
368
  ```
package/dist/index.d.mts CHANGED
@@ -293,6 +293,8 @@ interface WsReplay {
293
293
  end?: number;
294
294
  /** Playback speed multiplier (1 = real-time, 10 = 10x faster) */
295
295
  speed?: number;
296
+ /** Data resolution for Lighter orderbook ('checkpoint', '30s', '10s', '1s', 'tick') */
297
+ granularity?: string;
296
298
  }
297
299
  /** Replay control messages */
298
300
  interface WsReplayPause {
@@ -319,6 +321,8 @@ interface WsStream {
319
321
  end: number;
320
322
  /** Batch size (records per message) */
321
323
  batch_size?: number;
324
+ /** Data resolution for Lighter orderbook ('checkpoint', '30s', '10s', '1s', 'tick') */
325
+ granularity?: string;
322
326
  }
323
327
  /** Stream control messages */
324
328
  interface WsStreamStop {
@@ -395,6 +399,29 @@ interface WsHistoricalData<T = unknown> {
395
399
  timestamp: number;
396
400
  data: T;
397
401
  }
402
+ /** Orderbook delta for tick-level data */
403
+ interface OrderbookDelta {
404
+ /** Timestamp in milliseconds */
405
+ timestamp: number;
406
+ /** Side: 'bid' or 'ask' */
407
+ side: 'bid' | 'ask';
408
+ /** Price level */
409
+ price: number;
410
+ /** New size (0 = level removed) */
411
+ size: number;
412
+ /** Sequence number for ordering */
413
+ sequence: number;
414
+ }
415
+ /** Historical tick data (granularity='tick' mode) - checkpoint + deltas */
416
+ interface WsHistoricalTickData {
417
+ type: 'historical_tick_data';
418
+ channel: WsChannel;
419
+ coin: string;
420
+ /** Initial checkpoint (full orderbook snapshot) */
421
+ checkpoint: OrderBook;
422
+ /** Incremental deltas to apply after checkpoint */
423
+ deltas: OrderbookDelta[];
424
+ }
398
425
  /** Stream started response */
399
426
  interface WsStreamStarted {
400
427
  type: 'stream_started';
@@ -435,7 +462,7 @@ interface WsStreamStopped {
435
462
  snapshots_sent: number;
436
463
  }
437
464
  /** Server message union type */
438
- type WsServerMessage = WsSubscribed | WsUnsubscribed | WsPong | WsError | WsData | WsReplayStarted | WsReplayPaused | WsReplayResumed | WsReplayCompleted | WsReplayStopped | WsHistoricalData | WsStreamStarted | WsStreamProgress | WsHistoricalBatch | WsStreamCompleted | WsStreamStopped;
465
+ type WsServerMessage = WsSubscribed | WsUnsubscribed | WsPong | WsError | WsData | WsReplayStarted | WsReplayPaused | WsReplayResumed | WsReplayCompleted | WsReplayStopped | WsHistoricalData | WsHistoricalTickData | WsStreamStarted | WsStreamProgress | WsHistoricalBatch | WsStreamCompleted | WsStreamStopped;
439
466
  /**
440
467
  * WebSocket connection options.
441
468
  *
@@ -1023,6 +1050,7 @@ declare class OxArchiveWs {
1023
1050
  private pingTimer;
1024
1051
  private reconnectTimer;
1025
1052
  private historicalDataHandlers;
1053
+ private historicalTickDataHandlers;
1026
1054
  private batchHandlers;
1027
1055
  private replayStartHandlers;
1028
1056
  private replayCompleteHandlers;
@@ -1106,6 +1134,7 @@ declare class OxArchiveWs {
1106
1134
  start: number;
1107
1135
  end?: number;
1108
1136
  speed?: number;
1137
+ granularity?: string;
1109
1138
  }): void;
1110
1139
  /**
1111
1140
  * Pause the current replay
@@ -1144,6 +1173,7 @@ declare class OxArchiveWs {
1144
1173
  start: number;
1145
1174
  end: number;
1146
1175
  batchSize?: number;
1176
+ granularity?: string;
1147
1177
  }): void;
1148
1178
  /**
1149
1179
  * Stop the current bulk stream
@@ -1153,6 +1183,12 @@ declare class OxArchiveWs {
1153
1183
  * Handle historical data points (replay mode)
1154
1184
  */
1155
1185
  onHistoricalData<T = unknown>(handler: (coin: string, timestamp: number, data: T) => void): void;
1186
+ /**
1187
+ * Handle historical tick data (granularity='tick' mode)
1188
+ * Receives a checkpoint (full orderbook) followed by incremental deltas.
1189
+ * This is for tick-level granularity on Lighter.xyz orderbook data.
1190
+ */
1191
+ onHistoricalTickData(handler: (coin: string, checkpoint: OrderBook, deltas: OrderbookDelta[]) => void): void;
1156
1192
  /**
1157
1193
  * Handle batched data (bulk stream mode)
1158
1194
  */
package/dist/index.d.ts CHANGED
@@ -293,6 +293,8 @@ interface WsReplay {
293
293
  end?: number;
294
294
  /** Playback speed multiplier (1 = real-time, 10 = 10x faster) */
295
295
  speed?: number;
296
+ /** Data resolution for Lighter orderbook ('checkpoint', '30s', '10s', '1s', 'tick') */
297
+ granularity?: string;
296
298
  }
297
299
  /** Replay control messages */
298
300
  interface WsReplayPause {
@@ -319,6 +321,8 @@ interface WsStream {
319
321
  end: number;
320
322
  /** Batch size (records per message) */
321
323
  batch_size?: number;
324
+ /** Data resolution for Lighter orderbook ('checkpoint', '30s', '10s', '1s', 'tick') */
325
+ granularity?: string;
322
326
  }
323
327
  /** Stream control messages */
324
328
  interface WsStreamStop {
@@ -395,6 +399,29 @@ interface WsHistoricalData<T = unknown> {
395
399
  timestamp: number;
396
400
  data: T;
397
401
  }
402
+ /** Orderbook delta for tick-level data */
403
+ interface OrderbookDelta {
404
+ /** Timestamp in milliseconds */
405
+ timestamp: number;
406
+ /** Side: 'bid' or 'ask' */
407
+ side: 'bid' | 'ask';
408
+ /** Price level */
409
+ price: number;
410
+ /** New size (0 = level removed) */
411
+ size: number;
412
+ /** Sequence number for ordering */
413
+ sequence: number;
414
+ }
415
+ /** Historical tick data (granularity='tick' mode) - checkpoint + deltas */
416
+ interface WsHistoricalTickData {
417
+ type: 'historical_tick_data';
418
+ channel: WsChannel;
419
+ coin: string;
420
+ /** Initial checkpoint (full orderbook snapshot) */
421
+ checkpoint: OrderBook;
422
+ /** Incremental deltas to apply after checkpoint */
423
+ deltas: OrderbookDelta[];
424
+ }
398
425
  /** Stream started response */
399
426
  interface WsStreamStarted {
400
427
  type: 'stream_started';
@@ -435,7 +462,7 @@ interface WsStreamStopped {
435
462
  snapshots_sent: number;
436
463
  }
437
464
  /** Server message union type */
438
- type WsServerMessage = WsSubscribed | WsUnsubscribed | WsPong | WsError | WsData | WsReplayStarted | WsReplayPaused | WsReplayResumed | WsReplayCompleted | WsReplayStopped | WsHistoricalData | WsStreamStarted | WsStreamProgress | WsHistoricalBatch | WsStreamCompleted | WsStreamStopped;
465
+ type WsServerMessage = WsSubscribed | WsUnsubscribed | WsPong | WsError | WsData | WsReplayStarted | WsReplayPaused | WsReplayResumed | WsReplayCompleted | WsReplayStopped | WsHistoricalData | WsHistoricalTickData | WsStreamStarted | WsStreamProgress | WsHistoricalBatch | WsStreamCompleted | WsStreamStopped;
439
466
  /**
440
467
  * WebSocket connection options.
441
468
  *
@@ -1023,6 +1050,7 @@ declare class OxArchiveWs {
1023
1050
  private pingTimer;
1024
1051
  private reconnectTimer;
1025
1052
  private historicalDataHandlers;
1053
+ private historicalTickDataHandlers;
1026
1054
  private batchHandlers;
1027
1055
  private replayStartHandlers;
1028
1056
  private replayCompleteHandlers;
@@ -1106,6 +1134,7 @@ declare class OxArchiveWs {
1106
1134
  start: number;
1107
1135
  end?: number;
1108
1136
  speed?: number;
1137
+ granularity?: string;
1109
1138
  }): void;
1110
1139
  /**
1111
1140
  * Pause the current replay
@@ -1144,6 +1173,7 @@ declare class OxArchiveWs {
1144
1173
  start: number;
1145
1174
  end: number;
1146
1175
  batchSize?: number;
1176
+ granularity?: string;
1147
1177
  }): void;
1148
1178
  /**
1149
1179
  * Stop the current bulk stream
@@ -1153,6 +1183,12 @@ declare class OxArchiveWs {
1153
1183
  * Handle historical data points (replay mode)
1154
1184
  */
1155
1185
  onHistoricalData<T = unknown>(handler: (coin: string, timestamp: number, data: T) => void): void;
1186
+ /**
1187
+ * Handle historical tick data (granularity='tick' mode)
1188
+ * Receives a checkpoint (full orderbook) followed by incremental deltas.
1189
+ * This is for tick-level granularity on Lighter.xyz orderbook data.
1190
+ */
1191
+ onHistoricalTickData(handler: (coin: string, checkpoint: OrderBook, deltas: OrderbookDelta[]) => void): void;
1156
1192
  /**
1157
1193
  * Handle batched data (bulk stream mode)
1158
1194
  */
package/dist/index.js CHANGED
@@ -854,6 +854,7 @@ var OxArchiveWs = class {
854
854
  reconnectTimer = null;
855
855
  // Typed event handlers (separate from WsEventHandlers to avoid wrapping issues)
856
856
  historicalDataHandlers = [];
857
+ historicalTickDataHandlers = [];
857
858
  batchHandlers = [];
858
859
  replayStartHandlers = [];
859
860
  replayCompleteHandlers = [];
@@ -1031,7 +1032,8 @@ var OxArchiveWs = class {
1031
1032
  coin,
1032
1033
  start: options.start,
1033
1034
  end: options.end,
1034
- speed: options.speed ?? 1
1035
+ speed: options.speed ?? 1,
1036
+ granularity: options.granularity
1035
1037
  });
1036
1038
  }
1037
1039
  /**
@@ -1085,7 +1087,8 @@ var OxArchiveWs = class {
1085
1087
  coin,
1086
1088
  start: options.start,
1087
1089
  end: options.end,
1088
- batch_size: options.batchSize ?? 1e3
1090
+ batch_size: options.batchSize ?? 1e3,
1091
+ granularity: options.granularity
1089
1092
  });
1090
1093
  }
1091
1094
  /**
@@ -1103,6 +1106,14 @@ var OxArchiveWs = class {
1103
1106
  onHistoricalData(handler) {
1104
1107
  this.historicalDataHandlers.push(handler);
1105
1108
  }
1109
+ /**
1110
+ * Handle historical tick data (granularity='tick' mode)
1111
+ * Receives a checkpoint (full orderbook) followed by incremental deltas.
1112
+ * This is for tick-level granularity on Lighter.xyz orderbook data.
1113
+ */
1114
+ onHistoricalTickData(handler) {
1115
+ this.historicalTickDataHandlers.push(handler);
1116
+ }
1106
1117
  /**
1107
1118
  * Handle batched data (bulk stream mode)
1108
1119
  */
@@ -1232,6 +1243,13 @@ var OxArchiveWs = class {
1232
1243
  }
1233
1244
  break;
1234
1245
  }
1246
+ case "historical_tick_data": {
1247
+ const msg = message;
1248
+ for (const handler of this.historicalTickDataHandlers) {
1249
+ handler(msg.coin, msg.checkpoint, msg.deltas);
1250
+ }
1251
+ break;
1252
+ }
1235
1253
  case "historical_batch": {
1236
1254
  const msg = message;
1237
1255
  for (const handler of this.batchHandlers) {