@0xarchive/sdk 1.2.0 → 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 +36 -0
- package/dist/index.d.mts +155 -1
- package/dist/index.d.ts +155 -1
- package/dist/index.js +189 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +187 -0
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -568,6 +568,38 @@ while (l3History.nextCursor) {
|
|
|
568
568
|
}
|
|
569
569
|
```
|
|
570
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');
|
|
601
|
+
```
|
|
602
|
+
|
|
571
603
|
### Freshness
|
|
572
604
|
|
|
573
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.
|
|
@@ -1066,6 +1098,8 @@ const ws = new OxArchiveWs({
|
|
|
1066
1098
|
| `funding` | Funding rate snapshots | Yes | Replay/stream only |
|
|
1067
1099
|
| `ticker` | Price and 24h volume | Yes | Real-time only |
|
|
1068
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 |
|
|
1069
1103
|
|
|
1070
1104
|
#### HIP-3 Builder Perps Channels
|
|
1071
1105
|
|
|
@@ -1077,6 +1111,8 @@ const ws = new OxArchiveWs({
|
|
|
1077
1111
|
| `hip3_open_interest` | HIP-3 open interest snapshots | Yes | Replay/stream only |
|
|
1078
1112
|
| `hip3_funding` | HIP-3 funding rate snapshots | Yes | Replay/stream only |
|
|
1079
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 |
|
|
1080
1116
|
|
|
1081
1117
|
> **Note:** HIP-3 coins are case-sensitive (e.g., `km:US500`, `xyz:XYZ100`). Do not uppercase them.
|
|
1082
1118
|
|
package/dist/index.d.mts
CHANGED
|
@@ -2288,6 +2288,49 @@ declare class L4OrderBookResource {
|
|
|
2288
2288
|
history(symbol: string, params: CursorPaginationParams): Promise<CursorResponse<any[]>>;
|
|
2289
2289
|
}
|
|
2290
2290
|
|
|
2291
|
+
interface L2OrderBookParams {
|
|
2292
|
+
timestamp?: number | string;
|
|
2293
|
+
depth?: number;
|
|
2294
|
+
}
|
|
2295
|
+
/**
|
|
2296
|
+
* L2 Full-Depth Order Book API resource (derived from L4 data)
|
|
2297
|
+
*
|
|
2298
|
+
* Access aggregated price-level orderbook snapshots, history, and tick-level diffs.
|
|
2299
|
+
* Data available from March 10, 2026.
|
|
2300
|
+
*
|
|
2301
|
+
* @example
|
|
2302
|
+
* ```typescript
|
|
2303
|
+
* // Get current full-depth L2 orderbook
|
|
2304
|
+
* const orderbook = await client.hyperliquid.l2Orderbook.get('BTC');
|
|
2305
|
+
*
|
|
2306
|
+
* // Get L2 orderbook at a historical timestamp
|
|
2307
|
+
* const historical = await client.hyperliquid.l2Orderbook.get('BTC', {
|
|
2308
|
+
* timestamp: 1711900800000
|
|
2309
|
+
* });
|
|
2310
|
+
*
|
|
2311
|
+
* // Get L2 orderbook history
|
|
2312
|
+
* const history = await client.hyperliquid.l2Orderbook.history('BTC', {
|
|
2313
|
+
* start: Date.now() - 86400000,
|
|
2314
|
+
* end: Date.now(),
|
|
2315
|
+
* limit: 100
|
|
2316
|
+
* });
|
|
2317
|
+
* ```
|
|
2318
|
+
*/
|
|
2319
|
+
declare class L2OrderBookResource {
|
|
2320
|
+
private http;
|
|
2321
|
+
private basePath;
|
|
2322
|
+
private coinTransform;
|
|
2323
|
+
constructor(http: HttpClient, basePath?: string, coinTransform?: (s: string) => string);
|
|
2324
|
+
/** Get full-depth L2 order book snapshot. */
|
|
2325
|
+
get(symbol: string, params?: L2OrderBookParams): Promise<any>;
|
|
2326
|
+
/** Get paginated L2 full-depth history. */
|
|
2327
|
+
history(symbol: string, params: CursorPaginationParams & {
|
|
2328
|
+
depth?: number;
|
|
2329
|
+
}): Promise<CursorResponse<any[]>>;
|
|
2330
|
+
/** Get tick-level L2 order book diffs. */
|
|
2331
|
+
diffs(symbol: string, params: CursorPaginationParams): Promise<CursorResponse<any[]>>;
|
|
2332
|
+
}
|
|
2333
|
+
|
|
2291
2334
|
interface L3OrderBookParams {
|
|
2292
2335
|
timestamp?: number | string;
|
|
2293
2336
|
depth?: number;
|
|
@@ -2382,6 +2425,10 @@ declare class HyperliquidClient {
|
|
|
2382
2425
|
* L4 order book (snapshots, diffs, history)
|
|
2383
2426
|
*/
|
|
2384
2427
|
readonly l4Orderbook: L4OrderBookResource;
|
|
2428
|
+
/**
|
|
2429
|
+
* L2 full-depth order book (derived from L4)
|
|
2430
|
+
*/
|
|
2431
|
+
readonly l2Orderbook: L2OrderBookResource;
|
|
2385
2432
|
/**
|
|
2386
2433
|
* HIP-3 builder-deployed perpetuals (February 2026+)
|
|
2387
2434
|
*/
|
|
@@ -2461,6 +2508,10 @@ declare class Hip3Client {
|
|
|
2461
2508
|
* L4 order book (snapshots, diffs, history)
|
|
2462
2509
|
*/
|
|
2463
2510
|
readonly l4Orderbook: L4OrderBookResource;
|
|
2511
|
+
/**
|
|
2512
|
+
* L2 full-depth order book (derived from L4)
|
|
2513
|
+
*/
|
|
2514
|
+
readonly l2Orderbook: L2OrderBookResource;
|
|
2464
2515
|
private http;
|
|
2465
2516
|
constructor(http: HttpClient);
|
|
2466
2517
|
/**
|
|
@@ -3003,6 +3054,109 @@ declare class OxArchiveWs {
|
|
|
3003
3054
|
private handleMessage;
|
|
3004
3055
|
}
|
|
3005
3056
|
|
|
3057
|
+
/**
|
|
3058
|
+
* L4 order book reconstructor with matching engine.
|
|
3059
|
+
*
|
|
3060
|
+
* Reconstructs Hyperliquid and HIP-3 L4 order books from checkpoints and diffs.
|
|
3061
|
+
* The same class works for both exchanges — the diff format is identical.
|
|
3062
|
+
*
|
|
3063
|
+
* When a new order crosses the spread, the matching engine filled opposite-side
|
|
3064
|
+
* orders at crossing prices. Without removing them, the reconstructed book will
|
|
3065
|
+
* be "crossed" (best bid > best ask).
|
|
3066
|
+
*
|
|
3067
|
+
* Ref: https://github.com/hyperliquid-dex/order_book_server
|
|
3068
|
+
*/
|
|
3069
|
+
interface L4Order {
|
|
3070
|
+
oid: number;
|
|
3071
|
+
userAddress: string;
|
|
3072
|
+
side: 'B' | 'A';
|
|
3073
|
+
price: number;
|
|
3074
|
+
size: number;
|
|
3075
|
+
}
|
|
3076
|
+
interface L2Level {
|
|
3077
|
+
px: number;
|
|
3078
|
+
sz: number;
|
|
3079
|
+
n: number;
|
|
3080
|
+
}
|
|
3081
|
+
interface L4Diff {
|
|
3082
|
+
diff_type?: 'new' | 'update' | 'remove';
|
|
3083
|
+
diffType?: 'new' | 'update' | 'remove';
|
|
3084
|
+
oid: number;
|
|
3085
|
+
side: 'B' | 'A';
|
|
3086
|
+
price: number;
|
|
3087
|
+
new_size?: number | null;
|
|
3088
|
+
newSize?: number | null;
|
|
3089
|
+
user_address?: string;
|
|
3090
|
+
userAddress?: string;
|
|
3091
|
+
block_number?: number;
|
|
3092
|
+
blockNumber?: number;
|
|
3093
|
+
}
|
|
3094
|
+
interface L4Checkpoint {
|
|
3095
|
+
bids: Array<{
|
|
3096
|
+
oid: number;
|
|
3097
|
+
user_address?: string;
|
|
3098
|
+
userAddress?: string;
|
|
3099
|
+
side: string;
|
|
3100
|
+
price: number;
|
|
3101
|
+
size: number;
|
|
3102
|
+
}>;
|
|
3103
|
+
asks: Array<{
|
|
3104
|
+
oid: number;
|
|
3105
|
+
user_address?: string;
|
|
3106
|
+
userAddress?: string;
|
|
3107
|
+
side: string;
|
|
3108
|
+
price: number;
|
|
3109
|
+
size: number;
|
|
3110
|
+
}>;
|
|
3111
|
+
}
|
|
3112
|
+
/**
|
|
3113
|
+
* L4 orderbook reconstructor with matching engine.
|
|
3114
|
+
*
|
|
3115
|
+
* Works identically for Hyperliquid and HIP-3 — same diff format,
|
|
3116
|
+
* same checkpoint format, same crossing logic.
|
|
3117
|
+
*
|
|
3118
|
+
* @example
|
|
3119
|
+
* ```typescript
|
|
3120
|
+
* const book = new L4OrderBookReconstructor();
|
|
3121
|
+
* book.loadCheckpoint(checkpoint);
|
|
3122
|
+
*
|
|
3123
|
+
* // Group diffs by block, apply in order
|
|
3124
|
+
* for (const bn of sortedBlockNumbers) {
|
|
3125
|
+
* const nr = nonRestingByBlock.get(bn);
|
|
3126
|
+
* for (const diff of blocks.get(bn)!) {
|
|
3127
|
+
* book.applyDiff(diff, nr);
|
|
3128
|
+
* }
|
|
3129
|
+
* }
|
|
3130
|
+
*
|
|
3131
|
+
* console.log(book.isCrossed()); // false
|
|
3132
|
+
* const { bids: l2Bids, asks: l2Asks } = book.deriveL2();
|
|
3133
|
+
* ```
|
|
3134
|
+
*/
|
|
3135
|
+
declare class L4OrderBookReconstructor {
|
|
3136
|
+
private orders;
|
|
3137
|
+
private bidPrices;
|
|
3138
|
+
private askPrices;
|
|
3139
|
+
/** Initialize from an L4 checkpoint. */
|
|
3140
|
+
loadCheckpoint(checkpoint: L4Checkpoint): void;
|
|
3141
|
+
/** Apply a single L4 diff with matching engine. */
|
|
3142
|
+
applyDiff(diff: L4Diff, nonRestingOids?: Set<number>): void;
|
|
3143
|
+
/** Return bids sorted by price descending. */
|
|
3144
|
+
bids(): L4Order[];
|
|
3145
|
+
/** Return asks sorted by price ascending. */
|
|
3146
|
+
asks(): L4Order[];
|
|
3147
|
+
bestBid(): number | null;
|
|
3148
|
+
bestAsk(): number | null;
|
|
3149
|
+
/** Check if the book is crossed. Should be false after correct reconstruction. */
|
|
3150
|
+
isCrossed(): boolean;
|
|
3151
|
+
get bidCount(): number;
|
|
3152
|
+
get askCount(): number;
|
|
3153
|
+
/** Aggregate L4 orders into L2 price levels. */
|
|
3154
|
+
deriveL2(): {
|
|
3155
|
+
bids: L2Level[];
|
|
3156
|
+
asks: L2Level[];
|
|
3157
|
+
};
|
|
3158
|
+
}
|
|
3159
|
+
|
|
3006
3160
|
/**
|
|
3007
3161
|
* Zod schemas for runtime validation of API responses
|
|
3008
3162
|
*
|
|
@@ -5462,4 +5616,4 @@ type ValidatedCandle = z.infer<typeof CandleSchema>;
|
|
|
5462
5616
|
type ValidatedLiquidation = z.infer<typeof LiquidationSchema>;
|
|
5463
5617
|
type ValidatedWsServerMessage = z.infer<typeof WsServerMessageSchema>;
|
|
5464
5618
|
|
|
5465
|
-
export { type ApiError, type ApiMeta, ApiMetaSchema, type ApiResponse, ApiResponseSchema, type Candle, CandleArrayResponseSchema, type CandleHistoryParams, type CandleInterval, CandleIntervalSchema, CandleSchema, type ClientOptions, type CoinFreshness, CoinFreshnessResponseSchema, CoinFreshnessSchema, type CoinSummary, CoinSummaryResponseSchema, CoinSummarySchema, type CompletenessMetrics, type CoverageGap, type CoverageResponse, type CursorResponse, type DataCadence, type DataFreshness, type DataTypeCoverage, type DataTypeFreshnessInfo, DataTypeFreshnessInfoSchema, type DataTypeStatus, type ExchangeCoverage, type ExchangeLatency, type ExchangeStatus, type FundingHistoryParams, type FundingRate, FundingRateArrayResponseSchema, FundingRateResponseSchema, FundingRateSchema, type GetOrderBookParams, type GetTradesCursorParams, Hip3Client, type Hip3Instrument, 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 LiquidationVolume, LiquidationVolumeArrayResponseSchema, type LiquidationVolumeParams, LiquidationVolumeSchema, type LiquidationsByUserParams, type ListIncidentsParams, type OiFundingInterval, type OpenInterest, OpenInterestArrayResponseSchema, type OpenInterestHistoryParams, OpenInterestResponseSchema, OpenInterestSchema, type OrderBook, OrderBookArrayResponseSchema, type OrderBookHistoryParams, OrderBookReconstructor, OrderBookResponseSchema, OrderBookSchema, type OrderbookDelta, OxArchive, OxArchiveError, OxArchiveWs, type Pagination, type PriceHistoryParams, type PriceLevel, PriceLevelSchema, type PriceSnapshot, PriceSnapshotArrayResponseSchema, PriceSnapshotSchema, type ReconstructOptions, type ReconstructedOrderBook, type RestApiLatency, type SiweChallenge, 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 Web3ApiKey, type Web3KeysList, type Web3PaymentRequired, type Web3RevokeResult, type Web3SignupResult, type Web3SubscribeResult, type WebSocketLatency, type WsChannel, WsChannelSchema, type WsClientMessage, type WsConnectionState, WsConnectionStateSchema, type WsData, WsDataSchema, type WsError, WsErrorSchema, type WsEventHandlers, type WsGapDetected, type WsHistoricalBatch, WsHistoricalBatchSchema, type WsHistoricalData, WsHistoricalDataSchema, type WsHistoricalTickData, type WsL4Batch, type WsL4Snapshot, 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 WsReplaySnapshot, WsReplaySnapshotSchema, 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 };
|
|
5619
|
+
export { type ApiError, type ApiMeta, ApiMetaSchema, type ApiResponse, ApiResponseSchema, type Candle, CandleArrayResponseSchema, type CandleHistoryParams, type CandleInterval, CandleIntervalSchema, CandleSchema, type ClientOptions, type CoinFreshness, CoinFreshnessResponseSchema, CoinFreshnessSchema, type CoinSummary, CoinSummaryResponseSchema, CoinSummarySchema, type CompletenessMetrics, type CoverageGap, type CoverageResponse, type CursorResponse, type DataCadence, type DataFreshness, type DataTypeCoverage, type DataTypeFreshnessInfo, DataTypeFreshnessInfoSchema, type DataTypeStatus, type ExchangeCoverage, type ExchangeLatency, type ExchangeStatus, type FundingHistoryParams, type FundingRate, FundingRateArrayResponseSchema, FundingRateResponseSchema, FundingRateSchema, type GetOrderBookParams, type GetTradesCursorParams, Hip3Client, type Hip3Instrument, HyperliquidClient, type Incident, type IncidentSeverityValue, type IncidentStatusValue, type IncidentsResponse, type Instrument, InstrumentArrayResponseSchema, InstrumentResponseSchema, InstrumentSchema, type InstrumentType, InstrumentTypeSchema, type L2Level, type L2OrderBookParams, L2OrderBookResource, type L4Checkpoint, type L4Diff, type L4Order, L4OrderBookReconstructor, type LatencyResponse, LighterClient, type LighterGranularity, type LighterInstrument, type Liquidation, LiquidationArrayResponseSchema, type LiquidationHistoryParams, LiquidationSchema, LiquidationSideSchema, type LiquidationVolume, LiquidationVolumeArrayResponseSchema, type LiquidationVolumeParams, LiquidationVolumeSchema, type LiquidationsByUserParams, type ListIncidentsParams, type OiFundingInterval, type OpenInterest, OpenInterestArrayResponseSchema, type OpenInterestHistoryParams, OpenInterestResponseSchema, OpenInterestSchema, type OrderBook, OrderBookArrayResponseSchema, type OrderBookHistoryParams, OrderBookReconstructor, OrderBookResponseSchema, OrderBookSchema, type OrderbookDelta, OxArchive, OxArchiveError, OxArchiveWs, type Pagination, type PriceHistoryParams, type PriceLevel, PriceLevelSchema, type PriceSnapshot, PriceSnapshotArrayResponseSchema, PriceSnapshotSchema, type ReconstructOptions, type ReconstructedOrderBook, type RestApiLatency, type SiweChallenge, 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 Web3ApiKey, type Web3KeysList, type Web3PaymentRequired, type Web3RevokeResult, type Web3SignupResult, type Web3SubscribeResult, type WebSocketLatency, type WsChannel, WsChannelSchema, type WsClientMessage, type WsConnectionState, WsConnectionStateSchema, type WsData, WsDataSchema, type WsError, WsErrorSchema, type WsEventHandlers, type WsGapDetected, type WsHistoricalBatch, WsHistoricalBatchSchema, type WsHistoricalData, WsHistoricalDataSchema, type WsHistoricalTickData, type WsL4Batch, type WsL4Snapshot, 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 WsReplaySnapshot, WsReplaySnapshotSchema, 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
|
@@ -2288,6 +2288,49 @@ declare class L4OrderBookResource {
|
|
|
2288
2288
|
history(symbol: string, params: CursorPaginationParams): Promise<CursorResponse<any[]>>;
|
|
2289
2289
|
}
|
|
2290
2290
|
|
|
2291
|
+
interface L2OrderBookParams {
|
|
2292
|
+
timestamp?: number | string;
|
|
2293
|
+
depth?: number;
|
|
2294
|
+
}
|
|
2295
|
+
/**
|
|
2296
|
+
* L2 Full-Depth Order Book API resource (derived from L4 data)
|
|
2297
|
+
*
|
|
2298
|
+
* Access aggregated price-level orderbook snapshots, history, and tick-level diffs.
|
|
2299
|
+
* Data available from March 10, 2026.
|
|
2300
|
+
*
|
|
2301
|
+
* @example
|
|
2302
|
+
* ```typescript
|
|
2303
|
+
* // Get current full-depth L2 orderbook
|
|
2304
|
+
* const orderbook = await client.hyperliquid.l2Orderbook.get('BTC');
|
|
2305
|
+
*
|
|
2306
|
+
* // Get L2 orderbook at a historical timestamp
|
|
2307
|
+
* const historical = await client.hyperliquid.l2Orderbook.get('BTC', {
|
|
2308
|
+
* timestamp: 1711900800000
|
|
2309
|
+
* });
|
|
2310
|
+
*
|
|
2311
|
+
* // Get L2 orderbook history
|
|
2312
|
+
* const history = await client.hyperliquid.l2Orderbook.history('BTC', {
|
|
2313
|
+
* start: Date.now() - 86400000,
|
|
2314
|
+
* end: Date.now(),
|
|
2315
|
+
* limit: 100
|
|
2316
|
+
* });
|
|
2317
|
+
* ```
|
|
2318
|
+
*/
|
|
2319
|
+
declare class L2OrderBookResource {
|
|
2320
|
+
private http;
|
|
2321
|
+
private basePath;
|
|
2322
|
+
private coinTransform;
|
|
2323
|
+
constructor(http: HttpClient, basePath?: string, coinTransform?: (s: string) => string);
|
|
2324
|
+
/** Get full-depth L2 order book snapshot. */
|
|
2325
|
+
get(symbol: string, params?: L2OrderBookParams): Promise<any>;
|
|
2326
|
+
/** Get paginated L2 full-depth history. */
|
|
2327
|
+
history(symbol: string, params: CursorPaginationParams & {
|
|
2328
|
+
depth?: number;
|
|
2329
|
+
}): Promise<CursorResponse<any[]>>;
|
|
2330
|
+
/** Get tick-level L2 order book diffs. */
|
|
2331
|
+
diffs(symbol: string, params: CursorPaginationParams): Promise<CursorResponse<any[]>>;
|
|
2332
|
+
}
|
|
2333
|
+
|
|
2291
2334
|
interface L3OrderBookParams {
|
|
2292
2335
|
timestamp?: number | string;
|
|
2293
2336
|
depth?: number;
|
|
@@ -2382,6 +2425,10 @@ declare class HyperliquidClient {
|
|
|
2382
2425
|
* L4 order book (snapshots, diffs, history)
|
|
2383
2426
|
*/
|
|
2384
2427
|
readonly l4Orderbook: L4OrderBookResource;
|
|
2428
|
+
/**
|
|
2429
|
+
* L2 full-depth order book (derived from L4)
|
|
2430
|
+
*/
|
|
2431
|
+
readonly l2Orderbook: L2OrderBookResource;
|
|
2385
2432
|
/**
|
|
2386
2433
|
* HIP-3 builder-deployed perpetuals (February 2026+)
|
|
2387
2434
|
*/
|
|
@@ -2461,6 +2508,10 @@ declare class Hip3Client {
|
|
|
2461
2508
|
* L4 order book (snapshots, diffs, history)
|
|
2462
2509
|
*/
|
|
2463
2510
|
readonly l4Orderbook: L4OrderBookResource;
|
|
2511
|
+
/**
|
|
2512
|
+
* L2 full-depth order book (derived from L4)
|
|
2513
|
+
*/
|
|
2514
|
+
readonly l2Orderbook: L2OrderBookResource;
|
|
2464
2515
|
private http;
|
|
2465
2516
|
constructor(http: HttpClient);
|
|
2466
2517
|
/**
|
|
@@ -3003,6 +3054,109 @@ declare class OxArchiveWs {
|
|
|
3003
3054
|
private handleMessage;
|
|
3004
3055
|
}
|
|
3005
3056
|
|
|
3057
|
+
/**
|
|
3058
|
+
* L4 order book reconstructor with matching engine.
|
|
3059
|
+
*
|
|
3060
|
+
* Reconstructs Hyperliquid and HIP-3 L4 order books from checkpoints and diffs.
|
|
3061
|
+
* The same class works for both exchanges — the diff format is identical.
|
|
3062
|
+
*
|
|
3063
|
+
* When a new order crosses the spread, the matching engine filled opposite-side
|
|
3064
|
+
* orders at crossing prices. Without removing them, the reconstructed book will
|
|
3065
|
+
* be "crossed" (best bid > best ask).
|
|
3066
|
+
*
|
|
3067
|
+
* Ref: https://github.com/hyperliquid-dex/order_book_server
|
|
3068
|
+
*/
|
|
3069
|
+
interface L4Order {
|
|
3070
|
+
oid: number;
|
|
3071
|
+
userAddress: string;
|
|
3072
|
+
side: 'B' | 'A';
|
|
3073
|
+
price: number;
|
|
3074
|
+
size: number;
|
|
3075
|
+
}
|
|
3076
|
+
interface L2Level {
|
|
3077
|
+
px: number;
|
|
3078
|
+
sz: number;
|
|
3079
|
+
n: number;
|
|
3080
|
+
}
|
|
3081
|
+
interface L4Diff {
|
|
3082
|
+
diff_type?: 'new' | 'update' | 'remove';
|
|
3083
|
+
diffType?: 'new' | 'update' | 'remove';
|
|
3084
|
+
oid: number;
|
|
3085
|
+
side: 'B' | 'A';
|
|
3086
|
+
price: number;
|
|
3087
|
+
new_size?: number | null;
|
|
3088
|
+
newSize?: number | null;
|
|
3089
|
+
user_address?: string;
|
|
3090
|
+
userAddress?: string;
|
|
3091
|
+
block_number?: number;
|
|
3092
|
+
blockNumber?: number;
|
|
3093
|
+
}
|
|
3094
|
+
interface L4Checkpoint {
|
|
3095
|
+
bids: Array<{
|
|
3096
|
+
oid: number;
|
|
3097
|
+
user_address?: string;
|
|
3098
|
+
userAddress?: string;
|
|
3099
|
+
side: string;
|
|
3100
|
+
price: number;
|
|
3101
|
+
size: number;
|
|
3102
|
+
}>;
|
|
3103
|
+
asks: Array<{
|
|
3104
|
+
oid: number;
|
|
3105
|
+
user_address?: string;
|
|
3106
|
+
userAddress?: string;
|
|
3107
|
+
side: string;
|
|
3108
|
+
price: number;
|
|
3109
|
+
size: number;
|
|
3110
|
+
}>;
|
|
3111
|
+
}
|
|
3112
|
+
/**
|
|
3113
|
+
* L4 orderbook reconstructor with matching engine.
|
|
3114
|
+
*
|
|
3115
|
+
* Works identically for Hyperliquid and HIP-3 — same diff format,
|
|
3116
|
+
* same checkpoint format, same crossing logic.
|
|
3117
|
+
*
|
|
3118
|
+
* @example
|
|
3119
|
+
* ```typescript
|
|
3120
|
+
* const book = new L4OrderBookReconstructor();
|
|
3121
|
+
* book.loadCheckpoint(checkpoint);
|
|
3122
|
+
*
|
|
3123
|
+
* // Group diffs by block, apply in order
|
|
3124
|
+
* for (const bn of sortedBlockNumbers) {
|
|
3125
|
+
* const nr = nonRestingByBlock.get(bn);
|
|
3126
|
+
* for (const diff of blocks.get(bn)!) {
|
|
3127
|
+
* book.applyDiff(diff, nr);
|
|
3128
|
+
* }
|
|
3129
|
+
* }
|
|
3130
|
+
*
|
|
3131
|
+
* console.log(book.isCrossed()); // false
|
|
3132
|
+
* const { bids: l2Bids, asks: l2Asks } = book.deriveL2();
|
|
3133
|
+
* ```
|
|
3134
|
+
*/
|
|
3135
|
+
declare class L4OrderBookReconstructor {
|
|
3136
|
+
private orders;
|
|
3137
|
+
private bidPrices;
|
|
3138
|
+
private askPrices;
|
|
3139
|
+
/** Initialize from an L4 checkpoint. */
|
|
3140
|
+
loadCheckpoint(checkpoint: L4Checkpoint): void;
|
|
3141
|
+
/** Apply a single L4 diff with matching engine. */
|
|
3142
|
+
applyDiff(diff: L4Diff, nonRestingOids?: Set<number>): void;
|
|
3143
|
+
/** Return bids sorted by price descending. */
|
|
3144
|
+
bids(): L4Order[];
|
|
3145
|
+
/** Return asks sorted by price ascending. */
|
|
3146
|
+
asks(): L4Order[];
|
|
3147
|
+
bestBid(): number | null;
|
|
3148
|
+
bestAsk(): number | null;
|
|
3149
|
+
/** Check if the book is crossed. Should be false after correct reconstruction. */
|
|
3150
|
+
isCrossed(): boolean;
|
|
3151
|
+
get bidCount(): number;
|
|
3152
|
+
get askCount(): number;
|
|
3153
|
+
/** Aggregate L4 orders into L2 price levels. */
|
|
3154
|
+
deriveL2(): {
|
|
3155
|
+
bids: L2Level[];
|
|
3156
|
+
asks: L2Level[];
|
|
3157
|
+
};
|
|
3158
|
+
}
|
|
3159
|
+
|
|
3006
3160
|
/**
|
|
3007
3161
|
* Zod schemas for runtime validation of API responses
|
|
3008
3162
|
*
|
|
@@ -5462,4 +5616,4 @@ type ValidatedCandle = z.infer<typeof CandleSchema>;
|
|
|
5462
5616
|
type ValidatedLiquidation = z.infer<typeof LiquidationSchema>;
|
|
5463
5617
|
type ValidatedWsServerMessage = z.infer<typeof WsServerMessageSchema>;
|
|
5464
5618
|
|
|
5465
|
-
export { type ApiError, type ApiMeta, ApiMetaSchema, type ApiResponse, ApiResponseSchema, type Candle, CandleArrayResponseSchema, type CandleHistoryParams, type CandleInterval, CandleIntervalSchema, CandleSchema, type ClientOptions, type CoinFreshness, CoinFreshnessResponseSchema, CoinFreshnessSchema, type CoinSummary, CoinSummaryResponseSchema, CoinSummarySchema, type CompletenessMetrics, type CoverageGap, type CoverageResponse, type CursorResponse, type DataCadence, type DataFreshness, type DataTypeCoverage, type DataTypeFreshnessInfo, DataTypeFreshnessInfoSchema, type DataTypeStatus, type ExchangeCoverage, type ExchangeLatency, type ExchangeStatus, type FundingHistoryParams, type FundingRate, FundingRateArrayResponseSchema, FundingRateResponseSchema, FundingRateSchema, type GetOrderBookParams, type GetTradesCursorParams, Hip3Client, type Hip3Instrument, 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 LiquidationVolume, LiquidationVolumeArrayResponseSchema, type LiquidationVolumeParams, LiquidationVolumeSchema, type LiquidationsByUserParams, type ListIncidentsParams, type OiFundingInterval, type OpenInterest, OpenInterestArrayResponseSchema, type OpenInterestHistoryParams, OpenInterestResponseSchema, OpenInterestSchema, type OrderBook, OrderBookArrayResponseSchema, type OrderBookHistoryParams, OrderBookReconstructor, OrderBookResponseSchema, OrderBookSchema, type OrderbookDelta, OxArchive, OxArchiveError, OxArchiveWs, type Pagination, type PriceHistoryParams, type PriceLevel, PriceLevelSchema, type PriceSnapshot, PriceSnapshotArrayResponseSchema, PriceSnapshotSchema, type ReconstructOptions, type ReconstructedOrderBook, type RestApiLatency, type SiweChallenge, 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 Web3ApiKey, type Web3KeysList, type Web3PaymentRequired, type Web3RevokeResult, type Web3SignupResult, type Web3SubscribeResult, type WebSocketLatency, type WsChannel, WsChannelSchema, type WsClientMessage, type WsConnectionState, WsConnectionStateSchema, type WsData, WsDataSchema, type WsError, WsErrorSchema, type WsEventHandlers, type WsGapDetected, type WsHistoricalBatch, WsHistoricalBatchSchema, type WsHistoricalData, WsHistoricalDataSchema, type WsHistoricalTickData, type WsL4Batch, type WsL4Snapshot, 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 WsReplaySnapshot, WsReplaySnapshotSchema, 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 };
|
|
5619
|
+
export { type ApiError, type ApiMeta, ApiMetaSchema, type ApiResponse, ApiResponseSchema, type Candle, CandleArrayResponseSchema, type CandleHistoryParams, type CandleInterval, CandleIntervalSchema, CandleSchema, type ClientOptions, type CoinFreshness, CoinFreshnessResponseSchema, CoinFreshnessSchema, type CoinSummary, CoinSummaryResponseSchema, CoinSummarySchema, type CompletenessMetrics, type CoverageGap, type CoverageResponse, type CursorResponse, type DataCadence, type DataFreshness, type DataTypeCoverage, type DataTypeFreshnessInfo, DataTypeFreshnessInfoSchema, type DataTypeStatus, type ExchangeCoverage, type ExchangeLatency, type ExchangeStatus, type FundingHistoryParams, type FundingRate, FundingRateArrayResponseSchema, FundingRateResponseSchema, FundingRateSchema, type GetOrderBookParams, type GetTradesCursorParams, Hip3Client, type Hip3Instrument, HyperliquidClient, type Incident, type IncidentSeverityValue, type IncidentStatusValue, type IncidentsResponse, type Instrument, InstrumentArrayResponseSchema, InstrumentResponseSchema, InstrumentSchema, type InstrumentType, InstrumentTypeSchema, type L2Level, type L2OrderBookParams, L2OrderBookResource, type L4Checkpoint, type L4Diff, type L4Order, L4OrderBookReconstructor, type LatencyResponse, LighterClient, type LighterGranularity, type LighterInstrument, type Liquidation, LiquidationArrayResponseSchema, type LiquidationHistoryParams, LiquidationSchema, LiquidationSideSchema, type LiquidationVolume, LiquidationVolumeArrayResponseSchema, type LiquidationVolumeParams, LiquidationVolumeSchema, type LiquidationsByUserParams, type ListIncidentsParams, type OiFundingInterval, type OpenInterest, OpenInterestArrayResponseSchema, type OpenInterestHistoryParams, OpenInterestResponseSchema, OpenInterestSchema, type OrderBook, OrderBookArrayResponseSchema, type OrderBookHistoryParams, OrderBookReconstructor, OrderBookResponseSchema, OrderBookSchema, type OrderbookDelta, OxArchive, OxArchiveError, OxArchiveWs, type Pagination, type PriceHistoryParams, type PriceLevel, PriceLevelSchema, type PriceSnapshot, PriceSnapshotArrayResponseSchema, PriceSnapshotSchema, type ReconstructOptions, type ReconstructedOrderBook, type RestApiLatency, type SiweChallenge, 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 Web3ApiKey, type Web3KeysList, type Web3PaymentRequired, type Web3RevokeResult, type Web3SignupResult, type Web3SubscribeResult, type WebSocketLatency, type WsChannel, WsChannelSchema, type WsClientMessage, type WsConnectionState, WsConnectionStateSchema, type WsData, WsDataSchema, type WsError, WsErrorSchema, type WsEventHandlers, type WsGapDetected, type WsHistoricalBatch, WsHistoricalBatchSchema, type WsHistoricalData, WsHistoricalDataSchema, type WsHistoricalTickData, type WsL4Batch, type WsL4Snapshot, 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 WsReplaySnapshot, WsReplaySnapshotSchema, 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 };
|