@0xarchive/sdk 0.2.0 → 0.2.2

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 CHANGED
@@ -77,19 +77,6 @@ const trades = await client.trades.list('ETH', {
77
77
  });
78
78
  ```
79
79
 
80
- ### Candles (OHLCV)
81
-
82
- ```typescript
83
- // Get hourly candles
84
- const candles = await client.candles.list('BTC', {
85
- interval: '1h',
86
- start: Date.now() - 86400000,
87
- end: Date.now()
88
- });
89
-
90
- // Available intervals: '1m', '5m', '15m', '1h', '4h', '1d'
91
- ```
92
-
93
80
  ### Instruments
94
81
 
95
82
  ```typescript
@@ -183,8 +170,8 @@ ws.onHistoricalData((coin, timestamp, data) => {
183
170
  console.log(`${new Date(timestamp)}: ${data.mid_price}`);
184
171
  });
185
172
 
186
- ws.onReplayStart((channel, coin, totalRecords, speed) => {
187
- console.log(`Starting replay of ${totalRecords} records at ${speed}x`);
173
+ ws.onReplayStart((channel, coin, start, end, speed) => {
174
+ console.log(`Starting replay from ${start} to ${end} at ${speed}x`);
188
175
  });
189
176
 
190
177
  ws.onReplayComplete((channel, coin, recordsSent) => {
@@ -219,8 +206,8 @@ ws.onBatch((coin, records) => {
219
206
  allData.push(...records.map(r => r.data));
220
207
  });
221
208
 
222
- ws.onStreamProgress((sent, total, pct) => {
223
- console.log(`Progress: ${pct.toFixed(1)}%`);
209
+ ws.onStreamProgress((snapshotsSent) => {
210
+ console.log(`Sent: ${snapshotsSent} snapshots`);
224
211
  });
225
212
 
226
213
  ws.onStreamComplete((channel, coin, recordsSent) => {
@@ -284,7 +271,6 @@ Full TypeScript support with exported types:
284
271
  import type {
285
272
  OrderBook,
286
273
  Trade,
287
- Candle,
288
274
  Instrument,
289
275
  FundingRate,
290
276
  OpenInterest
package/dist/index.d.mts CHANGED
@@ -41,10 +41,10 @@ interface PaginationParams {
41
41
  * Time range parameters for historical queries
42
42
  */
43
43
  interface TimeRangeParams extends PaginationParams {
44
- /** Start timestamp (Unix ms or ISO string) */
45
- start?: number | string;
46
- /** End timestamp (Unix ms or ISO string) */
47
- end?: number | string;
44
+ /** Start timestamp (Unix ms or ISO string) - REQUIRED for history endpoints */
45
+ start: number | string;
46
+ /** End timestamp (Unix ms or ISO string) - REQUIRED for history endpoints */
47
+ end: number | string;
48
48
  }
49
49
  /**
50
50
  * A price level in the order book
@@ -142,15 +142,15 @@ interface Instrument {
142
142
  /** Instrument symbol (e.g., BTC) */
143
143
  name: string;
144
144
  /** Size decimal precision */
145
- sz_decimals: number;
145
+ szDecimals: number;
146
146
  /** Maximum leverage allowed */
147
- max_leverage?: number;
147
+ maxLeverage?: number;
148
148
  /** If true, only isolated margin mode is allowed */
149
- only_isolated?: boolean;
149
+ onlyIsolated?: boolean;
150
150
  /** Type of instrument */
151
- instrument_type?: InstrumentType;
151
+ instrumentType?: InstrumentType;
152
152
  /** Whether the instrument is currently tradeable */
153
- is_active: boolean;
153
+ isActive: boolean;
154
154
  }
155
155
  /**
156
156
  * Funding rate record
@@ -467,10 +467,10 @@ declare class OrderBookResource {
467
467
  * Get historical order book snapshots
468
468
  *
469
469
  * @param coin - The coin symbol (e.g., 'BTC', 'ETH')
470
- * @param params - Time range and pagination parameters
470
+ * @param params - Time range and pagination parameters (start is required)
471
471
  * @returns Array of order book snapshots
472
472
  */
473
- history(coin: string, params?: OrderBookHistoryParams): Promise<OrderBook[]>;
473
+ history(coin: string, params: OrderBookHistoryParams): Promise<OrderBook[]>;
474
474
  }
475
475
 
476
476
  /**
@@ -496,10 +496,10 @@ declare class TradesResource {
496
496
  * Get trade history for a coin
497
497
  *
498
498
  * @param coin - The coin symbol (e.g., 'BTC', 'ETH')
499
- * @param params - Time range and pagination parameters
499
+ * @param params - Time range and pagination parameters (start is required)
500
500
  * @returns Array of trades
501
501
  */
502
- list(coin: string, params?: GetTradesParams): Promise<Trade[]>;
502
+ list(coin: string, params: GetTradesParams): Promise<Trade[]>;
503
503
  /**
504
504
  * Get most recent trades for a coin
505
505
  *
@@ -562,10 +562,10 @@ declare class FundingResource {
562
562
  * Get funding rate history for a coin
563
563
  *
564
564
  * @param coin - The coin symbol (e.g., 'BTC', 'ETH')
565
- * @param params - Time range and pagination parameters
565
+ * @param params - Time range and pagination parameters (start is required)
566
566
  * @returns Array of funding rate records
567
567
  */
568
- history(coin: string, params?: TimeRangeParams): Promise<FundingRate[]>;
568
+ history(coin: string, params: TimeRangeParams): Promise<FundingRate[]>;
569
569
  /**
570
570
  * Get current funding rate for a coin
571
571
  *
@@ -598,10 +598,10 @@ declare class OpenInterestResource {
598
598
  * Get open interest history for a coin
599
599
  *
600
600
  * @param coin - The coin symbol (e.g., 'BTC', 'ETH')
601
- * @param params - Time range and pagination parameters
601
+ * @param params - Time range and pagination parameters (start is required)
602
602
  * @returns Array of open interest records
603
603
  */
604
- history(coin: string, params?: TimeRangeParams): Promise<OpenInterest[]>;
604
+ history(coin: string, params: TimeRangeParams): Promise<OpenInterest[]>;
605
605
  /**
606
606
  * Get current open interest for a coin
607
607
  *
@@ -727,6 +727,15 @@ declare class OxArchiveWs {
727
727
  private reconnectAttempts;
728
728
  private pingTimer;
729
729
  private reconnectTimer;
730
+ private historicalDataHandlers;
731
+ private batchHandlers;
732
+ private replayStartHandlers;
733
+ private replayCompleteHandlers;
734
+ private streamStartHandlers;
735
+ private streamProgressHandlers;
736
+ private streamCompleteHandlers;
737
+ private orderbookHandlers;
738
+ private tradesHandlers;
730
739
  constructor(options: WsOptions);
731
740
  /**
732
741
  * Connect to the WebSocket server
@@ -897,6 +906,7 @@ declare class OxArchiveWs {
897
906
  private resubscribe;
898
907
  private scheduleReconnect;
899
908
  private clearReconnectTimer;
909
+ private handleMessage;
900
910
  }
901
911
 
902
912
  export { type ApiError, type ApiMeta, type ApiResponse, type ClientOptions, type DataSource, type FundingRate, type GetOrderBookParams, type GetTradesParams, type Instrument, type InstrumentType, type OpenInterest, type OrderBook, type OrderBookHistoryParams, OxArchive, OxArchiveError, OxArchiveWs, type PaginationParams, type PriceLevel, type TimeRangeParams, type Timestamp, type TimestampedRecord, type Trade, type TradeDirection, type TradeSide, type WsChannel, type WsClientMessage, type WsConnectionState, type WsData, type WsError, type WsEventHandlers, type WsHistoricalBatch, type WsHistoricalData, type WsOptions, type WsPing, type WsPong, type WsReplay, type WsReplayCompleted, type WsReplayPause, type WsReplayPaused, type WsReplayResume, type WsReplayResumed, type WsReplaySeek, type WsReplayStarted, type WsReplayStop, type WsReplayStopped, type WsServerMessage, type WsStream, type WsStreamCompleted, type WsStreamProgress, type WsStreamStarted, type WsStreamStop, type WsStreamStopped, type WsSubscribe, type WsSubscribed, type WsUnsubscribe, type WsUnsubscribed, OxArchive as default };
package/dist/index.d.ts CHANGED
@@ -41,10 +41,10 @@ interface PaginationParams {
41
41
  * Time range parameters for historical queries
42
42
  */
43
43
  interface TimeRangeParams extends PaginationParams {
44
- /** Start timestamp (Unix ms or ISO string) */
45
- start?: number | string;
46
- /** End timestamp (Unix ms or ISO string) */
47
- end?: number | string;
44
+ /** Start timestamp (Unix ms or ISO string) - REQUIRED for history endpoints */
45
+ start: number | string;
46
+ /** End timestamp (Unix ms or ISO string) - REQUIRED for history endpoints */
47
+ end: number | string;
48
48
  }
49
49
  /**
50
50
  * A price level in the order book
@@ -142,15 +142,15 @@ interface Instrument {
142
142
  /** Instrument symbol (e.g., BTC) */
143
143
  name: string;
144
144
  /** Size decimal precision */
145
- sz_decimals: number;
145
+ szDecimals: number;
146
146
  /** Maximum leverage allowed */
147
- max_leverage?: number;
147
+ maxLeverage?: number;
148
148
  /** If true, only isolated margin mode is allowed */
149
- only_isolated?: boolean;
149
+ onlyIsolated?: boolean;
150
150
  /** Type of instrument */
151
- instrument_type?: InstrumentType;
151
+ instrumentType?: InstrumentType;
152
152
  /** Whether the instrument is currently tradeable */
153
- is_active: boolean;
153
+ isActive: boolean;
154
154
  }
155
155
  /**
156
156
  * Funding rate record
@@ -467,10 +467,10 @@ declare class OrderBookResource {
467
467
  * Get historical order book snapshots
468
468
  *
469
469
  * @param coin - The coin symbol (e.g., 'BTC', 'ETH')
470
- * @param params - Time range and pagination parameters
470
+ * @param params - Time range and pagination parameters (start is required)
471
471
  * @returns Array of order book snapshots
472
472
  */
473
- history(coin: string, params?: OrderBookHistoryParams): Promise<OrderBook[]>;
473
+ history(coin: string, params: OrderBookHistoryParams): Promise<OrderBook[]>;
474
474
  }
475
475
 
476
476
  /**
@@ -496,10 +496,10 @@ declare class TradesResource {
496
496
  * Get trade history for a coin
497
497
  *
498
498
  * @param coin - The coin symbol (e.g., 'BTC', 'ETH')
499
- * @param params - Time range and pagination parameters
499
+ * @param params - Time range and pagination parameters (start is required)
500
500
  * @returns Array of trades
501
501
  */
502
- list(coin: string, params?: GetTradesParams): Promise<Trade[]>;
502
+ list(coin: string, params: GetTradesParams): Promise<Trade[]>;
503
503
  /**
504
504
  * Get most recent trades for a coin
505
505
  *
@@ -562,10 +562,10 @@ declare class FundingResource {
562
562
  * Get funding rate history for a coin
563
563
  *
564
564
  * @param coin - The coin symbol (e.g., 'BTC', 'ETH')
565
- * @param params - Time range and pagination parameters
565
+ * @param params - Time range and pagination parameters (start is required)
566
566
  * @returns Array of funding rate records
567
567
  */
568
- history(coin: string, params?: TimeRangeParams): Promise<FundingRate[]>;
568
+ history(coin: string, params: TimeRangeParams): Promise<FundingRate[]>;
569
569
  /**
570
570
  * Get current funding rate for a coin
571
571
  *
@@ -598,10 +598,10 @@ declare class OpenInterestResource {
598
598
  * Get open interest history for a coin
599
599
  *
600
600
  * @param coin - The coin symbol (e.g., 'BTC', 'ETH')
601
- * @param params - Time range and pagination parameters
601
+ * @param params - Time range and pagination parameters (start is required)
602
602
  * @returns Array of open interest records
603
603
  */
604
- history(coin: string, params?: TimeRangeParams): Promise<OpenInterest[]>;
604
+ history(coin: string, params: TimeRangeParams): Promise<OpenInterest[]>;
605
605
  /**
606
606
  * Get current open interest for a coin
607
607
  *
@@ -727,6 +727,15 @@ declare class OxArchiveWs {
727
727
  private reconnectAttempts;
728
728
  private pingTimer;
729
729
  private reconnectTimer;
730
+ private historicalDataHandlers;
731
+ private batchHandlers;
732
+ private replayStartHandlers;
733
+ private replayCompleteHandlers;
734
+ private streamStartHandlers;
735
+ private streamProgressHandlers;
736
+ private streamCompleteHandlers;
737
+ private orderbookHandlers;
738
+ private tradesHandlers;
730
739
  constructor(options: WsOptions);
731
740
  /**
732
741
  * Connect to the WebSocket server
@@ -897,6 +906,7 @@ declare class OxArchiveWs {
897
906
  private resubscribe;
898
907
  private scheduleReconnect;
899
908
  private clearReconnectTimer;
909
+ private handleMessage;
900
910
  }
901
911
 
902
912
  export { type ApiError, type ApiMeta, type ApiResponse, type ClientOptions, type DataSource, type FundingRate, type GetOrderBookParams, type GetTradesParams, type Instrument, type InstrumentType, type OpenInterest, type OrderBook, type OrderBookHistoryParams, OxArchive, OxArchiveError, OxArchiveWs, type PaginationParams, type PriceLevel, type TimeRangeParams, type Timestamp, type TimestampedRecord, type Trade, type TradeDirection, type TradeSide, type WsChannel, type WsClientMessage, type WsConnectionState, type WsData, type WsError, type WsEventHandlers, type WsHistoricalBatch, type WsHistoricalData, type WsOptions, type WsPing, type WsPong, type WsReplay, type WsReplayCompleted, type WsReplayPause, type WsReplayPaused, type WsReplayResume, type WsReplayResumed, type WsReplaySeek, type WsReplayStarted, type WsReplayStop, type WsReplayStopped, type WsServerMessage, type WsStream, type WsStreamCompleted, type WsStreamProgress, type WsStreamStarted, type WsStreamStop, type WsStreamStopped, type WsSubscribe, type WsSubscribed, type WsUnsubscribe, type WsUnsubscribed, OxArchive as default };
package/dist/index.js CHANGED
@@ -122,7 +122,7 @@ var OrderBookResource = class {
122
122
  * Get historical order book snapshots
123
123
  *
124
124
  * @param coin - The coin symbol (e.g., 'BTC', 'ETH')
125
- * @param params - Time range and pagination parameters
125
+ * @param params - Time range and pagination parameters (start is required)
126
126
  * @returns Array of order book snapshots
127
127
  */
128
128
  async history(coin, params) {
@@ -143,7 +143,7 @@ var TradesResource = class {
143
143
  * Get trade history for a coin
144
144
  *
145
145
  * @param coin - The coin symbol (e.g., 'BTC', 'ETH')
146
- * @param params - Time range and pagination parameters
146
+ * @param params - Time range and pagination parameters (start is required)
147
147
  * @returns Array of trades
148
148
  */
149
149
  async list(coin, params) {
@@ -208,7 +208,7 @@ var FundingResource = class {
208
208
  * Get funding rate history for a coin
209
209
  *
210
210
  * @param coin - The coin symbol (e.g., 'BTC', 'ETH')
211
- * @param params - Time range and pagination parameters
211
+ * @param params - Time range and pagination parameters (start is required)
212
212
  * @returns Array of funding rate records
213
213
  */
214
214
  async history(coin, params) {
@@ -241,7 +241,7 @@ var OpenInterestResource = class {
241
241
  * Get open interest history for a coin
242
242
  *
243
243
  * @param coin - The coin symbol (e.g., 'BTC', 'ETH')
244
- * @param params - Time range and pagination parameters
244
+ * @param params - Time range and pagination parameters (start is required)
245
245
  * @returns Array of open interest records
246
246
  */
247
247
  async history(coin, params) {
@@ -317,6 +317,43 @@ var DEFAULT_WS_URL = "wss://api.0xarchive.io/ws";
317
317
  var DEFAULT_PING_INTERVAL = 3e4;
318
318
  var DEFAULT_RECONNECT_DELAY = 1e3;
319
319
  var DEFAULT_MAX_RECONNECT_ATTEMPTS = 10;
320
+ function transformOrderbook(coin, raw) {
321
+ if ("bids" in raw && "asks" in raw) {
322
+ return raw;
323
+ }
324
+ const levels = raw.levels;
325
+ const time = raw.time;
326
+ const bids = [];
327
+ const asks = [];
328
+ if (levels && levels.length >= 2) {
329
+ for (const level of levels[0] || []) {
330
+ bids.push({ px: level.px, sz: level.sz, n: level.n });
331
+ }
332
+ for (const level of levels[1] || []) {
333
+ asks.push({ px: level.px, sz: level.sz, n: level.n });
334
+ }
335
+ }
336
+ let mid_price;
337
+ let spread;
338
+ let spread_bps;
339
+ if (bids.length > 0 && asks.length > 0) {
340
+ const bestBid = parseFloat(bids[0].px);
341
+ const bestAsk = parseFloat(asks[0].px);
342
+ const mid = (bestBid + bestAsk) / 2;
343
+ mid_price = mid.toString();
344
+ spread = (bestAsk - bestBid).toString();
345
+ spread_bps = ((bestAsk - bestBid) / mid * 1e4).toFixed(2);
346
+ }
347
+ return {
348
+ coin,
349
+ timestamp: time ? new Date(time).toISOString() : (/* @__PURE__ */ new Date()).toISOString(),
350
+ bids,
351
+ asks,
352
+ mid_price,
353
+ spread,
354
+ spread_bps
355
+ };
356
+ }
320
357
  var OxArchiveWs = class {
321
358
  ws = null;
322
359
  options;
@@ -326,6 +363,16 @@ var OxArchiveWs = class {
326
363
  reconnectAttempts = 0;
327
364
  pingTimer = null;
328
365
  reconnectTimer = null;
366
+ // Typed event handlers (separate from WsEventHandlers to avoid wrapping issues)
367
+ historicalDataHandlers = [];
368
+ batchHandlers = [];
369
+ replayStartHandlers = [];
370
+ replayCompleteHandlers = [];
371
+ streamStartHandlers = [];
372
+ streamProgressHandlers = [];
373
+ streamCompleteHandlers = [];
374
+ orderbookHandlers = [];
375
+ tradesHandlers = [];
329
376
  constructor(options) {
330
377
  this.options = {
331
378
  apiKey: options.apiKey,
@@ -369,7 +416,7 @@ var OxArchiveWs = class {
369
416
  this.ws.onmessage = (event) => {
370
417
  try {
371
418
  const message = JSON.parse(event.data);
372
- this.handlers.onMessage?.(message);
419
+ this.handleMessage(message);
373
420
  } catch {
374
421
  }
375
422
  };
@@ -549,92 +596,43 @@ var OxArchiveWs = class {
549
596
  * Handle historical data points (replay mode)
550
597
  */
551
598
  onHistoricalData(handler) {
552
- const originalHandler = this.handlers.onMessage;
553
- this.handlers.onMessage = (message) => {
554
- if (message.type === "historical_data") {
555
- const msg = message;
556
- handler(msg.coin, msg.timestamp, msg.data);
557
- }
558
- originalHandler?.(message);
559
- };
599
+ this.historicalDataHandlers.push(handler);
560
600
  }
561
601
  /**
562
602
  * Handle batched data (bulk stream mode)
563
603
  */
564
604
  onBatch(handler) {
565
- const originalHandler = this.handlers.onMessage;
566
- this.handlers.onMessage = (message) => {
567
- if (message.type === "historical_batch") {
568
- const msg = message;
569
- handler(msg.coin, msg.data);
570
- }
571
- originalHandler?.(message);
572
- };
605
+ this.batchHandlers.push(handler);
573
606
  }
574
607
  /**
575
608
  * Handle replay started event
576
609
  */
577
610
  onReplayStart(handler) {
578
- const originalHandler = this.handlers.onMessage;
579
- this.handlers.onMessage = (message) => {
580
- if (message.type === "replay_started") {
581
- const msg = message;
582
- handler(msg.channel, msg.coin, msg.start, msg.end, msg.speed);
583
- }
584
- originalHandler?.(message);
585
- };
611
+ this.replayStartHandlers.push(handler);
586
612
  }
587
613
  /**
588
614
  * Handle replay completed event
589
615
  */
590
616
  onReplayComplete(handler) {
591
- const originalHandler = this.handlers.onMessage;
592
- this.handlers.onMessage = (message) => {
593
- if (message.type === "replay_completed") {
594
- const msg = message;
595
- handler(msg.channel, msg.coin, msg.snapshots_sent);
596
- }
597
- originalHandler?.(message);
598
- };
617
+ this.replayCompleteHandlers.push(handler);
599
618
  }
600
619
  /**
601
620
  * Handle stream started event
602
621
  */
603
622
  onStreamStart(handler) {
604
- const originalHandler = this.handlers.onMessage;
605
- this.handlers.onMessage = (message) => {
606
- if (message.type === "stream_started") {
607
- const msg = message;
608
- handler(msg.channel, msg.coin, msg.start, msg.end);
609
- }
610
- originalHandler?.(message);
611
- };
623
+ this.streamStartHandlers.push(handler);
612
624
  }
613
625
  /**
614
626
  * Handle stream progress event
615
627
  */
616
628
  onStreamProgress(handler) {
617
- const originalHandler = this.handlers.onMessage;
618
- this.handlers.onMessage = (message) => {
619
- if (message.type === "stream_progress") {
620
- const msg = message;
621
- handler(msg.snapshots_sent);
622
- }
623
- originalHandler?.(message);
624
- };
629
+ this.streamProgressHandlers.push(handler);
625
630
  }
626
631
  /**
627
632
  * Handle stream completed event
628
633
  */
629
634
  onStreamComplete(handler) {
630
- const originalHandler = this.handlers.onMessage;
631
- this.handlers.onMessage = (message) => {
632
- if (message.type === "stream_completed") {
633
- const msg = message;
634
- handler(msg.channel, msg.coin, msg.snapshots_sent);
635
- }
636
- originalHandler?.(message);
637
- };
635
+ this.streamCompleteHandlers.push(handler);
638
636
  }
639
637
  /**
640
638
  * Get current connection state
@@ -658,25 +656,13 @@ var OxArchiveWs = class {
658
656
  * Helper to handle typed orderbook data
659
657
  */
660
658
  onOrderbook(handler) {
661
- const originalHandler = this.handlers.onMessage;
662
- this.handlers.onMessage = (message) => {
663
- if (message.type === "data" && message.channel === "orderbook") {
664
- handler(message.coin, message.data);
665
- }
666
- originalHandler?.(message);
667
- };
659
+ this.orderbookHandlers.push(handler);
668
660
  }
669
661
  /**
670
662
  * Helper to handle typed trade data
671
663
  */
672
664
  onTrades(handler) {
673
- const originalHandler = this.handlers.onMessage;
674
- this.handlers.onMessage = (message) => {
675
- if (message.type === "data" && message.channel === "trades") {
676
- handler(message.coin, message.data);
677
- }
678
- originalHandler?.(message);
679
- };
665
+ this.tradesHandlers.push(handler);
680
666
  }
681
667
  // Private methods
682
668
  send(message) {
@@ -727,6 +713,73 @@ var OxArchiveWs = class {
727
713
  this.reconnectTimer = null;
728
714
  }
729
715
  }
716
+ handleMessage(message) {
717
+ this.handlers.onMessage?.(message);
718
+ switch (message.type) {
719
+ case "historical_data": {
720
+ const msg = message;
721
+ for (const handler of this.historicalDataHandlers) {
722
+ handler(msg.coin, msg.timestamp, msg.data);
723
+ }
724
+ break;
725
+ }
726
+ case "historical_batch": {
727
+ const msg = message;
728
+ for (const handler of this.batchHandlers) {
729
+ handler(msg.coin, msg.data);
730
+ }
731
+ break;
732
+ }
733
+ case "replay_started": {
734
+ const msg = message;
735
+ for (const handler of this.replayStartHandlers) {
736
+ handler(msg.channel, msg.coin, msg.start, msg.end, msg.speed);
737
+ }
738
+ break;
739
+ }
740
+ case "replay_completed": {
741
+ const msg = message;
742
+ for (const handler of this.replayCompleteHandlers) {
743
+ handler(msg.channel, msg.coin, msg.snapshots_sent);
744
+ }
745
+ break;
746
+ }
747
+ case "stream_started": {
748
+ const msg = message;
749
+ for (const handler of this.streamStartHandlers) {
750
+ handler(msg.channel, msg.coin, msg.start, msg.end);
751
+ }
752
+ break;
753
+ }
754
+ case "stream_progress": {
755
+ const msg = message;
756
+ for (const handler of this.streamProgressHandlers) {
757
+ handler(msg.snapshots_sent);
758
+ }
759
+ break;
760
+ }
761
+ case "stream_completed": {
762
+ const msg = message;
763
+ for (const handler of this.streamCompleteHandlers) {
764
+ handler(msg.channel, msg.coin, msg.snapshots_sent);
765
+ }
766
+ break;
767
+ }
768
+ case "data": {
769
+ if (message.channel === "orderbook") {
770
+ const orderbook = transformOrderbook(message.coin, message.data);
771
+ for (const handler of this.orderbookHandlers) {
772
+ handler(message.coin, orderbook);
773
+ }
774
+ } else if (message.channel === "trades") {
775
+ for (const handler of this.tradesHandlers) {
776
+ handler(message.coin, message.data);
777
+ }
778
+ }
779
+ break;
780
+ }
781
+ }
782
+ }
730
783
  };
731
784
  // Annotate the CommonJS export names for ESM import in node:
732
785
  0 && (module.exports = {