@0xarchive/sdk 0.9.2 → 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 +228 -111
- package/dist/index.d.mts +437 -64
- package/dist/index.d.ts +437 -64
- package/dist/index.js +443 -84
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +441 -84
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -39,6 +39,8 @@ __export(index_exports, {
|
|
|
39
39
|
InstrumentResponseSchema: () => InstrumentResponseSchema,
|
|
40
40
|
InstrumentSchema: () => InstrumentSchema,
|
|
41
41
|
InstrumentTypeSchema: () => InstrumentTypeSchema,
|
|
42
|
+
L2OrderBookResource: () => L2OrderBookResource,
|
|
43
|
+
L4OrderBookReconstructor: () => L4OrderBookReconstructor,
|
|
42
44
|
LighterClient: () => LighterClient,
|
|
43
45
|
LiquidationArrayResponseSchema: () => LiquidationArrayResponseSchema,
|
|
44
46
|
LiquidationSchema: () => LiquidationSchema,
|
|
@@ -772,15 +774,15 @@ var OrderBookResource = class {
|
|
|
772
774
|
this.coinTransform = coinTransform;
|
|
773
775
|
}
|
|
774
776
|
/**
|
|
775
|
-
* Get order book snapshot for a
|
|
777
|
+
* Get order book snapshot for a symbol
|
|
776
778
|
*
|
|
777
|
-
* @param
|
|
779
|
+
* @param symbol - The symbol (e.g., 'BTC', 'ETH')
|
|
778
780
|
* @param params - Optional parameters
|
|
779
781
|
* @returns Order book snapshot
|
|
780
782
|
*/
|
|
781
|
-
async get(
|
|
783
|
+
async get(symbol, params) {
|
|
782
784
|
const response = await this.http.get(
|
|
783
|
-
`${this.basePath}/orderbook/${this.coinTransform(
|
|
785
|
+
`${this.basePath}/orderbook/${this.coinTransform(symbol)}`,
|
|
784
786
|
params,
|
|
785
787
|
this.http.validationEnabled ? OrderBookResponseSchema : void 0
|
|
786
788
|
);
|
|
@@ -789,7 +791,7 @@ var OrderBookResource = class {
|
|
|
789
791
|
/**
|
|
790
792
|
* Get historical order book snapshots with cursor-based pagination
|
|
791
793
|
*
|
|
792
|
-
* @param
|
|
794
|
+
* @param symbol - The symbol (e.g., 'BTC', 'ETH')
|
|
793
795
|
* @param params - Time range and cursor pagination parameters (start and end are required)
|
|
794
796
|
* @returns CursorResponse with order book snapshots and nextCursor for pagination
|
|
795
797
|
*
|
|
@@ -813,9 +815,9 @@ var OrderBookResource = class {
|
|
|
813
815
|
* }
|
|
814
816
|
* ```
|
|
815
817
|
*/
|
|
816
|
-
async history(
|
|
818
|
+
async history(symbol, params) {
|
|
817
819
|
const response = await this.http.get(
|
|
818
|
-
`${this.basePath}/orderbook/${this.coinTransform(
|
|
820
|
+
`${this.basePath}/orderbook/${this.coinTransform(symbol)}/history`,
|
|
819
821
|
params,
|
|
820
822
|
this.http.validationEnabled ? OrderBookArrayResponseSchema : void 0
|
|
821
823
|
);
|
|
@@ -833,7 +835,7 @@ var OrderBookResource = class {
|
|
|
833
835
|
*
|
|
834
836
|
* For automatic reconstruction, use `historyReconstructed()` instead.
|
|
835
837
|
*
|
|
836
|
-
* @param
|
|
838
|
+
* @param symbol - The symbol (e.g., 'BTC', 'ETH')
|
|
837
839
|
* @param params - Time range parameters
|
|
838
840
|
* @returns Tick data with checkpoint and deltas
|
|
839
841
|
*
|
|
@@ -853,9 +855,9 @@ var OrderBookResource = class {
|
|
|
853
855
|
* }
|
|
854
856
|
* ```
|
|
855
857
|
*/
|
|
856
|
-
async historyTick(
|
|
858
|
+
async historyTick(symbol, params) {
|
|
857
859
|
const response = await this.http.get(
|
|
858
|
-
`${this.basePath}/orderbook/${this.coinTransform(
|
|
860
|
+
`${this.basePath}/orderbook/${this.coinTransform(symbol)}/history`,
|
|
859
861
|
{
|
|
860
862
|
...params,
|
|
861
863
|
granularity: "tick"
|
|
@@ -880,7 +882,7 @@ var OrderBookResource = class {
|
|
|
880
882
|
* For large time ranges, consider using `historyTick()` with the
|
|
881
883
|
* `OrderBookReconstructor.iterate()` method for memory efficiency.
|
|
882
884
|
*
|
|
883
|
-
* @param
|
|
885
|
+
* @param symbol - The symbol (e.g., 'BTC', 'ETH')
|
|
884
886
|
* @param params - Time range parameters
|
|
885
887
|
* @param options - Reconstruction options
|
|
886
888
|
* @returns Array of reconstructed orderbook snapshots
|
|
@@ -904,8 +906,8 @@ var OrderBookResource = class {
|
|
|
904
906
|
* );
|
|
905
907
|
* ```
|
|
906
908
|
*/
|
|
907
|
-
async historyReconstructed(
|
|
908
|
-
const tickData = await this.historyTick(
|
|
909
|
+
async historyReconstructed(symbol, params, options = {}) {
|
|
910
|
+
const tickData = await this.historyTick(symbol, params);
|
|
909
911
|
const reconstructor = new OrderBookReconstructor();
|
|
910
912
|
return reconstructor.reconstructAll(tickData.checkpoint, tickData.deltas, options);
|
|
911
913
|
}
|
|
@@ -945,7 +947,7 @@ var OrderBookResource = class {
|
|
|
945
947
|
* per API request and yielding reconstructed orderbook snapshots one at a time.
|
|
946
948
|
* Memory-efficient for processing large time ranges.
|
|
947
949
|
*
|
|
948
|
-
* @param
|
|
950
|
+
* @param symbol - The symbol (e.g., 'BTC', 'ETH')
|
|
949
951
|
* @param params - Time range parameters
|
|
950
952
|
* @param depth - Maximum price levels to include in output snapshots
|
|
951
953
|
* @yields Reconstructed orderbook snapshots
|
|
@@ -968,7 +970,7 @@ var OrderBookResource = class {
|
|
|
968
970
|
* }
|
|
969
971
|
* ```
|
|
970
972
|
*/
|
|
971
|
-
async *iterateTickHistory(
|
|
973
|
+
async *iterateTickHistory(symbol, params, depth) {
|
|
972
974
|
const startTs = typeof params.start === "string" ? new Date(params.start).getTime() : params.start;
|
|
973
975
|
const endTs = typeof params.end === "string" ? new Date(params.end).getTime() : params.end;
|
|
974
976
|
let cursor = startTs;
|
|
@@ -976,7 +978,7 @@ var OrderBookResource = class {
|
|
|
976
978
|
const MAX_DELTAS_PER_PAGE = 1e3;
|
|
977
979
|
let isFirstPage = true;
|
|
978
980
|
while (cursor < endTs) {
|
|
979
|
-
const tickData = await this.historyTick(
|
|
981
|
+
const tickData = await this.historyTick(symbol, {
|
|
980
982
|
start: cursor,
|
|
981
983
|
end: endTs,
|
|
982
984
|
depth: params.depth
|
|
@@ -1014,12 +1016,12 @@ var TradesResource = class {
|
|
|
1014
1016
|
this.coinTransform = coinTransform;
|
|
1015
1017
|
}
|
|
1016
1018
|
/**
|
|
1017
|
-
* Get trade history for a
|
|
1019
|
+
* Get trade history for a symbol using cursor-based pagination
|
|
1018
1020
|
*
|
|
1019
1021
|
* Uses cursor-based pagination by default, which is more efficient for large datasets.
|
|
1020
1022
|
* Use the `nextCursor` from the response as the `cursor` parameter to get the next page.
|
|
1021
1023
|
*
|
|
1022
|
-
* @param
|
|
1024
|
+
* @param symbol - The symbol (e.g., 'BTC', 'ETH')
|
|
1023
1025
|
* @param params - Time range and cursor pagination parameters (start and end are required)
|
|
1024
1026
|
* @returns Object with trades array and nextCursor for pagination
|
|
1025
1027
|
*
|
|
@@ -1043,9 +1045,9 @@ var TradesResource = class {
|
|
|
1043
1045
|
* }
|
|
1044
1046
|
* ```
|
|
1045
1047
|
*/
|
|
1046
|
-
async list(
|
|
1048
|
+
async list(symbol, params) {
|
|
1047
1049
|
const response = await this.http.get(
|
|
1048
|
-
`${this.basePath}/trades/${this.coinTransform(
|
|
1050
|
+
`${this.basePath}/trades/${this.coinTransform(symbol)}`,
|
|
1049
1051
|
params,
|
|
1050
1052
|
this.http.validationEnabled ? TradeArrayResponseSchema : void 0
|
|
1051
1053
|
);
|
|
@@ -1055,20 +1057,20 @@ var TradesResource = class {
|
|
|
1055
1057
|
};
|
|
1056
1058
|
}
|
|
1057
1059
|
/**
|
|
1058
|
-
* Get most recent trades for a
|
|
1060
|
+
* Get most recent trades for a symbol.
|
|
1059
1061
|
*
|
|
1060
1062
|
* Note: This method is available for Lighter (client.lighter.trades.recent())
|
|
1061
1063
|
* and HIP-3 (client.hyperliquid.hip3.trades.recent()) which have real-time data
|
|
1062
1064
|
* ingestion. Hyperliquid uses hourly backfill so this endpoint is not available
|
|
1063
1065
|
* for Hyperliquid.
|
|
1064
1066
|
*
|
|
1065
|
-
* @param
|
|
1067
|
+
* @param symbol - The symbol (e.g., 'BTC', 'ETH')
|
|
1066
1068
|
* @param limit - Number of trades to return (default: 100)
|
|
1067
1069
|
* @returns Array of recent trades
|
|
1068
1070
|
*/
|
|
1069
|
-
async recent(
|
|
1071
|
+
async recent(symbol, limit) {
|
|
1070
1072
|
const response = await this.http.get(
|
|
1071
|
-
`${this.basePath}/trades/${this.coinTransform(
|
|
1073
|
+
`${this.basePath}/trades/${this.coinTransform(symbol)}/recent`,
|
|
1072
1074
|
{ limit },
|
|
1073
1075
|
this.http.validationEnabled ? TradeArrayResponseSchema : void 0
|
|
1074
1076
|
);
|
|
@@ -1180,15 +1182,15 @@ var FundingResource = class {
|
|
|
1180
1182
|
this.coinTransform = coinTransform;
|
|
1181
1183
|
}
|
|
1182
1184
|
/**
|
|
1183
|
-
* Get funding rate history for a
|
|
1185
|
+
* Get funding rate history for a symbol with cursor-based pagination
|
|
1184
1186
|
*
|
|
1185
|
-
* @param
|
|
1187
|
+
* @param symbol - The symbol (e.g., 'BTC', 'ETH')
|
|
1186
1188
|
* @param params - Time range and cursor pagination parameters (start and end are required)
|
|
1187
1189
|
* @returns CursorResponse with funding rate records and nextCursor for pagination
|
|
1188
1190
|
*/
|
|
1189
|
-
async history(
|
|
1191
|
+
async history(symbol, params) {
|
|
1190
1192
|
const response = await this.http.get(
|
|
1191
|
-
`${this.basePath}/funding/${this.coinTransform(
|
|
1193
|
+
`${this.basePath}/funding/${this.coinTransform(symbol)}`,
|
|
1192
1194
|
params,
|
|
1193
1195
|
this.http.validationEnabled ? FundingRateArrayResponseSchema : void 0
|
|
1194
1196
|
);
|
|
@@ -1198,14 +1200,14 @@ var FundingResource = class {
|
|
|
1198
1200
|
};
|
|
1199
1201
|
}
|
|
1200
1202
|
/**
|
|
1201
|
-
* Get current funding rate for a
|
|
1203
|
+
* Get current funding rate for a symbol
|
|
1202
1204
|
*
|
|
1203
|
-
* @param
|
|
1205
|
+
* @param symbol - The symbol (e.g., 'BTC', 'ETH')
|
|
1204
1206
|
* @returns Current funding rate
|
|
1205
1207
|
*/
|
|
1206
|
-
async current(
|
|
1208
|
+
async current(symbol) {
|
|
1207
1209
|
const response = await this.http.get(
|
|
1208
|
-
`${this.basePath}/funding/${this.coinTransform(
|
|
1210
|
+
`${this.basePath}/funding/${this.coinTransform(symbol)}/current`,
|
|
1209
1211
|
void 0,
|
|
1210
1212
|
this.http.validationEnabled ? FundingRateResponseSchema : void 0
|
|
1211
1213
|
);
|
|
@@ -1221,15 +1223,15 @@ var OpenInterestResource = class {
|
|
|
1221
1223
|
this.coinTransform = coinTransform;
|
|
1222
1224
|
}
|
|
1223
1225
|
/**
|
|
1224
|
-
* Get open interest history for a
|
|
1226
|
+
* Get open interest history for a symbol with cursor-based pagination
|
|
1225
1227
|
*
|
|
1226
|
-
* @param
|
|
1228
|
+
* @param symbol - The symbol (e.g., 'BTC', 'ETH')
|
|
1227
1229
|
* @param params - Time range and cursor pagination parameters (start and end are required)
|
|
1228
1230
|
* @returns CursorResponse with open interest records and nextCursor for pagination
|
|
1229
1231
|
*/
|
|
1230
|
-
async history(
|
|
1232
|
+
async history(symbol, params) {
|
|
1231
1233
|
const response = await this.http.get(
|
|
1232
|
-
`${this.basePath}/openinterest/${this.coinTransform(
|
|
1234
|
+
`${this.basePath}/openinterest/${this.coinTransform(symbol)}`,
|
|
1233
1235
|
params,
|
|
1234
1236
|
this.http.validationEnabled ? OpenInterestArrayResponseSchema : void 0
|
|
1235
1237
|
);
|
|
@@ -1239,14 +1241,14 @@ var OpenInterestResource = class {
|
|
|
1239
1241
|
};
|
|
1240
1242
|
}
|
|
1241
1243
|
/**
|
|
1242
|
-
* Get current open interest for a
|
|
1244
|
+
* Get current open interest for a symbol
|
|
1243
1245
|
*
|
|
1244
|
-
* @param
|
|
1246
|
+
* @param symbol - The symbol (e.g., 'BTC', 'ETH')
|
|
1245
1247
|
* @returns Current open interest
|
|
1246
1248
|
*/
|
|
1247
|
-
async current(
|
|
1249
|
+
async current(symbol) {
|
|
1248
1250
|
const response = await this.http.get(
|
|
1249
|
-
`${this.basePath}/openinterest/${this.coinTransform(
|
|
1251
|
+
`${this.basePath}/openinterest/${this.coinTransform(symbol)}/current`,
|
|
1250
1252
|
void 0,
|
|
1251
1253
|
this.http.validationEnabled ? OpenInterestResponseSchema : void 0
|
|
1252
1254
|
);
|
|
@@ -1264,13 +1266,13 @@ var CandlesResource = class {
|
|
|
1264
1266
|
/**
|
|
1265
1267
|
* Get historical OHLCV candle data with cursor-based pagination
|
|
1266
1268
|
*
|
|
1267
|
-
* @param
|
|
1269
|
+
* @param symbol - The symbol (e.g., 'BTC', 'ETH')
|
|
1268
1270
|
* @param params - Time range, interval, and cursor pagination parameters (start and end are required)
|
|
1269
1271
|
* @returns CursorResponse with candle records and nextCursor for pagination
|
|
1270
1272
|
*/
|
|
1271
|
-
async history(
|
|
1273
|
+
async history(symbol, params) {
|
|
1272
1274
|
const response = await this.http.get(
|
|
1273
|
-
`${this.basePath}/candles/${this.coinTransform(
|
|
1275
|
+
`${this.basePath}/candles/${this.coinTransform(symbol)}`,
|
|
1274
1276
|
params,
|
|
1275
1277
|
this.http.validationEnabled ? CandleArrayResponseSchema : void 0
|
|
1276
1278
|
);
|
|
@@ -1283,20 +1285,21 @@ var CandlesResource = class {
|
|
|
1283
1285
|
|
|
1284
1286
|
// src/resources/liquidations.ts
|
|
1285
1287
|
var LiquidationsResource = class {
|
|
1286
|
-
constructor(http, basePath = "/v1") {
|
|
1288
|
+
constructor(http, basePath = "/v1", coinTransform = (c) => c.toUpperCase()) {
|
|
1287
1289
|
this.http = http;
|
|
1288
1290
|
this.basePath = basePath;
|
|
1291
|
+
this.coinTransform = coinTransform;
|
|
1289
1292
|
}
|
|
1290
1293
|
/**
|
|
1291
|
-
* Get liquidation history for a
|
|
1294
|
+
* Get liquidation history for a symbol with cursor-based pagination
|
|
1292
1295
|
*
|
|
1293
|
-
* @param
|
|
1296
|
+
* @param symbol - The symbol (e.g., 'BTC', 'ETH')
|
|
1294
1297
|
* @param params - Time range and cursor pagination parameters (start and end are required)
|
|
1295
1298
|
* @returns CursorResponse with liquidation records and nextCursor for pagination
|
|
1296
1299
|
*/
|
|
1297
|
-
async history(
|
|
1300
|
+
async history(symbol, params) {
|
|
1298
1301
|
const response = await this.http.get(
|
|
1299
|
-
`${this.basePath}/liquidations/${
|
|
1302
|
+
`${this.basePath}/liquidations/${this.coinTransform(symbol)}`,
|
|
1300
1303
|
params,
|
|
1301
1304
|
this.http.validationEnabled ? LiquidationArrayResponseSchema : void 0
|
|
1302
1305
|
);
|
|
@@ -1333,13 +1336,13 @@ var LiquidationsResource = class {
|
|
|
1333
1336
|
* Returns pre-aggregated data with total/long/short USD volumes per bucket,
|
|
1334
1337
|
* reducing data transfer by 100-1000x compared to individual liquidation records.
|
|
1335
1338
|
*
|
|
1336
|
-
* @param
|
|
1339
|
+
* @param symbol - The symbol (e.g., 'BTC', 'ETH')
|
|
1337
1340
|
* @param params - Time range, cursor, and interval parameters
|
|
1338
1341
|
* @returns CursorResponse with liquidation volume buckets
|
|
1339
1342
|
*/
|
|
1340
|
-
async volume(
|
|
1343
|
+
async volume(symbol, params) {
|
|
1341
1344
|
const response = await this.http.get(
|
|
1342
|
-
`${this.basePath}/liquidations/${
|
|
1345
|
+
`${this.basePath}/liquidations/${this.coinTransform(symbol)}/volume`,
|
|
1343
1346
|
params,
|
|
1344
1347
|
this.http.validationEnabled ? LiquidationVolumeArrayResponseSchema : void 0
|
|
1345
1348
|
);
|
|
@@ -1686,6 +1689,190 @@ var Web3Resource = class {
|
|
|
1686
1689
|
}
|
|
1687
1690
|
};
|
|
1688
1691
|
|
|
1692
|
+
// src/resources/orders.ts
|
|
1693
|
+
var OrdersResource = class {
|
|
1694
|
+
constructor(http, basePath = "/v1", coinTransform = (c) => c.toUpperCase()) {
|
|
1695
|
+
this.http = http;
|
|
1696
|
+
this.basePath = basePath;
|
|
1697
|
+
this.coinTransform = coinTransform;
|
|
1698
|
+
}
|
|
1699
|
+
/**
|
|
1700
|
+
* Get order history for a symbol with cursor-based pagination
|
|
1701
|
+
*
|
|
1702
|
+
* @param symbol - The symbol (e.g., 'BTC', 'ETH')
|
|
1703
|
+
* @param params - Time range, cursor pagination, and filter parameters
|
|
1704
|
+
* @returns CursorResponse with order records and nextCursor for pagination
|
|
1705
|
+
*/
|
|
1706
|
+
async history(symbol, params) {
|
|
1707
|
+
const response = await this.http.get(
|
|
1708
|
+
`${this.basePath}/orders/${this.coinTransform(symbol)}/history`,
|
|
1709
|
+
params
|
|
1710
|
+
);
|
|
1711
|
+
return { data: response.data, nextCursor: response.meta.nextCursor };
|
|
1712
|
+
}
|
|
1713
|
+
/**
|
|
1714
|
+
* Get order flow for a symbol
|
|
1715
|
+
*
|
|
1716
|
+
* @param symbol - The symbol (e.g., 'BTC', 'ETH')
|
|
1717
|
+
* @param params - Time range and interval parameters
|
|
1718
|
+
* @returns CursorResponse with order flow records
|
|
1719
|
+
*/
|
|
1720
|
+
async flow(symbol, params) {
|
|
1721
|
+
const response = await this.http.get(
|
|
1722
|
+
`${this.basePath}/orders/${this.coinTransform(symbol)}/flow`,
|
|
1723
|
+
params
|
|
1724
|
+
);
|
|
1725
|
+
return { data: response.data, nextCursor: response.meta.nextCursor };
|
|
1726
|
+
}
|
|
1727
|
+
/**
|
|
1728
|
+
* Get TP/SL orders for a symbol with cursor-based pagination
|
|
1729
|
+
*
|
|
1730
|
+
* @param symbol - The symbol (e.g., 'BTC', 'ETH')
|
|
1731
|
+
* @param params - Time range, cursor pagination, and filter parameters
|
|
1732
|
+
* @returns CursorResponse with TP/SL order records
|
|
1733
|
+
*/
|
|
1734
|
+
async tpsl(symbol, params) {
|
|
1735
|
+
const response = await this.http.get(
|
|
1736
|
+
`${this.basePath}/orders/${this.coinTransform(symbol)}/tpsl`,
|
|
1737
|
+
params
|
|
1738
|
+
);
|
|
1739
|
+
return { data: response.data, nextCursor: response.meta.nextCursor };
|
|
1740
|
+
}
|
|
1741
|
+
};
|
|
1742
|
+
|
|
1743
|
+
// src/resources/l4-orderbook.ts
|
|
1744
|
+
var L4OrderBookResource = class {
|
|
1745
|
+
constructor(http, basePath = "/v1", coinTransform = (c) => c.toUpperCase()) {
|
|
1746
|
+
this.http = http;
|
|
1747
|
+
this.basePath = basePath;
|
|
1748
|
+
this.coinTransform = coinTransform;
|
|
1749
|
+
}
|
|
1750
|
+
/**
|
|
1751
|
+
* Get L4 order book snapshot for a symbol
|
|
1752
|
+
*
|
|
1753
|
+
* @param symbol - The symbol (e.g., 'BTC', 'ETH')
|
|
1754
|
+
* @param params - Optional parameters (timestamp, depth)
|
|
1755
|
+
* @returns L4 order book snapshot
|
|
1756
|
+
*/
|
|
1757
|
+
async get(symbol, params) {
|
|
1758
|
+
const response = await this.http.get(
|
|
1759
|
+
`${this.basePath}/orderbook/${this.coinTransform(symbol)}/l4`,
|
|
1760
|
+
params
|
|
1761
|
+
);
|
|
1762
|
+
return response.data;
|
|
1763
|
+
}
|
|
1764
|
+
/**
|
|
1765
|
+
* Get L4 order book diffs with cursor-based pagination
|
|
1766
|
+
*
|
|
1767
|
+
* @param symbol - The symbol (e.g., 'BTC', 'ETH')
|
|
1768
|
+
* @param params - Time range and cursor pagination parameters
|
|
1769
|
+
* @returns CursorResponse with L4 orderbook diffs and nextCursor for pagination
|
|
1770
|
+
*/
|
|
1771
|
+
async diffs(symbol, params) {
|
|
1772
|
+
const response = await this.http.get(
|
|
1773
|
+
`${this.basePath}/orderbook/${this.coinTransform(symbol)}/l4/diffs`,
|
|
1774
|
+
params
|
|
1775
|
+
);
|
|
1776
|
+
return { data: response.data, nextCursor: response.meta.nextCursor };
|
|
1777
|
+
}
|
|
1778
|
+
/**
|
|
1779
|
+
* Get L4 order book history with cursor-based pagination
|
|
1780
|
+
*
|
|
1781
|
+
* @param symbol - The symbol (e.g., 'BTC', 'ETH')
|
|
1782
|
+
* @param params - Time range and cursor pagination parameters
|
|
1783
|
+
* @returns CursorResponse with L4 orderbook snapshots and nextCursor for pagination
|
|
1784
|
+
*/
|
|
1785
|
+
async history(symbol, params) {
|
|
1786
|
+
const response = await this.http.get(
|
|
1787
|
+
`${this.basePath}/orderbook/${this.coinTransform(symbol)}/l4/history`,
|
|
1788
|
+
params
|
|
1789
|
+
);
|
|
1790
|
+
return { data: response.data, nextCursor: response.meta.nextCursor };
|
|
1791
|
+
}
|
|
1792
|
+
};
|
|
1793
|
+
|
|
1794
|
+
// src/resources/l2-orderbook.ts
|
|
1795
|
+
var L2OrderBookResource = class {
|
|
1796
|
+
constructor(http, basePath = "/v1", coinTransform = (c) => c.toUpperCase()) {
|
|
1797
|
+
this.http = http;
|
|
1798
|
+
this.basePath = basePath;
|
|
1799
|
+
this.coinTransform = coinTransform;
|
|
1800
|
+
}
|
|
1801
|
+
/** Get full-depth L2 order book snapshot. */
|
|
1802
|
+
async get(symbol, params) {
|
|
1803
|
+
const coin = this.coinTransform(symbol);
|
|
1804
|
+
const query = {};
|
|
1805
|
+
if (params?.timestamp != null) query.timestamp = params.timestamp;
|
|
1806
|
+
if (params?.depth != null) query.depth = params.depth;
|
|
1807
|
+
const resp = await this.http.get(
|
|
1808
|
+
`${this.basePath}/orderbook/${encodeURIComponent(coin)}/l2`,
|
|
1809
|
+
query
|
|
1810
|
+
);
|
|
1811
|
+
return resp.data;
|
|
1812
|
+
}
|
|
1813
|
+
/** Get paginated L2 full-depth history. */
|
|
1814
|
+
async history(symbol, params) {
|
|
1815
|
+
const coin = this.coinTransform(symbol);
|
|
1816
|
+
const resp = await this.http.get(
|
|
1817
|
+
`${this.basePath}/orderbook/${encodeURIComponent(coin)}/l2/history`,
|
|
1818
|
+
params
|
|
1819
|
+
);
|
|
1820
|
+
return {
|
|
1821
|
+
data: resp.data,
|
|
1822
|
+
nextCursor: resp.meta?.next_cursor ?? void 0
|
|
1823
|
+
};
|
|
1824
|
+
}
|
|
1825
|
+
/** Get tick-level L2 order book diffs. */
|
|
1826
|
+
async diffs(symbol, params) {
|
|
1827
|
+
const coin = this.coinTransform(symbol);
|
|
1828
|
+
const resp = await this.http.get(
|
|
1829
|
+
`${this.basePath}/orderbook/${encodeURIComponent(coin)}/l2/diffs`,
|
|
1830
|
+
params
|
|
1831
|
+
);
|
|
1832
|
+
return {
|
|
1833
|
+
data: resp.data,
|
|
1834
|
+
nextCursor: resp.meta?.next_cursor ?? void 0
|
|
1835
|
+
};
|
|
1836
|
+
}
|
|
1837
|
+
};
|
|
1838
|
+
|
|
1839
|
+
// src/resources/l3-orderbook.ts
|
|
1840
|
+
var L3OrderBookResource = class {
|
|
1841
|
+
constructor(http, basePath = "/v1", coinTransform = (c) => c.toUpperCase()) {
|
|
1842
|
+
this.http = http;
|
|
1843
|
+
this.basePath = basePath;
|
|
1844
|
+
this.coinTransform = coinTransform;
|
|
1845
|
+
}
|
|
1846
|
+
/**
|
|
1847
|
+
* Get L3 order book snapshot for a symbol
|
|
1848
|
+
*
|
|
1849
|
+
* @param symbol - The symbol (e.g., 'BTC', 'ETH')
|
|
1850
|
+
* @param params - Optional parameters (timestamp, depth)
|
|
1851
|
+
* @returns L3 order book snapshot
|
|
1852
|
+
*/
|
|
1853
|
+
async get(symbol, params) {
|
|
1854
|
+
const response = await this.http.get(
|
|
1855
|
+
`${this.basePath}/l3orderbook/${this.coinTransform(symbol)}`,
|
|
1856
|
+
params
|
|
1857
|
+
);
|
|
1858
|
+
return response.data;
|
|
1859
|
+
}
|
|
1860
|
+
/**
|
|
1861
|
+
* Get L3 order book history with cursor-based pagination
|
|
1862
|
+
*
|
|
1863
|
+
* @param symbol - The symbol (e.g., 'BTC', 'ETH')
|
|
1864
|
+
* @param params - Time range and cursor pagination parameters
|
|
1865
|
+
* @returns CursorResponse with L3 orderbook snapshots and nextCursor for pagination
|
|
1866
|
+
*/
|
|
1867
|
+
async history(symbol, params) {
|
|
1868
|
+
const response = await this.http.get(
|
|
1869
|
+
`${this.basePath}/l3orderbook/${this.coinTransform(symbol)}/history`,
|
|
1870
|
+
params
|
|
1871
|
+
);
|
|
1872
|
+
return { data: response.data, nextCursor: response.meta.nextCursor };
|
|
1873
|
+
}
|
|
1874
|
+
};
|
|
1875
|
+
|
|
1689
1876
|
// src/exchanges.ts
|
|
1690
1877
|
var HyperliquidClient = class {
|
|
1691
1878
|
/**
|
|
@@ -1716,6 +1903,18 @@ var HyperliquidClient = class {
|
|
|
1716
1903
|
* Liquidation events (May 2025+)
|
|
1717
1904
|
*/
|
|
1718
1905
|
liquidations;
|
|
1906
|
+
/**
|
|
1907
|
+
* Order history, flow, and TP/SL
|
|
1908
|
+
*/
|
|
1909
|
+
orders;
|
|
1910
|
+
/**
|
|
1911
|
+
* L4 order book (snapshots, diffs, history)
|
|
1912
|
+
*/
|
|
1913
|
+
l4Orderbook;
|
|
1914
|
+
/**
|
|
1915
|
+
* L2 full-depth order book (derived from L4)
|
|
1916
|
+
*/
|
|
1917
|
+
l2Orderbook;
|
|
1719
1918
|
/**
|
|
1720
1919
|
* HIP-3 builder-deployed perpetuals (February 2026+)
|
|
1721
1920
|
*/
|
|
@@ -1731,17 +1930,20 @@ var HyperliquidClient = class {
|
|
|
1731
1930
|
this.openInterest = new OpenInterestResource(http, basePath);
|
|
1732
1931
|
this.candles = new CandlesResource(http, basePath);
|
|
1733
1932
|
this.liquidations = new LiquidationsResource(http, basePath);
|
|
1933
|
+
this.orders = new OrdersResource(http, basePath);
|
|
1934
|
+
this.l4Orderbook = new L4OrderBookResource(http, basePath);
|
|
1935
|
+
this.l2Orderbook = new L2OrderBookResource(http, basePath);
|
|
1734
1936
|
this.hip3 = new Hip3Client(http);
|
|
1735
1937
|
}
|
|
1736
1938
|
/**
|
|
1737
|
-
* Get per-
|
|
1939
|
+
* Get per-symbol data freshness across all data types
|
|
1738
1940
|
*
|
|
1739
|
-
* @param
|
|
1740
|
-
* @returns Per-
|
|
1941
|
+
* @param symbol - The symbol (e.g., 'BTC', 'ETH')
|
|
1942
|
+
* @returns Per-symbol freshness with last_updated and lag_ms for each data type
|
|
1741
1943
|
*/
|
|
1742
|
-
async freshness(
|
|
1944
|
+
async freshness(symbol) {
|
|
1743
1945
|
const response = await this.http.get(
|
|
1744
|
-
`/v1/hyperliquid/freshness/${
|
|
1946
|
+
`/v1/hyperliquid/freshness/${symbol.toUpperCase()}`,
|
|
1745
1947
|
void 0,
|
|
1746
1948
|
this.http.validationEnabled ? CoinFreshnessResponseSchema : void 0
|
|
1747
1949
|
);
|
|
@@ -1750,12 +1952,12 @@ var HyperliquidClient = class {
|
|
|
1750
1952
|
/**
|
|
1751
1953
|
* Get combined market summary (price, funding, OI, volume, liquidations) in one call
|
|
1752
1954
|
*
|
|
1753
|
-
* @param
|
|
1955
|
+
* @param symbol - The symbol (e.g., 'BTC', 'ETH')
|
|
1754
1956
|
* @returns Combined market summary
|
|
1755
1957
|
*/
|
|
1756
|
-
async summary(
|
|
1958
|
+
async summary(symbol) {
|
|
1757
1959
|
const response = await this.http.get(
|
|
1758
|
-
`/v1/hyperliquid/summary/${
|
|
1960
|
+
`/v1/hyperliquid/summary/${symbol.toUpperCase()}`,
|
|
1759
1961
|
void 0,
|
|
1760
1962
|
this.http.validationEnabled ? CoinSummaryResponseSchema : void 0
|
|
1761
1963
|
);
|
|
@@ -1764,13 +1966,13 @@ var HyperliquidClient = class {
|
|
|
1764
1966
|
/**
|
|
1765
1967
|
* Get mark/oracle/mid price history (projected from OI data)
|
|
1766
1968
|
*
|
|
1767
|
-
* @param
|
|
1969
|
+
* @param symbol - The symbol (e.g., 'BTC', 'ETH')
|
|
1768
1970
|
* @param params - Time range, cursor, and interval parameters
|
|
1769
1971
|
* @returns CursorResponse with price snapshots
|
|
1770
1972
|
*/
|
|
1771
|
-
async priceHistory(
|
|
1973
|
+
async priceHistory(symbol, params) {
|
|
1772
1974
|
const response = await this.http.get(
|
|
1773
|
-
`/v1/hyperliquid/prices/${
|
|
1975
|
+
`/v1/hyperliquid/prices/${symbol.toUpperCase()}`,
|
|
1774
1976
|
params,
|
|
1775
1977
|
this.http.validationEnabled ? PriceSnapshotArrayResponseSchema : void 0
|
|
1776
1978
|
);
|
|
@@ -1805,6 +2007,22 @@ var Hip3Client = class {
|
|
|
1805
2007
|
* OHLCV candle data
|
|
1806
2008
|
*/
|
|
1807
2009
|
candles;
|
|
2010
|
+
/**
|
|
2011
|
+
* Liquidation events
|
|
2012
|
+
*/
|
|
2013
|
+
liquidations;
|
|
2014
|
+
/**
|
|
2015
|
+
* Order history, flow, and TP/SL
|
|
2016
|
+
*/
|
|
2017
|
+
orders;
|
|
2018
|
+
/**
|
|
2019
|
+
* L4 order book (snapshots, diffs, history)
|
|
2020
|
+
*/
|
|
2021
|
+
l4Orderbook;
|
|
2022
|
+
/**
|
|
2023
|
+
* L2 full-depth order book (derived from L4)
|
|
2024
|
+
*/
|
|
2025
|
+
l2Orderbook;
|
|
1808
2026
|
http;
|
|
1809
2027
|
constructor(http) {
|
|
1810
2028
|
this.http = http;
|
|
@@ -1816,16 +2034,20 @@ var Hip3Client = class {
|
|
|
1816
2034
|
this.funding = new FundingResource(http, basePath, coinTransform);
|
|
1817
2035
|
this.openInterest = new OpenInterestResource(http, basePath, coinTransform);
|
|
1818
2036
|
this.candles = new CandlesResource(http, basePath, coinTransform);
|
|
2037
|
+
this.liquidations = new LiquidationsResource(http, basePath, coinTransform);
|
|
2038
|
+
this.orders = new OrdersResource(http, basePath, coinTransform);
|
|
2039
|
+
this.l4Orderbook = new L4OrderBookResource(http, basePath, coinTransform);
|
|
2040
|
+
this.l2Orderbook = new L2OrderBookResource(http, basePath, coinTransform);
|
|
1819
2041
|
}
|
|
1820
2042
|
/**
|
|
1821
|
-
* Get per-
|
|
2043
|
+
* Get per-symbol data freshness across all data types
|
|
1822
2044
|
*
|
|
1823
|
-
* @param
|
|
1824
|
-
* @returns Per-
|
|
2045
|
+
* @param symbol - The symbol (case-sensitive, e.g., 'km:US500')
|
|
2046
|
+
* @returns Per-symbol freshness with last_updated and lag_ms for each data type
|
|
1825
2047
|
*/
|
|
1826
|
-
async freshness(
|
|
2048
|
+
async freshness(symbol) {
|
|
1827
2049
|
const response = await this.http.get(
|
|
1828
|
-
`/v1/hyperliquid/hip3/freshness/${
|
|
2050
|
+
`/v1/hyperliquid/hip3/freshness/${symbol}`,
|
|
1829
2051
|
void 0,
|
|
1830
2052
|
this.http.validationEnabled ? CoinFreshnessResponseSchema : void 0
|
|
1831
2053
|
);
|
|
@@ -1834,12 +2056,12 @@ var Hip3Client = class {
|
|
|
1834
2056
|
/**
|
|
1835
2057
|
* Get combined market summary (price, funding, OI) in one call
|
|
1836
2058
|
*
|
|
1837
|
-
* @param
|
|
2059
|
+
* @param symbol - The symbol (case-sensitive, e.g., 'km:US500')
|
|
1838
2060
|
* @returns Combined market summary
|
|
1839
2061
|
*/
|
|
1840
|
-
async summary(
|
|
2062
|
+
async summary(symbol) {
|
|
1841
2063
|
const response = await this.http.get(
|
|
1842
|
-
`/v1/hyperliquid/hip3/summary/${
|
|
2064
|
+
`/v1/hyperliquid/hip3/summary/${symbol}`,
|
|
1843
2065
|
void 0,
|
|
1844
2066
|
this.http.validationEnabled ? CoinSummaryResponseSchema : void 0
|
|
1845
2067
|
);
|
|
@@ -1848,13 +2070,13 @@ var Hip3Client = class {
|
|
|
1848
2070
|
/**
|
|
1849
2071
|
* Get mark/oracle/mid price history (projected from OI data)
|
|
1850
2072
|
*
|
|
1851
|
-
* @param
|
|
2073
|
+
* @param symbol - The symbol (case-sensitive, e.g., 'km:US500')
|
|
1852
2074
|
* @param params - Time range, cursor, and interval parameters
|
|
1853
2075
|
* @returns CursorResponse with price snapshots
|
|
1854
2076
|
*/
|
|
1855
|
-
async priceHistory(
|
|
2077
|
+
async priceHistory(symbol, params) {
|
|
1856
2078
|
const response = await this.http.get(
|
|
1857
|
-
`/v1/hyperliquid/hip3/prices/${
|
|
2079
|
+
`/v1/hyperliquid/hip3/prices/${symbol}`,
|
|
1858
2080
|
params,
|
|
1859
2081
|
this.http.validationEnabled ? PriceSnapshotArrayResponseSchema : void 0
|
|
1860
2082
|
);
|
|
@@ -1889,6 +2111,10 @@ var LighterClient = class {
|
|
|
1889
2111
|
* OHLCV candle data
|
|
1890
2112
|
*/
|
|
1891
2113
|
candles;
|
|
2114
|
+
/**
|
|
2115
|
+
* L3 order book (Lighter only)
|
|
2116
|
+
*/
|
|
2117
|
+
l3Orderbook;
|
|
1892
2118
|
http;
|
|
1893
2119
|
constructor(http) {
|
|
1894
2120
|
this.http = http;
|
|
@@ -1899,16 +2125,17 @@ var LighterClient = class {
|
|
|
1899
2125
|
this.funding = new FundingResource(http, basePath);
|
|
1900
2126
|
this.openInterest = new OpenInterestResource(http, basePath);
|
|
1901
2127
|
this.candles = new CandlesResource(http, basePath);
|
|
2128
|
+
this.l3Orderbook = new L3OrderBookResource(http, basePath);
|
|
1902
2129
|
}
|
|
1903
2130
|
/**
|
|
1904
|
-
* Get per-
|
|
2131
|
+
* Get per-symbol data freshness across all data types
|
|
1905
2132
|
*
|
|
1906
|
-
* @param
|
|
1907
|
-
* @returns Per-
|
|
2133
|
+
* @param symbol - The symbol (e.g., 'BTC', 'ETH')
|
|
2134
|
+
* @returns Per-symbol freshness with last_updated and lag_ms for each data type
|
|
1908
2135
|
*/
|
|
1909
|
-
async freshness(
|
|
2136
|
+
async freshness(symbol) {
|
|
1910
2137
|
const response = await this.http.get(
|
|
1911
|
-
`/v1/lighter/freshness/${
|
|
2138
|
+
`/v1/lighter/freshness/${symbol.toUpperCase()}`,
|
|
1912
2139
|
void 0,
|
|
1913
2140
|
this.http.validationEnabled ? CoinFreshnessResponseSchema : void 0
|
|
1914
2141
|
);
|
|
@@ -1917,12 +2144,12 @@ var LighterClient = class {
|
|
|
1917
2144
|
/**
|
|
1918
2145
|
* Get combined market summary (price, funding, OI) in one call
|
|
1919
2146
|
*
|
|
1920
|
-
* @param
|
|
2147
|
+
* @param symbol - The symbol (e.g., 'BTC', 'ETH')
|
|
1921
2148
|
* @returns Combined market summary
|
|
1922
2149
|
*/
|
|
1923
|
-
async summary(
|
|
2150
|
+
async summary(symbol) {
|
|
1924
2151
|
const response = await this.http.get(
|
|
1925
|
-
`/v1/lighter/summary/${
|
|
2152
|
+
`/v1/lighter/summary/${symbol.toUpperCase()}`,
|
|
1926
2153
|
void 0,
|
|
1927
2154
|
this.http.validationEnabled ? CoinSummaryResponseSchema : void 0
|
|
1928
2155
|
);
|
|
@@ -1931,13 +2158,13 @@ var LighterClient = class {
|
|
|
1931
2158
|
/**
|
|
1932
2159
|
* Get mark/oracle price history (projected from OI data)
|
|
1933
2160
|
*
|
|
1934
|
-
* @param
|
|
2161
|
+
* @param symbol - The symbol (e.g., 'BTC', 'ETH')
|
|
1935
2162
|
* @param params - Time range, cursor, and interval parameters
|
|
1936
2163
|
* @returns CursorResponse with price snapshots
|
|
1937
2164
|
*/
|
|
1938
|
-
async priceHistory(
|
|
2165
|
+
async priceHistory(symbol, params) {
|
|
1939
2166
|
const response = await this.http.get(
|
|
1940
|
-
`/v1/lighter/prices/${
|
|
2167
|
+
`/v1/lighter/prices/${symbol.toUpperCase()}`,
|
|
1941
2168
|
params,
|
|
1942
2169
|
this.http.validationEnabled ? PriceSnapshotArrayResponseSchema : void 0
|
|
1943
2170
|
);
|
|
@@ -2690,6 +2917,136 @@ var OxArchiveWs = class {
|
|
|
2690
2917
|
}
|
|
2691
2918
|
}
|
|
2692
2919
|
};
|
|
2920
|
+
|
|
2921
|
+
// src/l4-reconstructor.ts
|
|
2922
|
+
var L4OrderBookReconstructor = class {
|
|
2923
|
+
orders = /* @__PURE__ */ new Map();
|
|
2924
|
+
bidPrices = /* @__PURE__ */ new Map();
|
|
2925
|
+
askPrices = /* @__PURE__ */ new Map();
|
|
2926
|
+
/** Initialize from an L4 checkpoint. */
|
|
2927
|
+
loadCheckpoint(checkpoint) {
|
|
2928
|
+
this.orders.clear();
|
|
2929
|
+
this.bidPrices.clear();
|
|
2930
|
+
this.askPrices.clear();
|
|
2931
|
+
for (const order of [...checkpoint.bids, ...checkpoint.asks]) {
|
|
2932
|
+
const oid = order.oid;
|
|
2933
|
+
const price = Number(order.price);
|
|
2934
|
+
const size = Number(order.size);
|
|
2935
|
+
const side = order.side;
|
|
2936
|
+
this.orders.set(oid, {
|
|
2937
|
+
oid,
|
|
2938
|
+
userAddress: order.user_address ?? order.userAddress ?? "",
|
|
2939
|
+
side,
|
|
2940
|
+
price,
|
|
2941
|
+
size
|
|
2942
|
+
});
|
|
2943
|
+
const priceMap = side === "B" ? this.bidPrices : this.askPrices;
|
|
2944
|
+
if (!priceMap.has(price)) priceMap.set(price, /* @__PURE__ */ new Set());
|
|
2945
|
+
priceMap.get(price).add(oid);
|
|
2946
|
+
}
|
|
2947
|
+
}
|
|
2948
|
+
/** Apply a single L4 diff with matching engine. */
|
|
2949
|
+
applyDiff(diff, nonRestingOids) {
|
|
2950
|
+
const dt = diff.diff_type ?? diff.diffType;
|
|
2951
|
+
const oid = diff.oid;
|
|
2952
|
+
if (dt === "new") {
|
|
2953
|
+
if (nonRestingOids?.has(oid)) return;
|
|
2954
|
+
const newSize = diff.new_size ?? diff.newSize;
|
|
2955
|
+
if (newSize == null || newSize <= 0) return;
|
|
2956
|
+
const { side, price } = diff;
|
|
2957
|
+
const sz = newSize;
|
|
2958
|
+
if (side === "B") {
|
|
2959
|
+
for (const [askPx, oids] of this.askPrices) {
|
|
2960
|
+
if (askPx <= price) {
|
|
2961
|
+
for (const crossedOid of oids) this.orders.delete(crossedOid);
|
|
2962
|
+
this.askPrices.delete(askPx);
|
|
2963
|
+
}
|
|
2964
|
+
}
|
|
2965
|
+
} else {
|
|
2966
|
+
for (const [bidPx, oids] of this.bidPrices) {
|
|
2967
|
+
if (bidPx >= price) {
|
|
2968
|
+
for (const crossedOid of oids) this.orders.delete(crossedOid);
|
|
2969
|
+
this.bidPrices.delete(bidPx);
|
|
2970
|
+
}
|
|
2971
|
+
}
|
|
2972
|
+
}
|
|
2973
|
+
this.orders.set(oid, {
|
|
2974
|
+
oid,
|
|
2975
|
+
userAddress: diff.user_address ?? diff.userAddress ?? "",
|
|
2976
|
+
side,
|
|
2977
|
+
price,
|
|
2978
|
+
size: sz
|
|
2979
|
+
});
|
|
2980
|
+
const priceMap = side === "B" ? this.bidPrices : this.askPrices;
|
|
2981
|
+
if (!priceMap.has(price)) priceMap.set(price, /* @__PURE__ */ new Set());
|
|
2982
|
+
priceMap.get(price).add(oid);
|
|
2983
|
+
} else if (dt === "update") {
|
|
2984
|
+
const order = this.orders.get(oid);
|
|
2985
|
+
const updSize = diff.new_size ?? diff.newSize;
|
|
2986
|
+
if (order && updSize != null) {
|
|
2987
|
+
order.size = updSize;
|
|
2988
|
+
}
|
|
2989
|
+
} else if (dt === "remove") {
|
|
2990
|
+
const order = this.orders.get(oid);
|
|
2991
|
+
if (order) {
|
|
2992
|
+
this.orders.delete(oid);
|
|
2993
|
+
const priceMap = order.side === "B" ? this.bidPrices : this.askPrices;
|
|
2994
|
+
const oids = priceMap.get(order.price);
|
|
2995
|
+
if (oids) {
|
|
2996
|
+
oids.delete(oid);
|
|
2997
|
+
if (oids.size === 0) priceMap.delete(order.price);
|
|
2998
|
+
}
|
|
2999
|
+
}
|
|
3000
|
+
}
|
|
3001
|
+
}
|
|
3002
|
+
/** Return bids sorted by price descending. */
|
|
3003
|
+
bids() {
|
|
3004
|
+
return [...this.orders.values()].filter((o) => o.side === "B" && o.size > 0).sort((a, b) => b.price - a.price);
|
|
3005
|
+
}
|
|
3006
|
+
/** Return asks sorted by price ascending. */
|
|
3007
|
+
asks() {
|
|
3008
|
+
return [...this.orders.values()].filter((o) => o.side === "A" && o.size > 0).sort((a, b) => a.price - b.price);
|
|
3009
|
+
}
|
|
3010
|
+
bestBid() {
|
|
3011
|
+
const b = this.bids();
|
|
3012
|
+
return b.length > 0 ? b[0].price : null;
|
|
3013
|
+
}
|
|
3014
|
+
bestAsk() {
|
|
3015
|
+
const a = this.asks();
|
|
3016
|
+
return a.length > 0 ? a[0].price : null;
|
|
3017
|
+
}
|
|
3018
|
+
/** Check if the book is crossed. Should be false after correct reconstruction. */
|
|
3019
|
+
isCrossed() {
|
|
3020
|
+
const bb = this.bestBid();
|
|
3021
|
+
const ba = this.bestAsk();
|
|
3022
|
+
return bb != null && ba != null && bb >= ba;
|
|
3023
|
+
}
|
|
3024
|
+
get bidCount() {
|
|
3025
|
+
return [...this.orders.values()].filter((o) => o.side === "B" && o.size > 0).length;
|
|
3026
|
+
}
|
|
3027
|
+
get askCount() {
|
|
3028
|
+
return [...this.orders.values()].filter((o) => o.side === "A" && o.size > 0).length;
|
|
3029
|
+
}
|
|
3030
|
+
/** Aggregate L4 orders into L2 price levels. */
|
|
3031
|
+
deriveL2() {
|
|
3032
|
+
const bidAgg = /* @__PURE__ */ new Map();
|
|
3033
|
+
const askAgg = /* @__PURE__ */ new Map();
|
|
3034
|
+
for (const o of this.orders.values()) {
|
|
3035
|
+
if (o.size <= 0) continue;
|
|
3036
|
+
const agg = o.side === "B" ? bidAgg : askAgg;
|
|
3037
|
+
const existing = agg.get(o.price);
|
|
3038
|
+
if (existing) {
|
|
3039
|
+
existing.sz += o.size;
|
|
3040
|
+
existing.n += 1;
|
|
3041
|
+
} else {
|
|
3042
|
+
agg.set(o.price, { sz: o.size, n: 1 });
|
|
3043
|
+
}
|
|
3044
|
+
}
|
|
3045
|
+
const bids = [...bidAgg.entries()].sort(([a], [b]) => b - a).map(([px, v]) => ({ px, sz: v.sz, n: v.n }));
|
|
3046
|
+
const asks = [...askAgg.entries()].sort(([a], [b]) => a - b).map(([px, v]) => ({ px, sz: v.sz, n: v.n }));
|
|
3047
|
+
return { bids, asks };
|
|
3048
|
+
}
|
|
3049
|
+
};
|
|
2693
3050
|
// Annotate the CommonJS export names for ESM import in node:
|
|
2694
3051
|
0 && (module.exports = {
|
|
2695
3052
|
ApiMetaSchema,
|
|
@@ -2711,6 +3068,8 @@ var OxArchiveWs = class {
|
|
|
2711
3068
|
InstrumentResponseSchema,
|
|
2712
3069
|
InstrumentSchema,
|
|
2713
3070
|
InstrumentTypeSchema,
|
|
3071
|
+
L2OrderBookResource,
|
|
3072
|
+
L4OrderBookReconstructor,
|
|
2714
3073
|
LighterClient,
|
|
2715
3074
|
LiquidationArrayResponseSchema,
|
|
2716
3075
|
LiquidationSchema,
|