@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/dist/index.mjs CHANGED
@@ -681,15 +681,15 @@ var OrderBookResource = class {
681
681
  this.coinTransform = coinTransform;
682
682
  }
683
683
  /**
684
- * Get order book snapshot for a coin
684
+ * Get order book snapshot for a symbol
685
685
  *
686
- * @param coin - The coin symbol (e.g., 'BTC', 'ETH')
686
+ * @param symbol - The symbol (e.g., 'BTC', 'ETH')
687
687
  * @param params - Optional parameters
688
688
  * @returns Order book snapshot
689
689
  */
690
- async get(coin, params) {
690
+ async get(symbol, params) {
691
691
  const response = await this.http.get(
692
- `${this.basePath}/orderbook/${this.coinTransform(coin)}`,
692
+ `${this.basePath}/orderbook/${this.coinTransform(symbol)}`,
693
693
  params,
694
694
  this.http.validationEnabled ? OrderBookResponseSchema : void 0
695
695
  );
@@ -698,7 +698,7 @@ var OrderBookResource = class {
698
698
  /**
699
699
  * Get historical order book snapshots with cursor-based pagination
700
700
  *
701
- * @param coin - The coin symbol (e.g., 'BTC', 'ETH')
701
+ * @param symbol - The symbol (e.g., 'BTC', 'ETH')
702
702
  * @param params - Time range and cursor pagination parameters (start and end are required)
703
703
  * @returns CursorResponse with order book snapshots and nextCursor for pagination
704
704
  *
@@ -722,9 +722,9 @@ var OrderBookResource = class {
722
722
  * }
723
723
  * ```
724
724
  */
725
- async history(coin, params) {
725
+ async history(symbol, params) {
726
726
  const response = await this.http.get(
727
- `${this.basePath}/orderbook/${this.coinTransform(coin)}/history`,
727
+ `${this.basePath}/orderbook/${this.coinTransform(symbol)}/history`,
728
728
  params,
729
729
  this.http.validationEnabled ? OrderBookArrayResponseSchema : void 0
730
730
  );
@@ -742,7 +742,7 @@ var OrderBookResource = class {
742
742
  *
743
743
  * For automatic reconstruction, use `historyReconstructed()` instead.
744
744
  *
745
- * @param coin - The coin symbol (e.g., 'BTC', 'ETH')
745
+ * @param symbol - The symbol (e.g., 'BTC', 'ETH')
746
746
  * @param params - Time range parameters
747
747
  * @returns Tick data with checkpoint and deltas
748
748
  *
@@ -762,9 +762,9 @@ var OrderBookResource = class {
762
762
  * }
763
763
  * ```
764
764
  */
765
- async historyTick(coin, params) {
765
+ async historyTick(symbol, params) {
766
766
  const response = await this.http.get(
767
- `${this.basePath}/orderbook/${this.coinTransform(coin)}/history`,
767
+ `${this.basePath}/orderbook/${this.coinTransform(symbol)}/history`,
768
768
  {
769
769
  ...params,
770
770
  granularity: "tick"
@@ -789,7 +789,7 @@ var OrderBookResource = class {
789
789
  * For large time ranges, consider using `historyTick()` with the
790
790
  * `OrderBookReconstructor.iterate()` method for memory efficiency.
791
791
  *
792
- * @param coin - The coin symbol (e.g., 'BTC', 'ETH')
792
+ * @param symbol - The symbol (e.g., 'BTC', 'ETH')
793
793
  * @param params - Time range parameters
794
794
  * @param options - Reconstruction options
795
795
  * @returns Array of reconstructed orderbook snapshots
@@ -813,8 +813,8 @@ var OrderBookResource = class {
813
813
  * );
814
814
  * ```
815
815
  */
816
- async historyReconstructed(coin, params, options = {}) {
817
- const tickData = await this.historyTick(coin, params);
816
+ async historyReconstructed(symbol, params, options = {}) {
817
+ const tickData = await this.historyTick(symbol, params);
818
818
  const reconstructor = new OrderBookReconstructor();
819
819
  return reconstructor.reconstructAll(tickData.checkpoint, tickData.deltas, options);
820
820
  }
@@ -854,7 +854,7 @@ var OrderBookResource = class {
854
854
  * per API request and yielding reconstructed orderbook snapshots one at a time.
855
855
  * Memory-efficient for processing large time ranges.
856
856
  *
857
- * @param coin - The coin symbol (e.g., 'BTC', 'ETH')
857
+ * @param symbol - The symbol (e.g., 'BTC', 'ETH')
858
858
  * @param params - Time range parameters
859
859
  * @param depth - Maximum price levels to include in output snapshots
860
860
  * @yields Reconstructed orderbook snapshots
@@ -877,7 +877,7 @@ var OrderBookResource = class {
877
877
  * }
878
878
  * ```
879
879
  */
880
- async *iterateTickHistory(coin, params, depth) {
880
+ async *iterateTickHistory(symbol, params, depth) {
881
881
  const startTs = typeof params.start === "string" ? new Date(params.start).getTime() : params.start;
882
882
  const endTs = typeof params.end === "string" ? new Date(params.end).getTime() : params.end;
883
883
  let cursor = startTs;
@@ -885,7 +885,7 @@ var OrderBookResource = class {
885
885
  const MAX_DELTAS_PER_PAGE = 1e3;
886
886
  let isFirstPage = true;
887
887
  while (cursor < endTs) {
888
- const tickData = await this.historyTick(coin, {
888
+ const tickData = await this.historyTick(symbol, {
889
889
  start: cursor,
890
890
  end: endTs,
891
891
  depth: params.depth
@@ -923,12 +923,12 @@ var TradesResource = class {
923
923
  this.coinTransform = coinTransform;
924
924
  }
925
925
  /**
926
- * Get trade history for a coin using cursor-based pagination
926
+ * Get trade history for a symbol using cursor-based pagination
927
927
  *
928
928
  * Uses cursor-based pagination by default, which is more efficient for large datasets.
929
929
  * Use the `nextCursor` from the response as the `cursor` parameter to get the next page.
930
930
  *
931
- * @param coin - The coin symbol (e.g., 'BTC', 'ETH')
931
+ * @param symbol - The symbol (e.g., 'BTC', 'ETH')
932
932
  * @param params - Time range and cursor pagination parameters (start and end are required)
933
933
  * @returns Object with trades array and nextCursor for pagination
934
934
  *
@@ -952,9 +952,9 @@ var TradesResource = class {
952
952
  * }
953
953
  * ```
954
954
  */
955
- async list(coin, params) {
955
+ async list(symbol, params) {
956
956
  const response = await this.http.get(
957
- `${this.basePath}/trades/${this.coinTransform(coin)}`,
957
+ `${this.basePath}/trades/${this.coinTransform(symbol)}`,
958
958
  params,
959
959
  this.http.validationEnabled ? TradeArrayResponseSchema : void 0
960
960
  );
@@ -964,20 +964,20 @@ var TradesResource = class {
964
964
  };
965
965
  }
966
966
  /**
967
- * Get most recent trades for a coin.
967
+ * Get most recent trades for a symbol.
968
968
  *
969
969
  * Note: This method is available for Lighter (client.lighter.trades.recent())
970
970
  * and HIP-3 (client.hyperliquid.hip3.trades.recent()) which have real-time data
971
971
  * ingestion. Hyperliquid uses hourly backfill so this endpoint is not available
972
972
  * for Hyperliquid.
973
973
  *
974
- * @param coin - The coin symbol (e.g., 'BTC', 'ETH')
974
+ * @param symbol - The symbol (e.g., 'BTC', 'ETH')
975
975
  * @param limit - Number of trades to return (default: 100)
976
976
  * @returns Array of recent trades
977
977
  */
978
- async recent(coin, limit) {
978
+ async recent(symbol, limit) {
979
979
  const response = await this.http.get(
980
- `${this.basePath}/trades/${this.coinTransform(coin)}/recent`,
980
+ `${this.basePath}/trades/${this.coinTransform(symbol)}/recent`,
981
981
  { limit },
982
982
  this.http.validationEnabled ? TradeArrayResponseSchema : void 0
983
983
  );
@@ -1089,15 +1089,15 @@ var FundingResource = class {
1089
1089
  this.coinTransform = coinTransform;
1090
1090
  }
1091
1091
  /**
1092
- * Get funding rate history for a coin with cursor-based pagination
1092
+ * Get funding rate history for a symbol with cursor-based pagination
1093
1093
  *
1094
- * @param coin - The coin symbol (e.g., 'BTC', 'ETH')
1094
+ * @param symbol - The symbol (e.g., 'BTC', 'ETH')
1095
1095
  * @param params - Time range and cursor pagination parameters (start and end are required)
1096
1096
  * @returns CursorResponse with funding rate records and nextCursor for pagination
1097
1097
  */
1098
- async history(coin, params) {
1098
+ async history(symbol, params) {
1099
1099
  const response = await this.http.get(
1100
- `${this.basePath}/funding/${this.coinTransform(coin)}`,
1100
+ `${this.basePath}/funding/${this.coinTransform(symbol)}`,
1101
1101
  params,
1102
1102
  this.http.validationEnabled ? FundingRateArrayResponseSchema : void 0
1103
1103
  );
@@ -1107,14 +1107,14 @@ var FundingResource = class {
1107
1107
  };
1108
1108
  }
1109
1109
  /**
1110
- * Get current funding rate for a coin
1110
+ * Get current funding rate for a symbol
1111
1111
  *
1112
- * @param coin - The coin symbol (e.g., 'BTC', 'ETH')
1112
+ * @param symbol - The symbol (e.g., 'BTC', 'ETH')
1113
1113
  * @returns Current funding rate
1114
1114
  */
1115
- async current(coin) {
1115
+ async current(symbol) {
1116
1116
  const response = await this.http.get(
1117
- `${this.basePath}/funding/${this.coinTransform(coin)}/current`,
1117
+ `${this.basePath}/funding/${this.coinTransform(symbol)}/current`,
1118
1118
  void 0,
1119
1119
  this.http.validationEnabled ? FundingRateResponseSchema : void 0
1120
1120
  );
@@ -1130,15 +1130,15 @@ var OpenInterestResource = class {
1130
1130
  this.coinTransform = coinTransform;
1131
1131
  }
1132
1132
  /**
1133
- * Get open interest history for a coin with cursor-based pagination
1133
+ * Get open interest history for a symbol with cursor-based pagination
1134
1134
  *
1135
- * @param coin - The coin symbol (e.g., 'BTC', 'ETH')
1135
+ * @param symbol - The symbol (e.g., 'BTC', 'ETH')
1136
1136
  * @param params - Time range and cursor pagination parameters (start and end are required)
1137
1137
  * @returns CursorResponse with open interest records and nextCursor for pagination
1138
1138
  */
1139
- async history(coin, params) {
1139
+ async history(symbol, params) {
1140
1140
  const response = await this.http.get(
1141
- `${this.basePath}/openinterest/${this.coinTransform(coin)}`,
1141
+ `${this.basePath}/openinterest/${this.coinTransform(symbol)}`,
1142
1142
  params,
1143
1143
  this.http.validationEnabled ? OpenInterestArrayResponseSchema : void 0
1144
1144
  );
@@ -1148,14 +1148,14 @@ var OpenInterestResource = class {
1148
1148
  };
1149
1149
  }
1150
1150
  /**
1151
- * Get current open interest for a coin
1151
+ * Get current open interest for a symbol
1152
1152
  *
1153
- * @param coin - The coin symbol (e.g., 'BTC', 'ETH')
1153
+ * @param symbol - The symbol (e.g., 'BTC', 'ETH')
1154
1154
  * @returns Current open interest
1155
1155
  */
1156
- async current(coin) {
1156
+ async current(symbol) {
1157
1157
  const response = await this.http.get(
1158
- `${this.basePath}/openinterest/${this.coinTransform(coin)}/current`,
1158
+ `${this.basePath}/openinterest/${this.coinTransform(symbol)}/current`,
1159
1159
  void 0,
1160
1160
  this.http.validationEnabled ? OpenInterestResponseSchema : void 0
1161
1161
  );
@@ -1173,13 +1173,13 @@ var CandlesResource = class {
1173
1173
  /**
1174
1174
  * Get historical OHLCV candle data with cursor-based pagination
1175
1175
  *
1176
- * @param coin - The coin symbol (e.g., 'BTC', 'ETH')
1176
+ * @param symbol - The symbol (e.g., 'BTC', 'ETH')
1177
1177
  * @param params - Time range, interval, and cursor pagination parameters (start and end are required)
1178
1178
  * @returns CursorResponse with candle records and nextCursor for pagination
1179
1179
  */
1180
- async history(coin, params) {
1180
+ async history(symbol, params) {
1181
1181
  const response = await this.http.get(
1182
- `${this.basePath}/candles/${this.coinTransform(coin)}`,
1182
+ `${this.basePath}/candles/${this.coinTransform(symbol)}`,
1183
1183
  params,
1184
1184
  this.http.validationEnabled ? CandleArrayResponseSchema : void 0
1185
1185
  );
@@ -1192,20 +1192,21 @@ var CandlesResource = class {
1192
1192
 
1193
1193
  // src/resources/liquidations.ts
1194
1194
  var LiquidationsResource = class {
1195
- constructor(http, basePath = "/v1") {
1195
+ constructor(http, basePath = "/v1", coinTransform = (c) => c.toUpperCase()) {
1196
1196
  this.http = http;
1197
1197
  this.basePath = basePath;
1198
+ this.coinTransform = coinTransform;
1198
1199
  }
1199
1200
  /**
1200
- * Get liquidation history for a coin with cursor-based pagination
1201
+ * Get liquidation history for a symbol with cursor-based pagination
1201
1202
  *
1202
- * @param coin - The coin symbol (e.g., 'BTC', 'ETH')
1203
+ * @param symbol - The symbol (e.g., 'BTC', 'ETH')
1203
1204
  * @param params - Time range and cursor pagination parameters (start and end are required)
1204
1205
  * @returns CursorResponse with liquidation records and nextCursor for pagination
1205
1206
  */
1206
- async history(coin, params) {
1207
+ async history(symbol, params) {
1207
1208
  const response = await this.http.get(
1208
- `${this.basePath}/liquidations/${coin.toUpperCase()}`,
1209
+ `${this.basePath}/liquidations/${this.coinTransform(symbol)}`,
1209
1210
  params,
1210
1211
  this.http.validationEnabled ? LiquidationArrayResponseSchema : void 0
1211
1212
  );
@@ -1242,13 +1243,13 @@ var LiquidationsResource = class {
1242
1243
  * Returns pre-aggregated data with total/long/short USD volumes per bucket,
1243
1244
  * reducing data transfer by 100-1000x compared to individual liquidation records.
1244
1245
  *
1245
- * @param coin - The coin symbol (e.g., 'BTC', 'ETH')
1246
+ * @param symbol - The symbol (e.g., 'BTC', 'ETH')
1246
1247
  * @param params - Time range, cursor, and interval parameters
1247
1248
  * @returns CursorResponse with liquidation volume buckets
1248
1249
  */
1249
- async volume(coin, params) {
1250
+ async volume(symbol, params) {
1250
1251
  const response = await this.http.get(
1251
- `${this.basePath}/liquidations/${coin.toUpperCase()}/volume`,
1252
+ `${this.basePath}/liquidations/${this.coinTransform(symbol)}/volume`,
1252
1253
  params,
1253
1254
  this.http.validationEnabled ? LiquidationVolumeArrayResponseSchema : void 0
1254
1255
  );
@@ -1595,6 +1596,190 @@ var Web3Resource = class {
1595
1596
  }
1596
1597
  };
1597
1598
 
1599
+ // src/resources/orders.ts
1600
+ var OrdersResource = class {
1601
+ constructor(http, basePath = "/v1", coinTransform = (c) => c.toUpperCase()) {
1602
+ this.http = http;
1603
+ this.basePath = basePath;
1604
+ this.coinTransform = coinTransform;
1605
+ }
1606
+ /**
1607
+ * Get order history for a symbol with cursor-based pagination
1608
+ *
1609
+ * @param symbol - The symbol (e.g., 'BTC', 'ETH')
1610
+ * @param params - Time range, cursor pagination, and filter parameters
1611
+ * @returns CursorResponse with order records and nextCursor for pagination
1612
+ */
1613
+ async history(symbol, params) {
1614
+ const response = await this.http.get(
1615
+ `${this.basePath}/orders/${this.coinTransform(symbol)}/history`,
1616
+ params
1617
+ );
1618
+ return { data: response.data, nextCursor: response.meta.nextCursor };
1619
+ }
1620
+ /**
1621
+ * Get order flow for a symbol
1622
+ *
1623
+ * @param symbol - The symbol (e.g., 'BTC', 'ETH')
1624
+ * @param params - Time range and interval parameters
1625
+ * @returns CursorResponse with order flow records
1626
+ */
1627
+ async flow(symbol, params) {
1628
+ const response = await this.http.get(
1629
+ `${this.basePath}/orders/${this.coinTransform(symbol)}/flow`,
1630
+ params
1631
+ );
1632
+ return { data: response.data, nextCursor: response.meta.nextCursor };
1633
+ }
1634
+ /**
1635
+ * Get TP/SL orders for a symbol with cursor-based pagination
1636
+ *
1637
+ * @param symbol - The symbol (e.g., 'BTC', 'ETH')
1638
+ * @param params - Time range, cursor pagination, and filter parameters
1639
+ * @returns CursorResponse with TP/SL order records
1640
+ */
1641
+ async tpsl(symbol, params) {
1642
+ const response = await this.http.get(
1643
+ `${this.basePath}/orders/${this.coinTransform(symbol)}/tpsl`,
1644
+ params
1645
+ );
1646
+ return { data: response.data, nextCursor: response.meta.nextCursor };
1647
+ }
1648
+ };
1649
+
1650
+ // src/resources/l4-orderbook.ts
1651
+ var L4OrderBookResource = class {
1652
+ constructor(http, basePath = "/v1", coinTransform = (c) => c.toUpperCase()) {
1653
+ this.http = http;
1654
+ this.basePath = basePath;
1655
+ this.coinTransform = coinTransform;
1656
+ }
1657
+ /**
1658
+ * Get L4 order book snapshot for a symbol
1659
+ *
1660
+ * @param symbol - The symbol (e.g., 'BTC', 'ETH')
1661
+ * @param params - Optional parameters (timestamp, depth)
1662
+ * @returns L4 order book snapshot
1663
+ */
1664
+ async get(symbol, params) {
1665
+ const response = await this.http.get(
1666
+ `${this.basePath}/orderbook/${this.coinTransform(symbol)}/l4`,
1667
+ params
1668
+ );
1669
+ return response.data;
1670
+ }
1671
+ /**
1672
+ * Get L4 order book diffs with cursor-based pagination
1673
+ *
1674
+ * @param symbol - The symbol (e.g., 'BTC', 'ETH')
1675
+ * @param params - Time range and cursor pagination parameters
1676
+ * @returns CursorResponse with L4 orderbook diffs and nextCursor for pagination
1677
+ */
1678
+ async diffs(symbol, params) {
1679
+ const response = await this.http.get(
1680
+ `${this.basePath}/orderbook/${this.coinTransform(symbol)}/l4/diffs`,
1681
+ params
1682
+ );
1683
+ return { data: response.data, nextCursor: response.meta.nextCursor };
1684
+ }
1685
+ /**
1686
+ * Get L4 order book history with cursor-based pagination
1687
+ *
1688
+ * @param symbol - The symbol (e.g., 'BTC', 'ETH')
1689
+ * @param params - Time range and cursor pagination parameters
1690
+ * @returns CursorResponse with L4 orderbook snapshots and nextCursor for pagination
1691
+ */
1692
+ async history(symbol, params) {
1693
+ const response = await this.http.get(
1694
+ `${this.basePath}/orderbook/${this.coinTransform(symbol)}/l4/history`,
1695
+ params
1696
+ );
1697
+ return { data: response.data, nextCursor: response.meta.nextCursor };
1698
+ }
1699
+ };
1700
+
1701
+ // src/resources/l2-orderbook.ts
1702
+ var L2OrderBookResource = class {
1703
+ constructor(http, basePath = "/v1", coinTransform = (c) => c.toUpperCase()) {
1704
+ this.http = http;
1705
+ this.basePath = basePath;
1706
+ this.coinTransform = coinTransform;
1707
+ }
1708
+ /** Get full-depth L2 order book snapshot. */
1709
+ async get(symbol, params) {
1710
+ const coin = this.coinTransform(symbol);
1711
+ const query = {};
1712
+ if (params?.timestamp != null) query.timestamp = params.timestamp;
1713
+ if (params?.depth != null) query.depth = params.depth;
1714
+ const resp = await this.http.get(
1715
+ `${this.basePath}/orderbook/${encodeURIComponent(coin)}/l2`,
1716
+ query
1717
+ );
1718
+ return resp.data;
1719
+ }
1720
+ /** Get paginated L2 full-depth history. */
1721
+ async history(symbol, params) {
1722
+ const coin = this.coinTransform(symbol);
1723
+ const resp = await this.http.get(
1724
+ `${this.basePath}/orderbook/${encodeURIComponent(coin)}/l2/history`,
1725
+ params
1726
+ );
1727
+ return {
1728
+ data: resp.data,
1729
+ nextCursor: resp.meta?.next_cursor ?? void 0
1730
+ };
1731
+ }
1732
+ /** Get tick-level L2 order book diffs. */
1733
+ async diffs(symbol, params) {
1734
+ const coin = this.coinTransform(symbol);
1735
+ const resp = await this.http.get(
1736
+ `${this.basePath}/orderbook/${encodeURIComponent(coin)}/l2/diffs`,
1737
+ params
1738
+ );
1739
+ return {
1740
+ data: resp.data,
1741
+ nextCursor: resp.meta?.next_cursor ?? void 0
1742
+ };
1743
+ }
1744
+ };
1745
+
1746
+ // src/resources/l3-orderbook.ts
1747
+ var L3OrderBookResource = class {
1748
+ constructor(http, basePath = "/v1", coinTransform = (c) => c.toUpperCase()) {
1749
+ this.http = http;
1750
+ this.basePath = basePath;
1751
+ this.coinTransform = coinTransform;
1752
+ }
1753
+ /**
1754
+ * Get L3 order book snapshot for a symbol
1755
+ *
1756
+ * @param symbol - The symbol (e.g., 'BTC', 'ETH')
1757
+ * @param params - Optional parameters (timestamp, depth)
1758
+ * @returns L3 order book snapshot
1759
+ */
1760
+ async get(symbol, params) {
1761
+ const response = await this.http.get(
1762
+ `${this.basePath}/l3orderbook/${this.coinTransform(symbol)}`,
1763
+ params
1764
+ );
1765
+ return response.data;
1766
+ }
1767
+ /**
1768
+ * Get L3 order book history with cursor-based pagination
1769
+ *
1770
+ * @param symbol - The symbol (e.g., 'BTC', 'ETH')
1771
+ * @param params - Time range and cursor pagination parameters
1772
+ * @returns CursorResponse with L3 orderbook snapshots and nextCursor for pagination
1773
+ */
1774
+ async history(symbol, params) {
1775
+ const response = await this.http.get(
1776
+ `${this.basePath}/l3orderbook/${this.coinTransform(symbol)}/history`,
1777
+ params
1778
+ );
1779
+ return { data: response.data, nextCursor: response.meta.nextCursor };
1780
+ }
1781
+ };
1782
+
1598
1783
  // src/exchanges.ts
1599
1784
  var HyperliquidClient = class {
1600
1785
  /**
@@ -1625,6 +1810,18 @@ var HyperliquidClient = class {
1625
1810
  * Liquidation events (May 2025+)
1626
1811
  */
1627
1812
  liquidations;
1813
+ /**
1814
+ * Order history, flow, and TP/SL
1815
+ */
1816
+ orders;
1817
+ /**
1818
+ * L4 order book (snapshots, diffs, history)
1819
+ */
1820
+ l4Orderbook;
1821
+ /**
1822
+ * L2 full-depth order book (derived from L4)
1823
+ */
1824
+ l2Orderbook;
1628
1825
  /**
1629
1826
  * HIP-3 builder-deployed perpetuals (February 2026+)
1630
1827
  */
@@ -1640,17 +1837,20 @@ var HyperliquidClient = class {
1640
1837
  this.openInterest = new OpenInterestResource(http, basePath);
1641
1838
  this.candles = new CandlesResource(http, basePath);
1642
1839
  this.liquidations = new LiquidationsResource(http, basePath);
1840
+ this.orders = new OrdersResource(http, basePath);
1841
+ this.l4Orderbook = new L4OrderBookResource(http, basePath);
1842
+ this.l2Orderbook = new L2OrderBookResource(http, basePath);
1643
1843
  this.hip3 = new Hip3Client(http);
1644
1844
  }
1645
1845
  /**
1646
- * Get per-coin data freshness across all data types
1846
+ * Get per-symbol data freshness across all data types
1647
1847
  *
1648
- * @param coin - The coin symbol (e.g., 'BTC', 'ETH')
1649
- * @returns Per-coin freshness with last_updated and lag_ms for each data type
1848
+ * @param symbol - The symbol (e.g., 'BTC', 'ETH')
1849
+ * @returns Per-symbol freshness with last_updated and lag_ms for each data type
1650
1850
  */
1651
- async freshness(coin) {
1851
+ async freshness(symbol) {
1652
1852
  const response = await this.http.get(
1653
- `/v1/hyperliquid/freshness/${coin.toUpperCase()}`,
1853
+ `/v1/hyperliquid/freshness/${symbol.toUpperCase()}`,
1654
1854
  void 0,
1655
1855
  this.http.validationEnabled ? CoinFreshnessResponseSchema : void 0
1656
1856
  );
@@ -1659,12 +1859,12 @@ var HyperliquidClient = class {
1659
1859
  /**
1660
1860
  * Get combined market summary (price, funding, OI, volume, liquidations) in one call
1661
1861
  *
1662
- * @param coin - The coin symbol (e.g., 'BTC', 'ETH')
1862
+ * @param symbol - The symbol (e.g., 'BTC', 'ETH')
1663
1863
  * @returns Combined market summary
1664
1864
  */
1665
- async summary(coin) {
1865
+ async summary(symbol) {
1666
1866
  const response = await this.http.get(
1667
- `/v1/hyperliquid/summary/${coin.toUpperCase()}`,
1867
+ `/v1/hyperliquid/summary/${symbol.toUpperCase()}`,
1668
1868
  void 0,
1669
1869
  this.http.validationEnabled ? CoinSummaryResponseSchema : void 0
1670
1870
  );
@@ -1673,13 +1873,13 @@ var HyperliquidClient = class {
1673
1873
  /**
1674
1874
  * Get mark/oracle/mid price history (projected from OI data)
1675
1875
  *
1676
- * @param coin - The coin symbol (e.g., 'BTC', 'ETH')
1876
+ * @param symbol - The symbol (e.g., 'BTC', 'ETH')
1677
1877
  * @param params - Time range, cursor, and interval parameters
1678
1878
  * @returns CursorResponse with price snapshots
1679
1879
  */
1680
- async priceHistory(coin, params) {
1880
+ async priceHistory(symbol, params) {
1681
1881
  const response = await this.http.get(
1682
- `/v1/hyperliquid/prices/${coin.toUpperCase()}`,
1882
+ `/v1/hyperliquid/prices/${symbol.toUpperCase()}`,
1683
1883
  params,
1684
1884
  this.http.validationEnabled ? PriceSnapshotArrayResponseSchema : void 0
1685
1885
  );
@@ -1714,6 +1914,22 @@ var Hip3Client = class {
1714
1914
  * OHLCV candle data
1715
1915
  */
1716
1916
  candles;
1917
+ /**
1918
+ * Liquidation events
1919
+ */
1920
+ liquidations;
1921
+ /**
1922
+ * Order history, flow, and TP/SL
1923
+ */
1924
+ orders;
1925
+ /**
1926
+ * L4 order book (snapshots, diffs, history)
1927
+ */
1928
+ l4Orderbook;
1929
+ /**
1930
+ * L2 full-depth order book (derived from L4)
1931
+ */
1932
+ l2Orderbook;
1717
1933
  http;
1718
1934
  constructor(http) {
1719
1935
  this.http = http;
@@ -1725,16 +1941,20 @@ var Hip3Client = class {
1725
1941
  this.funding = new FundingResource(http, basePath, coinTransform);
1726
1942
  this.openInterest = new OpenInterestResource(http, basePath, coinTransform);
1727
1943
  this.candles = new CandlesResource(http, basePath, coinTransform);
1944
+ this.liquidations = new LiquidationsResource(http, basePath, coinTransform);
1945
+ this.orders = new OrdersResource(http, basePath, coinTransform);
1946
+ this.l4Orderbook = new L4OrderBookResource(http, basePath, coinTransform);
1947
+ this.l2Orderbook = new L2OrderBookResource(http, basePath, coinTransform);
1728
1948
  }
1729
1949
  /**
1730
- * Get per-coin data freshness across all data types
1950
+ * Get per-symbol data freshness across all data types
1731
1951
  *
1732
- * @param coin - The coin symbol (case-sensitive, e.g., 'km:US500')
1733
- * @returns Per-coin freshness with last_updated and lag_ms for each data type
1952
+ * @param symbol - The symbol (case-sensitive, e.g., 'km:US500')
1953
+ * @returns Per-symbol freshness with last_updated and lag_ms for each data type
1734
1954
  */
1735
- async freshness(coin) {
1955
+ async freshness(symbol) {
1736
1956
  const response = await this.http.get(
1737
- `/v1/hyperliquid/hip3/freshness/${coin}`,
1957
+ `/v1/hyperliquid/hip3/freshness/${symbol}`,
1738
1958
  void 0,
1739
1959
  this.http.validationEnabled ? CoinFreshnessResponseSchema : void 0
1740
1960
  );
@@ -1743,12 +1963,12 @@ var Hip3Client = class {
1743
1963
  /**
1744
1964
  * Get combined market summary (price, funding, OI) in one call
1745
1965
  *
1746
- * @param coin - The coin symbol (case-sensitive, e.g., 'km:US500')
1966
+ * @param symbol - The symbol (case-sensitive, e.g., 'km:US500')
1747
1967
  * @returns Combined market summary
1748
1968
  */
1749
- async summary(coin) {
1969
+ async summary(symbol) {
1750
1970
  const response = await this.http.get(
1751
- `/v1/hyperliquid/hip3/summary/${coin}`,
1971
+ `/v1/hyperliquid/hip3/summary/${symbol}`,
1752
1972
  void 0,
1753
1973
  this.http.validationEnabled ? CoinSummaryResponseSchema : void 0
1754
1974
  );
@@ -1757,13 +1977,13 @@ var Hip3Client = class {
1757
1977
  /**
1758
1978
  * Get mark/oracle/mid price history (projected from OI data)
1759
1979
  *
1760
- * @param coin - The coin symbol (case-sensitive, e.g., 'km:US500')
1980
+ * @param symbol - The symbol (case-sensitive, e.g., 'km:US500')
1761
1981
  * @param params - Time range, cursor, and interval parameters
1762
1982
  * @returns CursorResponse with price snapshots
1763
1983
  */
1764
- async priceHistory(coin, params) {
1984
+ async priceHistory(symbol, params) {
1765
1985
  const response = await this.http.get(
1766
- `/v1/hyperliquid/hip3/prices/${coin}`,
1986
+ `/v1/hyperliquid/hip3/prices/${symbol}`,
1767
1987
  params,
1768
1988
  this.http.validationEnabled ? PriceSnapshotArrayResponseSchema : void 0
1769
1989
  );
@@ -1798,6 +2018,10 @@ var LighterClient = class {
1798
2018
  * OHLCV candle data
1799
2019
  */
1800
2020
  candles;
2021
+ /**
2022
+ * L3 order book (Lighter only)
2023
+ */
2024
+ l3Orderbook;
1801
2025
  http;
1802
2026
  constructor(http) {
1803
2027
  this.http = http;
@@ -1808,16 +2032,17 @@ var LighterClient = class {
1808
2032
  this.funding = new FundingResource(http, basePath);
1809
2033
  this.openInterest = new OpenInterestResource(http, basePath);
1810
2034
  this.candles = new CandlesResource(http, basePath);
2035
+ this.l3Orderbook = new L3OrderBookResource(http, basePath);
1811
2036
  }
1812
2037
  /**
1813
- * Get per-coin data freshness across all data types
2038
+ * Get per-symbol data freshness across all data types
1814
2039
  *
1815
- * @param coin - The coin symbol (e.g., 'BTC', 'ETH')
1816
- * @returns Per-coin freshness with last_updated and lag_ms for each data type
2040
+ * @param symbol - The symbol (e.g., 'BTC', 'ETH')
2041
+ * @returns Per-symbol freshness with last_updated and lag_ms for each data type
1817
2042
  */
1818
- async freshness(coin) {
2043
+ async freshness(symbol) {
1819
2044
  const response = await this.http.get(
1820
- `/v1/lighter/freshness/${coin.toUpperCase()}`,
2045
+ `/v1/lighter/freshness/${symbol.toUpperCase()}`,
1821
2046
  void 0,
1822
2047
  this.http.validationEnabled ? CoinFreshnessResponseSchema : void 0
1823
2048
  );
@@ -1826,12 +2051,12 @@ var LighterClient = class {
1826
2051
  /**
1827
2052
  * Get combined market summary (price, funding, OI) in one call
1828
2053
  *
1829
- * @param coin - The coin symbol (e.g., 'BTC', 'ETH')
2054
+ * @param symbol - The symbol (e.g., 'BTC', 'ETH')
1830
2055
  * @returns Combined market summary
1831
2056
  */
1832
- async summary(coin) {
2057
+ async summary(symbol) {
1833
2058
  const response = await this.http.get(
1834
- `/v1/lighter/summary/${coin.toUpperCase()}`,
2059
+ `/v1/lighter/summary/${symbol.toUpperCase()}`,
1835
2060
  void 0,
1836
2061
  this.http.validationEnabled ? CoinSummaryResponseSchema : void 0
1837
2062
  );
@@ -1840,13 +2065,13 @@ var LighterClient = class {
1840
2065
  /**
1841
2066
  * Get mark/oracle price history (projected from OI data)
1842
2067
  *
1843
- * @param coin - The coin symbol (e.g., 'BTC', 'ETH')
2068
+ * @param symbol - The symbol (e.g., 'BTC', 'ETH')
1844
2069
  * @param params - Time range, cursor, and interval parameters
1845
2070
  * @returns CursorResponse with price snapshots
1846
2071
  */
1847
- async priceHistory(coin, params) {
2072
+ async priceHistory(symbol, params) {
1848
2073
  const response = await this.http.get(
1849
- `/v1/lighter/prices/${coin.toUpperCase()}`,
2074
+ `/v1/lighter/prices/${symbol.toUpperCase()}`,
1850
2075
  params,
1851
2076
  this.http.validationEnabled ? PriceSnapshotArrayResponseSchema : void 0
1852
2077
  );
@@ -2599,6 +2824,136 @@ var OxArchiveWs = class {
2599
2824
  }
2600
2825
  }
2601
2826
  };
2827
+
2828
+ // src/l4-reconstructor.ts
2829
+ var L4OrderBookReconstructor = class {
2830
+ orders = /* @__PURE__ */ new Map();
2831
+ bidPrices = /* @__PURE__ */ new Map();
2832
+ askPrices = /* @__PURE__ */ new Map();
2833
+ /** Initialize from an L4 checkpoint. */
2834
+ loadCheckpoint(checkpoint) {
2835
+ this.orders.clear();
2836
+ this.bidPrices.clear();
2837
+ this.askPrices.clear();
2838
+ for (const order of [...checkpoint.bids, ...checkpoint.asks]) {
2839
+ const oid = order.oid;
2840
+ const price = Number(order.price);
2841
+ const size = Number(order.size);
2842
+ const side = order.side;
2843
+ this.orders.set(oid, {
2844
+ oid,
2845
+ userAddress: order.user_address ?? order.userAddress ?? "",
2846
+ side,
2847
+ price,
2848
+ size
2849
+ });
2850
+ const priceMap = side === "B" ? this.bidPrices : this.askPrices;
2851
+ if (!priceMap.has(price)) priceMap.set(price, /* @__PURE__ */ new Set());
2852
+ priceMap.get(price).add(oid);
2853
+ }
2854
+ }
2855
+ /** Apply a single L4 diff with matching engine. */
2856
+ applyDiff(diff, nonRestingOids) {
2857
+ const dt = diff.diff_type ?? diff.diffType;
2858
+ const oid = diff.oid;
2859
+ if (dt === "new") {
2860
+ if (nonRestingOids?.has(oid)) return;
2861
+ const newSize = diff.new_size ?? diff.newSize;
2862
+ if (newSize == null || newSize <= 0) return;
2863
+ const { side, price } = diff;
2864
+ const sz = newSize;
2865
+ if (side === "B") {
2866
+ for (const [askPx, oids] of this.askPrices) {
2867
+ if (askPx <= price) {
2868
+ for (const crossedOid of oids) this.orders.delete(crossedOid);
2869
+ this.askPrices.delete(askPx);
2870
+ }
2871
+ }
2872
+ } else {
2873
+ for (const [bidPx, oids] of this.bidPrices) {
2874
+ if (bidPx >= price) {
2875
+ for (const crossedOid of oids) this.orders.delete(crossedOid);
2876
+ this.bidPrices.delete(bidPx);
2877
+ }
2878
+ }
2879
+ }
2880
+ this.orders.set(oid, {
2881
+ oid,
2882
+ userAddress: diff.user_address ?? diff.userAddress ?? "",
2883
+ side,
2884
+ price,
2885
+ size: sz
2886
+ });
2887
+ const priceMap = side === "B" ? this.bidPrices : this.askPrices;
2888
+ if (!priceMap.has(price)) priceMap.set(price, /* @__PURE__ */ new Set());
2889
+ priceMap.get(price).add(oid);
2890
+ } else if (dt === "update") {
2891
+ const order = this.orders.get(oid);
2892
+ const updSize = diff.new_size ?? diff.newSize;
2893
+ if (order && updSize != null) {
2894
+ order.size = updSize;
2895
+ }
2896
+ } else if (dt === "remove") {
2897
+ const order = this.orders.get(oid);
2898
+ if (order) {
2899
+ this.orders.delete(oid);
2900
+ const priceMap = order.side === "B" ? this.bidPrices : this.askPrices;
2901
+ const oids = priceMap.get(order.price);
2902
+ if (oids) {
2903
+ oids.delete(oid);
2904
+ if (oids.size === 0) priceMap.delete(order.price);
2905
+ }
2906
+ }
2907
+ }
2908
+ }
2909
+ /** Return bids sorted by price descending. */
2910
+ bids() {
2911
+ return [...this.orders.values()].filter((o) => o.side === "B" && o.size > 0).sort((a, b) => b.price - a.price);
2912
+ }
2913
+ /** Return asks sorted by price ascending. */
2914
+ asks() {
2915
+ return [...this.orders.values()].filter((o) => o.side === "A" && o.size > 0).sort((a, b) => a.price - b.price);
2916
+ }
2917
+ bestBid() {
2918
+ const b = this.bids();
2919
+ return b.length > 0 ? b[0].price : null;
2920
+ }
2921
+ bestAsk() {
2922
+ const a = this.asks();
2923
+ return a.length > 0 ? a[0].price : null;
2924
+ }
2925
+ /** Check if the book is crossed. Should be false after correct reconstruction. */
2926
+ isCrossed() {
2927
+ const bb = this.bestBid();
2928
+ const ba = this.bestAsk();
2929
+ return bb != null && ba != null && bb >= ba;
2930
+ }
2931
+ get bidCount() {
2932
+ return [...this.orders.values()].filter((o) => o.side === "B" && o.size > 0).length;
2933
+ }
2934
+ get askCount() {
2935
+ return [...this.orders.values()].filter((o) => o.side === "A" && o.size > 0).length;
2936
+ }
2937
+ /** Aggregate L4 orders into L2 price levels. */
2938
+ deriveL2() {
2939
+ const bidAgg = /* @__PURE__ */ new Map();
2940
+ const askAgg = /* @__PURE__ */ new Map();
2941
+ for (const o of this.orders.values()) {
2942
+ if (o.size <= 0) continue;
2943
+ const agg = o.side === "B" ? bidAgg : askAgg;
2944
+ const existing = agg.get(o.price);
2945
+ if (existing) {
2946
+ existing.sz += o.size;
2947
+ existing.n += 1;
2948
+ } else {
2949
+ agg.set(o.price, { sz: o.size, n: 1 });
2950
+ }
2951
+ }
2952
+ const bids = [...bidAgg.entries()].sort(([a], [b]) => b - a).map(([px, v]) => ({ px, sz: v.sz, n: v.n }));
2953
+ const asks = [...askAgg.entries()].sort(([a], [b]) => a - b).map(([px, v]) => ({ px, sz: v.sz, n: v.n }));
2954
+ return { bids, asks };
2955
+ }
2956
+ };
2602
2957
  export {
2603
2958
  ApiMetaSchema,
2604
2959
  ApiResponseSchema,
@@ -2619,6 +2974,8 @@ export {
2619
2974
  InstrumentResponseSchema,
2620
2975
  InstrumentSchema,
2621
2976
  InstrumentTypeSchema,
2977
+ L2OrderBookResource,
2978
+ L4OrderBookReconstructor,
2622
2979
  LighterClient,
2623
2980
  LiquidationArrayResponseSchema,
2624
2981
  LiquidationSchema,