@0xarchive/sdk 0.8.3 → 0.9.1

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
@@ -303,8 +303,25 @@ const history = await client.hyperliquid.funding.history('ETH', {
303
303
  start: Date.now() - 86400000 * 7,
304
304
  end: Date.now()
305
305
  });
306
+
307
+ // Get funding rate history with aggregation interval
308
+ const hourly = await client.hyperliquid.funding.history('BTC', {
309
+ start: Date.now() - 86400000 * 7,
310
+ end: Date.now(),
311
+ interval: '1h'
312
+ });
306
313
  ```
307
314
 
315
+ #### Funding History Parameters
316
+
317
+ | Parameter | Type | Required | Description |
318
+ |-----------|------|----------|-------------|
319
+ | `start` | `number \| string` | Yes | Start timestamp (Unix ms or ISO string) |
320
+ | `end` | `number \| string` | Yes | End timestamp (Unix ms or ISO string) |
321
+ | `cursor` | `number \| string` | No | Cursor from previous response for pagination |
322
+ | `limit` | `number` | No | Max results (default: 100, max: 1000) |
323
+ | `interval` | `OiFundingInterval` | No | Aggregation interval: `'5m'`, `'15m'`, `'30m'`, `'1h'`, `'4h'`, `'1d'`. When omitted, raw ~1 min data is returned. |
324
+
308
325
  ### Open Interest
309
326
 
310
327
  ```typescript
@@ -317,8 +334,25 @@ const history = await client.hyperliquid.openInterest.history('ETH', {
317
334
  end: Date.now(),
318
335
  limit: 100
319
336
  });
337
+
338
+ // Get open interest history with aggregation interval
339
+ const hourly = await client.hyperliquid.openInterest.history('BTC', {
340
+ start: Date.now() - 86400000,
341
+ end: Date.now(),
342
+ interval: '1h'
343
+ });
320
344
  ```
321
345
 
346
+ #### Open Interest History Parameters
347
+
348
+ | Parameter | Type | Required | Description |
349
+ |-----------|------|----------|-------------|
350
+ | `start` | `number \| string` | Yes | Start timestamp (Unix ms or ISO string) |
351
+ | `end` | `number \| string` | Yes | End timestamp (Unix ms or ISO string) |
352
+ | `cursor` | `number \| string` | No | Cursor from previous response for pagination |
353
+ | `limit` | `number` | No | Max results (default: 100, max: 1000) |
354
+ | `interval` | `OiFundingInterval` | No | Aggregation interval: `'5m'`, `'15m'`, `'30m'`, `'1h'`, `'4h'`, `'1d'`. When omitted, raw ~1 min data is returned. |
355
+
322
356
  ### Liquidations (Hyperliquid only)
323
357
 
324
358
  Get historical liquidation events. Data available from May 2025 onwards.
@@ -351,6 +385,114 @@ const userLiquidations = await client.hyperliquid.liquidations.byUser('0x1234...
351
385
  });
352
386
  ```
353
387
 
