@0xarchive/sdk 0.9.2 → 1.3.0

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
@@ -4,7 +4,7 @@ Official TypeScript/JavaScript SDK for [0xarchive](https://0xarchive.io) - Histo
4
4
 
5
5
  Supports multiple exchanges:
6
6
  - **Hyperliquid** - Perpetuals data from April 2023
7
- - **Hyperliquid HIP-3** - Builder-deployed perpetuals (Pro+ only, February 2026+)
7
+ - **Hyperliquid HIP-3** - Builder-deployed perpetuals (February 2026+, free tier: km:US500, Build+: all symbols, Pro+: orderbook history)
8
8
  - **Lighter.xyz** - Perpetuals data (August 2025+ for fills, Jan 2026+ for OB, OI, Funding Rate)
9
9
 
10
10
  ## Installation
@@ -60,7 +60,7 @@ const client = new OxArchive({
60
60
 
61
61
  ## REST API Reference
62
62
 
63
- All examples use `client.hyperliquid.*` but the same methods are available on `client.lighter.*` for Lighter.xyz data.
63
+ Core resources (orderbook, trades, instruments, funding, openInterest, candles, freshness, summary, priceHistory) are available on both `client.hyperliquid.*` and `client.lighter.*`. Some resources are exchange-specific -- see each section for details.
64
64
 
65
65
  ### Order Book
66
66
 
@@ -232,7 +232,7 @@ while (result.nextCursor) {
232
232
  const recent = await client.lighter.trades.recent('BTC', 100);
233
233
  ```
234
234
 
235
- **Note:** The `recent()` method is only available for Lighter.xyz (`client.lighter.trades.recent()`). Hyperliquid does not have a recent trades endpoint - use `list()` with a time range instead.
235
+ **Note:** The `recent()` method is available for Lighter.xyz (`client.lighter.trades.recent()`) and HIP-3 (`client.hyperliquid.hip3.trades.recent()`). Hyperliquid does not have a recent trades endpoint -- use `list()` with a time range instead.
236
236
 
237
237
  ### Instruments
238
238
 
@@ -353,12 +353,12 @@ const hourly = await client.hyperliquid.openInterest.history('BTC', {
353
353
  | `limit` | `number` | No | Max results (default: 100, max: 1000) |
354
354
  | `interval` | `OiFundingInterval` | No | Aggregation interval: `'5m'`, `'15m'`, `'30m'`, `'1h'`, `'4h'`, `'1d'`. When omitted, raw ~1 min data is returned. |
355
355
 
356
- ### Liquidations (Hyperliquid only)
356
+ ### Liquidations
357
357
 
358
- Get historical liquidation events. Data available from May 2025 onwards.
358
+ Get historical liquidation events. Data available from May 2025 onwards for Hyperliquid, and from February 2026 for HIP-3.
359
359
 
360
360
  ```typescript
361
- // Get liquidation history for a coin
361
+ // Get liquidation history for a coin (Hyperliquid)
362
362
  const liquidations = await client.hyperliquid.liquidations.history('BTC', {
363
363
  start: Date.now() - 86400000,
364
364
  end: Date.now(),
@@ -383,14 +383,21 @@ const userLiquidations = await client.hyperliquid.liquidations.byUser('0x1234...
383
383
  end: Date.now(),
384
384
  coin: 'BTC' // optional filter
385
385
  });
386
+
387
+ // HIP-3 liquidations (case-sensitive coins)
388
+ const hip3Liquidations = await client.hyperliquid.hip3.liquidations.history('km:US500', {
389
+ start: Date.now() - 86400000,
390
+ end: Date.now(),
391
+ limit: 100
392
+ });
386
393
  ```
387
394
 
388
- ### Liquidation Volume (Hyperliquid only)
395
+ ### Liquidation Volume
389
396
 
390
397
  Get pre-aggregated liquidation volume in time-bucketed intervals. Returns total, long, and short USD volumes per bucket -- 100-1000x less data than individual liquidation records.
391
398
 
392
399
  ```typescript
393
- // Get hourly liquidation volume for the last week
400
+ // Get hourly liquidation volume for the last week (Hyperliquid)
394
401
  const volume = await client.hyperliquid.liquidations.volume('BTC', {
395
402
  start: Date.now() - 86400000 * 7,
396
403
  end: Date.now(),
@@ -400,11 +407,202 @@ const volume = await client.hyperliquid.liquidations.volume('BTC', {
400
407
  for (const bucket of volume.data) {
401
408
  console.log(`${bucket.timestamp}: total=$${bucket.totalUsd}, long=$${bucket.longUsd}, short=$${bucket.shortUsd}`);
402
409
  }
410
+
411
+ // HIP-3 liquidation volume (case-sensitive coins)
412
+ const hip3Volume = await client.hyperliquid.hip3.liquidations.volume('km:US500', {
413
+ start: Date.now() - 86400000 * 7,
414
+ end: Date.now(),
415
+ interval: '1h'
416
+ });
417
+ ```
418
+
419
+ ### Orders
420
+
421
+ Access order history, order flow aggregations, and TP/SL (take-profit/stop-loss) orders. Available for Hyperliquid and HIP-3.
422
+
423
+ ```typescript
424
+ // Get order history for a coin
425
+ const orders = await client.hyperliquid.orders.history('BTC', {
426
+ start: Date.now() - 86400000,
427
+ end: Date.now(),
428
+ limit: 1000,
429
+ user: '0x1234...', // optional: filter by user address
430
+ status: 'filled', // optional: filter by status
431
+ order_type: 'limit', // optional: filter by order type
432
+ });
433
+
434
+ // Paginate through all results
435
+ const allOrders = [...orders.data];
436
+ while (orders.nextCursor) {
437
+ const next = await client.hyperliquid.orders.history('BTC', {
438
+ start: Date.now() - 86400000,
439
+ end: Date.now(),
440
+ cursor: orders.nextCursor,
441
+ limit: 1000
442
+ });
443
+ allOrders.push(...next.data);
444
+ }
445
+
446
+ // Get order flow (aggregated order activity over time)
447
+ const flow = await client.hyperliquid.orders.flow('BTC', {
448
+ start: Date.now() - 86400000,
449
+ end: Date.now(),
450
+ interval: '1h', // optional aggregation interval
451
+ limit: 100
452
+ });
453
+
454
+ // Get TP/SL orders
455
+ const tpsl = await client.hyperliquid.orders.tpsl('BTC', {
456
+ start: Date.now() - 86400000,
457
+ end: Date.now(),
458
+ user: '0x1234...', // optional: filter by user
459
+ triggered: true, // optional: filter by triggered status
460
+ });
461
+
462
+ // HIP-3 orders (case-sensitive coins)
463
+ const hip3Orders = await client.hyperliquid.hip3.orders.history('km:US500', {
464
+ start: Date.now() - 86400000,
465
+ end: Date.now(),
466
+ limit: 1000
467
+ });
468
+
469
+ const hip3Flow = await client.hyperliquid.hip3.orders.flow('km:US500', {
470
+ start: Date.now() - 86400000,
471
+ end: Date.now(),
472
+ interval: '1h'
473
+ });
474
+
475
+ const hip3Tpsl = await client.hyperliquid.hip3.orders.tpsl('km:US500', {
476
+ start: Date.now() - 86400000,
477
+ end: Date.now()
478
+ });
479
+ ```
480
+
481
+ ### L4 Order Book
482
+
483
+ Access L4 orderbook snapshots, diffs, and history. L4 data includes user attribution (who placed each order). Available for Hyperliquid and HIP-3.
484
+
485
+ ```typescript
486
+ // Get current L4 orderbook snapshot
487
+ const l4Ob = await client.hyperliquid.l4Orderbook.get('BTC');
488
+
489
+ // Get L4 orderbook at a specific timestamp with custom depth
490
+ const l4Historical = await client.hyperliquid.l4Orderbook.get('BTC', {
491
+ timestamp: 1704067200000,
492
+ depth: 20
493
+ });
494
+
495
+ // Get L4 orderbook diffs (incremental updates)
496
+ const diffs = await client.hyperliquid.l4Orderbook.diffs('BTC', {
497
+ start: Date.now() - 3600000,
498
+ end: Date.now(),
499
+ limit: 1000
500
+ });
501
+
502
+ // Paginate through diffs
503
+ const allDiffs = [...diffs.data];
504
+ while (diffs.nextCursor) {
505
+ const next = await client.hyperliquid.l4Orderbook.diffs('BTC', {
506
+ start: Date.now() - 3600000,
507
+ end: Date.now(),
508
+ cursor: diffs.nextCursor,
509
+ limit: 1000
510
+ });
511
+ allDiffs.push(...next.data);
512
+ }
513
+
514
+ // Get L4 orderbook history (full snapshots over time)
515
+ const l4History = await client.hyperliquid.l4Orderbook.history('BTC', {
516
+ start: Date.now() - 86400000,
517
+ end: Date.now(),
518
+ limit: 1000
519
+ });
520
+
521
+ // HIP-3 L4 orderbook (case-sensitive coins)
522
+ const hip3L4 = await client.hyperliquid.hip3.l4Orderbook.get('km:US500');
523
+
524
+ const hip3L4Diffs = await client.hyperliquid.hip3.l4Orderbook.diffs('km:US500', {
525
+ start: Date.now() - 3600000,
526
+ end: Date.now(),
527
+ limit: 1000
528
+ });
529
+
530
+ const hip3L4History = await client.hyperliquid.hip3.l4Orderbook.history('km:US500', {
531
+ start: Date.now() - 86400000,
532
+ end: Date.now(),
533
+ limit: 1000
534
+ });
535
+ ```
536
+
537
+ ### L3 Order Book (Lighter only)
538
+
539
+ Access L3 orderbook snapshots and history from Lighter.xyz. L3 data includes individual order-level detail.
540
+
541
+ ```typescript
542
+ // Get current L3 orderbook
543
+ const l3Ob = await client.lighter.l3Orderbook.get('BTC');
544
+
545
+ // Get L3 orderbook at a specific timestamp with custom depth
546
+ const l3Historical = await client.lighter.l3Orderbook.get('BTC', {
547
+ timestamp: 1704067200000,
548
+ depth: 20
549
+ });
550
+
551
+ // Get L3 orderbook history
552
+ const l3History = await client.lighter.l3Orderbook.history('BTC', {
553
+ start: Date.now() - 86400000,
554
+ end: Date.now(),
555
+ limit: 1000
556
+ });
557
+
558
+ // Paginate through L3 history
559
+ const allL3 = [...l3History.data];
560
+ while (l3History.nextCursor) {
561
+ const next = await client.lighter.l3Orderbook.history('BTC', {
562
+ start: Date.now() - 86400000,
563
+ end: Date.now(),
564
+ cursor: l3History.nextCursor,
565
+ limit: 1000
566
+ });
567
+ allL3.push(...next.data);
568
+ }
569
+ ```
570
+
571
+ ### L2 Order Book (Full-Depth)
572
+
573
+ Access L2 full-depth orderbook derived from L4 data. Available for Hyperliquid and HIP-3.
574
+
575
+ ```typescript
576
+ // L2 full-depth orderbook (Build+ tier)
577
+ const l2 = await client.hyperliquid.l2Orderbook.get('BTC');
578
+
579
+ // L2 orderbook at a specific timestamp with depth
580
+ const l2Historical = await client.hyperliquid.l2Orderbook.get('BTC', {
581
+ timestamp: 1704067200000,
582
+ depth: 50
583
+ });
584
+
585
+ // L2 orderbook history (Build+ tier)
586
+ const l2History = await client.hyperliquid.l2Orderbook.history('BTC', {
587
+ start: Date.now() - 86400000,
588
+ end: Date.now(),
589
+ limit: 1000
590
+ });
591
+
592
+ // L2 tick-level diffs (Pro+ tier)
593
+ const l2Diffs = await client.hyperliquid.l2Orderbook.diffs('BTC', {
594
+ start: Date.now() - 3600000,
595
+ end: Date.now(),
596
+ limit: 1000
597
+ });
598
+
599
+ // HIP-3 L2 orderbook
600
+ const hip3L2 = await client.hyperliquid.hip3.l2Orderbook.get('km:US500');
403
601
  ```
404
602
 
405
- ### Freshness (Hyperliquid only)
603
+ ### Freshness
406
604
 
407
- Check when each data type was last updated for a specific coin. Useful for verifying data recency before pulling it.
605
+ Check when each data type was last updated for a specific coin. Useful for verifying data recency before pulling it. Available for all exchanges.
408
606
 
409
607
  ```typescript
410
608
  // Hyperliquid
@@ -754,7 +952,7 @@ const trades = await client.trades.list('BTC', { start, end });
754
952
 
755
953
  ## WebSocket Client
756
954
 
757
- The WebSocket client supports three modes: real-time streaming, historical replay, and bulk streaming.
955
+ The WebSocket client supports two modes: real-time streaming and historical replay. For bulk data downloads, use the S3 Parquet bulk export via the [Data Explorer](https://0xarchive.io/data).
758
956
 
759
957
  ```typescript
760
958
  import { OxArchiveWs } from '@0xarchive/sdk';
@@ -848,53 +1046,12 @@ ws.replaySeek(1704067200000); // Jump to timestamp
848
1046
  ws.replayStop();
849
1047
  ```
850
1048
 
851
- ### Bulk Streaming
852
-
853
- Fast bulk download for data pipelines. Data arrives in batches without timing delays.
854
-
855
- ```typescript
856
- const ws = new OxArchiveWs({ apiKey: 'ox_...' });
857
- ws.connect();
858
-
859
- const allData: OrderBook[] = [];
860
-
861
- // Handle batched data
862
- ws.onBatch((coin, records) => {
863
- allData.push(...records.map(r => r.data));
864
- });
865
-
866
- ws.onStreamProgress((snapshotsSent) => {
867
- console.log(`Progress: ${snapshotsSent} snapshots`);
868
- });
869
-
870
- ws.onStreamComplete((channel, coin, recordsSent) => {
871
- console.log(`Downloaded ${recordsSent} records`);
872
- });
873
-
874
- // Start bulk stream
875
- ws.stream('orderbook', 'ETH', {
876
- start: Date.now() - 3600000, // 1 hour ago
877
- end: Date.now(),
878
- batchSize: 1000 // Optional, defaults to 1000
879
- });
880
-
881
- // Lighter.xyz stream with granularity (tier restrictions apply)
882
- ws.stream('orderbook', 'BTC', {
883
- start: Date.now() - 3600000,
884
- end: Date.now(),
885
- granularity: '10s' // Options: 'checkpoint', '30s', '10s', '1s', 'tick'
886
- });
887
-
888
- // Stop if needed
889
- ws.streamStop();
890
- ```
891
-
892
1049
  ### Gap Detection
893
1050
 
894
- During historical replay and bulk streaming, the server automatically detects gaps in the data and notifies the client. This helps identify periods where data may be missing.
1051
+ During historical replay, the server automatically detects gaps in the data and notifies the client. This helps identify periods where data may be missing.
895
1052
 
896
1053
  ```typescript
897
- // Handle gap notifications during replay/stream
1054
+ // Handle gap notifications during replay
898
1055
  ws.onGap((channel, coin, gapStart, gapEnd, durationMinutes) => {
899
1056
  console.log(`Gap detected in ${channel}/${coin}:`);
900
1057
  console.log(` From: ${new Date(gapStart).toISOString()}`);
@@ -935,12 +1092,14 @@ const ws = new OxArchiveWs({
935
1092
  |---------|-------------|---------------|-------------------|
936
1093
  | `orderbook` | L2 order book updates | Yes | Yes |
937
1094
  | `trades` | Trade/fill updates | Yes | Yes |
938
- | `candles` | OHLCV candle data | Yes | Yes (replay/stream only) |
939
- | `liquidations` | Liquidation events (May 2025+) | Yes | Yes (replay/stream only) |
1095
+ | `candles` | OHLCV candle data | Yes | Yes (replay only) |
1096
+ | `liquidations` | Liquidation events (May 2025+) | Yes | Yes (replay only) |
940
1097
  | `open_interest` | Open interest snapshots | Yes | Replay/stream only |
941
1098
  | `funding` | Funding rate snapshots | Yes | Replay/stream only |
942
1099
  | `ticker` | Price and 24h volume | Yes | Real-time only |
943
1100
  | `all_tickers` | All market tickers | No | Real-time only |
1101
+ | `l4_diffs` | L4 orderbook diffs with user attribution (Pro+) | Yes | Real-time only |
1102
+ | `l4_orders` | Order lifecycle events with user attribution (Pro+) | Yes | Real-time only |
944
1103
 
945
1104
  #### HIP-3 Builder Perps Channels
946
1105
 
@@ -951,6 +1110,9 @@ const ws = new OxArchiveWs({
951
1110
  | `hip3_candles` | HIP-3 OHLCV candle data | Yes | Yes |
952
1111
  | `hip3_open_interest` | HIP-3 open interest snapshots | Yes | Replay/stream only |
953
1112
  | `hip3_funding` | HIP-3 funding rate snapshots | Yes | Replay/stream only |
1113
+ | `hip3_liquidations` | HIP-3 liquidation events (Feb 2026+) | Yes | Yes (replay only) |
1114
+ | `hip3_l4_diffs` | HIP-3 L4 orderbook diffs (Pro+) | Yes | Real-time only |
1115
+ | `hip3_l4_orders` | HIP-3 order lifecycle events (Pro+) | Yes | Real-time only |
954
1116
 
955
1117
  > **Note:** HIP-3 coins are case-sensitive (e.g., `km:US500`, `xyz:XYZ100`). Do not uppercase them.
956
1118
 
@@ -963,6 +1125,7 @@ const ws = new OxArchiveWs({
963
1125
  | `lighter_candles` | Lighter OHLCV candle data | Yes | Yes |
964
1126
  | `lighter_open_interest` | Lighter open interest snapshots | Yes | Replay/stream only |
965
1127
  | `lighter_funding` | Lighter funding rate snapshots | Yes | Replay/stream only |
1128
+ | `lighter_l3_orderbook` | Lighter L3 order-level orderbook (Pro+) | Yes | Yes |
966
1129
 
967
1130
  #### Candle Replay/Stream
968
1131
 
@@ -975,14 +1138,6 @@ ws.replay('candles', 'BTC', {
975
1138
  interval: '15m' // 1m, 5m, 15m, 30m, 1h, 4h, 1d, 1w
976
1139
  });
977
1140
 
978
- // Bulk stream candles
979
- ws.stream('candles', 'ETH', {
980
- start: Date.now() - 3600000,
981
- end: Date.now(),
982
- batchSize: 1000,
983
- interval: '1h'
984
- });
985
-
986
1141
  // Lighter.xyz candles
987
1142
  ws.replay('lighter_candles', 'BTC', {
988
1143
  start: Date.now() - 86400000,
@@ -991,7 +1146,7 @@ ws.replay('lighter_candles', 'BTC', {
991
1146
  });
992
1147
  ```
993
1148
 
994
- #### HIP-3 Replay/Stream
1149
+ #### HIP-3 Replay
995
1150
 
996
1151
  ```typescript
997
1152
  // Replay HIP-3 orderbook at 50x speed
@@ -1001,13 +1156,6 @@ ws.replay('hip3_orderbook', 'km:US500', {
1001
1156
  speed: 50,
1002
1157
  });
1003
1158
 
1004
- // Bulk stream HIP-3 trades
1005
- ws.stream('hip3_trades', 'xyz:XYZ100', {
1006
- start: Date.now() - 86400000,
1007
- end: Date.now(),
1008
- batchSize: 1000,
1009
- });
1010
-
1011
1159
  // HIP-3 candles
1012
1160
  ws.replay('hip3_candles', 'km:US500', {
1013
1161
  start: Date.now() - 86400000,
@@ -1062,42 +1210,7 @@ ws.replaySeek(1704067200000);
1062
1210
  ws.replayStop();
1063
1211
  ```
1064
1212
 
1065
- ### Multi-Channel Bulk Stream
1066
-
1067
- Stream multiple channels simultaneously for fast bulk download.
1068
-
1069
- ```typescript
1070
- const ws = new OxArchiveWs({ apiKey: 'ox_...' });
1071
- await ws.connect();
1072
-
1073
- // Handle initial snapshots
1074
- ws.onReplaySnapshot((channel, coin, timestamp, data) => {
1075
- console.log(`Initial ${channel} snapshot`);
1076
- });
1077
-
1078
- // Handle batched data from all channels
1079
- ws.onBatch((coin, records) => {
1080
- for (const record of records) {
1081
- // Process interleaved data from all channels
1082
- }
1083
- });
1084
-
1085
- ws.onStreamComplete((channel, coin, count) => {
1086
- console.log(`Stream complete: ${count} records`);
1087
- });
1088
-
1089
- // Start multi-channel stream
1090
- ws.multiStream(['orderbook', 'trades', 'open_interest', 'funding'], 'ETH', {
1091
- start: Date.now() - 3600000,
1092
- end: Date.now(),
1093
- batchSize: 1000
1094
- });
1095
-
1096
- // Stop if needed
1097
- ws.streamStop();
1098
- ```
1099
-
1100
- **Channels available for multi-channel mode:** All historical channels can be combined in a single multi-channel replay or stream. This includes `orderbook`, `trades`, `candles`, `liquidations`, `open_interest`, `funding`, and their `lighter_*` and `hip3_*` variants.
1213
+ **Channels available for multi-channel replay:** All historical channels can be combined in a single multi-channel replay. This includes `orderbook`, `trades`, `candles`, `liquidations`, `open_interest`, `funding`, and their `lighter_*` and `hip3_*` variants.
1101
1214
 
1102
1215
  ### WebSocket Connection States
1103
1216
 
@@ -1112,18 +1225,18 @@ The SDK accepts timestamps as Unix milliseconds or Date objects:
1112
1225
 
1113
1226
  ```typescript
1114
1227
  // Unix milliseconds (recommended)
1115
- client.orderbook.history('BTC', {
1228
+ client.hyperliquid.orderbook.history('BTC', {
1116
1229
  start: Date.now() - 86400000,
1117
1230
  end: Date.now()
1118
1231
  });
1119
1232
 
1120
1233
  // Date objects (converted automatically)
1121
- client.orderbook.history('BTC', {
1234
+ client.hyperliquid.orderbook.history('BTC', {
1122
1235
  start: new Date('2024-01-01'),
1123
1236
  end: new Date('2024-01-02')
1124
1237
  });
1125
1238
 
1126
- // WebSocket replay/stream also accepts both
1239
+ // WebSocket replay also accepts both
1127
1240
  ws.replay('orderbook', 'BTC', {
1128
1241
  start: Date.now() - 3600000,
1129
1242
  end: Date.now(),
@@ -1198,6 +1311,10 @@ const client = new OxArchive({
1198
1311
 
1199
1312
  When enabled, responses are validated against Zod schemas and throw `OxArchiveError` with status 422 if validation fails.
1200
1313
 
1314
+ ## Bulk Data Downloads
1315
+
1316
+ For large-scale data exports (full order books, complete trade history, etc.), use the S3 Parquet bulk export available at [0xarchive.io/data](https://0xarchive.io/data). The Data Explorer lets you select time ranges, symbols, and data types, then download compressed Parquet files directly.
1317
+
1201
1318
  ## Requirements
1202
1319
 
1203
1320
  - Node.js 18+ or modern browsers with `fetch` and `WebSocket` support