@xapy/orderbook 0.1.4 → 0.1.6

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 (69) hide show
  1. package/dist/exchanges/binance/index.cjs +605 -0
  2. package/dist/exchanges/binance/index.cjs.map +1 -0
  3. package/dist/exchanges/binance/index.d.cts +60 -0
  4. package/dist/exchanges/binance/index.d.ts +60 -0
  5. package/dist/exchanges/binance/index.js +601 -0
  6. package/dist/exchanges/binance/index.js.map +1 -0
  7. package/dist/exchanges/bingx/index.cjs +2 -1
  8. package/dist/exchanges/bingx/index.cjs.map +1 -1
  9. package/dist/exchanges/bingx/index.d.cts +1 -1
  10. package/dist/exchanges/bingx/index.d.ts +1 -1
  11. package/dist/exchanges/bingx/index.js +2 -1
  12. package/dist/exchanges/bingx/index.js.map +1 -1
  13. package/dist/exchanges/bitget/index.cjs +2 -1
  14. package/dist/exchanges/bitget/index.cjs.map +1 -1
  15. package/dist/exchanges/bitget/index.d.cts +1 -1
  16. package/dist/exchanges/bitget/index.d.ts +1 -1
  17. package/dist/exchanges/bitget/index.js +2 -1
  18. package/dist/exchanges/bitget/index.js.map +1 -1
  19. package/dist/exchanges/bybit/index.cjs +2 -1
  20. package/dist/exchanges/bybit/index.cjs.map +1 -1
  21. package/dist/exchanges/bybit/index.d.cts +1 -1
  22. package/dist/exchanges/bybit/index.d.ts +1 -1
  23. package/dist/exchanges/bybit/index.js +2 -1
  24. package/dist/exchanges/bybit/index.js.map +1 -1
  25. package/dist/exchanges/coinex/index.cjs +111 -24
  26. package/dist/exchanges/coinex/index.cjs.map +1 -1
  27. package/dist/exchanges/coinex/index.d.cts +13 -5
  28. package/dist/exchanges/coinex/index.d.ts +13 -5
  29. package/dist/exchanges/coinex/index.js +111 -24
  30. package/dist/exchanges/coinex/index.js.map +1 -1
  31. package/dist/exchanges/gate/index.cjs +2 -1
  32. package/dist/exchanges/gate/index.cjs.map +1 -1
  33. package/dist/exchanges/gate/index.d.cts +1 -1
  34. package/dist/exchanges/gate/index.d.ts +1 -1
  35. package/dist/exchanges/gate/index.js +2 -1
  36. package/dist/exchanges/gate/index.js.map +1 -1
  37. package/dist/exchanges/huobi/index.cjs +2 -1
  38. package/dist/exchanges/huobi/index.cjs.map +1 -1
  39. package/dist/exchanges/huobi/index.d.cts +1 -1
  40. package/dist/exchanges/huobi/index.d.ts +1 -1
  41. package/dist/exchanges/huobi/index.js +2 -1
  42. package/dist/exchanges/huobi/index.js.map +1 -1
  43. package/dist/exchanges/hyperliquid/index.cjs +536 -0
  44. package/dist/exchanges/hyperliquid/index.cjs.map +1 -0
  45. package/dist/exchanges/hyperliquid/index.d.cts +45 -0
  46. package/dist/exchanges/hyperliquid/index.d.ts +45 -0
  47. package/dist/exchanges/hyperliquid/index.js +532 -0
  48. package/dist/exchanges/hyperliquid/index.js.map +1 -0
  49. package/dist/exchanges/kucoin/index.cjs +614 -0
  50. package/dist/exchanges/kucoin/index.cjs.map +1 -0
  51. package/dist/exchanges/kucoin/index.d.cts +60 -0
  52. package/dist/exchanges/kucoin/index.d.ts +60 -0
  53. package/dist/exchanges/kucoin/index.js +609 -0
  54. package/dist/exchanges/kucoin/index.js.map +1 -0
  55. package/dist/exchanges/okx/index.cjs +2 -1
  56. package/dist/exchanges/okx/index.cjs.map +1 -1
  57. package/dist/exchanges/okx/index.d.cts +1 -1
  58. package/dist/exchanges/okx/index.d.ts +1 -1
  59. package/dist/exchanges/okx/index.js +2 -1
  60. package/dist/exchanges/okx/index.js.map +1 -1
  61. package/dist/index.cjs +736 -24
  62. package/dist/index.cjs.map +1 -1
  63. package/dist/index.d.cts +5 -2
  64. package/dist/index.d.ts +5 -2
  65. package/dist/index.js +734 -25
  66. package/dist/index.js.map +1 -1
  67. package/dist/{stream-BKpWmRYN.d.cts → stream-C73HPYqT.d.cts} +1 -1
  68. package/dist/{stream-BKpWmRYN.d.ts → stream-C73HPYqT.d.ts} +1 -1
  69. package/package.json +34 -1
