@0xarchive/sdk 1.3.0 → 1.6.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/LICENSE +21 -0
- package/README.md +1449 -1324
- package/dist/index.d.mts +818 -214
- package/dist/index.d.ts +818 -214
- package/dist/index.js +421 -27
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +419 -27
- package/dist/index.mjs.map +1 -1
- package/package.json +10 -6
package/dist/index.mjs
CHANGED
|
@@ -230,7 +230,13 @@ var TradeSchema = z.object({
|
|
|
230
230
|
startPosition: z.string().optional(),
|
|
231
231
|
userAddress: z.string().optional(),
|
|
232
232
|
makerAddress: z.string().optional(),
|
|
233
|
-
takerAddress: z.string().optional()
|
|
233
|
+
takerAddress: z.string().optional(),
|
|
234
|
+
builderAddress: z.string().optional(),
|
|
235
|
+
builderFee: z.string().optional(),
|
|
236
|
+
deployerFee: z.string().optional(),
|
|
237
|
+
priorityGas: z.number().optional(),
|
|
238
|
+
cloid: z.string().optional(),
|
|
239
|
+
twapId: z.number().optional()
|
|
234
240
|
});
|
|
235
241
|
var InstrumentTypeSchema = z.enum(["perp", "spot"]);
|
|
236
242
|
var InstrumentSchema = z.object({
|
|
@@ -299,11 +305,22 @@ var WsChannelSchema = z.enum([
|
|
|
299
305
|
"lighter_candles",
|
|
300
306
|
"lighter_open_interest",
|
|
301
307
|
"lighter_funding",
|
|
308
|
+
"lighter_l3_orderbook",
|
|
302
309
|
"hip3_orderbook",
|
|
303
310
|
"hip3_trades",
|
|
304
311
|
"hip3_candles",
|
|
305
312
|
"hip3_open_interest",
|
|
306
|
-
"hip3_funding"
|
|
313
|
+
"hip3_funding",
|
|
314
|
+
"hip3_liquidations",
|
|
315
|
+
"hip4_orderbook",
|
|
316
|
+
"hip4_trades",
|
|
317
|
+
"hip4_open_interest",
|
|
318
|
+
"l4_diffs",
|
|
319
|
+
"l4_orders",
|
|
320
|
+
"hip3_l4_diffs",
|
|
321
|
+
"hip3_l4_orders",
|
|
322
|
+
"hip4_l4_diffs",
|
|
323
|
+
"hip4_l4_orders"
|
|
307
324
|
]);
|
|
308
325
|
var WsConnectionStateSchema = z.enum(["connecting", "connected", "disconnected", "reconnecting"]);
|
|
309
326
|
var WsSubscribedSchema = z.object({
|
|
@@ -399,6 +416,14 @@ var WsStreamStoppedSchema = z.object({
|
|
|
399
416
|
type: z.literal("stream_stopped"),
|
|
400
417
|
snapshots_sent: z.number()
|
|
401
418
|
});
|
|
419
|
+
var WsOutcomeSettledSchema = z.object({
|
|
420
|
+
type: z.literal("outcome_settled"),
|
|
421
|
+
coin: z.string(),
|
|
422
|
+
outcome_id: z.number(),
|
|
423
|
+
side: z.number(),
|
|
424
|
+
settlement_value: z.number().optional(),
|
|
425
|
+
settlement_at: z.string().optional()
|
|
426
|
+
});
|
|
402
427
|
var WsServerMessageSchema = z.discriminatedUnion("type", [
|
|
403
428
|
WsSubscribedSchema,
|
|
404
429
|
WsUnsubscribedSchema,
|
|
@@ -416,7 +441,8 @@ var WsServerMessageSchema = z.discriminatedUnion("type", [
|
|
|
416
441
|
WsStreamProgressSchema,
|
|
417
442
|
WsHistoricalBatchSchema,
|
|
418
443
|
WsStreamCompletedSchema,
|
|
419
|
-
WsStreamStoppedSchema
|
|
444
|
+
WsStreamStoppedSchema,
|
|
445
|
+
WsOutcomeSettledSchema
|
|
420
446
|
]);
|
|
421
447
|
var OrderBookResponseSchema = ApiResponseSchema(OrderBookSchema);
|
|
422
448
|
var OrderBookArrayResponseSchema = ApiResponseSchema(z.array(OrderBookSchema));
|
|
@@ -966,16 +992,26 @@ var TradesResource = class {
|
|
|
966
992
|
/**
|
|
967
993
|
* Get most recent trades for a symbol.
|
|
968
994
|
*
|
|
969
|
-
* Note: This method is available
|
|
970
|
-
*
|
|
971
|
-
*
|
|
972
|
-
*
|
|
995
|
+
* Note: This method is available on Lighter (`client.lighter.trades.recent()`),
|
|
996
|
+
* HIP-3 (`client.hyperliquid.hip3.trades.recent()`), and HIP-4
|
|
997
|
+
* (`client.hyperliquid.hip4.trades.recent()`) which have real-time ingestion.
|
|
998
|
+
* Hyperliquid uses hourly S3 backfill and does NOT expose a recent endpoint —
|
|
999
|
+
* calling `client.hyperliquid.trades.recent()` (or the legacy
|
|
1000
|
+
* `client.trades.recent()`) throws a structured `OxArchiveError` rather than
|
|
1001
|
+
* letting the request fail with an opaque JSON parse error.
|
|
973
1002
|
*
|
|
974
1003
|
* @param symbol - The symbol (e.g., 'BTC', 'ETH')
|
|
975
1004
|
* @param limit - Number of trades to return (default: 100)
|
|
976
1005
|
* @returns Array of recent trades
|
|
1006
|
+
* @throws {OxArchiveError} When called on the bare Hyperliquid namespace.
|
|
977
1007
|
*/
|
|
978
1008
|
async recent(symbol, limit) {
|
|
1009
|
+
if (this.basePath === "/v1/hyperliquid" || this.basePath === "/v1") {
|
|
1010
|
+
throw new OxArchiveError(
|
|
1011
|
+
"trades.recent() is not available on Hyperliquid (no real-time ingestion). Use client.hyperliquid.trades.list(symbol, { start, end }) with a time range, or call recent() on a real-time namespace: client.hyperliquid.hip3.trades.recent(), client.hyperliquid.hip4.trades.recent(), or client.lighter.trades.recent().",
|
|
1012
|
+
404
|
|
1013
|
+
);
|
|
1014
|
+
}
|
|
979
1015
|
const response = await this.http.get(
|
|
980
1016
|
`${this.basePath}/trades/${this.coinTransform(symbol)}/recent`,
|
|
981
1017
|
{ limit },
|
|
@@ -1080,6 +1116,61 @@ var Hip3InstrumentsResource = class {
|
|
|
1080
1116
|
return response.data;
|
|
1081
1117
|
}
|
|
1082
1118
|
};
|
|
1119
|
+
var Hip4InstrumentsResource = class {
|
|
1120
|
+
constructor(http, basePath = "/v1/hyperliquid/hip4", coinTransform) {
|
|
1121
|
+
this.http = http;
|
|
1122
|
+
this.basePath = basePath;
|
|
1123
|
+
this.coinTransform = coinTransform || ((c) => encodeURIComponent(c));
|
|
1124
|
+
}
|
|
1125
|
+
coinTransform;
|
|
1126
|
+
async list() {
|
|
1127
|
+
const response = await this.http.get(
|
|
1128
|
+
`${this.basePath}/instruments`
|
|
1129
|
+
);
|
|
1130
|
+
return response.data;
|
|
1131
|
+
}
|
|
1132
|
+
async get(coin) {
|
|
1133
|
+
const response = await this.http.get(
|
|
1134
|
+
`${this.basePath}/instruments/${this.coinTransform(coin)}`
|
|
1135
|
+
);
|
|
1136
|
+
return response.data;
|
|
1137
|
+
}
|
|
1138
|
+
};
|
|
1139
|
+
var Hip4OutcomesResource = class {
|
|
1140
|
+
constructor(http, basePath = "/v1/hyperliquid/hip4") {
|
|
1141
|
+
this.http = http;
|
|
1142
|
+
this.basePath = basePath;
|
|
1143
|
+
}
|
|
1144
|
+
/** List per-outcome aggregates. `aggregatedOi` is omitted on list responses. */
|
|
1145
|
+
async list(params) {
|
|
1146
|
+
const response = await this.http.get(
|
|
1147
|
+
`${this.basePath}/outcomes`,
|
|
1148
|
+
params
|
|
1149
|
+
);
|
|
1150
|
+
return {
|
|
1151
|
+
data: response.data,
|
|
1152
|
+
nextCursor: response.meta.nextCursor
|
|
1153
|
+
};
|
|
1154
|
+
}
|
|
1155
|
+
/** Get a single outcome aggregate. Response includes `aggregatedOi`. */
|
|
1156
|
+
async get(outcomeId) {
|
|
1157
|
+
const response = await this.http.get(
|
|
1158
|
+
`${this.basePath}/outcomes/${outcomeId}`
|
|
1159
|
+
);
|
|
1160
|
+
return response.data;
|
|
1161
|
+
}
|
|
1162
|
+
/**
|
|
1163
|
+
* Look up an outcome aggregate by its synthesized slug. Accepts the
|
|
1164
|
+
* per-outcome slug (`btc-above-78213-may-04-0600`) OR a per-side slug
|
|
1165
|
+
* (`btc-above-78213-yes-may-04-0600`). Response includes `aggregatedOi`.
|
|
1166
|
+
*/
|
|
1167
|
+
async getBySlug(slug) {
|
|
1168
|
+
const response = await this.http.get(
|
|
1169
|
+
`${this.basePath}/outcomes/by-slug/${slug}`
|
|
1170
|
+
);
|
|
1171
|
+
return response.data;
|
|
1172
|
+
}
|
|
1173
|
+
};
|
|
1083
1174
|
|
|
1084
1175
|
// src/resources/funding.ts
|
|
1085
1176
|
var FundingResource = class {
|
|
@@ -1272,7 +1363,7 @@ var DataQualityResource = class {
|
|
|
1272
1363
|
/**
|
|
1273
1364
|
* Get overall system health status
|
|
1274
1365
|
*
|
|
1275
|
-
* @returns StatusResponse with overall status, per-
|
|
1366
|
+
* @returns StatusResponse with overall status, per-scope status,
|
|
1276
1367
|
* per-data-type status, and active incident count
|
|
1277
1368
|
*
|
|
1278
1369
|
* @example
|
|
@@ -1291,9 +1382,9 @@ var DataQualityResource = class {
|
|
|
1291
1382
|
// Coverage Endpoints
|
|
1292
1383
|
// ===========================================================================
|
|
1293
1384
|
/**
|
|
1294
|
-
* Get data coverage summary
|
|
1385
|
+
* Get data coverage summary across venue APIs
|
|
1295
1386
|
*
|
|
1296
|
-
* @returns CoverageResponse with coverage info for
|
|
1387
|
+
* @returns CoverageResponse with coverage info for supported venue APIs and data types
|
|
1297
1388
|
*
|
|
1298
1389
|
* @example
|
|
1299
1390
|
* ```typescript
|
|
@@ -1310,10 +1401,10 @@ var DataQualityResource = class {
|
|
|
1310
1401
|
return this.http.get(`${this.basePath}/coverage`);
|
|
1311
1402
|
}
|
|
1312
1403
|
/**
|
|
1313
|
-
* Get data coverage for a specific
|
|
1404
|
+
* Get data coverage for a specific venue scope
|
|
1314
1405
|
*
|
|
1315
|
-
* @param exchange -
|
|
1316
|
-
* @returns ExchangeCoverage with coverage info for all data types on this
|
|
1406
|
+
* @param exchange - Venue scope ('hyperliquid', 'lighter', 'hip3', or 'hip4')
|
|
1407
|
+
* @returns ExchangeCoverage with coverage info for all data types on this venue scope
|
|
1317
1408
|
*
|
|
1318
1409
|
* @example
|
|
1319
1410
|
* ```typescript
|
|
@@ -1327,12 +1418,12 @@ var DataQualityResource = class {
|
|
|
1327
1418
|
);
|
|
1328
1419
|
}
|
|
1329
1420
|
/**
|
|
1330
|
-
* Get data coverage for a specific symbol on
|
|
1421
|
+
* Get data coverage for a specific symbol on a venue scope
|
|
1331
1422
|
*
|
|
1332
1423
|
* Includes gap detection, empirical data cadence, and hour-level historical coverage.
|
|
1333
1424
|
* Supports optional time bounds for gap detection (default: last 30 days).
|
|
1334
1425
|
*
|
|
1335
|
-
* @param exchange -
|
|
1426
|
+
* @param exchange - Venue scope ('hyperliquid', 'lighter', 'hip3', or 'hip4')
|
|
1336
1427
|
* @param symbol - Symbol name (e.g., 'BTC', 'ETH', or HIP3 coins like 'xyz:XYZ100')
|
|
1337
1428
|
* @param options - Optional time bounds for gap detection window
|
|
1338
1429
|
* @returns SymbolCoverageResponse with per-data-type coverage including gaps, cadence, and historical coverage
|
|
@@ -1410,7 +1501,7 @@ var DataQualityResource = class {
|
|
|
1410
1501
|
// Latency Endpoints
|
|
1411
1502
|
// ===========================================================================
|
|
1412
1503
|
/**
|
|
1413
|
-
* Get current latency metrics for
|
|
1504
|
+
* Get current latency metrics for supported venue APIs
|
|
1414
1505
|
*
|
|
1415
1506
|
* @returns LatencyResponse with WebSocket, REST API, and data freshness metrics
|
|
1416
1507
|
*
|
|
@@ -1712,7 +1803,7 @@ var L2OrderBookResource = class {
|
|
|
1712
1803
|
if (params?.timestamp != null) query.timestamp = params.timestamp;
|
|
1713
1804
|
if (params?.depth != null) query.depth = params.depth;
|
|
1714
1805
|
const resp = await this.http.get(
|
|
1715
|
-
`${this.basePath}/orderbook/${
|
|
1806
|
+
`${this.basePath}/orderbook/${coin}/l2`,
|
|
1716
1807
|
query
|
|
1717
1808
|
);
|
|
1718
1809
|
return resp.data;
|
|
@@ -1721,7 +1812,7 @@ var L2OrderBookResource = class {
|
|
|
1721
1812
|
async history(symbol, params) {
|
|
1722
1813
|
const coin = this.coinTransform(symbol);
|
|
1723
1814
|
const resp = await this.http.get(
|
|
1724
|
-
`${this.basePath}/orderbook/${
|
|
1815
|
+
`${this.basePath}/orderbook/${coin}/l2/history`,
|
|
1725
1816
|
params
|
|
1726
1817
|
);
|
|
1727
1818
|
return {
|
|
@@ -1733,7 +1824,7 @@ var L2OrderBookResource = class {
|
|
|
1733
1824
|
async diffs(symbol, params) {
|
|
1734
1825
|
const coin = this.coinTransform(symbol);
|
|
1735
1826
|
const resp = await this.http.get(
|
|
1736
|
-
`${this.basePath}/orderbook/${
|
|
1827
|
+
`${this.basePath}/orderbook/${coin}/l2/diffs`,
|
|
1737
1828
|
params
|
|
1738
1829
|
);
|
|
1739
1830
|
return {
|
|
@@ -1826,6 +1917,10 @@ var HyperliquidClient = class {
|
|
|
1826
1917
|
* HIP-3 builder-deployed perpetuals (February 2026+)
|
|
1827
1918
|
*/
|
|
1828
1919
|
hip3;
|
|
1920
|
+
/**
|
|
1921
|
+
* HIP-4 outcome markets (binary YES/NO; May 2026+)
|
|
1922
|
+
*/
|
|
1923
|
+
hip4;
|
|
1829
1924
|
http;
|
|
1830
1925
|
constructor(http) {
|
|
1831
1926
|
this.http = http;
|
|
@@ -1841,6 +1936,7 @@ var HyperliquidClient = class {
|
|
|
1841
1936
|
this.l4Orderbook = new L4OrderBookResource(http, basePath);
|
|
1842
1937
|
this.l2Orderbook = new L2OrderBookResource(http, basePath);
|
|
1843
1938
|
this.hip3 = new Hip3Client(http);
|
|
1939
|
+
this.hip4 = new Hip4Client(http);
|
|
1844
1940
|
}
|
|
1845
1941
|
/**
|
|
1846
1942
|
* Get per-symbol data freshness across all data types
|
|
@@ -1993,6 +2089,205 @@ var Hip3Client = class {
|
|
|
1993
2089
|
};
|
|
1994
2090
|
}
|
|
1995
2091
|
};
|
|
2092
|
+
var Hip4Client = class {
|
|
2093
|
+
/**
|
|
2094
|
+
* HIP-4 per-side instruments (one row per `#N`).
|
|
2095
|
+
*/
|
|
2096
|
+
instruments;
|
|
2097
|
+
/**
|
|
2098
|
+
* HIP-4 per-outcome aggregates (one row per outcome). HIP-4-specific, no HIP-3 analog.
|
|
2099
|
+
*/
|
|
2100
|
+
outcomes;
|
|
2101
|
+
/**
|
|
2102
|
+
* L2 orderbook snapshots (Pro+).
|
|
2103
|
+
*/
|
|
2104
|
+
orderbook;
|
|
2105
|
+
/**
|
|
2106
|
+
* Trade/fill history.
|
|
2107
|
+
*/
|
|
2108
|
+
trades;
|
|
2109
|
+
/**
|
|
2110
|
+
* Open interest (per side).
|
|
2111
|
+
*/
|
|
2112
|
+
openInterest;
|
|
2113
|
+
/**
|
|
2114
|
+
* Order history, flow, and TP/SL (Pro+).
|
|
2115
|
+
*/
|
|
2116
|
+
orders;
|
|
2117
|
+
/**
|
|
2118
|
+
* L4 orderbook (snapshots, diffs, history).
|
|
2119
|
+
*/
|
|
2120
|
+
l4Orderbook;
|
|
2121
|
+
/**
|
|
2122
|
+
* L2 full-depth orderbook (derived from L4).
|
|
2123
|
+
*/
|
|
2124
|
+
l2Orderbook;
|
|
2125
|
+
http;
|
|
2126
|
+
constructor(http) {
|
|
2127
|
+
this.http = http;
|
|
2128
|
+
const basePath = "/v1/hyperliquid/hip4";
|
|
2129
|
+
const coinTransform = (c) => encodeURIComponent(c);
|
|
2130
|
+
this.instruments = new Hip4InstrumentsResource(http, basePath, coinTransform);
|
|
2131
|
+
this.outcomes = new Hip4OutcomesResource(http, basePath);
|
|
2132
|
+
this.orderbook = new OrderBookResource(http, basePath, coinTransform);
|
|
2133
|
+
this.trades = new TradesResource(http, basePath, coinTransform);
|
|
2134
|
+
this.openInterest = new OpenInterestResource(http, basePath, coinTransform);
|
|
2135
|
+
this.orders = new OrdersResource(http, basePath, coinTransform);
|
|
2136
|
+
this.l4Orderbook = new L4OrderBookResource(http, basePath, coinTransform);
|
|
2137
|
+
this.l2Orderbook = new L2OrderBookResource(http, basePath, coinTransform);
|
|
2138
|
+
}
|
|
2139
|
+
/** @internal Encode a HIP-4 coin for use in URL paths. */
|
|
2140
|
+
encodeCoin(coin) {
|
|
2141
|
+
return encodeURIComponent(coin);
|
|
2142
|
+
}
|
|
2143
|
+
/**
|
|
2144
|
+
* List per-outcome aggregates. `aggregatedOi` is omitted on list responses.
|
|
2145
|
+
*/
|
|
2146
|
+
async listOutcomes(params) {
|
|
2147
|
+
return this.outcomes.list(params);
|
|
2148
|
+
}
|
|
2149
|
+
/**
|
|
2150
|
+
* Get a single outcome aggregate (includes `aggregatedOi`).
|
|
2151
|
+
*/
|
|
2152
|
+
async getOutcome(outcomeId) {
|
|
2153
|
+
return this.outcomes.get(outcomeId);
|
|
2154
|
+
}
|
|
2155
|
+
/**
|
|
2156
|
+
* Look up an outcome aggregate by slug. Accepts the per-outcome slug
|
|
2157
|
+
* (e.g. `btc-above-78213-may-04-0600`) OR a per-side slug
|
|
2158
|
+
* (e.g. `btc-above-78213-yes-may-04-0600`). Includes `aggregatedOi`.
|
|
2159
|
+
*/
|
|
2160
|
+
async getOutcomeBySlug(slug) {
|
|
2161
|
+
return this.outcomes.getBySlug(slug);
|
|
2162
|
+
}
|
|
2163
|
+
/**
|
|
2164
|
+
* List all per-side instruments (one row per `#N`).
|
|
2165
|
+
*/
|
|
2166
|
+
async getInstruments() {
|
|
2167
|
+
return this.instruments.list();
|
|
2168
|
+
}
|
|
2169
|
+
/**
|
|
2170
|
+
* Get a single per-side instrument by coin (e.g. `#0`).
|
|
2171
|
+
*/
|
|
2172
|
+
async getInstrument(coin) {
|
|
2173
|
+
return this.instruments.get(coin);
|
|
2174
|
+
}
|
|
2175
|
+
/**
|
|
2176
|
+
* Get current L2 orderbook snapshot for a HIP-4 coin (Pro+).
|
|
2177
|
+
* @param coin Coin string with leading `#` (e.g. `#0`).
|
|
2178
|
+
*/
|
|
2179
|
+
async getOrderbook(coin, params) {
|
|
2180
|
+
return this.orderbook.get(coin, params);
|
|
2181
|
+
}
|
|
2182
|
+
/**
|
|
2183
|
+
* Get historical L2 orderbook snapshots for a HIP-4 coin (Pro+).
|
|
2184
|
+
*/
|
|
2185
|
+
async getOrderbookHistory(coin, params) {
|
|
2186
|
+
return this.orderbook.history(coin, params);
|
|
2187
|
+
}
|
|
2188
|
+
/**
|
|
2189
|
+
* Get historical fills for a HIP-4 coin.
|
|
2190
|
+
*/
|
|
2191
|
+
async getTrades(coin, params) {
|
|
2192
|
+
return this.trades.list(coin, params);
|
|
2193
|
+
}
|
|
2194
|
+
/**
|
|
2195
|
+
* Get most recent N fills for a HIP-4 coin (latest first).
|
|
2196
|
+
*/
|
|
2197
|
+
async getTradesRecent(coin, limit) {
|
|
2198
|
+
return this.trades.recent(coin, limit);
|
|
2199
|
+
}
|
|
2200
|
+
/**
|
|
2201
|
+
* Get per-side open interest history for a HIP-4 coin.
|
|
2202
|
+
* Note: `markPrice` on the response is an implied probability (0..1), not USD.
|
|
2203
|
+
*/
|
|
2204
|
+
async getOpenInterest(coin, params) {
|
|
2205
|
+
return this.openInterest.history(coin, params);
|
|
2206
|
+
}
|
|
2207
|
+
/**
|
|
2208
|
+
* Get current per-side open interest for a HIP-4 coin.
|
|
2209
|
+
* Note: `markPrice` on the response is an implied probability (0..1), not USD.
|
|
2210
|
+
*/
|
|
2211
|
+
async getOpenInterestCurrent(coin) {
|
|
2212
|
+
return this.openInterest.current(coin);
|
|
2213
|
+
}
|
|
2214
|
+
/**
|
|
2215
|
+
* Get combined market summary for a HIP-4 coin.
|
|
2216
|
+
* @param coin Either bare numeric form (`'0'`) or `#`-prefixed form (`'#0'`). The SDK URL-encodes `#` so both work.
|
|
2217
|
+
*/
|
|
2218
|
+
async getSummary(coin) {
|
|
2219
|
+
const response = await this.http.get(
|
|
2220
|
+
`/v1/hyperliquid/hip4/summary/${this.encodeCoin(coin)}`,
|
|
2221
|
+
void 0,
|
|
2222
|
+
this.http.validationEnabled ? CoinSummaryResponseSchema : void 0
|
|
2223
|
+
);
|
|
2224
|
+
return response.data;
|
|
2225
|
+
}
|
|
2226
|
+
/**
|
|
2227
|
+
* Get per-symbol data freshness across all HIP-4 data types.
|
|
2228
|
+
* @param coin Either bare numeric form (`'0'`) or `#`-prefixed form (`'#0'`). The SDK URL-encodes `#` so both work.
|
|
2229
|
+
*/
|
|
2230
|
+
async getFreshness(coin) {
|
|
2231
|
+
const response = await this.http.get(
|
|
2232
|
+
`/v1/hyperliquid/hip4/freshness/${this.encodeCoin(coin)}`,
|
|
2233
|
+
void 0,
|
|
2234
|
+
this.http.validationEnabled ? CoinFreshnessResponseSchema : void 0
|
|
2235
|
+
);
|
|
2236
|
+
return response.data;
|
|
2237
|
+
}
|
|
2238
|
+
/**
|
|
2239
|
+
* Get mid-price history for a HIP-4 coin.
|
|
2240
|
+
* Note: returned `markPrice`/`midPrice` are probabilities (0..1), not USD.
|
|
2241
|
+
* @param coin Either bare numeric form (`'0'`) or `#`-prefixed form (`'#0'`). The SDK URL-encodes `#` so both work.
|
|
2242
|
+
*/
|
|
2243
|
+
async getPrices(coin, params) {
|
|
2244
|
+
const response = await this.http.get(
|
|
2245
|
+
`/v1/hyperliquid/hip4/prices/${this.encodeCoin(coin)}`,
|
|
2246
|
+
params,
|
|
2247
|
+
this.http.validationEnabled ? PriceSnapshotArrayResponseSchema : void 0
|
|
2248
|
+
);
|
|
2249
|
+
return {
|
|
2250
|
+
data: response.data,
|
|
2251
|
+
nextCursor: response.meta.nextCursor
|
|
2252
|
+
};
|
|
2253
|
+
}
|
|
2254
|
+
/**
|
|
2255
|
+
* Get order lifecycle events for a HIP-4 coin (Pro+).
|
|
2256
|
+
*/
|
|
2257
|
+
async getOrderHistory(coin, params) {
|
|
2258
|
+
return this.orders.history(coin, params);
|
|
2259
|
+
}
|
|
2260
|
+
/**
|
|
2261
|
+
* Get time-bucketed order-flow aggregates for a HIP-4 coin (Pro+).
|
|
2262
|
+
*/
|
|
2263
|
+
async getOrderFlow(coin, params) {
|
|
2264
|
+
return this.orders.flow(coin, params);
|
|
2265
|
+
}
|
|
2266
|
+
/**
|
|
2267
|
+
* Get TP/SL orders for a HIP-4 coin (Pro+).
|
|
2268
|
+
*/
|
|
2269
|
+
async getTpsl(coin, params) {
|
|
2270
|
+
return this.orders.tpsl(coin, params);
|
|
2271
|
+
}
|
|
2272
|
+
/**
|
|
2273
|
+
* Get full L4 reconstruction (current) for a HIP-4 coin (Pro+).
|
|
2274
|
+
*/
|
|
2275
|
+
async getL4Orderbook(coin, params) {
|
|
2276
|
+
return this.l4Orderbook.get(coin, params);
|
|
2277
|
+
}
|
|
2278
|
+
/**
|
|
2279
|
+
* Get L4 diffs (event stream) for a HIP-4 coin (Pro+).
|
|
2280
|
+
*/
|
|
2281
|
+
async getL4Diffs(coin, params) {
|
|
2282
|
+
return this.l4Orderbook.diffs(coin, params);
|
|
2283
|
+
}
|
|
2284
|
+
/**
|
|
2285
|
+
* Get L4 checkpoint history for a HIP-4 coin (Build+; hard cap limit=10).
|
|
2286
|
+
*/
|
|
2287
|
+
async getL4History(coin, params) {
|
|
2288
|
+
return this.l4Orderbook.history(coin, params);
|
|
2289
|
+
}
|
|
2290
|
+
};
|
|
1996
2291
|
var LighterClient = class {
|
|
1997
2292
|
/**
|
|
1998
2293
|
* Order book data (L2 snapshots)
|
|
@@ -2247,7 +2542,9 @@ var OxArchiveWs = class {
|
|
|
2247
2542
|
streamCompleteHandlers = [];
|
|
2248
2543
|
orderbookHandlers = [];
|
|
2249
2544
|
tradesHandlers = [];
|
|
2545
|
+
liquidationsHandlers = [];
|
|
2250
2546
|
gapHandlers = [];
|
|
2547
|
+
outcomeSettledHandlers = [];
|
|
2251
2548
|
constructor(options) {
|
|
2252
2549
|
this.options = {
|
|
2253
2550
|
apiKey: options.apiKey,
|
|
@@ -2331,7 +2628,7 @@ var OxArchiveWs = class {
|
|
|
2331
2628
|
const key = this.subscriptionKey(channel, coin);
|
|
2332
2629
|
this.subscriptions.add(key);
|
|
2333
2630
|
if (this.isConnected()) {
|
|
2334
|
-
this.send({ op: "subscribe", channel, coin });
|
|
2631
|
+
this.send({ op: "subscribe", channel, symbol: coin });
|
|
2335
2632
|
}
|
|
2336
2633
|
}
|
|
2337
2634
|
/**
|
|
@@ -2365,7 +2662,7 @@ var OxArchiveWs = class {
|
|
|
2365
2662
|
const key = this.subscriptionKey(channel, coin);
|
|
2366
2663
|
this.subscriptions.delete(key);
|
|
2367
2664
|
if (this.isConnected()) {
|
|
2368
|
-
this.send({ op: "unsubscribe", channel, coin });
|
|
2665
|
+
this.send({ op: "unsubscribe", channel, symbol: coin });
|
|
2369
2666
|
}
|
|
2370
2667
|
}
|
|
2371
2668
|
/**
|
|
@@ -2392,6 +2689,49 @@ var OxArchiveWs = class {
|
|
|
2392
2689
|
unsubscribeAllTickers() {
|
|
2393
2690
|
this.unsubscribe("all_tickers");
|
|
2394
2691
|
}
|
|
2692
|
+
/**
|
|
2693
|
+
* Subscribe to live liquidation events for a coin (Hyperliquid).
|
|
2694
|
+
*
|
|
2695
|
+
* Each message is a fill row with `is_liquidation: true`. Same wire shape as
|
|
2696
|
+
* trades. Live as of v1.6.0 (Hyperliquid + HIP-3 nodes); historical replay
|
|
2697
|
+
* also supported via `replay('liquidations', ...)`.
|
|
2698
|
+
*/
|
|
2699
|
+
subscribeLiquidations(coin) {
|
|
2700
|
+
this.subscribe("liquidations", coin);
|
|
2701
|
+
}
|
|
2702
|
+
/** Unsubscribe from live liquidation events (Hyperliquid). */
|
|
2703
|
+
unsubscribeLiquidations(coin) {
|
|
2704
|
+
this.unsubscribe("liquidations", coin);
|
|
2705
|
+
}
|
|
2706
|
+
/**
|
|
2707
|
+
* Subscribe to live HIP-3 liquidation events for a coin.
|
|
2708
|
+
* Each message is a fill row with `is_liquidation: true`.
|
|
2709
|
+
*/
|
|
2710
|
+
subscribeHip3Liquidations(coin) {
|
|
2711
|
+
this.subscribe("hip3_liquidations", coin);
|
|
2712
|
+
}
|
|
2713
|
+
/** Unsubscribe from live HIP-3 liquidation events. */
|
|
2714
|
+
unsubscribeHip3Liquidations(coin) {
|
|
2715
|
+
this.unsubscribe("hip3_liquidations", coin);
|
|
2716
|
+
}
|
|
2717
|
+
/**
|
|
2718
|
+
* Subscribe to a HIP-4 channel for a given outcome coin.
|
|
2719
|
+
*
|
|
2720
|
+
* @param channel One of `hip4_orderbook`, `hip4_trades`, `hip4_open_interest`,
|
|
2721
|
+
* `hip4_l4_diffs`, `hip4_l4_orders`.
|
|
2722
|
+
* @param coin HIP-4 coin (e.g. `'#0'` or `'0'`). The bare numeric form is
|
|
2723
|
+
* recommended; both are accepted by the backend.
|
|
2724
|
+
*/
|
|
2725
|
+
subscribeHip4(channel, coin) {
|
|
2726
|
+
const fullChannel = channel.startsWith("hip4_") ? channel : `hip4_${channel}`;
|
|
2727
|
+
this.subscribe(fullChannel, coin);
|
|
2728
|
+
}
|
|
2729
|
+
/** Unsubscribe from a HIP-4 channel for a given outcome coin. Accepts the
|
|
2730
|
+
* short channel form (`'orderbook'`) or the full form (`'hip4_orderbook'`). */
|
|
2731
|
+
unsubscribeHip4(channel, coin) {
|
|
2732
|
+
const fullChannel = channel.startsWith("hip4_") ? channel : `hip4_${channel}`;
|
|
2733
|
+
this.unsubscribe(fullChannel, coin);
|
|
2734
|
+
}
|
|
2395
2735
|
// ==========================================================================
|
|
2396
2736
|
// Historical Replay (Option B) - Like Tardis.dev
|
|
2397
2737
|
// ==========================================================================
|
|
@@ -2414,7 +2754,7 @@ var OxArchiveWs = class {
|
|
|
2414
2754
|
this.send({
|
|
2415
2755
|
op: "replay",
|
|
2416
2756
|
channel,
|
|
2417
|
-
coin,
|
|
2757
|
+
symbol: coin,
|
|
2418
2758
|
start: options.start,
|
|
2419
2759
|
end: options.end,
|
|
2420
2760
|
speed: options.speed ?? 1,
|
|
@@ -2449,7 +2789,7 @@ var OxArchiveWs = class {
|
|
|
2449
2789
|
this.send({
|
|
2450
2790
|
op: "replay",
|
|
2451
2791
|
channels,
|
|
2452
|
-
coin,
|
|
2792
|
+
symbol: coin,
|
|
2453
2793
|
start: options.start,
|
|
2454
2794
|
end: options.end,
|
|
2455
2795
|
speed: options.speed ?? 1,
|
|
@@ -2505,7 +2845,7 @@ var OxArchiveWs = class {
|
|
|
2505
2845
|
this.send({
|
|
2506
2846
|
op: "stream",
|
|
2507
2847
|
channel,
|
|
2508
|
-
coin,
|
|
2848
|
+
symbol: coin,
|
|
2509
2849
|
start: options.start,
|
|
2510
2850
|
end: options.end,
|
|
2511
2851
|
batch_size: options.batchSize ?? 1e3,
|
|
@@ -2542,7 +2882,7 @@ var OxArchiveWs = class {
|
|
|
2542
2882
|
this.send({
|
|
2543
2883
|
op: "stream",
|
|
2544
2884
|
channels,
|
|
2545
|
-
coin,
|
|
2885
|
+
symbol: coin,
|
|
2546
2886
|
start: options.start,
|
|
2547
2887
|
end: options.end,
|
|
2548
2888
|
batch_size: options.batchSize ?? 1e3,
|
|
@@ -2681,6 +3021,44 @@ var OxArchiveWs = class {
|
|
|
2681
3021
|
onTrades(handler) {
|
|
2682
3022
|
this.tradesHandlers.push(handler);
|
|
2683
3023
|
}
|
|
3024
|
+
/**
|
|
3025
|
+
* Helper to handle live liquidation events for both `liquidations` and
|
|
3026
|
+
* `hip3_liquidations` channels. Each item is a fill row with
|
|
3027
|
+
* `is_liquidation: true`, surfaced as a `Trade` (the wire shape matches
|
|
3028
|
+
* trades exactly).
|
|
3029
|
+
*
|
|
3030
|
+
* @param handler Called with the channel, coin, and parsed Trade array.
|
|
3031
|
+
*
|
|
3032
|
+
* @example
|
|
3033
|
+
* ```typescript
|
|
3034
|
+
* ws.onLiquidations((channel, coin, fills) => {
|
|
3035
|
+
* for (const f of fills) {
|
|
3036
|
+
* console.log(`${channel} ${coin} liq: ${f.side} ${f.size}@${f.price}`);
|
|
3037
|
+
* }
|
|
3038
|
+
* });
|
|
3039
|
+
* ws.subscribeLiquidations('BTC');
|
|
3040
|
+
* ws.subscribeHip3Liquidations('hyna:BTC');
|
|
3041
|
+
* ```
|
|
3042
|
+
*/
|
|
3043
|
+
onLiquidations(handler) {
|
|
3044
|
+
this.liquidationsHandlers.push(handler);
|
|
3045
|
+
}
|
|
3046
|
+
/**
|
|
3047
|
+
* Handle HIP-4 outcome settlement events. Pushed once per `(outcome_id, side)`
|
|
3048
|
+
* when the outcome flips to settled. After this event the server proactively
|
|
3049
|
+
* unsubscribes the client from every hip4_* subscription on the settled coin —
|
|
3050
|
+
* treat the event as a terminal signal for that coin.
|
|
3051
|
+
*
|
|
3052
|
+
* @example
|
|
3053
|
+
* ```typescript
|
|
3054
|
+
* ws.onOutcomeSettled((coin, outcomeId, side, value, at) => {
|
|
3055
|
+
* console.log(`${coin} (outcome ${outcomeId} side ${side}) settled to ${value} at ${at}`);
|
|
3056
|
+
* });
|
|
3057
|
+
* ```
|
|
3058
|
+
*/
|
|
3059
|
+
onOutcomeSettled(handler) {
|
|
3060
|
+
this.outcomeSettledHandlers.push(handler);
|
|
3061
|
+
}
|
|
2684
3062
|
// Private methods
|
|
2685
3063
|
send(message) {
|
|
2686
3064
|
if (this.ws?.readyState === WebSocket.OPEN) {
|
|
@@ -2808,16 +3186,28 @@ var OxArchiveWs = class {
|
|
|
2808
3186
|
break;
|
|
2809
3187
|
}
|
|
2810
3188
|
case "data": {
|
|
2811
|
-
if (message.channel === "orderbook") {
|
|
3189
|
+
if (message.channel === "orderbook" || message.channel === "hip3_orderbook" || message.channel === "hip4_orderbook" || message.channel === "lighter_orderbook") {
|
|
2812
3190
|
const orderbook = transformOrderbook(message.coin, message.data);
|
|
2813
3191
|
for (const handler of this.orderbookHandlers) {
|
|
2814
3192
|
handler(message.coin, orderbook);
|
|
2815
3193
|
}
|
|
2816
|
-
} else if (message.channel === "trades") {
|
|
3194
|
+
} else if (message.channel === "trades" || message.channel === "hip3_trades" || message.channel === "hip4_trades" || message.channel === "lighter_trades") {
|
|
2817
3195
|
const trades = transformTrades(message.coin, message.data);
|
|
2818
3196
|
for (const handler of this.tradesHandlers) {
|
|
2819
3197
|
handler(message.coin, trades);
|
|
2820
3198
|
}
|
|
3199
|
+
} else if (message.channel === "liquidations" || message.channel === "hip3_liquidations") {
|
|
3200
|
+
const fills = transformTrades(message.coin, message.data);
|
|
3201
|
+
for (const handler of this.liquidationsHandlers) {
|
|
3202
|
+
handler(message.channel, message.coin, fills);
|
|
3203
|
+
}
|
|
3204
|
+
}
|
|
3205
|
+
break;
|
|
3206
|
+
}
|
|
3207
|
+
case "outcome_settled": {
|
|
3208
|
+
const msg = message;
|
|
3209
|
+
for (const handler of this.outcomeSettledHandlers) {
|
|
3210
|
+
handler(msg.coin, msg.outcome_id, msg.side, msg.settlement_value, msg.settlement_at);
|
|
2821
3211
|
}
|
|
2822
3212
|
break;
|
|
2823
3213
|
}
|
|
@@ -2969,6 +3359,7 @@ export {
|
|
|
2969
3359
|
FundingRateResponseSchema,
|
|
2970
3360
|
FundingRateSchema,
|
|
2971
3361
|
Hip3Client,
|
|
3362
|
+
Hip4Client,
|
|
2972
3363
|
HyperliquidClient,
|
|
2973
3364
|
InstrumentArrayResponseSchema,
|
|
2974
3365
|
InstrumentResponseSchema,
|
|
@@ -3006,6 +3397,7 @@ export {
|
|
|
3006
3397
|
WsErrorSchema,
|
|
3007
3398
|
WsHistoricalBatchSchema,
|
|
3008
3399
|
WsHistoricalDataSchema,
|
|
3400
|
+
WsOutcomeSettledSchema,
|
|
3009
3401
|
WsPongSchema,
|
|
3010
3402
|
WsReplayCompletedSchema,
|
|
3011
3403
|
WsReplayPausedSchema,
|