@xapy/orderbook 0.1.25 → 0.1.27

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.
Files changed (50) hide show
  1. package/README.md +0 -1
  2. package/dist/exchanges/binance/index.d.cts +1 -1
  3. package/dist/exchanges/binance/index.d.ts +1 -1
  4. package/dist/exchanges/bingx/index.d.cts +1 -1
  5. package/dist/exchanges/bingx/index.d.ts +1 -1
  6. package/dist/exchanges/bitget/index.d.cts +1 -1
  7. package/dist/exchanges/bitget/index.d.ts +1 -1
  8. package/dist/exchanges/bybit/index.d.cts +1 -1
  9. package/dist/exchanges/bybit/index.d.ts +1 -1
  10. package/dist/exchanges/coinex/index.d.cts +1 -1
  11. package/dist/exchanges/coinex/index.d.ts +1 -1
  12. package/dist/exchanges/deribit/index.d.cts +1 -1
  13. package/dist/exchanges/deribit/index.d.ts +1 -1
  14. package/dist/exchanges/edgex/index.cjs +39 -23
  15. package/dist/exchanges/edgex/index.cjs.map +1 -1
  16. package/dist/exchanges/edgex/index.d.cts +37 -3
  17. package/dist/exchanges/edgex/index.d.ts +37 -3
  18. package/dist/exchanges/edgex/index.js +37 -24
  19. package/dist/exchanges/edgex/index.js.map +1 -1
  20. package/dist/exchanges/gate/index.d.cts +1 -1
  21. package/dist/exchanges/gate/index.d.ts +1 -1
  22. package/dist/exchanges/grvt/index.d.cts +1 -1
  23. package/dist/exchanges/grvt/index.d.ts +1 -1
  24. package/dist/exchanges/hyperliquid/index.d.cts +1 -1
  25. package/dist/exchanges/hyperliquid/index.d.ts +1 -1
  26. package/dist/exchanges/kucoin/index.d.cts +1 -1
  27. package/dist/exchanges/kucoin/index.d.ts +1 -1
  28. package/dist/exchanges/lighter/index.cjs +1 -0
  29. package/dist/exchanges/lighter/index.cjs.map +1 -1
  30. package/dist/exchanges/lighter/index.d.cts +3 -2
  31. package/dist/exchanges/lighter/index.d.ts +3 -2
  32. package/dist/exchanges/lighter/index.js +1 -1
  33. package/dist/exchanges/lighter/index.js.map +1 -1
  34. package/dist/exchanges/okx/index.d.cts +1 -1
  35. package/dist/exchanges/okx/index.d.ts +1 -1
  36. package/dist/index.cjs +43 -191
  37. package/dist/index.cjs.map +1 -1
  38. package/dist/index.d.cts +2 -3
  39. package/dist/index.d.ts +2 -3
  40. package/dist/index.js +44 -191
  41. package/dist/index.js.map +1 -1
  42. package/dist/{stream-CrvepB6m.d.cts → stream-YYPvjMV4.d.cts} +1 -1
  43. package/dist/{stream-CrvepB6m.d.ts → stream-YYPvjMV4.d.ts} +1 -1
  44. package/package.json +1 -11
  45. package/dist/exchanges/huobi/index.cjs +0 -589
  46. package/dist/exchanges/huobi/index.cjs.map +0 -1
  47. package/dist/exchanges/huobi/index.d.cts +0 -37
  48. package/dist/exchanges/huobi/index.d.ts +0 -37
  49. package/dist/exchanges/huobi/index.js +0 -585
  50. package/dist/exchanges/huobi/index.js.map +0 -1
