@xapy/orderbook 0.1.28 → 0.1.30

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 (48) hide show
  1. package/README.md +4 -0
  2. package/dist/exchanges/aster/index.cjs +610 -0
  3. package/dist/exchanges/aster/index.cjs.map +1 -0
  4. package/dist/exchanges/aster/index.d.cts +65 -0
  5. package/dist/exchanges/aster/index.d.ts +65 -0
  6. package/dist/exchanges/aster/index.js +602 -0
  7. package/dist/exchanges/aster/index.js.map +1 -0
  8. package/dist/exchanges/binance/index.d.cts +1 -1
  9. package/dist/exchanges/binance/index.d.ts +1 -1
  10. package/dist/exchanges/bingx/index.d.cts +1 -1
  11. package/dist/exchanges/bingx/index.d.ts +1 -1
  12. package/dist/exchanges/bitget/index.d.cts +1 -1
  13. package/dist/exchanges/bitget/index.d.ts +1 -1
  14. package/dist/exchanges/bybit/index.d.cts +1 -1
  15. package/dist/exchanges/bybit/index.d.ts +1 -1
  16. package/dist/exchanges/coinex/index.d.cts +1 -1
  17. package/dist/exchanges/coinex/index.d.ts +1 -1
  18. package/dist/exchanges/deribit/index.d.cts +1 -1
  19. package/dist/exchanges/deribit/index.d.ts +1 -1
  20. package/dist/exchanges/edgex/index.d.cts +1 -1
  21. package/dist/exchanges/edgex/index.d.ts +1 -1
  22. package/dist/exchanges/gate/index.d.cts +1 -1
  23. package/dist/exchanges/gate/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.d.cts +1 -1
  29. package/dist/exchanges/lighter/index.d.ts +1 -1
  30. package/dist/exchanges/mexc/index.cjs +729 -0
  31. package/dist/exchanges/mexc/index.cjs.map +1 -0
  32. package/dist/exchanges/mexc/index.d.cts +57 -0
  33. package/dist/exchanges/mexc/index.d.ts +57 -0
  34. package/dist/exchanges/mexc/index.js +721 -0
  35. package/dist/exchanges/mexc/index.js.map +1 -0
  36. package/dist/exchanges/okx/index.d.cts +1 -1
  37. package/dist/exchanges/okx/index.d.ts +1 -1
  38. package/dist/exchanges/whitebit/index.d.cts +1 -1
  39. package/dist/exchanges/whitebit/index.d.ts +1 -1
  40. package/dist/index.cjs +544 -0
  41. package/dist/index.cjs.map +1 -1
  42. package/dist/index.d.cts +4 -2
  43. package/dist/index.d.ts +4 -2
  44. package/dist/index.js +543 -1
  45. package/dist/index.js.map +1 -1
  46. package/dist/{stream-D8ErAue9.d.cts → stream-Dyq24thx.d.cts} +1 -1
  47. package/dist/{stream-D8ErAue9.d.ts → stream-Dyq24thx.d.ts} +1 -1
  48. package/package.json +23 -1
package/dist/index.cjs CHANGED
@@ -3437,6 +3437,549 @@ var WhitebitClient = class {
3437
3437
  }
3438
3438
  };
3439
3439
 
