@0xarchive/sdk 0.6.4 → 0.7.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 +43 -5
- package/dist/index.d.mts +71 -6
- package/dist/index.d.ts +71 -6
- package/dist/index.js +85 -4
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +85 -4
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -153,14 +153,24 @@ const tickData = await client.lighter.orderbook.historyTick('BTC', {
|
|
|
153
153
|
console.log(`Checkpoint: ${tickData.checkpoint.bids.length} bids`);
|
|
154
154
|
console.log(`Deltas: ${tickData.deltas.length} updates`);
|
|
155
155
|
|
|
156
|
-
// Option 3:
|
|
156
|
+
// Option 3: Auto-paginating iterator (recommended for large time ranges)
|
|
157
|
+
// Automatically handles pagination, fetching up to 1,000 deltas per request
|
|
158
|
+
for await (const snapshot of client.lighter.orderbook.iterateTickHistory('BTC', {
|
|
159
|
+
start: Date.now() - 86400000, // 24 hours of data
|
|
160
|
+
end: Date.now()
|
|
161
|
+
})) {
|
|
162
|
+
console.log(snapshot.timestamp, 'Mid:', snapshot.midPrice);
|
|
163
|
+
if (someCondition(snapshot)) break; // Early exit supported
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
// Option 4: Manual iteration (single page, for custom logic)
|
|
157
167
|
const reconstructor = client.lighter.orderbook.createReconstructor();
|
|
158
168
|
for (const snapshot of reconstructor.iterate(tickData.checkpoint, tickData.deltas)) {
|
|
159
169
|
// Process each snapshot without loading all into memory
|
|
160
170
|
if (someCondition(snapshot)) break; // Early exit if needed
|
|
161
171
|
}
|
|
162
172
|
|
|
163
|
-
// Option
|
|
173
|
+
// Option 5: Get only final state (most efficient)
|
|
164
174
|
const final = reconstructor.reconstructFinal(tickData.checkpoint, tickData.deltas);
|
|
165
175
|
|
|
166
176
|
// Check for sequence gaps
|
|
@@ -173,10 +183,13 @@ if (gaps.length > 0) {
|
|
|
173
183
|
**Methods:**
|
|
174
184
|
| Method | Description |
|
|
175
185
|
|--------|-------------|
|
|
176
|
-
| `historyTick(coin, params)` | Get raw checkpoint + deltas
|
|
177
|
-
| `historyReconstructed(coin, params, options)` | Get fully reconstructed snapshots |
|
|
186
|
+
| `historyTick(coin, params)` | Get raw checkpoint + deltas (single page, max 1,000 deltas) |
|
|
187
|
+
| `historyReconstructed(coin, params, options)` | Get fully reconstructed snapshots (single page) |
|
|
188
|
+
| `iterateTickHistory(coin, params, depth?)` | Auto-paginating async iterator for large time ranges |
|
|
178
189
|
| `createReconstructor()` | Create a reconstructor instance for manual control |
|
|
179
190
|
|
|
191
|
+
**Note:** The API returns a maximum of 1,000 deltas per request. For time ranges with more deltas, use `iterateTickHistory()` which handles pagination automatically.
|
|
192
|
+
|
|
180
193
|
**ReconstructOptions:**
|
|
181
194
|
| Option | Default | Description |
|
|
182
195
|
|--------|---------|-------------|
|
|
@@ -211,6 +224,8 @@ while (result.nextCursor) {
|
|
|
211
224
|
const recent = await client.lighter.trades.recent('BTC', 100);
|
|
212
225
|
```
|
|
213
226
|
|
|
227
|
+
**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.
|
|
228
|
+
|
|
214
229
|
### Instruments
|
|
215
230
|
|
|
216
231
|
```typescript
|
|
@@ -389,11 +404,25 @@ for (const exchange of coverage.exchanges) {
|
|
|
389
404
|
const btc = await client.dataQuality.symbolCoverage('hyperliquid', 'BTC');
|
|
390
405
|
const oi = btc.dataTypes.open_interest;
|
|
391
406
|
console.log(`BTC OI completeness: ${oi.completeness}%`);
|
|
407
|
+
console.log(`Historical coverage: ${oi.historicalCoverage}%`); // Hour-level granularity
|
|
392
408
|
console.log(`Gaps found: ${oi.gaps.length}`);
|
|
393
409
|
for (const gap of oi.gaps.slice(0, 5)) {
|
|
394
410
|
console.log(` ${gap.durationMinutes} min gap: ${gap.start} -> ${gap.end}`);
|
|
395
411
|
}
|
|
396
412
|
|
|
413
|
+
// Check empirical data cadence (when available)
|
|
414
|
+
const ob = btc.dataTypes.orderbook;
|
|
415
|
+
if (ob.cadence) {
|
|
416
|
+
console.log(`Orderbook cadence: ~${ob.cadence.medianIntervalSeconds}s median, p95=${ob.cadence.p95IntervalSeconds}s`);
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
// Time-bounded gap detection (last 7 days)
|
|
420
|
+
const weekAgo = Date.now() - 7 * 24 * 60 * 60 * 1000;
|
|
421
|
+
const btc7d = await client.dataQuality.symbolCoverage('hyperliquid', 'BTC', {
|
|
422
|
+
from: weekAgo,
|
|
423
|
+
to: Date.now(),
|
|
424
|
+
});
|
|
425
|
+
|
|
397
426
|
// List incidents with filtering
|
|
398
427
|
const result = await client.dataQuality.listIncidents({ status: 'open' });
|
|
399
428
|
for (const incident of result.incidents) {
|
|
@@ -420,12 +449,21 @@ console.log(`API P99: ${sla.actual.apiLatencyP99Ms}ms (${sla.actual.latencyStatu
|
|
|
420
449
|
| `status()` | Overall system health and per-exchange status |
|
|
421
450
|
| `coverage()` | Data coverage summary for all exchanges |
|
|
422
451
|
| `exchangeCoverage(exchange)` | Coverage details for a specific exchange |
|
|
423
|
-
| `symbolCoverage(exchange, symbol)` | Coverage with gap detection
|
|
452
|
+
| `symbolCoverage(exchange, symbol, options?)` | Coverage with gap detection, cadence, and historical coverage |
|
|
424
453
|
| `listIncidents(params)` | List incidents with filtering and pagination |
|
|
425
454
|
| `getIncident(incidentId)` | Get specific incident details |
|
|
426
455
|
| `latency()` | Current latency metrics (WebSocket, REST, data freshness) |
|
|
427
456
|
| `sla(params)` | SLA compliance metrics for a specific month |
|
|
428
457
|
|
|
458
|
+
**Note:** Data Quality endpoints (`coverage()`, `exchangeCoverage()`, `symbolCoverage()`) perform complex aggregation queries and may take 30-60 seconds on first request (results are cached server-side for 5 minutes). If you encounter timeout errors, create a client with a longer timeout:
|
|
459
|
+
|
|
460
|
+
```typescript
|
|
461
|
+
const client = new OxArchive({
|
|
462
|
+
apiKey: 'ox_your_api_key',
|
|
463
|
+
timeout: 60000 // 60 seconds for data quality endpoints
|
|
464
|
+
});
|
|
465
|
+
```
|
|
466
|
+
|
|
429
467
|
### Legacy API (Deprecated)
|
|
430
468
|
|
|
431
469
|
The following legacy methods are deprecated and will be removed in v2.0. They default to Hyperliquid data:
|
package/dist/index.d.mts
CHANGED
|
@@ -671,6 +671,15 @@ interface CoverageGap {
|
|
|
671
671
|
/** Duration of the gap in minutes */
|
|
672
672
|
durationMinutes: number;
|
|
673
673
|
}
|
|
674
|
+
/** Empirical data cadence measurement based on last 7 days of data */
|
|
675
|
+
interface DataCadence {
|
|
676
|
+
/** Median interval between consecutive records in seconds */
|
|
677
|
+
medianIntervalSeconds: number;
|
|
678
|
+
/** 95th percentile interval between consecutive records in seconds */
|
|
679
|
+
p95IntervalSeconds: number;
|
|
680
|
+
/** Number of intervals sampled for this measurement */
|
|
681
|
+
sampleCount: number;
|
|
682
|
+
}
|
|
674
683
|
/** Coverage for a specific symbol and data type */
|
|
675
684
|
interface SymbolDataTypeCoverage {
|
|
676
685
|
/** Earliest available data timestamp */
|
|
@@ -679,10 +688,21 @@ interface SymbolDataTypeCoverage {
|
|
|
679
688
|
latest: string;
|
|
680
689
|
/** Total number of records */
|
|
681
690
|
totalRecords: number;
|
|
682
|
-
/**
|
|
691
|
+
/** 24-hour completeness percentage (0-100) */
|
|
683
692
|
completeness: number;
|
|
684
|
-
/**
|
|
693
|
+
/** Historical coverage percentage (0-100) based on hours with data / total hours */
|
|
694
|
+
historicalCoverage?: number;
|
|
695
|
+
/** Detected data gaps within the requested time window */
|
|
685
696
|
gaps: CoverageGap[];
|
|
697
|
+
/** Empirical data cadence (present when sufficient data exists) */
|
|
698
|
+
cadence?: DataCadence;
|
|
699
|
+
}
|
|
700
|
+
/** Options for symbol coverage query */
|
|
701
|
+
interface SymbolCoverageOptions {
|
|
702
|
+
/** Start of gap detection window (Unix milliseconds). Default: now - 30 days */
|
|
703
|
+
from?: number;
|
|
704
|
+
/** End of gap detection window (Unix milliseconds). Default: now */
|
|
705
|
+
to?: number;
|
|
686
706
|
}
|
|
687
707
|
/** Per-symbol coverage response */
|
|
688
708
|
interface SymbolCoverageResponse {
|
|
@@ -1203,6 +1223,37 @@ declare class OrderBookResource {
|
|
|
1203
1223
|
* ```
|
|
1204
1224
|
*/
|
|
1205
1225
|
createReconstructor(): OrderBookReconstructor;
|
|
1226
|
+
/**
|
|
1227
|
+
* Iterate over tick-level orderbook history with automatic pagination (Enterprise tier only).
|
|
1228
|
+
*
|
|
1229
|
+
* This async generator automatically handles pagination, fetching up to 1,000 deltas
|
|
1230
|
+
* per API request and yielding reconstructed orderbook snapshots one at a time.
|
|
1231
|
+
* Memory-efficient for processing large time ranges.
|
|
1232
|
+
*
|
|
1233
|
+
* @param coin - The coin symbol (e.g., 'BTC', 'ETH')
|
|
1234
|
+
* @param params - Time range parameters
|
|
1235
|
+
* @param depth - Maximum price levels to include in output snapshots
|
|
1236
|
+
* @yields Reconstructed orderbook snapshots
|
|
1237
|
+
*
|
|
1238
|
+
* @example
|
|
1239
|
+
* ```typescript
|
|
1240
|
+
* // Process 24 hours of tick data with automatic pagination
|
|
1241
|
+
* for await (const snapshot of client.lighter.orderbook.iterateTickHistory('BTC', {
|
|
1242
|
+
* start: Date.now() - 86400000,
|
|
1243
|
+
* end: Date.now()
|
|
1244
|
+
* })) {
|
|
1245
|
+
* console.log(snapshot.timestamp, 'Mid:', snapshot.midPrice);
|
|
1246
|
+
* if (someCondition) break; // Early exit supported
|
|
1247
|
+
* }
|
|
1248
|
+
*
|
|
1249
|
+
* // Collect all snapshots (caution: may use significant memory for large ranges)
|
|
1250
|
+
* const allSnapshots: ReconstructedOrderBook[] = [];
|
|
1251
|
+
* for await (const snapshot of client.lighter.orderbook.iterateTickHistory('BTC', { start, end })) {
|
|
1252
|
+
* allSnapshots.push(snapshot);
|
|
1253
|
+
* }
|
|
1254
|
+
* ```
|
|
1255
|
+
*/
|
|
1256
|
+
iterateTickHistory(coin: string, params: TickHistoryParams, depth?: number): AsyncGenerator<ReconstructedOrderBook, void, undefined>;
|
|
1206
1257
|
}
|
|
1207
1258
|
|
|
1208
1259
|
/**
|
|
@@ -1627,11 +1678,13 @@ declare class DataQualityResource {
|
|
|
1627
1678
|
/**
|
|
1628
1679
|
* Get data coverage for a specific symbol on an exchange
|
|
1629
1680
|
*
|
|
1630
|
-
* Includes gap detection
|
|
1681
|
+
* Includes gap detection, empirical data cadence, and hour-level historical coverage.
|
|
1682
|
+
* Supports optional time bounds for gap detection (default: last 30 days).
|
|
1631
1683
|
*
|
|
1632
1684
|
* @param exchange - Exchange name ('hyperliquid' or 'lighter')
|
|
1633
1685
|
* @param symbol - Symbol name (e.g., 'BTC', 'ETH')
|
|
1634
|
-
* @
|
|
1686
|
+
* @param options - Optional time bounds for gap detection window
|
|
1687
|
+
* @returns SymbolCoverageResponse with per-data-type coverage including gaps, cadence, and historical coverage
|
|
1635
1688
|
*
|
|
1636
1689
|
* @example
|
|
1637
1690
|
* ```typescript
|
|
@@ -1642,9 +1695,21 @@ declare class DataQualityResource {
|
|
|
1642
1695
|
* for (const gap of oi.gaps.slice(0, 3)) {
|
|
1643
1696
|
* console.log(` ${gap.durationMinutes} min gap at ${gap.start}`);
|
|
1644
1697
|
* }
|
|
1698
|
+
*
|
|
1699
|
+
* // Check cadence
|
|
1700
|
+
* if (btc.dataTypes.orderbook.cadence) {
|
|
1701
|
+
* console.log(`Cadence: ~${btc.dataTypes.orderbook.cadence.medianIntervalSeconds}s`);
|
|
1702
|
+
* }
|
|
1703
|
+
*
|
|
1704
|
+
* // Time-bounded (last 7 days)
|
|
1705
|
+
* const weekAgo = Date.now() - 7 * 24 * 60 * 60 * 1000;
|
|
1706
|
+
* const btc7d = await client.dataQuality.symbolCoverage('hyperliquid', 'BTC', {
|
|
1707
|
+
* from: weekAgo,
|
|
1708
|
+
* to: Date.now(),
|
|
1709
|
+
* });
|
|
1645
1710
|
* ```
|
|
1646
1711
|
*/
|
|
1647
|
-
symbolCoverage(exchange: string, symbol: string): Promise<SymbolCoverageResponse>;
|
|
1712
|
+
symbolCoverage(exchange: string, symbol: string, options?: SymbolCoverageOptions): Promise<SymbolCoverageResponse>;
|
|
1648
1713
|
/**
|
|
1649
1714
|
* List incidents with filtering and pagination
|
|
1650
1715
|
*
|
|
@@ -3964,4 +4029,4 @@ type ValidatedCandle = z.infer<typeof CandleSchema>;
|
|
|
3964
4029
|
type ValidatedLiquidation = z.infer<typeof LiquidationSchema>;
|
|
3965
4030
|
type ValidatedWsServerMessage = z.infer<typeof WsServerMessageSchema>;
|
|
3966
4031
|
|
|
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 };
|
|
4032
|
+
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 DataCadence, 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 SymbolCoverageOptions, 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
|
@@ -671,6 +671,15 @@ interface CoverageGap {
|
|
|
671
671
|
/** Duration of the gap in minutes */
|
|
672
672
|
durationMinutes: number;
|
|
673
673
|
}
|
|
674
|
+
/** Empirical data cadence measurement based on last 7 days of data */
|
|
675
|
+
interface DataCadence {
|
|
676
|
+
/** Median interval between consecutive records in seconds */
|
|
677
|
+
medianIntervalSeconds: number;
|
|
678
|
+
/** 95th percentile interval between consecutive records in seconds */
|
|
679
|
+
p95IntervalSeconds: number;
|
|
680
|
+
/** Number of intervals sampled for this measurement */
|
|
681
|
+
sampleCount: number;
|
|
682
|
+
}
|
|
674
683
|
/** Coverage for a specific symbol and data type */
|
|
675
684
|
interface SymbolDataTypeCoverage {
|
|
676
685
|
/** Earliest available data timestamp */
|
|
@@ -679,10 +688,21 @@ interface SymbolDataTypeCoverage {
|
|
|
679
688
|
latest: string;
|
|
680
689
|
/** Total number of records */
|
|
681
690
|
totalRecords: number;
|
|
682
|
-
/**
|
|
691
|
+
/** 24-hour completeness percentage (0-100) */
|
|
683
692
|
completeness: number;
|
|
684
|
-
/**
|
|
693
|
+
/** Historical coverage percentage (0-100) based on hours with data / total hours */
|
|
694
|
+
historicalCoverage?: number;
|
|
695
|
+
/** Detected data gaps within the requested time window */
|
|
685
696
|
gaps: CoverageGap[];
|
|
697
|
+
/** Empirical data cadence (present when sufficient data exists) */
|
|
698
|
+
cadence?: DataCadence;
|
|
699
|
+
}
|
|
700
|
+
/** Options for symbol coverage query */
|
|
701
|
+
interface SymbolCoverageOptions {
|
|
702
|
+
/** Start of gap detection window (Unix milliseconds). Default: now - 30 days */
|
|
703
|
+
from?: number;
|
|
704
|
+
/** End of gap detection window (Unix milliseconds). Default: now */
|
|
705
|
+
to?: number;
|
|
686
706
|
}
|
|
687
707
|
/** Per-symbol coverage response */
|
|
688
708
|
interface SymbolCoverageResponse {
|
|
@@ -1203,6 +1223,37 @@ declare class OrderBookResource {
|
|
|
1203
1223
|
* ```
|
|
1204
1224
|
*/
|
|
1205
1225
|
createReconstructor(): OrderBookReconstructor;
|
|
1226
|
+
/**
|
|
1227
|
+
* Iterate over tick-level orderbook history with automatic pagination (Enterprise tier only).
|
|
1228
|
+
*
|
|
1229
|
+
* This async generator automatically handles pagination, fetching up to 1,000 deltas
|
|
1230
|
+
* per API request and yielding reconstructed orderbook snapshots one at a time.
|
|
1231
|
+
* Memory-efficient for processing large time ranges.
|
|
1232
|
+
*
|
|
1233
|
+
* @param coin - The coin symbol (e.g., 'BTC', 'ETH')
|
|
1234
|
+
* @param params - Time range parameters
|
|
1235
|
+
* @param depth - Maximum price levels to include in output snapshots
|
|
1236
|
+
* @yields Reconstructed orderbook snapshots
|
|
1237
|
+
*
|
|
1238
|
+
* @example
|
|
1239
|
+
* ```typescript
|
|
1240
|
+
* // Process 24 hours of tick data with automatic pagination
|
|
1241
|
+
* for await (const snapshot of client.lighter.orderbook.iterateTickHistory('BTC', {
|
|
1242
|
+
* start: Date.now() - 86400000,
|
|
1243
|
+
* end: Date.now()
|
|
1244
|
+
* })) {
|
|
1245
|
+
* console.log(snapshot.timestamp, 'Mid:', snapshot.midPrice);
|
|
1246
|
+
* if (someCondition) break; // Early exit supported
|
|
1247
|
+
* }
|
|
1248
|
+
*
|
|
1249
|
+
* // Collect all snapshots (caution: may use significant memory for large ranges)
|
|
1250
|
+
* const allSnapshots: ReconstructedOrderBook[] = [];
|
|
1251
|
+
* for await (const snapshot of client.lighter.orderbook.iterateTickHistory('BTC', { start, end })) {
|
|
1252
|
+
* allSnapshots.push(snapshot);
|
|
1253
|
+
* }
|
|
1254
|
+
* ```
|
|
1255
|
+
*/
|
|
1256
|
+
iterateTickHistory(coin: string, params: TickHistoryParams, depth?: number): AsyncGenerator<ReconstructedOrderBook, void, undefined>;
|
|
1206
1257
|
}
|
|
1207
1258
|
|
|
1208
1259
|
/**
|
|
@@ -1627,11 +1678,13 @@ declare class DataQualityResource {
|
|
|
1627
1678
|
/**
|
|
1628
1679
|
* Get data coverage for a specific symbol on an exchange
|
|
1629
1680
|
*
|
|
1630
|
-
* Includes gap detection
|
|
1681
|
+
* Includes gap detection, empirical data cadence, and hour-level historical coverage.
|
|
1682
|
+
* Supports optional time bounds for gap detection (default: last 30 days).
|
|
1631
1683
|
*
|
|
1632
1684
|
* @param exchange - Exchange name ('hyperliquid' or 'lighter')
|
|
1633
1685
|
* @param symbol - Symbol name (e.g., 'BTC', 'ETH')
|
|
1634
|
-
* @
|
|
1686
|
+
* @param options - Optional time bounds for gap detection window
|
|
1687
|
+
* @returns SymbolCoverageResponse with per-data-type coverage including gaps, cadence, and historical coverage
|
|
1635
1688
|
*
|
|
1636
1689
|
* @example
|
|
1637
1690
|
* ```typescript
|
|
@@ -1642,9 +1695,21 @@ declare class DataQualityResource {
|
|
|
1642
1695
|
* for (const gap of oi.gaps.slice(0, 3)) {
|
|
1643
1696
|
* console.log(` ${gap.durationMinutes} min gap at ${gap.start}`);
|
|
1644
1697
|
* }
|
|
1698
|
+
*
|
|
1699
|
+
* // Check cadence
|
|
1700
|
+
* if (btc.dataTypes.orderbook.cadence) {
|
|
1701
|
+
* console.log(`Cadence: ~${btc.dataTypes.orderbook.cadence.medianIntervalSeconds}s`);
|
|
1702
|
+
* }
|
|
1703
|
+
*
|
|
1704
|
+
* // Time-bounded (last 7 days)
|
|
1705
|
+
* const weekAgo = Date.now() - 7 * 24 * 60 * 60 * 1000;
|
|
1706
|
+
* const btc7d = await client.dataQuality.symbolCoverage('hyperliquid', 'BTC', {
|
|
1707
|
+
* from: weekAgo,
|
|
1708
|
+
* to: Date.now(),
|
|
1709
|
+
* });
|
|
1645
1710
|
* ```
|
|
1646
1711
|
*/
|
|
1647
|
-
symbolCoverage(exchange: string, symbol: string): Promise<SymbolCoverageResponse>;
|
|
1712
|
+
symbolCoverage(exchange: string, symbol: string, options?: SymbolCoverageOptions): Promise<SymbolCoverageResponse>;
|
|
1648
1713
|
/**
|
|
1649
1714
|
* List incidents with filtering and pagination
|
|
1650
1715
|
*
|
|
@@ -3964,4 +4029,4 @@ type ValidatedCandle = z.infer<typeof CandleSchema>;
|
|
|
3964
4029
|
type ValidatedLiquidation = z.infer<typeof LiquidationSchema>;
|
|
3965
4030
|
type ValidatedWsServerMessage = z.infer<typeof WsServerMessageSchema>;
|
|
3966
4031
|
|
|
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 };
|
|
4032
|
+
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 DataCadence, 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 SymbolCoverageOptions, 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.js
CHANGED
|
@@ -767,6 +767,72 @@ var OrderBookResource = class {
|
|
|
767
767
|
createReconstructor() {
|
|
768
768
|
return new OrderBookReconstructor();
|
|
769
769
|
}
|
|
770
|
+
/**
|
|
771
|
+
* Iterate over tick-level orderbook history with automatic pagination (Enterprise tier only).
|
|
772
|
+
*
|
|
773
|
+
* This async generator automatically handles pagination, fetching up to 1,000 deltas
|
|
774
|
+
* per API request and yielding reconstructed orderbook snapshots one at a time.
|
|
775
|
+
* Memory-efficient for processing large time ranges.
|
|
776
|
+
*
|
|
777
|
+
* @param coin - The coin symbol (e.g., 'BTC', 'ETH')
|
|
778
|
+
* @param params - Time range parameters
|
|
779
|
+
* @param depth - Maximum price levels to include in output snapshots
|
|
780
|
+
* @yields Reconstructed orderbook snapshots
|
|
781
|
+
*
|
|
782
|
+
* @example
|
|
783
|
+
* ```typescript
|
|
784
|
+
* // Process 24 hours of tick data with automatic pagination
|
|
785
|
+
* for await (const snapshot of client.lighter.orderbook.iterateTickHistory('BTC', {
|
|
786
|
+
* start: Date.now() - 86400000,
|
|
787
|
+
* end: Date.now()
|
|
788
|
+
* })) {
|
|
789
|
+
* console.log(snapshot.timestamp, 'Mid:', snapshot.midPrice);
|
|
790
|
+
* if (someCondition) break; // Early exit supported
|
|
791
|
+
* }
|
|
792
|
+
*
|
|
793
|
+
* // Collect all snapshots (caution: may use significant memory for large ranges)
|
|
794
|
+
* const allSnapshots: ReconstructedOrderBook[] = [];
|
|
795
|
+
* for await (const snapshot of client.lighter.orderbook.iterateTickHistory('BTC', { start, end })) {
|
|
796
|
+
* allSnapshots.push(snapshot);
|
|
797
|
+
* }
|
|
798
|
+
* ```
|
|
799
|
+
*/
|
|
800
|
+
async *iterateTickHistory(coin, params, depth) {
|
|
801
|
+
const startTs = typeof params.start === "string" ? new Date(params.start).getTime() : params.start;
|
|
802
|
+
const endTs = typeof params.end === "string" ? new Date(params.end).getTime() : params.end;
|
|
803
|
+
let cursor = startTs;
|
|
804
|
+
const reconstructor = new OrderBookReconstructor();
|
|
805
|
+
const MAX_DELTAS_PER_PAGE = 1e3;
|
|
806
|
+
let isFirstPage = true;
|
|
807
|
+
while (cursor < endTs) {
|
|
808
|
+
const tickData = await this.historyTick(coin, {
|
|
809
|
+
start: cursor,
|
|
810
|
+
end: endTs,
|
|
811
|
+
depth: params.depth
|
|
812
|
+
});
|
|
813
|
+
if (tickData.deltas.length === 0) {
|
|
814
|
+
if (isFirstPage) {
|
|
815
|
+
reconstructor.initialize(tickData.checkpoint);
|
|
816
|
+
yield reconstructor.getSnapshot(depth);
|
|
817
|
+
}
|
|
818
|
+
break;
|
|
819
|
+
}
|
|
820
|
+
let skipFirst = !isFirstPage;
|
|
821
|
+
for (const snapshot of reconstructor.iterate(tickData.checkpoint, tickData.deltas, { depth })) {
|
|
822
|
+
if (skipFirst) {
|
|
823
|
+
skipFirst = false;
|
|
824
|
+
continue;
|
|
825
|
+
}
|
|
826
|
+
yield snapshot;
|
|
827
|
+
}
|
|
828
|
+
isFirstPage = false;
|
|
829
|
+
const lastDelta = tickData.deltas[tickData.deltas.length - 1];
|
|
830
|
+
cursor = lastDelta.timestamp + 1;
|
|
831
|
+
if (tickData.deltas.length < MAX_DELTAS_PER_PAGE) {
|
|
832
|
+
break;
|
|
833
|
+
}
|
|
834
|
+
}
|
|
835
|
+
}
|
|
770
836
|
};
|
|
771
837
|
|
|
772
838
|
// src/resources/trades.ts
|
|
@@ -1124,11 +1190,13 @@ var DataQualityResource = class {
|
|
|
1124
1190
|
/**
|
|
1125
1191
|
* Get data coverage for a specific symbol on an exchange
|
|
1126
1192
|
*
|
|
1127
|
-
* Includes gap detection
|
|
1193
|
+
* Includes gap detection, empirical data cadence, and hour-level historical coverage.
|
|
1194
|
+
* Supports optional time bounds for gap detection (default: last 30 days).
|
|
1128
1195
|
*
|
|
1129
1196
|
* @param exchange - Exchange name ('hyperliquid' or 'lighter')
|
|
1130
1197
|
* @param symbol - Symbol name (e.g., 'BTC', 'ETH')
|
|
1131
|
-
* @
|
|
1198
|
+
* @param options - Optional time bounds for gap detection window
|
|
1199
|
+
* @returns SymbolCoverageResponse with per-data-type coverage including gaps, cadence, and historical coverage
|
|
1132
1200
|
*
|
|
1133
1201
|
* @example
|
|
1134
1202
|
* ```typescript
|
|
@@ -1139,11 +1207,24 @@ var DataQualityResource = class {
|
|
|
1139
1207
|
* for (const gap of oi.gaps.slice(0, 3)) {
|
|
1140
1208
|
* console.log(` ${gap.durationMinutes} min gap at ${gap.start}`);
|
|
1141
1209
|
* }
|
|
1210
|
+
*
|
|
1211
|
+
* // Check cadence
|
|
1212
|
+
* if (btc.dataTypes.orderbook.cadence) {
|
|
1213
|
+
* console.log(`Cadence: ~${btc.dataTypes.orderbook.cadence.medianIntervalSeconds}s`);
|
|
1214
|
+
* }
|
|
1215
|
+
*
|
|
1216
|
+
* // Time-bounded (last 7 days)
|
|
1217
|
+
* const weekAgo = Date.now() - 7 * 24 * 60 * 60 * 1000;
|
|
1218
|
+
* const btc7d = await client.dataQuality.symbolCoverage('hyperliquid', 'BTC', {
|
|
1219
|
+
* from: weekAgo,
|
|
1220
|
+
* to: Date.now(),
|
|
1221
|
+
* });
|
|
1142
1222
|
* ```
|
|
1143
1223
|
*/
|
|
1144
|
-
async symbolCoverage(exchange, symbol) {
|
|
1224
|
+
async symbolCoverage(exchange, symbol, options) {
|
|
1145
1225
|
return this.http.get(
|
|
1146
|
-
`${this.basePath}/coverage/${exchange.toLowerCase()}/${symbol.toUpperCase()}
|
|
1226
|
+
`${this.basePath}/coverage/${exchange.toLowerCase()}/${symbol.toUpperCase()}`,
|
|
1227
|
+
options
|
|
1147
1228
|
);
|
|
1148
1229
|
}
|
|
1149
1230
|
// ===========================================================================
|