package/dist/index.d.cts CHANGED
@@ -1,10 +1,9 @@
1
- import { B as BookEvent, O as OrderbookLevel, M as Market } from './stream-CrvepB6m.cjs';
2
- export { C as ClientOptions, E as ExchangeName, a as Orderbook, b as OrderbookOptions, c as OrderbookStream, S as Side, d as StreamEvents } from './stream-CrvepB6m.cjs';
1
+ import { B as BookEvent, O as OrderbookLevel, M as Market } from './stream-YYPvjMV4.cjs';
2
+ export { C as ClientOptions, E as ExchangeName, a as Orderbook, b as OrderbookOptions, c as OrderbookStream, S as Side, d as StreamEvents } from './stream-YYPvjMV4.cjs';
3
3
  export { BybitClient } from './exchanges/bybit/index.cjs';
4
4
  export { BitgetClient } from './exchanges/bitget/index.cjs';
5
5
  export { GateClient } from './exchanges/gate/index.cjs';
6
6
  export { BingxClient } from './exchanges/bingx/index.cjs';
7
- export { HuobiClient } from './exchanges/huobi/index.cjs';
8
7
  export { CoinexClient } from './exchanges/coinex/index.cjs';
9
8
  export { OkxClient } from './exchanges/okx/index.cjs';
10
9
  export { BinanceClient } from './exchanges/binance/index.cjs';
package/dist/index.d.ts CHANGED
@@ -1,10 +1,9 @@
1
- import { B as BookEvent, O as OrderbookLevel, M as Market } from './stream-CrvepB6m.js';
2
- export { C as ClientOptions, E as ExchangeName, a as Orderbook, b as OrderbookOptions, c as OrderbookStream, S as Side, d as StreamEvents } from './stream-CrvepB6m.js';
1
+ import { B as BookEvent, O as OrderbookLevel, M as Market } from './stream-YYPvjMV4.js';
2
+ export { C as ClientOptions, E as ExchangeName, a as Orderbook, b as OrderbookOptions, c as OrderbookStream, S as Side, d as StreamEvents } from './stream-YYPvjMV4.js';
3
3
  export { BybitClient } from './exchanges/bybit/index.js';
4
4
  export { BitgetClient } from './exchanges/bitget/index.js';
5
5
  export { GateClient } from './exchanges/gate/index.js';
6
6
  export { BingxClient } from './exchanges/bingx/index.js';
7
- export { HuobiClient } from './exchanges/huobi/index.js';
8
7
  export { CoinexClient } from './exchanges/coinex/index.js';
9
8
  export { OkxClient } from './exchanges/okx/index.js';
10
9
  export { BinanceClient } from './exchanges/binance/index.js';
package/dist/index.js CHANGED
@@ -1438,167 +1438,8 @@ var BingxClient = class {
1438
1438
  }
1439
1439
  };
1440
1440
 