388
+ ### Liquidation Volume (Hyperliquid only)
389
+
390
+ 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
+
392
+ ```typescript
393
+ // Get hourly liquidation volume for the last week
394
+ const volume = await client.hyperliquid.liquidations.volume('BTC', {
395
+ start: Date.now() - 86400000 * 7,
396
+ end: Date.now(),
397
+ interval: '1h' // 5m, 15m, 30m, 1h, 4h, 1d
398
+ });
399
+
400
+ for (const bucket of volume.data) {
401
+ console.log(`${bucket.timestamp}: total=$${bucket.totalUsd}, long=$${bucket.longUsd}, short=$${bucket.shortUsd}`);
402
+ }
403
+ ```
404
+
405
+ ### Freshness (Hyperliquid only)
406
+
407
+ Check when each data type was last updated for a specific coin. Useful for verifying data recency before pulling it.
408
+
409
+ ```typescript
410
+ // Hyperliquid
411
+ const freshness = await client.hyperliquid.freshness('BTC');
412
+ console.log(`Orderbook last updated: ${freshness.orderbook.lastUpdated}, lag: ${freshness.orderbook.lagMs}ms`);
413
+ console.log(`Trades last updated: ${freshness.trades.lastUpdated}, lag: ${freshness.trades.lagMs}ms`);
414
+ console.log(`Funding last updated: ${freshness.funding.lastUpdated}`);
415
+ console.log(`OI last updated: ${freshness.openInterest.lastUpdated}`);
416
+
417
+ // Lighter.xyz
418
+ const lighterFreshness = await client.lighter.freshness('BTC');
419
+
420
+ // HIP-3 (case-sensitive coins)
421
+ const hip3Freshness = await client.hyperliquid.hip3.freshness('km:US500');
422
+ ```
423
+
424
+ ### Summary
425
+
426
+ Get a combined market snapshot in a single call -- mark/oracle price, funding rate, open interest, 24h volume, and 24h liquidation volumes.
427
+
428
+ ```typescript
429
+ // Hyperliquid (includes volume + liquidation data)
430
+ const summary = await client.hyperliquid.summary('BTC');
431
+ console.log(`Mark price: ${summary.markPrice}`);
432
+ console.log(`Oracle price: ${summary.oraclePrice}`);
433
+ console.log(`Funding rate: ${summary.fundingRate}`);
434
+ console.log(`Open interest: ${summary.openInterest}`);
435
+ console.log(`24h volume: ${summary.volume24h}`);
436
+ console.log(`24h liquidation volume: $${summary.liquidationVolume24h}`);
437
+ console.log(` Long: $${summary.longLiquidationVolume24h}`);
438
+ console.log(` Short: $${summary.shortLiquidationVolume24h}`);
439
+
440
+ // Lighter.xyz (price, funding, OI — no volume/liquidation data)
441
+ const lighterSummary = await client.lighter.summary('BTC');
442
+
443
+ // HIP-3 (includes mid_price — case-sensitive coins)
444
+ const hip3Summary = await client.hyperliquid.hip3.summary('km:US500');
445
+ console.log(`Mid price: ${hip3Summary.midPrice}`);
446
+ ```
447
+
448
+ ### Price History
449
+
450
+ Get mark, oracle, and mid price history over time. Supports aggregation intervals. Data projected from open interest records.
451
+
452
+ ```typescript
453
+ // Hyperliquid — available from May 2023
454
+ const prices = await client.hyperliquid.priceHistory('BTC', {
455
+ start: Date.now() - 86400000,
456
+ end: Date.now(),
457
+ interval: '1h' // 5m, 15m, 30m, 1h, 4h, 1d
458
+ });
459
+
460
+ for (const snapshot of prices.data) {
461
+ console.log(`${snapshot.timestamp}: mark=${snapshot.markPrice}, oracle=${snapshot.oraclePrice}, mid=${snapshot.midPrice}`);
462
+ }
463
+
464
+ // Lighter.xyz
465
+ const lighterPrices = await client.lighter.priceHistory('BTC', {
466
+ start: Date.now() - 86400000,
467
+ end: Date.now(),
468
+ interval: '1h'
469
+ });
470
+
471
+ // HIP-3 (case-sensitive coins)
472
+ const hip3Prices = await client.hyperliquid.hip3.priceHistory('km:US500', {
473
+ start: Date.now() - 86400000,
474
+ end: Date.now(),
475
+ interval: '1d'
476
+ });
477
+
478
+ // Paginate for larger ranges
479
+ let result = await client.hyperliquid.priceHistory('BTC', {
480
+ start: Date.now() - 86400000 * 30,
481
+ end: Date.now(),
482
+ interval: '4h',
483
+ limit: 1000
484
+ });
485
+ while (result.nextCursor) {
486
+ result = await client.hyperliquid.priceHistory('BTC', {
487
+ start: Date.now() - 86400000 * 30,
488
+ end: Date.now(),
489
+ interval: '4h',
490
+ cursor: result.nextCursor,
491
+ limit: 1000
492
+ });
493
+ }
494
+ ```
495
+
354
496
  ### Candles (OHLCV)
355
497
 
356
498
  Get historical OHLCV candle data aggregated from trades.
