@0xarchive/sdk 0.8.2 → 0.9.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 +212 -6
- package/dist/index.d.mts +996 -98
- package/dist/index.d.ts +996 -98
- package/dist/index.js +292 -9
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +282 -9
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -22,7 +22,7 @@ pnpm add @0xarchive/sdk
|
|
|
22
22
|
```typescript
|
|
23
23
|
import { OxArchive } from '@0xarchive/sdk';
|
|
24
24
|
|
|
25
|
-
const client = new OxArchive({ apiKey: '
|
|
25
|
+
const client = new OxArchive({ apiKey: '0xa_your_api_key' });
|
|
26
26
|
|
|
27
27
|
// Hyperliquid data
|
|
28
28
|
const hlOrderbook = await client.hyperliquid.orderbook.get('BTC');
|
|
@@ -51,7 +51,7 @@ const history = await client.hyperliquid.orderbook.history('ETH', {
|
|
|
51
51
|
|
|
52
52
|
```typescript
|
|
53
53
|
const client = new OxArchive({
|
|
54
|
-
apiKey: '
|
|
54
|
+
apiKey: '0xa_your_api_key', // Required
|
|
55
55
|
baseUrl: 'https://api.0xarchive.io', // Optional
|
|
56
56
|
timeout: 30000, // Optional, request timeout in ms (default: 30000)
|
|
57
57
|
validate: false, // Optional, enable Zod schema validation
|
|
@@ -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,85 @@ 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
|
+
const freshness = await client.hyperliquid.freshness('BTC');
|
|
411
|
+
console.log(`Orderbook last updated: ${freshness.orderbook.lastUpdated}, lag: ${freshness.orderbook.lagMs}ms`);
|
|
412
|
+
console.log(`Trades last updated: ${freshness.trades.lastUpdated}, lag: ${freshness.trades.lagMs}ms`);
|
|
413
|
+
console.log(`Funding last updated: ${freshness.funding.lastUpdated}`);
|
|
414
|
+
console.log(`OI last updated: ${freshness.openInterest.lastUpdated}`);
|
|
415
|
+
```
|
|
416
|
+
|
|
417
|
+
### Summary (Hyperliquid only)
|
|
418
|
+
|
|
419
|
+
Get a combined market snapshot in a single call -- mark/oracle price, funding rate, open interest, 24h volume, and 24h liquidation volumes.
|
|
420
|
+
|
|
421
|
+
```typescript
|
|
422
|
+
const summary = await client.hyperliquid.summary('BTC');
|
|
423
|
+
console.log(`Mark price: ${summary.markPrice}`);
|
|
424
|
+
console.log(`Oracle price: ${summary.oraclePrice}`);
|
|
425
|
+
console.log(`Funding rate: ${summary.fundingRate}`);
|
|
426
|
+
console.log(`Open interest: ${summary.openInterest}`);
|
|
427
|
+
console.log(`24h volume: ${summary.volume24h}`);
|
|
428
|
+
console.log(`24h liquidation volume: $${summary.liquidationVolume24h}`);
|
|
429
|
+
console.log(` Long: $${summary.longLiquidationVolume24h}`);
|
|
430
|
+
console.log(` Short: $${summary.shortLiquidationVolume24h}`);
|
|
431
|
+
```
|
|
432
|
+
|
|
433
|
+
### Price History (Hyperliquid only)
|
|
434
|
+
|
|
435
|
+
Get mark, oracle, and mid price history over time. Supports aggregation intervals. Data projected from open interest records (available from May 2023).
|
|
436
|
+
|
|
437
|
+
```typescript
|
|
438
|
+
// Get hourly price history for the last 24 hours
|
|
439
|
+
const prices = await client.hyperliquid.priceHistory('BTC', {
|
|
440
|
+
start: Date.now() - 86400000,
|
|
441
|
+
end: Date.now(),
|
|
442
|
+
interval: '1h' // 5m, 15m, 30m, 1h, 4h, 1d
|
|
443
|
+
});
|
|
444
|
+
|
|
445
|
+
for (const snapshot of prices.data) {
|
|
446
|
+
console.log(`${snapshot.timestamp}: mark=${snapshot.markPrice}, oracle=${snapshot.oraclePrice}, mid=${snapshot.midPrice}`);
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
// Paginate for larger ranges
|
|
450
|
+
let result = await client.hyperliquid.priceHistory('BTC', {
|
|
451
|
+
start: Date.now() - 86400000 * 30,
|
|
452
|
+
end: Date.now(),
|
|
453
|
+
interval: '4h',
|
|
454
|
+
limit: 1000
|
|
455
|
+
});
|
|
456
|
+
while (result.nextCursor) {
|
|
457
|
+
result = await client.hyperliquid.priceHistory('BTC', {
|
|
458
|
+
start: Date.now() - 86400000 * 30,
|
|
459
|
+
end: Date.now(),
|
|
460
|
+
interval: '4h',
|
|
461
|
+
cursor: result.nextCursor,
|
|
462
|
+
limit: 1000
|
|
463
|
+
});
|
|
464
|
+
}
|
|
465
|
+
```
|
|
466
|
+
|
|
354
467
|
### Candles (OHLCV)
|
|
355
468
|
|
|
356
469
|
Get historical OHLCV candle data aggregated from trades.
|
|
@@ -489,7 +602,7 @@ console.log(`API P99: ${sla.actual.apiLatencyP99Ms}ms (${sla.actual.latencyStatu
|
|
|
489
602
|
|
|
490
603
|
```typescript
|
|
491
604
|
const client = new OxArchive({
|
|
492
|
-
apiKey: '
|
|
605
|
+
apiKey: '0xa_your_api_key',
|
|
493
606
|
timeout: 60000 // 60 seconds for data quality endpoints
|
|
494
607
|
});
|
|
495
608
|
```
|
|
@@ -513,7 +626,7 @@ The WebSocket client supports three modes: real-time streaming, historical repla
|
|
|
513
626
|
```typescript
|
|
514
627
|
import { OxArchiveWs } from '@0xarchive/sdk';
|
|
515
628
|
|
|
516
|
-
const ws = new OxArchiveWs({ apiKey: '
|
|
629
|
+
const ws = new OxArchiveWs({ apiKey: '0xa_your_api_key' });
|
|
517
630
|
```
|
|
518
631
|
|
|
519
632
|
### Real-time Streaming
|
|
@@ -672,7 +785,7 @@ Gap thresholds vary by channel:
|
|
|
672
785
|
|
|
673
786
|
```typescript
|
|
674
787
|
const ws = new OxArchiveWs({
|
|
675
|
-
apiKey: '
|
|
788
|
+
apiKey: '0xa_your_api_key', // Required
|
|
676
789
|
wsUrl: 'wss://api.0xarchive.io/ws', // Optional
|
|
677
790
|
autoReconnect: true, // Auto-reconnect on disconnect (default: true)
|
|
678
791
|
reconnectDelay: 1000, // Initial reconnect delay in ms (default: 1000)
|
|
@@ -691,6 +804,8 @@ const ws = new OxArchiveWs({
|
|
|
691
804
|
| `trades` | Trade/fill updates | Yes | Yes |
|
|
692
805
|
| `candles` | OHLCV candle data | Yes | Yes (replay/stream only) |
|
|
693
806
|
| `liquidations` | Liquidation events (May 2025+) | Yes | Yes (replay/stream only) |
|
|
807
|
+
| `open_interest` | Open interest snapshots | Yes | Replay/stream only |
|
|
808
|
+
| `funding` | Funding rate snapshots | Yes | Replay/stream only |
|
|
694
809
|
| `ticker` | Price and 24h volume | Yes | Real-time only |
|
|
695
810
|
| `all_tickers` | All market tickers | No | Real-time only |
|
|
696
811
|
|
|
@@ -701,6 +816,8 @@ const ws = new OxArchiveWs({
|
|
|
701
816
|
| `hip3_orderbook` | HIP-3 L2 order book snapshots | Yes | Yes |
|
|
702
817
|
| `hip3_trades` | HIP-3 trade/fill updates | Yes | Yes |
|
|
703
818
|
| `hip3_candles` | HIP-3 OHLCV candle data | Yes | Yes |
|
|
819
|
+
| `hip3_open_interest` | HIP-3 open interest snapshots | Yes | Replay/stream only |
|
|
820
|
+
| `hip3_funding` | HIP-3 funding rate snapshots | Yes | Replay/stream only |
|
|
704
821
|
|
|
705
822
|
> **Note:** HIP-3 coins are case-sensitive (e.g., `km:US500`, `xyz:XYZ100`). Do not uppercase them.
|
|
706
823
|
|
|
@@ -711,6 +828,8 @@ const ws = new OxArchiveWs({
|
|
|
711
828
|
| `lighter_orderbook` | Lighter L2 order book (reconstructed) | Yes | Yes |
|
|
712
829
|
| `lighter_trades` | Lighter trade/fill updates | Yes | Yes |
|
|
713
830
|
| `lighter_candles` | Lighter OHLCV candle data | Yes | Yes |
|
|
831
|
+
| `lighter_open_interest` | Lighter open interest snapshots | Yes | Replay/stream only |
|
|
832
|
+
| `lighter_funding` | Lighter funding rate snapshots | Yes | Replay/stream only |
|
|
714
833
|
|
|
715
834
|
#### Candle Replay/Stream
|
|
716
835
|
|
|
@@ -765,6 +884,88 @@ ws.replay('hip3_candles', 'km:US500', {
|
|
|
765
884
|
});
|
|
766
885
|
```
|
|
767
886
|
|
|
887
|
+
### Multi-Channel Replay
|
|
888
|
+
|
|
889
|
+
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.
|
|
890
|
+
|
|
891
|
+
```typescript
|
|
892
|
+
const ws = new OxArchiveWs({ apiKey: 'ox_...' });
|
|
893
|
+
await ws.connect();
|
|
894
|
+
|
|
895
|
+
// Handle initial snapshots (sent before timeline data)
|
|
896
|
+
ws.onReplaySnapshot((channel, coin, timestamp, data) => {
|
|
897
|
+
console.log(`Initial ${channel} state at ${new Date(timestamp).toISOString()}`);
|
|
898
|
+
if (channel === 'orderbook') {
|
|
899
|
+
currentOrderbook = data;
|
|
900
|
+
} else if (channel === 'funding') {
|
|
901
|
+
currentFundingRate = data;
|
|
902
|
+
} else if (channel === 'open_interest') {
|
|
903
|
+
currentOI = data;
|
|
904
|
+
}
|
|
905
|
+
});
|
|
906
|
+
|
|
907
|
+
// Handle interleaved historical data
|
|
908
|
+
ws.onHistoricalData((coin, timestamp, data) => {
|
|
909
|
+
// The `channel` field on the raw message indicates which channel
|
|
910
|
+
// this data point belongs to
|
|
911
|
+
console.log(`${new Date(timestamp).toISOString()}: data received`);
|
|
912
|
+
});
|
|
913
|
+
|
|
914
|
+
ws.onReplayComplete((channel, coin, count) => {
|
|
915
|
+
console.log(`Replay complete: ${count} records`);
|
|
916
|
+
});
|
|
917
|
+
|
|
918
|
+
// Start multi-channel replay
|
|
919
|
+
ws.multiReplay(['orderbook', 'trades', 'funding'], 'BTC', {
|
|
920
|
+
start: Date.now() - 86400000,
|
|
921
|
+
end: Date.now(),
|
|
922
|
+
speed: 10
|
|
923
|
+
});
|
|
924
|
+
|
|
925
|
+
// Playback controls work the same as single-channel
|
|
926
|
+
ws.replayPause();
|
|
927
|
+
ws.replayResume();
|
|
928
|
+
ws.replaySeek(1704067200000);
|
|
929
|
+
ws.replayStop();
|
|
930
|
+
```
|
|
931
|
+
|
|
932
|
+
### Multi-Channel Bulk Stream
|
|
933
|
+
|
|
934
|
+
Stream multiple channels simultaneously for fast bulk download.
|
|
935
|
+
|
|
936
|
+
```typescript
|
|
937
|
+
const ws = new OxArchiveWs({ apiKey: 'ox_...' });
|
|
938
|
+
await ws.connect();
|
|
939
|
+
|
|
940
|
+
// Handle initial snapshots
|
|
941
|
+
ws.onReplaySnapshot((channel, coin, timestamp, data) => {
|
|
942
|
+
console.log(`Initial ${channel} snapshot`);
|
|
943
|
+
});
|
|
944
|
+
|
|
945
|
+
// Handle batched data from all channels
|
|
946
|
+
ws.onBatch((coin, records) => {
|
|
947
|
+
for (const record of records) {
|
|
948
|
+
// Process interleaved data from all channels
|
|
949
|
+
}
|
|
950
|
+
});
|
|
951
|
+
|
|
952
|
+
ws.onStreamComplete((channel, coin, count) => {
|
|
953
|
+
console.log(`Stream complete: ${count} records`);
|
|
954
|
+
});
|
|
955
|
+
|
|
956
|
+
// Start multi-channel stream
|
|
957
|
+
ws.multiStream(['orderbook', 'trades', 'open_interest', 'funding'], 'ETH', {
|
|
958
|
+
start: Date.now() - 3600000,
|
|
959
|
+
end: Date.now(),
|
|
960
|
+
batchSize: 1000
|
|
961
|
+
});
|
|
962
|
+
|
|
963
|
+
// Stop if needed
|
|
964
|
+
ws.streamStop();
|
|
965
|
+
```
|
|
966
|
+
|
|
967
|
+
**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.
|
|
968
|
+
|
|
768
969
|
### WebSocket Connection States
|
|
769
970
|
|
|
770
971
|
```typescript
|
|
@@ -830,10 +1031,15 @@ import type {
|
|
|
830
1031
|
FundingRate,
|
|
831
1032
|
OpenInterest,
|
|
832
1033
|
Liquidation,
|
|
1034
|
+
LiquidationVolume,
|
|
1035
|
+
CoinFreshness,
|
|
1036
|
+
CoinSummary,
|
|
1037
|
+
PriceSnapshot,
|
|
833
1038
|
CursorResponse,
|
|
834
1039
|
WsOptions,
|
|
835
1040
|
WsChannel,
|
|
836
1041
|
WsConnectionState,
|
|
1042
|
+
WsReplaySnapshot,
|
|
837
1043
|
// Orderbook reconstruction (Enterprise)
|
|
838
1044
|
OrderbookDelta,
|
|
839
1045
|
TickData,
|
|
@@ -852,7 +1058,7 @@ Enable Zod schema validation for API responses:
|
|
|
852
1058
|
|
|
853
1059
|
```typescript
|
|
854
1060
|
const client = new OxArchive({
|
|
855
|
-
apiKey: '
|
|
1061
|
+
apiKey: '0xa_your_api_key',
|
|
856
1062
|
validate: true // Enable runtime validation
|
|
857
1063
|
});
|
|
858
1064
|
```
|