@xapy/orderbook 0.1.25 → 0.1.26
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 +0 -1
- package/dist/exchanges/binance/index.d.cts +1 -1
- package/dist/exchanges/binance/index.d.ts +1 -1
- package/dist/exchanges/bingx/index.d.cts +1 -1
- package/dist/exchanges/bingx/index.d.ts +1 -1
- package/dist/exchanges/bitget/index.d.cts +1 -1
- package/dist/exchanges/bitget/index.d.ts +1 -1
- package/dist/exchanges/bybit/index.d.cts +1 -1
- package/dist/exchanges/bybit/index.d.ts +1 -1
- package/dist/exchanges/coinex/index.d.cts +1 -1
- package/dist/exchanges/coinex/index.d.ts +1 -1
- package/dist/exchanges/deribit/index.d.cts +1 -1
- package/dist/exchanges/deribit/index.d.ts +1 -1
- package/dist/exchanges/edgex/index.d.cts +1 -1
- package/dist/exchanges/edgex/index.d.ts +1 -1
- package/dist/exchanges/gate/index.d.cts +1 -1
- package/dist/exchanges/gate/index.d.ts +1 -1
- package/dist/exchanges/grvt/index.d.cts +1 -1
- package/dist/exchanges/grvt/index.d.ts +1 -1
- package/dist/exchanges/hyperliquid/index.d.cts +1 -1
- package/dist/exchanges/hyperliquid/index.d.ts +1 -1
- package/dist/exchanges/kucoin/index.d.cts +1 -1
- package/dist/exchanges/kucoin/index.d.ts +1 -1
- package/dist/exchanges/lighter/index.d.cts +1 -1
- package/dist/exchanges/lighter/index.d.ts +1 -1
- package/dist/exchanges/okx/index.d.cts +1 -1
- package/dist/exchanges/okx/index.d.ts +1 -1
- package/dist/index.cjs +8 -168
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -3
- package/dist/index.d.ts +2 -3
- package/dist/index.js +9 -168
- package/dist/index.js.map +1 -1
- package/dist/{stream-CrvepB6m.d.cts → stream-YYPvjMV4.d.cts} +1 -1
- package/dist/{stream-CrvepB6m.d.ts → stream-YYPvjMV4.d.ts} +1 -1
- package/package.json +1 -11
- package/dist/exchanges/huobi/index.cjs +0 -589
- package/dist/exchanges/huobi/index.cjs.map +0 -1
- package/dist/exchanges/huobi/index.d.cts +0 -37
- package/dist/exchanges/huobi/index.d.ts +0 -37
- package/dist/exchanges/huobi/index.js +0 -585
- 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-
|
|
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-
|
|
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-
|
|
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-
|
|
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
|
|
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
|
|
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
|
|
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" ?
|
|
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
|
|
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
|
|
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
|
|
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 ?
|
|
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;
|
|
@@ -3603,6 +3444,6 @@ var EdgexClient = class {
|
|
|
3603
3444
|
}
|
|
3604
3445
|
};
|
|
3605
3446
|
|
|
3606
|
-
export { Backoff, BinanceClient, BingxClient, BitgetClient, BookMerger, BybitClient, CoinexClient, DeribitClient, EdgexClient, ExchangeError, GateClient, GrvtClient,
|
|
3447
|
+
export { Backoff, BinanceClient, BingxClient, BitgetClient, BookMerger, BybitClient, CoinexClient, DeribitClient, EdgexClient, ExchangeError, GateClient, GrvtClient, HyperliquidClient, KucoinClient, LighterClient, OkxClient, OrderbookStream, RateLimitError, SequenceGapError, parseSymbol };
|
|
3607
3448
|
//# sourceMappingURL=index.js.map
|
|
3608
3449
|
//# sourceMappingURL=index.js.map
|