@@ -0,0 +1,601 @@
1
+ // src/core/symbol.ts
2
+ function parseSymbol(symbol) {
3
+ const [pair, settle] = symbol.split(":");
4
+ const parts = (pair ?? "").split("/");
5
+ const base = parts[0]?.toUpperCase();
6
+ const quote = parts[1]?.toUpperCase();
7
+ if (!base || !quote) {
8
+ throw new Error(
9
+ `invalid symbol "${symbol}" \u2014 expected "BASE/QUOTE" or "BASE/QUOTE:SETTLE"`
10
+ );
11
+ }
12
+ if (settle && settle.toUpperCase() !== quote) {
13
+ throw new Error(
14
+ `unsupported settlement currency in "${symbol}" \u2014 only linear (settle === quote) is supported`
15
+ );
16
+ }
17
+ return {
18
+ base,
19
+ quote,
20
+ market: settle ? "perpetual" : "spot",
21
+ pair: `${base}/${quote}`
22
+ };
23
+ }
24
+
25
+ // src/transport/http.ts
26
+ async function httpJson(req) {
27
+ const url = req.transformUrl ? req.transformUrl(req.url) : req.url;
28
+ const controller = new AbortController();
29
+ const timer = setTimeout(() => controller.abort(), req.timeoutMs ?? 1e4);
30
+ try {
31
+ const res = await fetch(url, {
32
+ method: req.method ?? "GET",
33
+ headers: req.headers,
34
+ body: req.body,
35
+ signal: controller.signal
36
+ });
37
+ if (!res.ok) {
38
+ const text = await res.text().catch(() => "");
39
+ throw new Error(`HTTP ${res.status} ${res.statusText}: ${text.slice(0, 200)}`);
40
+ }
41
+ return await res.json();
42
+ } finally {
43
+ clearTimeout(timer);
44
+ }
45
+ }
46
+
47
+ // src/exchanges/binance/symbols.ts
48
+ var QUOTES = [
49
+ "USDT",
50
+ "USDC",
51
+ "FDUSD",
52
+ "BUSD",
53
+ "TUSD",
54
+ "USD",
55
+ "BTC",
56
+ "ETH",
57
+ "BNB"
58
+ ];
59
+ function toBinanceSymbol(symbol) {
60
+ const [base, quote] = symbol.split("/");
61
+ if (!base || !quote) {
62
+ throw new Error(`invalid symbol "${symbol}" \u2014 expected "BASE/QUOTE"`);
63
+ }
64
+ return `${base}${quote}`.toUpperCase();
65
+ }
66
+ function fromBinanceSymbol(s) {
67
+ const upper = s.toUpperCase();
68
+ for (const q of QUOTES) {
69
+ if (upper.endsWith(q) && upper.length > q.length) {
70
+ return `${upper.slice(0, -q.length)}/${q}`;
71
+ }
72
+ }
73
+ return upper;
74
+ }
75
+
76
+ // src/exchanges/binance/rest.ts
77
+ var BASE_SPOT = "https://api.binance.com";
78
+ var BASE_FAPI = "https://fapi.binance.com";
79
+ async function fetchBinanceOrderbook(opts) {
80
+ const symbol = toBinanceSymbol(opts.symbol);
81
+ const limit = opts.depth ?? 1e3;
82
+ const url = opts.market === "spot" ? `${BASE_SPOT}/api/v3/depth?symbol=${symbol}&limit=${limit}` : `${BASE_FAPI}/fapi/v1/depth?symbol=${symbol}&limit=${limit}`;
83
+ const data = await httpJson({
84
+ url,
85
+ timeoutMs: opts.timeoutMs,
86
+ transformUrl: opts.transformUrl
87
+ });
88
+ return {
89
+ exchange: "binance",
90
+ symbol: fromBinanceSymbol(symbol),
91
+ market: opts.market,
92
+ bids: data.bids.map(([p, s]) => ({ price: Number(p), size: Number(s) })),
93
+ asks: data.asks.map(([p, s]) => ({ price: Number(p), size: Number(s) })),
94
+ timestamp: data.E ?? data.T ?? Date.now(),
95
+ sequence: data.lastUpdateId
96
+ };
97
+ }
98
+
99
+ // src/core/book-merger.ts
100
+ var BookMerger = class {
101
+ bids = /* @__PURE__ */ new Map();
102
+ // price -> size
103
+ asks = /* @__PURE__ */ new Map();
104
+ sequence = -1;
105
+ timestamp = 0;
106
+ hasSnapshot = false;
107
+ apply(event) {
108
+ if (event.kind === "snapshot") {
109
+ this.bids.clear();
110
+ this.asks.clear();
111
+ for (const { price, size } of event.bids) {
112
+ if (size > 0) this.bids.set(price, size);
113
+ }
114
+ for (const { price, size } of event.asks) {
115
+ if (size > 0) this.asks.set(price, size);
116
+ }
117
+ this.sequence = event.sequence;
118
+ this.timestamp = event.timestamp;
119
+ this.hasSnapshot = true;
120
+ return this.emit();
121
+ }
122
+ if (!this.hasSnapshot) {
123
+ return { ok: false, reason: "no-snapshot" };
124
+ }
125
+ if (event.sequence <= this.sequence) {
126
+ return this.emit();
127
+ }
128
+ if (event.prevSequence !== void 0) {
129
+ if (event.prevSequence !== this.sequence) {
130
+ return {
131
+ ok: false,
132
+ reason: "gap",
133
+ expected: this.sequence,
134
+ received: event.prevSequence
135
+ };
136
+ }
137
+ } else if (event.sequence !== this.sequence + 1) {
138
+ return {
139
+ ok: false,
140
+ reason: "gap",
141
+ expected: this.sequence + 1,
142
+ received: event.sequence
143
+ };
144
+ }
145
+ for (const { price, size } of event.bids) {
146
+ if (size === 0) this.bids.delete(price);
147
+ else this.bids.set(price, size);
148
+ }
149
+ for (const { price, size } of event.asks) {
150
+ if (size === 0) this.asks.delete(price);
151
+ else this.asks.set(price, size);
152
+ }
153
+ this.sequence = event.sequence;
154
+ this.timestamp = event.timestamp;
155
+ return this.emit();
156
+ }
157
+ reset() {
158
+ this.bids.clear();
159
+ this.asks.clear();
160
+ this.sequence = -1;
161
+ this.timestamp = 0;
162
+ this.hasSnapshot = false;
163
+ }
164
+ /** Returns true once the merger has a usable book. */
165
+ isReady() {
166
+ return this.hasSnapshot;
167
+ }
168
+ emit() {
169
+ const bids = [];
170
+ for (const [price, size] of this.bids) bids.push({ price, size });
171
+ bids.sort((a, b) => b.price - a.price);
172
+ const asks = [];
173
+ for (const [price, size] of this.asks) asks.push({ price, size });
174
+ asks.sort((a, b) => a.price - b.price);
175
+ return {
176
+ ok: true,
177
+ bids,
178
+ asks,
179
+ sequence: this.sequence,
180
+ timestamp: this.timestamp
181
+ };
182
+ }
183
+ };
184
+
185
+ // src/core/event-emitter.ts
186
+ var TypedEmitter = class {
187
+ listeners = /* @__PURE__ */ new Map();
188
+ on(event, fn) {
189
+ let set = this.listeners.get(event);
190
+ if (!set) {
191
+ set = /* @__PURE__ */ new Set();
192
+ this.listeners.set(event, set);
193
+ }
194
+ set.add(fn);
195
+ return this;
196
+ }
197
+ off(event, fn) {
198
+ this.listeners.get(event)?.delete(fn);
199
+ return this;
200
+ }
201
+ emit(event, ...args) {
202
+ const set = this.listeners.get(event);
203
+ if (!set || set.size === 0) return false;
204
+ for (const fn of set) fn(...args);
205
+ return true;
206
+ }
207
+ removeAllListeners() {
208
+ this.listeners.clear();
209
+ }
210
+ };
211
+
212
+ // src/core/stream.ts
213
+ var OrderbookStream = class extends TypedEmitter {
214
+ constructor(onClose) {
215
+ super();
216
+ this.onClose = onClose;
217
+ }
218
+ onClose;
219
+ closed = false;
220
+ close() {
221
+ if (this.closed) return;
222
+ this.closed = true;
223
+ this.onClose();
224
+ this.removeAllListeners();
225
+ }
226
+ /** Yields each maintained book as it becomes available. */
227
+ async *iter() {
228
+ const queue = [];
229
+ let resolveNext = null;
230
+ let pendingError = null;
231
+ let ended = false;
232
+ const onUpdate = (b) => {
233
+ queue.push(b);
234
+ resolveNext?.();
235
+ };
236
+ const onError = (e) => {
237
+ pendingError = e;
238
+ resolveNext?.();
239
+ };
240
+ const onClose = () => {
241
+ ended = true;
242
+ resolveNext?.();
243
+ };
244
+ this.on("update", onUpdate);
245
+ this.on("error", onError);
246
+ this.on("disconnected", onClose);
247
+ try {
248
+ while (true) {
249
+ if (pendingError) throw pendingError;
250
+ const next = queue.shift();
251
+ if (next) {
252
+ yield next;
253
+ continue;
254
+ }
255
+ if (ended || this.closed) return;
256
+ await new Promise((r) => {
257
+ resolveNext = r;
258
+ });
259
+ resolveNext = null;
260
+ }
261
+ } finally {
262
+ this.off("update", onUpdate);
263
+ this.off("error", onError);
264
+ this.off("disconnected", onClose);
265
+ }
266
+ }
267
+ };
268
+
269
+ // src/core/reconnect.ts
270
+ var Backoff = class _Backoff {
271
+ attempt = 0;
272
+ opts;
273
+ constructor(opts) {
274
+ this.opts = opts;
275
+ }
276
+ static withDefaults(opts = {}) {
277
+ return new _Backoff({
278
+ initialMs: opts.initialMs ?? 500,
279
+ maxMs: opts.maxMs ?? 3e4,
280
+ factor: opts.factor ?? 2,
281
+ jitter: opts.jitter ?? 0.3,
282
+ maxAttempts: opts.maxAttempts ?? 0
283
+ });
284
+ }
285
+ next() {
286
+ if (this.opts.maxAttempts > 0 && this.attempt >= this.opts.maxAttempts) {
287
+ return null;
288
+ }
289
+ this.attempt += 1;
290
+ const base = Math.min(
291
+ this.opts.initialMs * Math.pow(this.opts.factor, this.attempt - 1),
292
+ this.opts.maxMs
293
+ );
294
+ const jitterRange = base * this.opts.jitter;
295
+ const wait = Math.max(0, base + (Math.random() * 2 - 1) * jitterRange);
296
+ return { wait, attempt: this.attempt };
297
+ }
298
+ reset() {
299
+ this.attempt = 0;
300
+ }
301
+ };
302
+ var hasNativeWebSocket = typeof globalThis.WebSocket !== "undefined";
303
+
304
+ // src/transport/ws.ts
305
+ var cachedCtor = null;
306
+ async function getWebSocketCtor() {
307
+ if (cachedCtor) return cachedCtor;
308
+ if (hasNativeWebSocket) {
309
+ cachedCtor = globalThis.WebSocket;
310
+ return cachedCtor;
311
+ }
312
+ try {
313
+ const mod = await import('ws');
314
+ const ctor = mod.default ?? mod.WebSocket;
315
+ if (!ctor) throw new Error("missing default export");
316
+ cachedCtor = ctor;
317
+ return cachedCtor;
318
+ } catch (err) {
319
+ throw new Error(
320
+ "WebSocket unavailable; install peer dep `ws` for Node <22. " + (err instanceof Error ? err.message : String(err))
321
+ );
322
+ }
323
+ }
324
+ var WSClient = class extends TypedEmitter {
325
+ constructor(cfg) {
326
+ super();
327
+ this.cfg = cfg;
328
+ this.backoff = Backoff.withDefaults(cfg.reconnect);
329
+ }
330
+ cfg;
331
+ ws = null;
332
+ backoff;
333
+ closed = false;
334
+ pingTimer = null;
335
+ async connect() {
336
+ if (this.closed) return;
337
+ const WS = await getWebSocketCtor();
338
+ const url = typeof this.cfg.url === "function" ? await this.cfg.url() : this.cfg.url;
339
+ const ws = new WS(url);
340
+ ws.binaryType = "arraybuffer";
341
+ this.ws = ws;
342
+ ws.onopen = async () => {
343
+ this.backoff.reset();
344
+ this.startPing();
345
+ this.emit("open");
346
+ try {
347
+ await this.cfg.onOpen?.({
348
+ send: (d) => ws.send(d),
349
+ close: () => this.close()
350
+ });
351
+ } catch (err) {
352
+ this.emit("error", err);
353
+ }
354
+ };
355
+ ws.onmessage = (e) => {
356
+ let result;
357
+ try {
358
+ result = this.cfg.onMessage(e.data);
359
+ } catch (err) {
360
+ this.emit("error", err);
361
+ return;
362
+ }
363
+ if (result && typeof result.catch === "function") {
364
+ result.catch(
365
+ (err) => this.emit("error", err)
366
+ );
367
+ }
368
+ };
369
+ ws.onerror = (e) => {
370
+ this.emit("error", new Error(e?.message ?? "WebSocket error"));
371
+ };
372
+ ws.onclose = (e) => {
373
+ this.stopPing();
374
+ const reason = e?.reason ?? "closed";
375
+ this.emit("close", reason);
376
+ if (!this.closed) this.scheduleReconnect();
377
+ };
378
+ }
379
+ send(data) {
380
+ this.ws?.send(data);
381
+ }
382
+ close() {
383
+ this.closed = true;
384
+ this.stopPing();
385
+ try {
386
+ this.ws?.close();
387
+ } catch {
388
+ }
389
+ }
390
+ startPing() {
391
+ if (!this.cfg.pingIntervalMs || !this.cfg.pingPayload) return;
392
+ this.stopPing();
393
+ this.pingTimer = setInterval(() => {
394
+ try {
395
+ this.ws?.send(this.cfg.pingPayload());
396
+ } catch {
397
+ }
398
+ }, this.cfg.pingIntervalMs);
399
+ }
400
+ stopPing() {
401
+ if (this.pingTimer) {
402
+ clearInterval(this.pingTimer);
403
+ this.pingTimer = null;
404
+ }
405
+ }
406
+ scheduleReconnect() {
407
+ const next = this.backoff.next();
408
+ if (!next) {
409
+ this.emit("error", new Error("max reconnect attempts exceeded"));
410
+ return;
411
+ }
412
+ this.emit("reconnecting", next.attempt, next.wait);
413
+ setTimeout(() => {
414
+ this.connect().catch((e) => this.emit("error", e));
415
+ }, next.wait);
416
+ }
417
+ };
418
+
419
+ // src/exchanges/binance/ws.ts
420
+ var WS_SPOT = "wss://stream.binance.com:9443/ws";
421
+ var WS_FUTURES = "wss://fstream.binance.com/ws";
422
+ function streamBinanceOrderbook(opts) {
423
+ const symbol = toBinanceSymbol(opts.symbol);
424
+ const isSpot = opts.market === "spot";
425
+ const interval = opts.interval ?? "100ms";
426
+ const wsBase = isSpot ? WS_SPOT : WS_FUTURES;
427
+ const wsUrl = `${wsBase}/${symbol.toLowerCase()}@depth@${interval}`;
428
+ const merger = new BookMerger();
429
+ let snapshotId = -1;
430
+ let lastU = -1;
431
+ let snapshotInFlight = false;
432
+ let snapshotDone = false;
433
+ let buffered = [];
434
+ let recovering = false;
435
+ let ws = null;
436
+ const stream = new OrderbookStream(() => ws?.close());
437
+ const emit = (r) => {
438
+ const book = {
439
+ exchange: "binance",
440
+ symbol: fromBinanceSymbol(symbol),
441
+ market: opts.market,
442
+ bids: r.bids,
443
+ asks: r.asks,
444
+ timestamp: r.timestamp,
445
+ sequence: r.sequence
446
+ };
447
+ stream.emit("update", book);
448
+ };
449
+ const triggerSnapshot = () => {
450
+ if (snapshotInFlight) return;
451
+ snapshotInFlight = true;
452
+ fetchBinanceOrderbook({
453
+ symbol: opts.symbol,
454
+ market: opts.market,
455
+ depth: opts.depth ?? 1e3,
456
+ timeoutMs: opts.timeoutMs,
457
+ transformUrl: opts.transformUrl
458
+ }).then((snap) => {
459
+ snapshotId = snap.sequence;
460
+ const r = merger.apply({
461
+ kind: "snapshot",
462
+ bids: snap.bids,
463
+ asks: snap.asks,
464
+ sequence: snap.sequence,
465
+ timestamp: snap.timestamp
466
+ });
467
+ if (r.ok) emit(r);
468
+ snapshotDone = true;
469
+ lastU = -1;
470
+ const pending = buffered;
471
+ buffered = [];
472
+ for (const ev of pending) processDelta(ev);
473
+ }).catch((err) => stream.emit("error", err)).finally(() => {
474
+ snapshotInFlight = false;
475
+ });
476
+ };
477
+ const resync = () => {
478
+ if (recovering) return;
479
+ recovering = true;
480
+ merger.reset();
481
+ snapshotId = -1;
482
+ snapshotDone = false;
483
+ lastU = -1;
484
+ buffered = [];
485
+ setTimeout(() => {
486
+ recovering = false;
487
+ triggerSnapshot();
488
+ }, 100);
489
+ };
490
+ const processDelta = (ev) => {
491
+ if (ev.u < snapshotId + 1) return;
492
+ const bids = ev.b.map(([p, s]) => ({
493
+ price: Number(p),
494
+ size: Number(s)
495
+ }));
496
+ const asks = ev.a.map(([p, s]) => ({
497
+ price: Number(p),
498
+ size: Number(s)
499
+ }));
500
+ let prevSequence;
501
+ if (lastU < 0) {
502
+ const overlap = isSpot ? ev.U <= snapshotId + 1 : ev.U <= snapshotId;
503
+ if (!overlap) {
504
+ resync();
505
+ return;
506
+ }
507
+ prevSequence = snapshotId;
508
+ } else if (isSpot) {
509
+ prevSequence = ev.U - 1;
510
+ } else {
511
+ if (ev.pu === void 0) {
512
+ resync();
513
+ return;
514
+ }
515
+ prevSequence = ev.pu;
516
+ }
517
+ const r = merger.apply({
518
+ kind: "delta",
519
+ bids,
520
+ asks,
521
+ sequence: ev.u,
522
+ prevSequence,
523
+ timestamp: ev.E
524
+ });
525
+ if (r.ok) {
526
+ lastU = ev.u;
527
+ emit(r);
528
+ } else if (r.reason === "gap" || r.reason === "no-snapshot") {
529
+ resync();
530
+ }
531
+ };
532
+ const onMessage = (raw) => {
533
+ if (typeof raw !== "string") return;
534
+ let msg;
535
+ try {
536
+ msg = JSON.parse(raw);
537
+ } catch {
538
+ return;
539
+ }
540
+ if (msg.e !== "depthUpdate") return;
541
+ if (!snapshotDone) {
542
+ buffered.push(msg);
543
+ if (!snapshotInFlight) triggerSnapshot();
544
+ return;
545
+ }
546
+ processDelta(msg);
547
+ };
548
+ ws = new WSClient({
549
+ url: wsUrl,
550
+ onOpen: () => {
551
+ merger.reset();
552
+ snapshotId = -1;
553
+ snapshotDone = false;
554
+ lastU = -1;
555
+ buffered = [];
556
+ },
557
+ onMessage
558
+ // Binance server-initiated WS-level ping; auto-handled by the WS impl.
559
+ });
560
+ ws.on("open", () => stream.emit("connected"));
561
+ ws.on("close", (r) => stream.emit("disconnected", r));
562
+ ws.on("reconnecting", (a, w) => stream.emit("reconnecting", a, w));
563
+ ws.on("error", (e) => stream.emit("error", e));
564
+ ws.connect().catch((e) => stream.emit("error", e));
565
+ return stream;
566
+ }
567
+
568
+ // src/exchanges/binance/index.ts
569
+ var BinanceClient = class {
570
+ exchange = "binance";
571
+ transformUrl;
572
+ timeoutMs;
573
+ constructor(opts = {}) {
574
+ this.transformUrl = opts.transformUrl;
575
+ this.timeoutMs = opts.timeoutMs;
576
+ }
577
+ fetchOrderbook(symbol, opts = {}) {
578
+ const { pair, market } = parseSymbol(symbol);
579
+ return fetchBinanceOrderbook({
580
+ symbol: pair,
581
+ market,
582
+ depth: opts.depth,
583
+ timeoutMs: this.timeoutMs,
584
+ transformUrl: this.transformUrl
585
+ });
586
+ }
587
+ streamOrderbook(symbol, opts = {}) {
588
+ const { pair, market } = parseSymbol(symbol);
589
+ return streamBinanceOrderbook({
590
+ symbol: pair,
591
+ market,
592
+ depth: opts.depth,
593
+ transformUrl: this.transformUrl,
594
+ timeoutMs: this.timeoutMs
595
+ });
596
+ }
597
+ };
598
+
599
+ export { BinanceClient, fetchBinanceOrderbook, streamBinanceOrderbook };
600
+ //# sourceMappingURL=index.js.map
601
+ //# sourceMappingURL=index.js.map