@xapy/orderbook 0.1.0

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