@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
@@ -1,4 +1,4 @@
1
- import { M as Market, a as Orderbook, c as OrderbookStream, C as ClientOptions, b as OrderbookOptions } from '../../stream-CrvepB6m.cjs';
1
+ import { M as Market, a as Orderbook, c as OrderbookStream, C as ClientOptions, b as OrderbookOptions } from '../../stream-YYPvjMV4.cjs';
2
2
 
3
3
  interface FetchOkxOrderbookOptions {
4
4
  symbol: string;
@@ -1,4 +1,4 @@
1
- import { M as Market, a as Orderbook, c as OrderbookStream, C as ClientOptions, b as OrderbookOptions } from '../../stream-CrvepB6m.js';
1
+ import { M as Market, a as Orderbook, c as OrderbookStream, C as ClientOptions, b as OrderbookOptions } from '../../stream-YYPvjMV4.js';
2
2
 
3
3
  interface FetchOkxOrderbookOptions {
4
4
  symbol: string;
package/dist/index.cjs CHANGED
@@ -1440,167 +1440,8 @@ var BingxClient = class {
1440
1440
  }
1441
1441
  };
1442
1442
 
1443
- // src/exchanges/huobi/symbols.ts
1444
- var QUOTES3 = ["USDT", "USDC", "USD", "BTC", "ETH"];
1445
- function toHuobiSymbol(symbol, market) {
1446
- const [base, quote] = symbol.split("/");
1447
- if (!base || !quote) {
1448
- throw new Error(`invalid symbol "${symbol}" \u2014 expected "BASE/QUOTE"`);
1449
- }
1450
- return market === "spot" ? `${base}${quote}`.toLowerCase() : `${base}-${quote}`.toUpperCase();
1451
- }
1452
- function fromHuobiSymbol(s, market) {
1453
- if (market === "spot") {
1454
- const upper = s.toUpperCase();
1455
- for (const q of QUOTES3) {
1456
- if (upper.endsWith(q)) return `${upper.slice(0, -q.length)}/${q}`;
1457
- }
1458
- return upper;
1459
- }
1460
- return s.toUpperCase().replace("-", "/");
1461
- }
1462
-
1463
- // src/exchanges/huobi/rest.ts
1464
- var SPOT_BASE = "https://api.huobi.pro";
1465
- var PERP_BASE = "https://api.hbdm.com";
1466
- async function fetchHuobiOrderbook(opts) {
1467
- const symbol = toHuobiSymbol(opts.symbol, opts.market);
1468
- const step = opts.step ?? "step0";
1469
- 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}`;
1470
- const res = await httpJson({
1471
- url,
1472
- timeoutMs: opts.timeoutMs,
1473
- transformUrl: opts.transformUrl
1474
- });
1475
- if (res.status !== "ok" || !res.tick) {
1476
- throw new ExchangeError(
1477
- "huobi",
1478
- res["err-msg"] ?? res["err-code"] ?? "missing tick"
1479
- );
1480
- }
1481
- const ts = res.tick.ts;
1482
- return {
1483
- exchange: "huobi",
1484
- symbol: fromHuobiSymbol(symbol, opts.market),
1485
- market: opts.market,
1486
- bids: res.tick.bids.map(([p, s]) => ({ price: Number(p), size: Number(s) })),
1487
- asks: res.tick.asks.map(([p, s]) => ({ price: Number(p), size: Number(s) })),
1488
- timestamp: ts,
1489
- sequence: res.tick.version ?? ts
1490
- };
1491
- }
1492
-
1493
- // src/exchanges/huobi/ws.ts
1494
- var WS_SPOT4 = "wss://api.huobi.pro/ws";
1495
- var WS_PERP = "wss://api.hbdm.com/linear-swap-ws";
1496
- function streamHuobiOrderbook(opts) {
1497
- const huobiSymbol = toHuobiSymbol(opts.symbol, opts.market);
1498
- const step = opts.step ?? "step0";
1499
- const channel = `market.${huobiSymbol}.depth.${step}`;
1500
- const merger = new BookMerger();
1501
- let ws = null;
1502
- const stream = new OrderbookStream(() => ws?.close());
1503
- const subscribePayload = JSON.stringify({
1504
- sub: channel,
1505
- id: `sub-${Date.now()}`
1506
- });
1507
- const handlePayload = (text) => {
1508
- let msg;
1509
- try {
1510
- msg = JSON.parse(text);
1511
- } catch {
1512
- return;
1513
- }
1514
- if (typeof msg.ping === "number") {
1515
- ws?.send(JSON.stringify({ pong: msg.ping }));
1516
- return;
1517
- }
1518
- if (msg.status === "ok" && msg.subbed) return;
1519
- if (msg.ch !== channel || !msg.tick) return;
1520
- const ts = msg.tick.ts;
1521
- const sequence = msg.tick.version ?? ts;
1522
- const event = {
1523
- kind: "snapshot",
1524
- bids: msg.tick.bids.map(([p, s]) => ({
1525
- price: Number(p),
1526
- size: Number(s)
1527
- })),
1528
- asks: msg.tick.asks.map(([p, s]) => ({
1529
- price: Number(p),
1530
- size: Number(s)
1531
- })),
1532
- sequence,
1533
- timestamp: ts
1534
- };
1535
- const r = merger.apply(event);
1536
- if (!r.ok) return;
1537
- const book = {
1538
- exchange: "huobi",
1539
- symbol: fromHuobiSymbol(huobiSymbol, opts.market),
1540
- market: opts.market,
1541
- bids: r.bids,
1542
- asks: r.asks,
1543
- timestamp: r.timestamp,
1544
- sequence: r.sequence
1545
- };
1546
- stream.emit("update", book);
1547
- };
1548
- const onMessage = async (raw) => {
1549
- if (typeof raw === "string") {
1550
- handlePayload(raw);
1551
- return;
1552
- }
1553
- const inflate = await getGzipInflate();
1554
- handlePayload(inflate(raw));
1555
- };
1556
- ws = new WSClient({
1557
- url: opts.market === "spot" ? WS_SPOT4 : WS_PERP,
1558
- onOpen: (sock) => {
1559
- merger.reset();
1560
- sock.send(subscribePayload);
1561
- },
1562
- onMessage
1563
- // Huobi heartbeat is server-initiated; we reply inline above. No client ping.
1564
- });
1565
- ws.on("open", () => stream.emit("connected"));
1566
- ws.on("close", (r) => stream.emit("disconnected", r));
1567
- ws.on("reconnecting", (a, w) => stream.emit("reconnecting", a, w));
1568
- ws.on("error", (e) => stream.emit("error", e));
1569
- ws.connect().catch((e) => stream.emit("error", e));
1570
- return stream;
1571
- }
1572
-
1573
- // src/exchanges/huobi/index.ts
1574
- var HuobiClient = class {
1575
- exchange = "huobi";
1576
- transformUrl;
1577
- timeoutMs;
1578
- constructor(opts = {}) {
1579
- this.transformUrl = opts.transformUrl;
1580
- this.timeoutMs = opts.timeoutMs;
1581
- }
1582
- fetchOrderbook(symbol, _opts = {}) {
1583
- const { pair, market } = parseSymbol(symbol);
1584
- return fetchHuobiOrderbook({
1585
- symbol: pair,
1586
- market,
1587
- timeoutMs: this.timeoutMs,
1588
- transformUrl: this.transformUrl
1589
- });
1590
- }
1591
- streamOrderbook(symbol, _opts = {}) {
1592
- const { pair, market } = parseSymbol(symbol);
1593
- return streamHuobiOrderbook({
1594
- symbol: pair,
1595
- market,
1596
- transformUrl: this.transformUrl,
1597
- timeoutMs: this.timeoutMs
1598
- });
1599
- }
1600
- };
1601
-
1602
1443
  // src/exchanges/coinex/symbols.ts
1603
- var QUOTES4 = ["USDT", "USDC", "USD"];
1444
+ var QUOTES3 = ["USDT", "USDC", "USD"];
1604
1445
  function toCoinexSymbol(symbol) {
1605
1446
  const [base, quote] = symbol.split("/");
1606
1447
  if (!base || !quote) {
@@ -1610,7 +1451,7 @@ function toCoinexSymbol(symbol) {
1610
1451
  }
1611
1452
  function fromCoinexSymbol(s) {
1612
1453
  const upper = s.toUpperCase();
1613
- for (const q of QUOTES4) {
1454
+ for (const q of QUOTES3) {
1614
1455
  if (upper.endsWith(q)) {
1615
1456
  return `${upper.slice(0, -q.length)}/${q}`;
1616
1457
  }
@@ -1645,7 +1486,7 @@ async function fetchCoinexOrderbook(opts) {
1645
1486
  }
1646
1487
 
1647
1488
  // src/exchanges/coinex/ws.ts
1648
- var WS_SPOT5 = "wss://socket.coinex.com/v2/spot";
1489
+ var WS_SPOT4 = "wss://socket.coinex.com/v2/spot";
1649
1490
  var WS_FUTURES2 = "wss://socket.coinex.com/v2/futures";
1650
1491
  function streamCoinexOrderbook(opts) {
1651
1492
  const market = toCoinexSymbol(opts.symbol);
@@ -1757,7 +1598,7 @@ function streamCoinexOrderbook(opts) {
1757
1598
  handlePayload(inflate(raw));
1758
1599
  };
1759
1600
  ws = new WSClient({
1760
- url: opts.market === "spot" ? WS_SPOT5 : WS_FUTURES2,
1601
+ url: opts.market === "spot" ? WS_SPOT4 : WS_FUTURES2,
1761
1602
  onOpen: (sock) => {
1762
1603
  merger.reset();
1763
1604
  lastMerged = null;
@@ -2028,7 +1869,7 @@ var OkxClient = class {
2028
1869
  };
2029
1870
 
2030
1871
  // src/exchanges/binance/symbols.ts
2031
- var QUOTES5 = [
1872
+ var QUOTES4 = [
2032
1873
  "USDT",
2033
1874
  "USDC",
2034
1875
  "FDUSD",
@@ -2048,7 +1889,7 @@ function toBinanceSymbol(symbol) {
2048
1889
  }
2049
1890
  function fromBinanceSymbol(s) {
2050
1891
  const upper = s.toUpperCase();
2051
- for (const q of QUOTES5) {
1892
+ for (const q of QUOTES4) {
2052
1893
  if (upper.endsWith(q) && upper.length > q.length) {
2053
1894
  return `${upper.slice(0, -q.length)}/${q}`;
2054
1895
  }
@@ -2080,13 +1921,13 @@ async function fetchBinanceOrderbook(opts) {
2080
1921
  }
2081
1922
 
2082
1923
  // src/exchanges/binance/ws.ts
2083
- var WS_SPOT6 = "wss://stream.binance.com:9443/ws";
1924
+ var WS_SPOT5 = "wss://stream.binance.com:9443/ws";
2084
1925
  var WS_FUTURES3 = "wss://fstream.binance.com/ws";
2085
1926
  function streamBinanceOrderbook(opts) {
2086
1927
  const symbol = toBinanceSymbol(opts.symbol);
2087
1928
  const isSpot = opts.market === "spot";
2088
1929
  const interval = opts.interval ?? "100ms";
2089
- const wsBase = isSpot ? WS_SPOT6 : WS_FUTURES3;
1930
+ const wsBase = isSpot ? WS_SPOT5 : WS_FUTURES3;
2090
1931
  const wsUrl = `${wsBase}/${symbol.toLowerCase()}@depth@${interval}`;
2091
1932
  const merger = new BookMerger();
2092
1933
  let snapshotId = -1;
@@ -3361,13 +3202,16 @@ var LighterClient = class {
3361
3202
  };
3362
3203
 
3363
3204
  // src/exchanges/edgex/markets.ts
3364
- var EDGEX_REST = "https://edgex-prod-v2.edgex.exchange";
3205
+ var EDGEX_REST = "https://cors.xapy.io/edgex";
3365
3206
  var EDGEX_WS = "wss://edgex-quote-prod-v2.edgex.exchange";
3366
- var cache2 = null;
3367
- var inflight2 = null;
3368
- async function fetchContracts(opts) {
3207
+ function edgexRestBase(opts) {
3208
+ return (opts.restBase ?? EDGEX_REST).replace(/\/+$/, "");
3209
+ }
3210
+ var caches = /* @__PURE__ */ new Map();
3211
+ var inflights = /* @__PURE__ */ new Map();
3212
+ async function fetchContracts(opts, base) {
3369
3213
  const res = await httpJson({
3370
- url: `${EDGEX_REST}/api/v2/public/meta/getMetaData`,
3214
+ url: `${base}/api/v2/public/meta/getMetaData`,
3371
3215
  timeoutMs: opts.timeoutMs,
3372
3216
  transformUrl: opts.transformUrl
3373
3217
  });
@@ -3382,24 +3226,29 @@ async function fetchContracts(opts) {
3382
3226
  for (const row of rows) map.set(row.contractName.toUpperCase(), row);
3383
3227
  return map;
3384
3228
  }
3385
- function loadContracts(opts) {
3386
- inflight2 ??= fetchContracts(opts).then(
3387
- (m) => {
3388
- cache2 = m;
3389
- inflight2 = null;
3390
- return m;
3391
- },
3392
- (err) => {
3393
- inflight2 = null;
3394
- throw err;
3395
- }
3396
- );
3397
- return inflight2;
3229
+ function loadContracts(opts, base) {
3230
+ let pending2 = inflights.get(base);
3231
+ if (!pending2) {
3232
+ pending2 = fetchContracts(opts, base).then(
3233
+ (m) => {
3234
+ caches.set(base, m);
3235
+ inflights.delete(base);
3236
+ return m;
3237
+ },
3238
+ (err) => {
3239
+ inflights.delete(base);
3240
+ throw err;
3241
+ }
3242
+ );
3243
+ inflights.set(base, pending2);
3244
+ }
3245
+ return pending2;
3398
3246
  }
3399
3247
  async function resolveEdgexContract(contractName, opts) {
3248
+ const base = edgexRestBase(opts);
3400
3249
  const k = contractName.toUpperCase();
3401
- const hit = cache2?.get(k);
3402
- const contract = hit ?? (await loadContracts(opts)).get(k);
3250
+ const hit = caches.get(base)?.get(k);
3251
+ const contract = hit ?? (await loadContracts(opts, base)).get(k);
3403
3252
  if (!contract) {
3404
3253
  throw new ExchangeError(
3405
3254
  "edgex",
@@ -3441,7 +3290,7 @@ async function fetchEdgexOrderbook(opts) {
3441
3290
  const contract = await resolveEdgexContract(contractName, opts);
3442
3291
  const level = snapLevel(opts.depth ?? 50);
3443
3292
  const res = await httpJson({
3444
- url: `${EDGEX_REST}/api/v2/public/quote/getDepth?contractId=${contract.contractId}&level=${level}`,
3293
+ url: `${edgexRestBase(opts)}/api/v2/public/quote/getDepth?contractId=${contract.contractId}&level=${level}`,
3445
3294
  timeoutMs: opts.timeoutMs,
3446
3295
  transformUrl: opts.transformUrl
3447
3296
  });
@@ -3579,9 +3428,11 @@ var EdgexClient = class {
3579
3428
  exchange = "edgex";
3580
3429
  transformUrl;
3581
3430
  timeoutMs;
3431
+ restBase;
3582
3432
  constructor(opts = {}) {
3583
3433
  this.transformUrl = opts.transformUrl;
3584
3434
  this.timeoutMs = opts.timeoutMs;
3435
+ this.restBase = opts.restBase;
3585
3436
  }
3586
3437
  fetchOrderbook(symbol, opts = {}) {
3587
3438
  const { pair, market } = parseSymbol(symbol);
@@ -3590,7 +3441,8 @@ var EdgexClient = class {
3590
3441
  market,
3591
3442
  depth: opts.depth,
3592
3443
  timeoutMs: this.timeoutMs,
3593
- transformUrl: this.transformUrl
3444
+ transformUrl: this.transformUrl,
3445
+ restBase: this.restBase
3594
3446
  });
3595
3447
  }
3596
3448
  streamOrderbook(symbol, opts = {}) {
@@ -3600,7 +3452,8 @@ var EdgexClient = class {
3600
3452
  market,
3601
3453
  depth: opts.depth,
3602
3454
  transformUrl: this.transformUrl,
3603
- timeoutMs: this.timeoutMs
3455
+ timeoutMs: this.timeoutMs,
3456
+ restBase: this.restBase
3604
3457
  });
3605
3458
  }
3606
3459
  };
@@ -3617,7 +3470,6 @@ exports.EdgexClient = EdgexClient;
3617
3470
  exports.ExchangeError = ExchangeError;
3618
3471
  exports.GateClient = GateClient;
3619
3472
  exports.GrvtClient = GrvtClient;
3620
- exports.HuobiClient = HuobiClient;
3621
3473
  exports.HyperliquidClient = HyperliquidClient;
3622
3474
  exports.KucoinClient = KucoinClient;
3623
3475
  exports.LighterClient = LighterClient;