3440
+ // src/exchanges/aster/symbols.ts
3441
+ var QUOTES5 = ["USDT", "USD1", "FORM", "USDC", "BTC", "ETH", "U"];
3442
+ function toAsterSymbol(symbol) {
3443
+ const [base, quote] = symbol.split("/");
3444
+ if (!base || !quote) {
3445
+ throw new Error(`invalid symbol "${symbol}" \u2014 expected "BASE/QUOTE"`);
3446
+ }
3447
+ return `${base}${quote}`.toUpperCase();
3448
+ }
3449
+ function fromAsterSymbol(s) {
3450
+ const upper = s.toUpperCase();
3451
+ for (const q of QUOTES5) {
3452
+ if (upper.endsWith(q) && upper.length > q.length) {
3453
+ return `${upper.slice(0, -q.length)}/${q}`;
3454
+ }
3455
+ }
3456
+ return upper;
3457
+ }
3458
+
3459
+ // src/exchanges/aster/rest.ts
3460
+ var ASTER_SPOT_REST = "https://sapi.asterdex.com";
3461
+ var ASTER_FUTURES_REST = "https://fapi.asterdex.com";
3462
+ async function fetchAsterOrderbook(opts) {
3463
+ const symbol = toAsterSymbol(opts.symbol);
3464
+ const limit = opts.depth ?? 1e3;
3465
+ const url = opts.market === "spot" ? `${ASTER_SPOT_REST}/api/v3/depth?symbol=${symbol}&limit=${limit}` : `${ASTER_FUTURES_REST}/fapi/v1/depth?symbol=${symbol}&limit=${limit}`;
3466
+ const data = await httpJson({
3467
+ url,
3468
+ timeoutMs: opts.timeoutMs,
3469
+ transformUrl: opts.transformUrl
3470
+ });
3471
+ return {
3472
+ exchange: "aster",
3473
+ symbol: fromAsterSymbol(data.symbol ?? symbol),
3474
+ market: opts.market,
3475
+ bids: data.bids.map(([p, s]) => ({ price: Number(p), size: Number(s) })),
3476
+ asks: data.asks.map(([p, s]) => ({ price: Number(p), size: Number(s) })),
3477
+ timestamp: data.E ?? data.T ?? Date.now(),
3478
+ sequence: data.lastUpdateId
3479
+ };
3480
+ }
3481
+
3482
+ // src/exchanges/aster/ws.ts
3483
+ var WS_SPOT6 = "wss://sstream.asterdex.com/ws";
3484
+ var WS_FUTURES4 = "wss://fstream.asterdex.com/ws";
3485
+ function streamAsterOrderbook(opts) {
3486
+ const symbol = toAsterSymbol(opts.symbol);
3487
+ const isSpot = opts.market === "spot";
3488
+ const wsBase = isSpot ? WS_SPOT6 : WS_FUTURES4;
3489
+ const wsUrl = `${wsBase}/${symbol.toLowerCase()}@depth@${opts.interval ?? "100ms"}`;
3490
+ const merger = new BookMerger();
3491
+ let snapshotId = -1;
3492
+ let lastU = -1;
3493
+ let snapshotInFlight = false;
3494
+ let snapshotDone = false;
3495
+ let buffered = [];
3496
+ let recovering = false;
3497
+ let ws = null;
3498
+ const stream = new OrderbookStream(() => ws?.close());
3499
+ const emit = (r) => {
3500
+ const book = {
3501
+ exchange: "aster",
3502
+ symbol: fromAsterSymbol(symbol),
3503
+ market: opts.market,
3504
+ bids: r.bids,
3505
+ asks: r.asks,
3506
+ timestamp: r.timestamp,
3507
+ sequence: r.sequence
3508
+ };
3509
+ stream.emit("update", book);
3510
+ };
3511
+ const triggerSnapshot = () => {
3512
+ if (snapshotInFlight) return;
3513
+ snapshotInFlight = true;
3514
+ fetchAsterOrderbook({
3515
+ symbol: opts.symbol,
3516
+ market: opts.market,
3517
+ depth: opts.depth ?? 1e3,
3518
+ timeoutMs: opts.timeoutMs,
3519
+ transformUrl: opts.transformUrl
3520
+ }).then((snap) => {
3521
+ snapshotId = snap.sequence;
3522
+ const r = merger.apply({
3523
+ kind: "snapshot",
3524
+ bids: snap.bids,
3525
+ asks: snap.asks,
3526
+ sequence: snap.sequence,
3527
+ timestamp: snap.timestamp
3528
+ });
3529
+ if (r.ok) emit(r);
3530
+ snapshotDone = true;
3531
+ lastU = -1;
3532
+ const pending2 = buffered;
3533
+ buffered = [];
3534
+ for (const ev of pending2) processDelta(ev);
3535
+ }).catch((err) => stream.emit("error", err)).finally(() => {
3536
+ snapshotInFlight = false;
3537
+ });
3538
+ };
3539
+ const resync = () => {
3540
+ if (recovering) return;
3541
+ recovering = true;
3542
+ merger.reset();
3543
+ snapshotId = -1;
3544
+ snapshotDone = false;
3545
+ lastU = -1;
3546
+ buffered = [];
3547
+ setTimeout(() => {
3548
+ recovering = false;
3549
+ triggerSnapshot();
3550
+ }, 100);
3551
+ };
3552
+ const processDelta = (ev) => {
3553
+ if (ev.u < snapshotId) return;
3554
+ const bids = ev.b.map(([p, s]) => ({
3555
+ price: Number(p),
3556
+ size: Number(s)
3557
+ }));
3558
+ const asks = ev.a.map(([p, s]) => ({
3559
+ price: Number(p),
3560
+ size: Number(s)
3561
+ }));
3562
+ let prevSequence;
3563
+ if (lastU < 0) {
3564
+ if (ev.U > snapshotId) {
3565
+ resync();
3566
+ return;
3567
+ }
3568
+ prevSequence = snapshotId;
3569
+ } else {
3570
+ if (ev.pu === void 0) {
3571
+ resync();
3572
+ return;
3573
+ }
3574
+ prevSequence = ev.pu;
3575
+ }
3576
+ const r = merger.apply({
3577
+ kind: "delta",
3578
+ bids,
3579
+ asks,
3580
+ sequence: ev.u,
3581
+ prevSequence,
3582
+ timestamp: ev.E
3583
+ });
3584
+ if (r.ok) {
3585
+ lastU = ev.u;
3586
+ emit(r);
3587
+ } else if (r.reason === "gap" || r.reason === "no-snapshot") {
3588
+ resync();
3589
+ }
3590
+ };
3591
+ const onMessage = (raw) => {
3592
+ if (typeof raw !== "string") return;
3593
+ let msg;
3594
+ try {
3595
+ msg = JSON.parse(raw);
3596
+ } catch {
3597
+ return;
3598
+ }
3599
+ if (msg.e !== "depthUpdate") return;
3600
+ if (!snapshotDone) {
3601
+ buffered.push(msg);
3602
+ if (!snapshotInFlight) triggerSnapshot();
3603
+ return;
3604
+ }
3605
+ processDelta(msg);
3606
+ };
3607
+ ws = new WSClient({
3608
+ url: wsUrl,
3609
+ onOpen: () => {
3610
+ merger.reset();
3611
+ snapshotId = -1;
3612
+ snapshotDone = false;
3613
+ lastU = -1;
3614
+ buffered = [];
3615
+ },
3616
+ onMessage
3617
+ // Server-initiated WS-level ping; auto-handled by the WS impl.
3618
+ });
3619
+ ws.on("open", () => stream.emit("connected"));
3620
+ ws.on("close", (r) => stream.emit("disconnected", r));
3621
+ ws.on("reconnecting", (a, w) => stream.emit("reconnecting", a, w));
3622
+ ws.on("error", (e) => stream.emit("error", e));
3623
+ ws.connect().catch((e) => stream.emit("error", e));
3624
+ return stream;
3625
+ }
3626
+
3627
+ // src/exchanges/aster/index.ts
3628
+ var AsterClient = class {
3629
+ exchange = "aster";
3630
+ transformUrl;
3631
+ timeoutMs;
3632
+ constructor(opts = {}) {
3633
+ this.transformUrl = opts.transformUrl;
3634
+ this.timeoutMs = opts.timeoutMs;
3635
+ }
3636
+ fetchOrderbook(symbol, opts = {}) {
3637
+ const { pair, market } = parseSymbol(symbol);
3638
+ return fetchAsterOrderbook({
3639
+ symbol: pair,
3640
+ market,
3641
+ depth: opts.depth,
3642
+ timeoutMs: this.timeoutMs,
3643
+ transformUrl: this.transformUrl
3644
+ });
3645
+ }
3646
+ streamOrderbook(symbol, opts = {}) {
3647
+ const { pair, market } = parseSymbol(symbol);
3648
+ return streamAsterOrderbook({
3649
+ symbol: pair,
3650
+ market,
3651
+ depth: opts.depth,
3652
+ transformUrl: this.transformUrl,
3653
+ timeoutMs: this.timeoutMs
3654
+ });
3655
+ }
3656
+ };
3657
+
3658
+ // src/exchanges/mexc/contracts.ts
3659
+ var MEXC_SPOT_REST = "https://api.mexc.com";
3660
+ var MEXC_FUTURES_REST = "https://contract.mexc.com";
3661
+ var cache2 = null;
3662
+ var inflight2 = null;
3663
+ async function fetchContracts2(opts) {
3664
+ const res = await httpJson({
3665
+ url: `${MEXC_FUTURES_REST}/api/v1/contract/detail`,
3666
+ timeoutMs: opts.timeoutMs,
3667
+ transformUrl: opts.transformUrl
3668
+ });
3669
+ const rows = res.data ?? [];
3670
+ if (rows.length === 0) {
3671
+ throw new ExchangeError(
3672
+ "mexc",
3673
+ res.message ? `${res.code}: ${res.message}` : "empty contract/detail response"
3674
+ );
3675
+ }
3676
+ const map = /* @__PURE__ */ new Map();
3677
+ for (const row of rows) map.set(row.symbol.toUpperCase(), row);
3678
+ return map;
3679
+ }
3680
+ function loadContracts2(opts) {
3681
+ inflight2 ??= fetchContracts2(opts).then(
3682
+ (m) => {
3683
+ cache2 = m;
3684
+ inflight2 = null;
3685
+ return m;
3686
+ },
3687
+ (err) => {
3688
+ inflight2 = null;
3689
+ throw err;
3690
+ }
3691
+ );
3692
+ return inflight2;
3693
+ }
3694
+ async function resolveContractSize(symbol, opts) {
3695
+ const k = symbol.toUpperCase();
3696
+ const hit = cache2?.get(k);
3697
+ const contract = hit ?? (await loadContracts2(opts)).get(k);
3698
+ if (!contract) {
3699
+ throw new ExchangeError(
3700
+ "mexc",
3701
+ `unknown futures contract "${symbol}" \u2014 not listed on mexc`
3702
+ );
3703
+ }
3704
+ const size = Number(contract.contractSize);
3705
+ if (!Number.isFinite(size) || size <= 0) {
3706
+ throw new ExchangeError(
3707
+ "mexc",
3708
+ `contract "${symbol}" has no usable contractSize (${contract.contractSize})`
3709
+ );
3710
+ }
3711
+ return size;
3712
+ }
3713
+
3714
+ // src/exchanges/mexc/symbols.ts
3715
+ var QUOTES6 = ["USDT", "USDC", "TUSD", "USD", "BTC", "ETH"];
3716
+ function toMexcSymbol(symbol, market) {
3717
+ const [base, quote] = symbol.split("/");
3718
+ if (!base || !quote) {
3719
+ throw new Error(`invalid symbol "${symbol}" \u2014 expected "BASE/QUOTE"`);
3720
+ }
3721
+ return market === "perpetual" ? `${base.toUpperCase()}_${quote.toUpperCase()}` : `${base}${quote}`.toUpperCase();
3722
+ }
3723
+ function fromMexcSymbol(s, market) {
3724
+ const upper = s.toUpperCase();
3725
+ if (market === "perpetual") {
3726
+ const [base, quote] = upper.split("_");
3727
+ return base && quote ? `${base}/${quote}` : upper;
3728
+ }
3729
+ for (const q of QUOTES6) {
3730
+ if (upper.endsWith(q) && upper.length > q.length) {
3731
+ return `${upper.slice(0, -q.length)}/${q}`;
3732
+ }
3733
+ }
3734
+ return upper;
3735
+ }
3736
+
3737
+ // src/exchanges/mexc/rest.ts
3738
+ var toSpotLevels = (rows) => (rows ?? []).map(([p, s]) => ({ price: Number(p), size: Number(s) }));
3739
+ var toFuturesLevels = (rows, contractSize) => (rows ?? []).map(([price, vol]) => ({
3740
+ price: Number(price),
3741
+ size: Number(vol) * contractSize
3742
+ }));
3743
+ async function fetchMexcOrderbook(opts) {
3744
+ const symbol = toMexcSymbol(opts.symbol, opts.market);
3745
+ const depth = opts.depth ?? 50;
3746
+ if (opts.market === "spot") {
3747
+ const data = await httpJson({
3748
+ url: `${MEXC_SPOT_REST}/api/v3/depth?symbol=${symbol}&limit=${depth}`,
3749
+ timeoutMs: opts.timeoutMs,
3750
+ transformUrl: opts.transformUrl
3751
+ });
3752
+ return {
3753
+ exchange: "mexc",
3754
+ symbol: fromMexcSymbol(symbol, opts.market),
3755
+ market: opts.market,
3756
+ bids: toSpotLevels(data.bids),
3757
+ asks: toSpotLevels(data.asks),
3758
+ // The spot depth endpoint returns no timestamp of its own.
3759
+ timestamp: Date.now(),
3760
+ sequence: data.lastUpdateId
3761
+ };
3762
+ }
3763
+ const contractSize = await resolveContractSize(symbol, opts);
3764
+ const res = await httpJson({
3765
+ url: `${MEXC_FUTURES_REST}/api/v1/contract/depth/${symbol}?limit=${depth}`,
3766
+ timeoutMs: opts.timeoutMs,
3767
+ transformUrl: opts.transformUrl
3768
+ });
3769
+ if (!res.data) {
3770
+ throw new ExchangeError(
3771
+ "mexc",
3772
+ res.message ? `${res.code}: ${res.message}` : "empty orderbook response"
3773
+ );
3774
+ }
3775
+ return {
3776
+ exchange: "mexc",
3777
+ symbol: fromMexcSymbol(symbol, opts.market),
3778
+ market: opts.market,
3779
+ bids: toFuturesLevels(res.data.bids, contractSize),
3780
+ asks: toFuturesLevels(res.data.asks, contractSize),
3781
+ timestamp: res.data.timestamp ?? Date.now(),
3782
+ sequence: Number(res.data.version ?? 0)
3783
+ };
3784
+ }
3785
+
3786
+ // src/exchanges/mexc/ws.ts
3787
+ var WS_FUTURES5 = "wss://contract.mexc.com/edge";
3788
+ var PING_INTERVAL_MS3 = 2e4;
3789
+ function streamMexcOrderbook(opts) {
3790
+ if (opts.market !== "perpetual") {
3791
+ throw new Error(
3792
+ `mexc spot streaming requires the protobuf WS feed, which this adapter does not decode \u2014 use fetchOrderbook("${opts.symbol}") for a REST snapshot, or stream the perpetual ("${opts.symbol}:${opts.symbol.split("/")[1]}")`
3793
+ );
3794
+ }
3795
+ const symbol = toMexcSymbol(opts.symbol, opts.market);
3796
+ const unified = fromMexcSymbol(symbol, opts.market);
3797
+ const contractSize = resolveContractSize(symbol, opts);
3798
+ contractSize.catch(() => {
3799
+ });
3800
+ const merger = new BookMerger();
3801
+ let seedVersion = -1;
3802
+ let lastVersion = -1;
3803
+ let snapshotInFlight = false;
3804
+ let snapshotDone = false;
3805
+ let buffered = [];
3806
+ let recovering = false;
3807
+ let scale = 0;
3808
+ let ws = null;
3809
+ const stream = new OrderbookStream(() => ws?.close());
3810
+ const emit = (r) => {
3811
+ const book = {
3812
+ exchange: "mexc",
3813
+ symbol: unified,
3814
+ market: opts.market,
3815
+ bids: r.bids,
3816
+ asks: r.asks,
3817
+ timestamp: r.timestamp,
3818
+ sequence: r.sequence
3819
+ };
3820
+ stream.emit("update", book);
3821
+ };
3822
+ const triggerSnapshot = () => {
3823
+ if (snapshotInFlight) return;
3824
+ snapshotInFlight = true;
3825
+ contractSize.then(async (size) => {
3826
+ scale = size;
3827
+ return fetchMexcOrderbook({
3828
+ symbol: opts.symbol,
3829
+ market: opts.market,
3830
+ depth: opts.depth ?? 200,
3831
+ timeoutMs: opts.timeoutMs,
3832
+ transformUrl: opts.transformUrl
3833
+ });
3834
+ }).then((snap) => {
3835
+ seedVersion = snap.sequence;
3836
+ const r = merger.apply({
3837
+ kind: "snapshot",
3838
+ bids: snap.bids,
3839
+ asks: snap.asks,
3840
+ sequence: snap.sequence,
3841
+ timestamp: snap.timestamp
3842
+ });
3843
+ if (r.ok) emit(r);
3844
+ snapshotDone = true;
3845
+ lastVersion = -1;
3846
+ const pending2 = buffered;
3847
+ buffered = [];
3848
+ for (const d of pending2) processDelta(d);
3849
+ }).catch((err) => stream.emit("error", err)).finally(() => {
3850
+ snapshotInFlight = false;
3851
+ });
3852
+ };
3853
+ const resync = () => {
3854
+ if (recovering) return;
3855
+ recovering = true;
3856
+ merger.reset();
3857
+ seedVersion = -1;
3858
+ snapshotDone = false;
3859
+ lastVersion = -1;
3860
+ buffered = [];
3861
+ setTimeout(() => {
3862
+ recovering = false;
3863
+ triggerSnapshot();
3864
+ }, 100);
3865
+ };
3866
+ const processDelta = (d) => {
3867
+ const end = Number(d.end ?? d.version ?? 0);
3868
+ const begin = Number(d.begin ?? end);
3869
+ if (end <= seedVersion) return;
3870
+ let prevSequence;
3871
+ if (lastVersion < 0) {
3872
+ if (begin - 1 > seedVersion) {
3873
+ resync();
3874
+ return;
3875
+ }
3876
+ prevSequence = seedVersion;
3877
+ } else {
3878
+ prevSequence = begin - 1;
3879
+ }
3880
+ const r = merger.apply({
3881
+ kind: "delta",
3882
+ bids: toFuturesLevels(d.bids, scale),
3883
+ asks: toFuturesLevels(d.asks, scale),
3884
+ sequence: end,
3885
+ prevSequence,
3886
+ timestamp: d.timestamp ?? d.cts ?? Date.now()
3887
+ });
3888
+ if (r.ok) {
3889
+ lastVersion = end;
3890
+ emit(r);
3891
+ } else if (r.reason === "gap" || r.reason === "no-snapshot") {
3892
+ resync();
3893
+ }
3894
+ };
3895
+ const onMessage = (raw) => {
3896
+ if (typeof raw !== "string") return;
3897
+ let msg;
3898
+ try {
3899
+ msg = JSON.parse(raw);
3900
+ } catch {
3901
+ return;
3902
+ }
3903
+ if (msg.channel === "push.depth") {
3904
+ if (msg.symbol && msg.symbol !== symbol) return;
3905
+ const d = msg.data;
3906
+ if (!d) return;
3907
+ if (!snapshotDone) {
3908
+ buffered.push(d);
3909
+ if (!snapshotInFlight) triggerSnapshot();
3910
+ return;
3911
+ }
3912
+ processDelta(d);
3913
+ return;
3914
+ }
3915
+ if (msg.channel === "rs.error" || msg.channel?.startsWith("rs.error")) {
3916
+ stream.emit("error", new ExchangeError("mexc", String(msg.data)));
3917
+ return;
3918
+ }
3919
+ if (msg.channel === "rs.sub.depth" && msg.data !== "success") {
3920
+ stream.emit(
3921
+ "error",
3922
+ new ExchangeError("mexc", `subscribe rejected: ${String(msg.data)}`)
3923
+ );
3924
+ }
3925
+ };
3926
+ ws = new WSClient({
3927
+ url: WS_FUTURES5,
3928
+ onOpen: (handle) => {
3929
+ merger.reset();
3930
+ seedVersion = -1;
3931
+ snapshotDone = false;
3932
+ lastVersion = -1;
3933
+ buffered = [];
3934
+ handle.send(
3935
+ JSON.stringify({ method: "sub.depth", param: { symbol } })
3936
+ );
3937
+ },
3938
+ onMessage,
3939
+ pingIntervalMs: PING_INTERVAL_MS3,
3940
+ pingPayload: () => JSON.stringify({ method: "ping" })
3941
+ });
3942
+ ws.on("open", () => stream.emit("connected"));
3943
+ ws.on("close", (r) => stream.emit("disconnected", r));
3944
+ ws.on("reconnecting", (a, w) => stream.emit("reconnecting", a, w));
3945
+ ws.on("error", (e) => stream.emit("error", e));
3946
+ ws.connect().catch((e) => stream.emit("error", e));
3947
+ return stream;
3948
+ }
3949
+
3950
+ // src/exchanges/mexc/index.ts
3951
+ var MexcClient = class {
3952
+ exchange = "mexc";
3953
+ transformUrl;
3954
+ timeoutMs;
3955
+ constructor(opts = {}) {
3956
+ this.transformUrl = opts.transformUrl;
3957
+ this.timeoutMs = opts.timeoutMs;
3958
+ }
3959
+ fetchOrderbook(symbol, opts = {}) {
3960
+ const { pair, market } = parseSymbol(symbol);
3961
+ return fetchMexcOrderbook({
3962
+ symbol: pair,
3963
+ market,
3964
+ depth: opts.depth,
3965
+ timeoutMs: this.timeoutMs,
3966
+ transformUrl: this.transformUrl
3967
+ });
3968
+ }
3969
+ /** Perpetuals only — see the class note on spot. */
3970
+ streamOrderbook(symbol, opts = {}) {
3971
+ const { pair, market } = parseSymbol(symbol);
3972
+ return streamMexcOrderbook({
3973
+ symbol: pair,
3974
+ market,
3975
+ depth: opts.depth,
3976
+ transformUrl: this.transformUrl,
3977
+ timeoutMs: this.timeoutMs
3978
+ });
3979
+ }
3980
+ };
3981
+
3982
+ exports.AsterClient = AsterClient;
3440
3983
  exports.Backoff = Backoff;
3441
3984
  exports.BinanceClient = BinanceClient;
3442
3985
  exports.BingxClient = BingxClient;
@@ -3451,6 +3994,7 @@ exports.GateClient = GateClient;
3451
3994
  exports.HyperliquidClient = HyperliquidClient;
3452
3995
  exports.KucoinClient = KucoinClient;
3453
3996
  exports.LighterClient = LighterClient;
3997
+ exports.MexcClient = MexcClient;
3454
3998
  exports.OkxClient = OkxClient;
3455
3999
  exports.OrderbookStream = OrderbookStream;
3456
4000
  exports.RateLimitError = RateLimitError;