1441
- // src/exchanges/huobi/symbols.ts
1442
- var QUOTES3 = ["USDT", "USDC", "USD", "BTC", "ETH"];
1443
- function toHuobiSymbol(symbol, market) {
1444
- const [base, quote] = symbol.split("/");
1445
- if (!base || !quote) {
1446
- throw new Error(`invalid symbol "${symbol}" \u2014 expected "BASE/QUOTE"`);
1447
- }
1448
- return market === "spot" ? `${base}${quote}`.toLowerCase() : `${base}-${quote}`.toUpperCase();
1449
- }
1450
- function fromHuobiSymbol(s, market) {
1451
- if (market === "spot") {
1452
- const upper = s.toUpperCase();
1453
- for (const q of QUOTES3) {
1454
- if (upper.endsWith(q)) return `${upper.slice(0, -q.length)}/${q}`;
1455
- }
1456
- return upper;
1457
- }
1458
- return s.toUpperCase().replace("-", "/");
1459
- }
1460
-
1461
- // src/exchanges/huobi/rest.ts
1462
- var SPOT_BASE = "https://api.huobi.pro";
1463
- var PERP_BASE = "https://api.hbdm.com";
1464
- async function fetchHuobiOrderbook(opts) {
1465
- const symbol = toHuobiSymbol(opts.symbol, opts.market);
1466
- const step = opts.step ?? "step0";
1467
- const url = opts.market === "spot" ? `${SPOT_BASE}/market/depth?symbol=${symbol}&type=${step}` : `${PERP_BASE}/linear-swap-ex/market/depth?contract_code=${symbol}&type=${step}`;
1468
- const res = await httpJson({
1469
- url,
1470
- timeoutMs: opts.timeoutMs,
1471
- transformUrl: opts.transformUrl
1472
- });
1473
- if (res.status !== "ok" || !res.tick) {
1474
- throw new ExchangeError(
1475
- "huobi",
1476
- res["err-msg"] ?? res["err-code"] ?? "missing tick"
1477
- );
1478
- }
1479
- const ts = res.tick.ts;
1480
- return {
1481
- exchange: "huobi",
1482
- symbol: fromHuobiSymbol(symbol, opts.market),
1483
- market: opts.market,
1484
- bids: res.tick.bids.map(([p, s]) => ({ price: Number(p), size: Number(s) })),
1485
- asks: res.tick.asks.map(([p, s]) => ({ price: Number(p), size: Number(s) })),
1486
- timestamp: ts,
1487
- sequence: res.tick.version ?? ts
1488
- };
1489
- }
1490
-
1491
- // src/exchanges/huobi/ws.ts
1492
- var WS_SPOT4 = "wss://api.huobi.pro/ws";
1493
- var WS_PERP = "wss://api.hbdm.com/linear-swap-ws";
1494
- function streamHuobiOrderbook(opts) {
1495
- const huobiSymbol = toHuobiSymbol(opts.symbol, opts.market);
1496
- const step = opts.step ?? "step0";
1497
- const channel = `market.${huobiSymbol}.depth.${step}`;
1498
- const merger = new BookMerger();
1499
- let ws = null;
1500
- const stream = new OrderbookStream(() => ws?.close());
1501
- const subscribePayload = JSON.stringify({
1502
- sub: channel,
1503
- id: `sub-${Date.now()}`
1504
- });
1505
- const handlePayload = (text) => {
1506
- let msg;
1507
- try {
1508
- msg = JSON.parse(text);
1509
- } catch {
1510
- return;
1511
- }
1512
- if (typeof msg.ping === "number") {
1513
- ws?.send(JSON.stringify({ pong: msg.ping }));
1514
- return;
1515
- }
1516
- if (msg.status === "ok" && msg.subbed) return;
1517
- if (msg.ch !== channel || !msg.tick) return;
1518
- const ts = msg.tick.ts;
1519
- const sequence = msg.tick.version ?? ts;
1520
- const event = {
1521
- kind: "snapshot",
1522
- bids: msg.tick.bids.map(([p, s]) => ({
1523
- price: Number(p),
1524
- size: Number(s)
1525
- })),
1526
- asks: msg.tick.asks.map(([p, s]) => ({
1527
- price: Number(p),
1528
- size: Number(s)
1529
- })),
1530
- sequence,
1531
- timestamp: ts
1532
- };
1533
- const r = merger.apply(event);
1534
- if (!r.ok) return;
1535
- const book = {
1536
- exchange: "huobi",
1537
- symbol: fromHuobiSymbol(huobiSymbol, opts.market),
1538
- market: opts.market,
1539
- bids: r.bids,
1540
- asks: r.asks,
1541
- timestamp: r.timestamp,
1542
- sequence: r.sequence
1543
- };
1544
- stream.emit("update", book);
1545
- };
1546
- const onMessage = async (raw) => {
1547
- if (typeof raw === "string") {
1548
- handlePayload(raw);
1549
- return;
1550
- }
1551
- const inflate = await getGzipInflate();
1552
- handlePayload(inflate(raw));
1553
- };
1554
- ws = new WSClient({
1555
- url: opts.market === "spot" ? WS_SPOT4 : WS_PERP,
1556
- onOpen: (sock) => {
1557
- merger.reset();
1558
- sock.send(subscribePayload);
1559
- },
1560
- onMessage
1561
- // Huobi heartbeat is server-initiated; we reply inline above. No client ping.
1562
- });
1563
- ws.on("open", () => stream.emit("connected"));
1564
- ws.on("close", (r) => stream.emit("disconnected", r));
1565
- ws.on("reconnecting", (a, w) => stream.emit("reconnecting", a, w));
1566
- ws.on("error", (e) => stream.emit("error", e));
1567
- ws.connect().catch((e) => stream.emit("error", e));
1568
- return stream;
1569
- }
1570
-
1571
- // src/exchanges/huobi/index.ts
1572
- var HuobiClient = class {
1573
- exchange = "huobi";
1574
- transformUrl;
1575
- timeoutMs;
1576
- constructor(opts = {}) {
1577
- this.transformUrl = opts.transformUrl;
1578
- this.timeoutMs = opts.timeoutMs;
1579
- }
1580
- fetchOrderbook(symbol, _opts = {}) {
1581
- const { pair, market } = parseSymbol(symbol);
1582
- return fetchHuobiOrderbook({
1583
- symbol: pair,
1584
- market,
1585
- timeoutMs: this.timeoutMs,
1586
- transformUrl: this.transformUrl
1587
- });
1588
- }
1589
- streamOrderbook(symbol, _opts = {}) {
1590
- const { pair, market } = parseSymbol(symbol);
1591
- return streamHuobiOrderbook({
1592
- symbol: pair,
1593
- market,
1594
- transformUrl: this.transformUrl,
1595
- timeoutMs: this.timeoutMs
1596
- });
1597
- }
1598
- };
1599
-
1600
1441
  // src/exchanges/coinex/symbols.ts