@@ -691,6 +833,8 @@ const ws = new OxArchiveWs({
691
833
  | `trades` | Trade/fill updates | Yes | Yes |
692
834
  | `candles` | OHLCV candle data | Yes | Yes (replay/stream only) |
693
835
  | `liquidations` | Liquidation events (May 2025+) | Yes | Yes (replay/stream only) |
836
+ | `open_interest` | Open interest snapshots | Yes | Replay/stream only |
837
+ | `funding` | Funding rate snapshots | Yes | Replay/stream only |
694
838
  | `ticker` | Price and 24h volume | Yes | Real-time only |
695
839
  | `all_tickers` | All market tickers | No | Real-time only |
696
840
 
@@ -701,6 +845,8 @@ const ws = new OxArchiveWs({
701
845
  | `hip3_orderbook` | HIP-3 L2 order book snapshots | Yes | Yes |
702
846
  | `hip3_trades` | HIP-3 trade/fill updates | Yes | Yes |
703
847
  | `hip3_candles` | HIP-3 OHLCV candle data | Yes | Yes |
848
+ | `hip3_open_interest` | HIP-3 open interest snapshots | Yes | Replay/stream only |
849
+ | `hip3_funding` | HIP-3 funding rate snapshots | Yes | Replay/stream only |
704
850
 
705
851
  > **Note:** HIP-3 coins are case-sensitive (e.g., `km:US500`, `xyz:XYZ100`). Do not uppercase them.
706
852
 
@@ -711,6 +857,8 @@ const ws = new OxArchiveWs({
711
857
  | `lighter_orderbook` | Lighter L2 order book (reconstructed) | Yes | Yes |
712
858
  | `lighter_trades` | Lighter trade/fill updates | Yes | Yes |
713
859
  | `lighter_candles` | Lighter OHLCV candle data | Yes | Yes |
860
+ | `lighter_open_interest` | Lighter open interest snapshots | Yes | Replay/stream only |
861
+ | `lighter_funding` | Lighter funding rate snapshots | Yes | Replay/stream only |
714
862
 
715
863
  #### Candle Replay/Stream
716
864
 
@@ -765,6 +913,88 @@ ws.replay('hip3_candles', 'km:US500', {
765
913
  });
766
914
  ```
767
915
 
916
+ ### Multi-Channel Replay
917
+
918
+ Replay multiple data channels simultaneously with synchronized timing. Data from all channels is interleaved chronologically. Before the timeline begins, `replay_snapshot` messages provide the initial state for each channel at the start timestamp.
919
+
920
+ ```typescript
921
+ const ws = new OxArchiveWs({ apiKey: 'ox_...' });
922
+ await ws.connect();
923
+
924
+ // Handle initial snapshots (sent before timeline data)
925
+ ws.onReplaySnapshot((channel, coin, timestamp, data) => {
926
+ console.log(`Initial ${channel} state at ${new Date(timestamp).toISOString()}`);
927
+ if (channel === 'orderbook') {
928
+ currentOrderbook = data;
929
+ } else if (channel === 'funding') {
930
+ currentFundingRate = data;
931
+ } else if (channel === 'open_interest') {
932
+ currentOI = data;
933
+ }
934
+ });
935
+
936
+ // Handle interleaved historical data
937
+ ws.onHistoricalData((coin, timestamp, data) => {
938
+ // The `channel` field on the raw message indicates which channel
939
+ // this data point belongs to
940
+ console.log(`${new Date(timestamp).toISOString()}: data received`);
941
+ });
942
+
943
+ ws.onReplayComplete((channel, coin, count) => {
944
+ console.log(`Replay complete: ${count} records`);
945
+ });
946
+
947
+ // Start multi-channel replay
948
+ ws.multiReplay(['orderbook', 'trades', 'funding'], 'BTC', {
949
+ start: Date.now() - 86400000,
950
+ end: Date.now(),
951
+ speed: 10
952
+ });
953
+
954
+ // Playback controls work the same as single-channel
955
+ ws.replayPause();
956
+ ws.replayResume();
957
+ ws.replaySeek(1704067200000);
958
+ ws.replayStop();
959
+ ```
960
+
961
+ ### Multi-Channel Bulk Stream
962
+
963
+ Stream multiple channels simultaneously for fast bulk download.
964
+
965
+ ```typescript
966
+ const ws = new OxArchiveWs({ apiKey: 'ox_...' });
967
+ await ws.connect();
968
+
969
+ // Handle initial snapshots
970
+ ws.onReplaySnapshot((channel, coin, timestamp, data) => {
971
+ console.log(`Initial ${channel} snapshot`);
972
+ });
973
+
974
+ // Handle batched data from all channels
975
+ ws.onBatch((coin, records) => {
976
+ for (const record of records) {
977
+ // Process interleaved data from all channels
978
+ }
979
+ });
980
+
981
+ ws.onStreamComplete((channel, coin, count) => {
982
+ console.log(`Stream complete: ${count} records`);
983
+ });
984
+
985
+ // Start multi-channel stream
986
+ ws.multiStream(['orderbook', 'trades', 'open_interest', 'funding'], 'ETH', {
987
+ start: Date.now() - 3600000,
988
+ end: Date.now(),
989
+ batchSize: 1000
990
+ });
991
+
992
+ // Stop if needed
993
+ ws.streamStop();
994
+ ```
995
+
996
+ **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.
997
+
768
998
  ### WebSocket Connection States
769
999
 
770
1000
  ```typescript
@@ -830,10 +1060,15 @@ import type {
830
1060
  FundingRate,
831
1061
  OpenInterest,
832
1062
  Liquidation,
1063
+ LiquidationVolume,
1064
+ CoinFreshness,
1065
+ CoinSummary,
1066
+ PriceSnapshot,
833
1067
  CursorResponse,
834
1068
  WsOptions,
835
1069
  WsChannel,
836
1070
  WsConnectionState,
1071
+ WsReplaySnapshot,
837
1072
  // Orderbook reconstruction (Enterprise)
838
1073
  OrderbookDelta,
839
1074
  TickData,