@xapy/orderbook 0.1.7 → 0.1.9
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/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/bitmart/index.cjs +594 -0
- package/dist/exchanges/bitmart/index.cjs.map +1 -0
- package/dist/exchanges/bitmart/index.d.cts +56 -0
- package/dist/exchanges/bitmart/index.d.ts +56 -0
- package/dist/exchanges/bitmart/index.js +590 -0
- package/dist/exchanges/bitmart/index.js.map +1 -0
- 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/gate/index.d.cts +1 -1
- package/dist/exchanges/gate/index.d.ts +1 -1
- package/dist/exchanges/huobi/index.d.cts +1 -1
- package/dist/exchanges/huobi/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/okx/index.d.cts +1 -1
- package/dist/exchanges/okx/index.d.ts +1 -1
- package/dist/index.cjs +180 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -2
- package/dist/index.d.ts +3 -2
- package/dist/index.js +180 -1
- package/dist/index.js.map +1 -1
- package/dist/{stream-C73HPYqT.d.cts → stream-L9MJjYbE.d.cts} +1 -1
- package/dist/{stream-C73HPYqT.d.ts → stream-L9MJjYbE.d.ts} +1 -1
- package/package.json +11 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { M as Market, a as Orderbook, c as OrderbookStream, C as ClientOptions, b as OrderbookOptions } from '../../stream-
|
|
1
|
+
import { M as Market, a as Orderbook, c as OrderbookStream, C as ClientOptions, b as OrderbookOptions } from '../../stream-L9MJjYbE.cjs';
|
|
2
2
|
|
|
3
3
|
interface FetchBybitOrderbookOptions {
|
|
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-
|
|
1
|
+
import { M as Market, a as Orderbook, c as OrderbookStream, C as ClientOptions, b as OrderbookOptions } from '../../stream-L9MJjYbE.js';
|
|
2
2
|
|
|
3
3
|
interface FetchBybitOrderbookOptions {
|
|
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-
|
|
1
|
+
import { M as Market, a as Orderbook, c as OrderbookStream, C as ClientOptions, b as OrderbookOptions } from '../../stream-L9MJjYbE.cjs';
|
|
2
2
|
|
|
3
3
|
interface FetchCoinexOrderbookOptions {
|
|
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-
|
|
1
|
+
import { M as Market, a as Orderbook, c as OrderbookStream, C as ClientOptions, b as OrderbookOptions } from '../../stream-L9MJjYbE.js';
|
|
2
2
|
|
|
3
3
|
interface FetchCoinexOrderbookOptions {
|
|
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-
|
|
1
|
+
import { M as Market, a as Orderbook, c as OrderbookStream, C as ClientOptions, b as OrderbookOptions } from '../../stream-L9MJjYbE.cjs';
|
|
2
2
|
|
|
3
3
|
interface FetchGateOrderbookOptions {
|
|
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-
|
|
1
|
+
import { M as Market, a as Orderbook, c as OrderbookStream, C as ClientOptions, b as OrderbookOptions } from '../../stream-L9MJjYbE.js';
|
|
2
2
|
|
|
3
3
|
interface FetchGateOrderbookOptions {
|
|
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-
|
|
1
|
+
import { M as Market, a as Orderbook, c as OrderbookStream, C as ClientOptions, b as OrderbookOptions } from '../../stream-L9MJjYbE.cjs';
|
|
2
2
|
|
|
3
3
|
interface FetchHuobiOrderbookOptions {
|
|
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-
|
|
1
|
+
import { M as Market, a as Orderbook, c as OrderbookStream, C as ClientOptions, b as OrderbookOptions } from '../../stream-L9MJjYbE.js';
|
|
2
2
|
|
|
3
3
|
interface FetchHuobiOrderbookOptions {
|
|
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-
|
|
1
|
+
import { M as Market, a as Orderbook, c as OrderbookStream, C as ClientOptions, b as OrderbookOptions } from '../../stream-L9MJjYbE.cjs';
|
|
2
2
|
|
|
3
3
|
interface FetchHyperliquidOrderbookOptions {
|
|
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-
|
|
1
|
+
import { M as Market, a as Orderbook, c as OrderbookStream, C as ClientOptions, b as OrderbookOptions } from '../../stream-L9MJjYbE.js';
|
|
2
2
|
|
|
3
3
|
interface FetchHyperliquidOrderbookOptions {
|
|
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-
|
|
1
|
+
import { M as Market, a as Orderbook, c as OrderbookStream, C as ClientOptions, b as OrderbookOptions } from '../../stream-L9MJjYbE.cjs';
|
|
2
2
|
|
|
3
3
|
interface FetchKucoinOrderbookOptions {
|
|
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-
|
|
1
|
+
import { M as Market, a as Orderbook, c as OrderbookStream, C as ClientOptions, b as OrderbookOptions } from '../../stream-L9MJjYbE.js';
|
|
2
2
|
|
|
3
3
|
interface FetchKucoinOrderbookOptions {
|
|
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-
|
|
1
|
+
import { M as Market, a as Orderbook, c as OrderbookStream, C as ClientOptions, b as OrderbookOptions } from '../../stream-L9MJjYbE.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-
|
|
1
|
+
import { M as Market, a as Orderbook, c as OrderbookStream, C as ClientOptions, b as OrderbookOptions } from '../../stream-L9MJjYbE.js';
|
|
2
2
|
|
|
3
3
|
interface FetchOkxOrderbookOptions {
|
|
4
4
|
symbol: string;
|
package/dist/index.cjs
CHANGED
|
@@ -2569,10 +2569,190 @@ var KucoinClient = class {
|
|
|
2569
2569
|
}
|
|
2570
2570
|
};
|
|
2571
2571
|
|
|
2572
|
+
// src/exchanges/bitmart/symbols.ts
|
|
2573
|
+
var QUOTES6 = ["USDT", "USDC", "USD"];
|
|
2574
|
+
function toBitmartSymbol(symbol) {
|
|
2575
|
+
const [base, quote] = symbol.split("/");
|
|
2576
|
+
if (!base || !quote) {
|
|
2577
|
+
throw new Error(`invalid symbol "${symbol}" \u2014 expected "BASE/QUOTE"`);
|
|
2578
|
+
}
|
|
2579
|
+
return `${base}${quote}`.toUpperCase();
|
|
2580
|
+
}
|
|
2581
|
+
function fromBitmartSymbol(s) {
|
|
2582
|
+
const upper = s.toUpperCase();
|
|
2583
|
+
for (const q of QUOTES6) {
|
|
2584
|
+
if (upper.endsWith(q) && upper.length > q.length) {
|
|
2585
|
+
return `${upper.slice(0, -q.length)}/${q}`;
|
|
2586
|
+
}
|
|
2587
|
+
}
|
|
2588
|
+
return upper;
|
|
2589
|
+
}
|
|
2590
|
+
|
|
2591
|
+
// src/exchanges/bitmart/rest.ts
|
|
2592
|
+
var BASE8 = "https://api-cloud-v2.bitmart.com";
|
|
2593
|
+
async function fetchBitmartOrderbook(opts) {
|
|
2594
|
+
if (opts.market !== "perpetual") {
|
|
2595
|
+
throw new ExchangeError(
|
|
2596
|
+
"bitmart",
|
|
2597
|
+
"spot is not supported \u2014 only USDT-M perpetual"
|
|
2598
|
+
);
|
|
2599
|
+
}
|
|
2600
|
+
const symbol = toBitmartSymbol(opts.symbol);
|
|
2601
|
+
const url = `${BASE8}/contract/public/depth?symbol=${symbol}`;
|
|
2602
|
+
const res = await httpJson({
|
|
2603
|
+
url,
|
|
2604
|
+
timeoutMs: opts.timeoutMs,
|
|
2605
|
+
transformUrl: opts.transformUrl
|
|
2606
|
+
});
|
|
2607
|
+
if (res.code !== 1e3) {
|
|
2608
|
+
throw new ExchangeError("bitmart", `${res.code}: ${res.message ?? ""}`);
|
|
2609
|
+
}
|
|
2610
|
+
return {
|
|
2611
|
+
exchange: "bitmart",
|
|
2612
|
+
symbol: fromBitmartSymbol(res.data.symbol),
|
|
2613
|
+
market: "perpetual",
|
|
2614
|
+
bids: parseLevels3(res.data.bids),
|
|
2615
|
+
asks: parseLevels3(res.data.asks),
|
|
2616
|
+
timestamp: res.data.timestamp,
|
|
2617
|
+
sequence: res.data.timestamp
|
|
2618
|
+
};
|
|
2619
|
+
}
|
|
2620
|
+
function parseLevels3(rows) {
|
|
2621
|
+
const out = [];
|
|
2622
|
+
for (const row of rows) {
|
|
2623
|
+
out.push({ price: Number(row[0]), size: Number(row[1]) });
|
|
2624
|
+
}
|
|
2625
|
+
return out;
|
|
2626
|
+
}
|
|
2627
|
+
|
|
2628
|
+
// src/exchanges/bitmart/ws.ts
|
|
2629
|
+
var WS_FUTURES4 = "wss://openapi-ws-v2.bitmart.com/api?protocol=1.1";
|
|
2630
|
+
function streamBitmartOrderbook(opts) {
|
|
2631
|
+
if (opts.market !== "perpetual") {
|
|
2632
|
+
throw new ExchangeError(
|
|
2633
|
+
"bitmart",
|
|
2634
|
+
"spot is not supported \u2014 only USDT-M perpetual"
|
|
2635
|
+
);
|
|
2636
|
+
}
|
|
2637
|
+
const symbol = toBitmartSymbol(opts.symbol);
|
|
2638
|
+
const channelArg = opts.interval ? `futures/depth:${symbol}@${opts.interval}` : `futures/depth:${symbol}`;
|
|
2639
|
+
const merger = new BookMerger();
|
|
2640
|
+
let ws = null;
|
|
2641
|
+
const stream = new OrderbookStream(() => ws?.close());
|
|
2642
|
+
const subscribePayload = JSON.stringify({
|
|
2643
|
+
action: "subscribe",
|
|
2644
|
+
args: [channelArg]
|
|
2645
|
+
});
|
|
2646
|
+
const pingPayload = () => JSON.stringify({ action: "ping" });
|
|
2647
|
+
const handleFrame = (frame) => {
|
|
2648
|
+
if (frame.symbol !== symbol) return;
|
|
2649
|
+
const event = {
|
|
2650
|
+
kind: "snapshot",
|
|
2651
|
+
bids: parseLevels4(frame.bids),
|
|
2652
|
+
asks: parseLevels4(frame.asks),
|
|
2653
|
+
sequence: frame.timestamp,
|
|
2654
|
+
timestamp: frame.timestamp
|
|
2655
|
+
};
|
|
2656
|
+
const r = merger.apply(event);
|
|
2657
|
+
if (!r.ok) return;
|
|
2658
|
+
const book = {
|
|
2659
|
+
exchange: "bitmart",
|
|
2660
|
+
symbol: fromBitmartSymbol(symbol),
|
|
2661
|
+
market: "perpetual",
|
|
2662
|
+
bids: r.bids,
|
|
2663
|
+
asks: r.asks,
|
|
2664
|
+
timestamp: r.timestamp,
|
|
2665
|
+
sequence: r.sequence
|
|
2666
|
+
};
|
|
2667
|
+
stream.emit("update", book);
|
|
2668
|
+
};
|
|
2669
|
+
const handlePayload = (text) => {
|
|
2670
|
+
let msg;
|
|
2671
|
+
try {
|
|
2672
|
+
msg = JSON.parse(text);
|
|
2673
|
+
} catch {
|
|
2674
|
+
return;
|
|
2675
|
+
}
|
|
2676
|
+
if (msg.action === "subscribe" || msg.action === "pong") return;
|
|
2677
|
+
if (msg.errorCode) {
|
|
2678
|
+
stream.emit(
|
|
2679
|
+
"error",
|
|
2680
|
+
new Error(`bitmart: ${msg.errorCode} ${msg.errorMessage ?? ""}`)
|
|
2681
|
+
);
|
|
2682
|
+
return;
|
|
2683
|
+
}
|
|
2684
|
+
if (msg.arg !== channelArg || !msg.data) return;
|
|
2685
|
+
handleFrame(msg.data);
|
|
2686
|
+
};
|
|
2687
|
+
const onMessage = async (raw) => {
|
|
2688
|
+
if (typeof raw === "string") {
|
|
2689
|
+
handlePayload(raw);
|
|
2690
|
+
return;
|
|
2691
|
+
}
|
|
2692
|
+
const inflate = await getGzipInflate();
|
|
2693
|
+
handlePayload(inflate(raw));
|
|
2694
|
+
};
|
|
2695
|
+
ws = new WSClient({
|
|
2696
|
+
url: WS_FUTURES4,
|
|
2697
|
+
onOpen: (sock) => {
|
|
2698
|
+
merger.reset();
|
|
2699
|
+
sock.send(subscribePayload);
|
|
2700
|
+
},
|
|
2701
|
+
onMessage,
|
|
2702
|
+
pingIntervalMs: 15e3,
|
|
2703
|
+
pingPayload
|
|
2704
|
+
});
|
|
2705
|
+
ws.on("open", () => stream.emit("connected"));
|
|
2706
|
+
ws.on("close", (r) => stream.emit("disconnected", r));
|
|
2707
|
+
ws.on("reconnecting", (a, w) => stream.emit("reconnecting", a, w));
|
|
2708
|
+
ws.on("error", (e) => stream.emit("error", e));
|
|
2709
|
+
ws.connect().catch((e) => stream.emit("error", e));
|
|
2710
|
+
return stream;
|
|
2711
|
+
}
|
|
2712
|
+
function parseLevels4(rows) {
|
|
2713
|
+
if (!rows) return [];
|
|
2714
|
+
const out = [];
|
|
2715
|
+
for (const row of rows) {
|
|
2716
|
+
out.push({ price: Number(row[0]), size: Number(row[1]) });
|
|
2717
|
+
}
|
|
2718
|
+
return out;
|
|
2719
|
+
}
|
|
2720
|
+
|
|
2721
|
+
// src/exchanges/bitmart/index.ts
|
|
2722
|
+
var BitmartClient = class {
|
|
2723
|
+
exchange = "bitmart";
|
|
2724
|
+
transformUrl;
|
|
2725
|
+
timeoutMs;
|
|
2726
|
+
constructor(opts = {}) {
|
|
2727
|
+
this.transformUrl = opts.transformUrl;
|
|
2728
|
+
this.timeoutMs = opts.timeoutMs;
|
|
2729
|
+
}
|
|
2730
|
+
fetchOrderbook(symbol, opts = {}) {
|
|
2731
|
+
const { pair, market } = parseSymbol(symbol);
|
|
2732
|
+
return fetchBitmartOrderbook({
|
|
2733
|
+
symbol: pair,
|
|
2734
|
+
market,
|
|
2735
|
+
depth: opts.depth,
|
|
2736
|
+
timeoutMs: this.timeoutMs,
|
|
2737
|
+
transformUrl: this.transformUrl
|
|
2738
|
+
});
|
|
2739
|
+
}
|
|
2740
|
+
streamOrderbook(symbol, _opts = {}) {
|
|
2741
|
+
const { pair, market } = parseSymbol(symbol);
|
|
2742
|
+
return streamBitmartOrderbook({
|
|
2743
|
+
symbol: pair,
|
|
2744
|
+
market,
|
|
2745
|
+
transformUrl: this.transformUrl,
|
|
2746
|
+
timeoutMs: this.timeoutMs
|
|
2747
|
+
});
|
|
2748
|
+
}
|
|
2749
|
+
};
|
|
2750
|
+
|
|
2572
2751
|
exports.Backoff = Backoff;
|
|
2573
2752
|
exports.BinanceClient = BinanceClient;
|
|
2574
2753
|
exports.BingxClient = BingxClient;
|
|
2575
2754
|
exports.BitgetClient = BitgetClient;
|
|
2755
|
+
exports.BitmartClient = BitmartClient;
|
|
2576
2756
|
exports.BookMerger = BookMerger;
|
|
2577
2757
|
exports.BybitClient = BybitClient;
|
|
2578
2758
|
exports.CoinexClient = CoinexClient;
|