1601
- var QUOTES4 = ["USDT", "USDC", "USD"];
1442
+ var QUOTES3 = ["USDT", "USDC", "USD"];
1602
1443
  function toCoinexSymbol(symbol) {
1603
1444
  const [base, quote] = symbol.split("/");
1604
1445
  if (!base || !quote) {
@@ -1608,7 +1449,7 @@ function toCoinexSymbol(symbol) {
1608
1449
  }
1609
1450
  function fromCoinexSymbol(s) {
1610
1451
  const upper = s.toUpperCase();
1611
- for (const q of QUOTES4) {
1452
+ for (const q of QUOTES3) {
1612
1453
  if (upper.endsWith(q)) {
1613
1454
  return `${upper.slice(0, -q.length)}/${q}`;
1614
1455
  }
@@ -1643,7 +1484,7 @@ async function fetchCoinexOrderbook(opts) {
1643
1484
  }
1644
1485
 
1645
1486
  // src/exchanges/coinex/ws.ts
1646
- var WS_SPOT5 = "wss://socket.coinex.com/v2/spot";
1487
+ var WS_SPOT4 = "wss://socket.coinex.com/v2/spot";
1647
1488
  var WS_FUTURES2 = "wss://socket.coinex.com/v2/futures";
1648
1489
  function streamCoinexOrderbook(opts) {
1649
1490
  const market = toCoinexSymbol(opts.symbol);
@@ -1755,7 +1596,7 @@ function streamCoinexOrderbook(opts) {
1755
1596
  handlePayload(inflate(raw));
1756
1597
  };
1757
1598
  ws = new WSClient({
1758
- url: opts.market === "spot" ? WS_SPOT5 : WS_FUTURES2,
1599
+ url: opts.market === "spot" ? WS_SPOT4 : WS_FUTURES2,
1759
1600
  onOpen: (sock) => {
1760
1601
  merger.reset();
1761
1602
  lastMerged = null;
@@ -2026,7 +1867,7 @@ var OkxClient = class {
2026
1867
  };
2027
1868
 
2028
1869
  // src/exchanges/binance/symbols.ts
2029
- var QUOTES5 = [
1870
+ var QUOTES4 = [
2030
1871
  "USDT",
2031
1872
  "USDC",
2032
1873
  "FDUSD",
@@ -2046,7 +1887,7 @@ function toBinanceSymbol(symbol) {
2046
1887
  }
2047
1888
  function fromBinanceSymbol(s) {
2048
1889
  const upper = s.toUpperCase();
2049
- for (const q of QUOTES5) {
1890
+ for (const q of QUOTES4) {
2050
1891
  if (upper.endsWith(q) && upper.length > q.length) {
2051
1892
  return `${upper.slice(0, -q.length)}/${q}`;
2052
1893
  }
@@ -2078,13 +1919,13 @@ async function fetchBinanceOrderbook(opts) {
2078
1919
  }
2079
1920
 
2080
1921
  // src/exchanges/binance/ws.ts
2081
- var WS_SPOT6 = "wss://stream.binance.com:9443/ws";
1922
+ var WS_SPOT5 = "wss://stream.binance.com:9443/ws";
2082
1923
  var WS_FUTURES3 = "wss://fstream.binance.com/ws";
2083
1924
  function streamBinanceOrderbook(opts) {
2084
1925
  const symbol = toBinanceSymbol(opts.symbol);
2085
1926
  const isSpot = opts.market === "spot";
2086
1927
  const interval = opts.interval ?? "100ms";
2087
- const wsBase = isSpot ? WS_SPOT6 : WS_FUTURES3;
1928
+ const wsBase = isSpot ? WS_SPOT5 : WS_FUTURES3;
2088
1929
  const wsUrl = `${wsBase}/${symbol.toLowerCase()}@depth@${interval}`;
2089
1930
  const merger = new BookMerger();
2090
1931
  let snapshotId = -1;
@@ -3359,13 +3200,16 @@ var LighterClient = class {
3359
3200
  };
3360
3201
 
3361
3202
  // src/exchanges/edgex/markets.ts
3362
- var EDGEX_REST = "https://edgex-prod-v2.edgex.exchange";
3203
+ var EDGEX_REST = "https://cors.xapy.io/edgex";
3363
3204
  var EDGEX_WS = "wss://edgex-quote-prod-v2.edgex.exchange";
3364
- var cache2 = null;
3365
- var inflight2 = null;
3366
- async function fetchContracts(opts) {
3205
+ function edgexRestBase(opts) {
3206
+ return (opts.restBase ?? EDGEX_REST).replace(/\/+$/, "");
3207
+ }
3208
+ var caches = /* @__PURE__ */ new Map();
3209
+ var inflights = /* @__PURE__ */ new Map();
3210
+ async function fetchContracts(opts, base) {
3367
3211
  const res = await httpJson({
3368
- url: `${EDGEX_REST}/api/v2/public/meta/getMetaData`,
3212
+ url: `${base}/api/v2/public/meta/getMetaData`,
3369
3213
  timeoutMs: opts.timeoutMs,
3370
3214
  transformUrl: opts.transformUrl
3371
3215
  });
@@ -3380,24 +3224,29 @@ async function fetchContracts(opts) {
3380
3224
  for (const row of rows) map.set(row.contractName.toUpperCase(), row);
3381
3225
  return map;
3382
3226
  }
3383
- function loadContracts(opts) {
3384
- inflight2 ??= fetchContracts(opts).then(
3385
- (m) => {
3386
- cache2 = m;
3387
- inflight2 = null;
3388
- return m;
3389
- },
3390
- (err) => {
3391
- inflight2 = null;
3392
- throw err;
3393
- }
3394
- );
3395
- return inflight2;
3227
+ function loadContracts(opts, base) {
3228
+ let pending2 = inflights.get(base);
3229
+ if (!pending2) {
3230
+ pending2 = fetchContracts(opts, base).then(
3231
+ (m) => {
3232
+ caches.set(base, m);
3233
+ inflights.delete(base);
3234
+ return m;
3235
+ },
3236
+ (err) => {
3237
+ inflights.delete(base);
3238
+ throw err;
3239
+ }
3240
+ );
3241
+ inflights.set(base, pending2);
3242
+ }
3243
+ return pending2;
3396
3244
  }
3397
3245
  async function resolveEdgexContract(contractName, opts) {
3246
+ const base = edgexRestBase(opts);
3398
3247
  const k = contractName.toUpperCase();
3399
- const hit = cache2?.get(k);
3400
- const contract = hit ?? (await loadContracts(opts)).get(k);
3248
+ const hit = caches.get(base)?.get(k);
3249
+ const contract = hit ?? (await loadContracts(opts, base)).get(k);
3401
3250
  if (!contract) {
3402
3251
  throw new ExchangeError(
3403
3252
  "edgex",
@@ -3439,7 +3288,7 @@ async function fetchEdgexOrderbook(opts) {
3439
3288
  const contract = await resolveEdgexContract(contractName, opts);
3440
3289
  const level = snapLevel(opts.depth ?? 50);
3441
3290
  const res = await httpJson({
3442
- url: `${EDGEX_REST}/api/v2/public/quote/getDepth?contractId=${contract.contractId}&level=${level}`,
3291
+ url: `${edgexRestBase(opts)}/api/v2/public/quote/getDepth?contractId=${contract.contractId}&level=${level}`,
3443
3292
  timeoutMs: opts.timeoutMs,
3444
3293
  transformUrl: opts.transformUrl
3445
3294
  });
@@ -3577,9 +3426,11 @@ var EdgexClient = class {
3577
3426
  exchange = "edgex";
3578
3427
  transformUrl;
3579
3428
  timeoutMs;
3429
+ restBase;
3580
3430
  constructor(opts = {}) {
3581
3431
  this.transformUrl = opts.transformUrl;
3582
3432
  this.timeoutMs = opts.timeoutMs;
3433
+ this.restBase = opts.restBase;
3583
3434
  }
3584
3435
  fetchOrderbook(symbol, opts = {}) {
3585
3436
  const { pair, market } = parseSymbol(symbol);
@@ -3588,7 +3439,8 @@ var EdgexClient = class {
3588
3439
  market,
3589
3440
  depth: opts.depth,
3590
3441
  timeoutMs: this.timeoutMs,
3591
- transformUrl: this.transformUrl
3442
+ transformUrl: this.transformUrl,
3443
+ restBase: this.restBase
3592
3444
  });
3593
3445
  }
3594
3446
  streamOrderbook(symbol, opts = {}) {
@@ -3598,11 +3450,12 @@ var EdgexClient = class {
3598
3450
  market,
3599
3451
  depth: opts.depth,
3600
3452
  transformUrl: this.transformUrl,
3601
- timeoutMs: this.timeoutMs
3453
+ timeoutMs: this.timeoutMs,
3454
+ restBase: this.restBase
3602
3455
  });
3603
3456
  }
3604
3457
  };
3605
3458
 
3606
- export { Backoff, BinanceClient, BingxClient, BitgetClient, BookMerger, BybitClient, CoinexClient, DeribitClient, EdgexClient, ExchangeError, GateClient, GrvtClient, HuobiClient, HyperliquidClient, KucoinClient, LighterClient, OkxClient, OrderbookStream, RateLimitError, SequenceGapError, parseSymbol };
3459
+ export { Backoff, BinanceClient, BingxClient, BitgetClient, BookMerger, BybitClient, CoinexClient, DeribitClient, EdgexClient, ExchangeError, GateClient, GrvtClient, HyperliquidClient, KucoinClient, LighterClient, OkxClient, OrderbookStream, RateLimitError, SequenceGapError, parseSymbol };
3607
3460
  //# sourceMappingURL=index.js.map
3608
3461
  //# sourceMappingURL=index.js.map