ccxt 4.3.98 → 4.4.1

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.
@@ -6,7 +6,7 @@
6
6
 
7
7
  // ---------------------------------------------------------------------------
8
8
  import hyperliquidRest from '../hyperliquid.js';
9
- import { ExchangeError } from '../base/errors.js';
9
+ import { ExchangeError, UnsubscribeError } from '../base/errors.js';
10
10
  import { ArrayCache, ArrayCacheByTimestamp, ArrayCacheBySymbolById } from '../base/ws/Cache.js';
11
11
  // ---------------------------------------------------------------------------
12
12
  export default class hyperliquid extends hyperliquidRest {
@@ -163,6 +163,34 @@ export default class hyperliquid extends hyperliquidRest {
163
163
  const orderbook = await this.watch(url, messageHash, message, messageHash);
164
164
  return orderbook.limit();
165
165
  }
166
+ async unWatchOrderBook(symbol, params = {}) {
167
+ /**
168
+ * @method
169
+ * @name hyperliquid#unWatchOrderBook
170
+ * @description unWatches information on open orders with bid (buy) and ask (sell) prices, volumes and other data
171
+ * @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/websocket/subscriptions
172
+ * @param {string} symbol unified symbol of the market to fetch the order book for
173
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
174
+ * @returns {object} A dictionary of [order book structures]{@link https://docs.ccxt.com/#/?id=order-book-structure} indexed by market symbols
175
+ */
176
+ await this.loadMarkets();
177
+ const market = this.market(symbol);
178
+ symbol = market['symbol'];
179
+ const subMessageHash = 'orderbook:' + symbol;
180
+ const messageHash = 'unsubscribe:' + subMessageHash;
181
+ const url = this.urls['api']['ws']['public'];
182
+ const id = this.nonce().toString();
183
+ const request = {
184
+ 'id': id,
185
+ 'method': 'unsubscribe',
186
+ 'subscription': {
187
+ 'type': 'l2Book',
188
+ 'coin': market['swap'] ? market['base'] : market['id'],
189
+ },
190
+ };
191
+ const message = this.extend(request, params);
192
+ return await this.watch(url, messageHash, message, messageHash);
193
+ }
166
194
  handleOrderBook(client, message) {
167
195
  //
168
196
  // {
@@ -237,6 +265,30 @@ export default class hyperliquid extends hyperliquidRest {
237
265
  }
238
266
  return this.tickers;
239
267
  }
268
+ async unWatchTickers(symbols = undefined, params = {}) {
269
+ /**
270
+ * @method
271
+ * @name hyperliquid#unWatchTickers
272
+ * @description unWatches a price ticker, a statistical calculation with the information calculated over the past 24 hours for all markets of a specific list
273
+ * @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/websocket/subscriptions
274
+ * @param {string[]} symbols unified symbol of the market to fetch the ticker for
275
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
276
+ * @returns {object} a [ticker structure]{@link https://docs.ccxt.com/#/?id=ticker-structure}
277
+ */
278
+ await this.loadMarkets();
279
+ symbols = this.marketSymbols(symbols, undefined, true);
280
+ const subMessageHash = 'tickers';
281
+ const messageHash = 'unsubscribe:' + subMessageHash;
282
+ const url = this.urls['api']['ws']['public'];
283
+ const request = {
284
+ 'method': 'unsubscribe',
285
+ 'subscription': {
286
+ 'type': 'webData2',
287
+ 'user': '0x0000000000000000000000000000000000000000',
288
+ },
289
+ };
290
+ return await this.watch(url, messageHash, this.extend(request, params), messageHash);
291
+ }
240
292
  async watchMyTrades(symbol = undefined, since = undefined, limit = undefined, params = {}) {
241
293
  /**
242
294
  * @method
@@ -406,17 +458,17 @@ export default class hyperliquid extends hyperliquidRest {
406
458
  client.resolve(trades, messageHash);
407
459
  }
408
460
  async watchTrades(symbol, since = undefined, limit = undefined, params = {}) {
409
- /**
410
- * @method
411
- * @name hyperliquid#watchTrades
412
- * @description watches information on multiple trades made in a market
413
- * @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/websocket/subscriptions
414
- * @param {string} symbol unified market symbol of the market trades were made in
415
- * @param {int} [since] the earliest time in ms to fetch trades for
416
- * @param {int} [limit] the maximum number of trade structures to retrieve
417
- * @param {object} [params] extra parameters specific to the exchange API endpoint
418
- * @returns {object[]} a list of [trade structures]{@link https://docs.ccxt.com/#/?id=trade-structure}
419
- */
461
+ // s
462
+ // @method
463
+ // @name hyperliquid#watchTrades
464
+ // @description watches information on multiple trades made in a market
465
+ // @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/websocket/subscriptions
466
+ // @param {string} symbol unified market symbol of the market trades were made in
467
+ // @param {int} [since] the earliest time in ms to fetch trades for
468
+ // @param {int} [limit] the maximum number of trade structures to retrieve
469
+ // @param {object} [params] extra parameters specific to the exchange API endpoint
470
+ // @returns {object[]} a list of [trade structures]{@link https://docs.ccxt.com/#/?id=trade-structure}
471
+ //
420
472
  await this.loadMarkets();
421
473
  const market = this.market(symbol);
422
474
  symbol = market['symbol'];
@@ -436,6 +488,32 @@ export default class hyperliquid extends hyperliquidRest {
436
488
  }
437
489
  return this.filterBySinceLimit(trades, since, limit, 'timestamp', true);
438
490
  }
491
+ async unWatchTrades(symbol, params = {}) {
492
+ /**
493
+ * @method
494
+ * @name hyperliquid#unWatchTrades
495
+ * @description unWatches information on multiple trades made in a market
496
+ * @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/websocket/subscriptions
497
+ * @param {string} symbol unified market symbol of the market trades were made in
498
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
499
+ * @returns {object[]} a list of [trade structures]{@link https://docs.ccxt.com/#/?id=trade-structure}
500
+ */
501
+ await this.loadMarkets();
502
+ const market = this.market(symbol);
503
+ symbol = market['symbol'];
504
+ const subMessageHash = 'trade:' + symbol;
505
+ const messageHash = 'unsubscribe:' + subMessageHash;
506
+ const url = this.urls['api']['ws']['public'];
507
+ const request = {
508
+ 'method': 'unsubscribe',
509
+ 'subscription': {
510
+ 'type': 'trades',
511
+ 'coin': market['swap'] ? market['base'] : market['id'],
512
+ },
513
+ };
514
+ const message = this.extend(request, params);
515
+ return await this.watch(url, messageHash, message, messageHash);
516
+ }
439
517
  handleTrades(client, message) {
440
518
  //
441
519
  // {
@@ -569,6 +647,34 @@ export default class hyperliquid extends hyperliquidRest {
569
647
  }
570
648
  return this.filterBySinceLimit(ohlcv, since, limit, 0, true);
571
649
  }
650
+ async unWatchOHLCV(symbol, timeframe = '1m', params = {}) {
651
+ /**
652
+ * @method
653
+ * @name hyperliquid#unWatchOHLCV
654
+ * @description watches historical candlestick data containing the open, high, low, close price, and the volume of a market
655
+ * @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/websocket/subscriptions
656
+ * @param {string} symbol unified symbol of the market to fetch OHLCV data for
657
+ * @param {string} timeframe the length of time each candle represents
658
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
659
+ * @returns {int[][]} A list of candles ordered as timestamp, open, high, low, close, volume
660
+ */
661
+ await this.loadMarkets();
662
+ const market = this.market(symbol);
663
+ symbol = market['symbol'];
664
+ const url = this.urls['api']['ws']['public'];
665
+ const request = {
666
+ 'method': 'unsubscribe',
667
+ 'subscription': {
668
+ 'type': 'candle',
669
+ 'coin': market['swap'] ? market['base'] : market['id'],
670
+ 'interval': timeframe,
671
+ },
672
+ };
673
+ const subMessageHash = 'candles:' + timeframe + ':' + symbol;
674
+ const messagehash = 'unsubscribe:' + subMessageHash;
675
+ const message = this.extend(request, params);
676
+ return await this.watch(url, messagehash, message, messagehash);
677
+ }
572
678
  handleOHLCV(client, message) {
573
679
  //
574
680
  // {
@@ -724,7 +830,153 @@ export default class hyperliquid extends hyperliquidRest {
724
830
  return false;
725
831
  }
726
832
  }
833
+ handleOrderBookUnsubscription(client, subscription) {
834
+ //
835
+ // "subscription":{
836
+ // "type":"l2Book",
837
+ // "coin":"BTC",
838
+ // "nSigFigs":5,
839
+ // "mantissa":null
840
+ // }
841
+ //
842
+ const coin = this.safeString(subscription, 'coin');
843
+ const marketId = this.coinToMarketId(coin);
844
+ const symbol = this.safeSymbol(marketId);
845
+ const subMessageHash = 'orderbook:' + symbol;
846
+ const messageHash = 'unsubscribe:' + subMessageHash;
847
+ if (messageHash in client.subscriptions) {
848
+ delete client.subscriptions[messageHash];
849
+ }
850
+ if (subMessageHash in client.subscriptions) {
851
+ delete client.subscriptions[subMessageHash];
852
+ }
853
+ const error = new UnsubscribeError(this.id + ' ' + subMessageHash);
854
+ client.reject(error, subMessageHash);
855
+ client.resolve(true, messageHash);
856
+ if (symbol in this.orderbooks) {
857
+ delete this.orderbooks[symbol];
858
+ }
859
+ }
860
+ handleTradesUnsubscription(client, subscription) {
861
+ //
862
+ const coin = this.safeString(subscription, 'coin');
863
+ const marketId = this.coinToMarketId(coin);
864
+ const symbol = this.safeSymbol(marketId);
865
+ const subMessageHash = 'trade:' + symbol;
866
+ const messageHash = 'unsubscribe:' + subMessageHash;
867
+ if (messageHash in client.subscriptions) {
868
+ delete client.subscriptions[messageHash];
869
+ }
870
+ if (subMessageHash in client.subscriptions) {
871
+ delete client.subscriptions[subMessageHash];
872
+ }
873
+ const error = new UnsubscribeError(this.id + ' ' + subMessageHash);
874
+ client.reject(error, subMessageHash);
875
+ client.resolve(true, messageHash);
876
+ if (symbol in this.trades) {
877
+ delete this.trades[symbol];
878
+ }
879
+ }
880
+ handleTickersUnsubscription(client, subscription) {
881
+ //
882
+ const subMessageHash = 'tickers';
883
+ const messageHash = 'unsubscribe:' + subMessageHash;
884
+ if (messageHash in client.subscriptions) {
885
+ delete client.subscriptions[messageHash];
886
+ }
887
+ if (subMessageHash in client.subscriptions) {
888
+ delete client.subscriptions[subMessageHash];
889
+ }
890
+ const error = new UnsubscribeError(this.id + ' ' + subMessageHash);
891
+ client.reject(error, subMessageHash);
892
+ client.resolve(true, messageHash);
893
+ const symbols = Object.keys(this.tickers);
894
+ for (let i = 0; i < symbols.length; i++) {
895
+ delete this.tickers[symbols[i]];
896
+ }
897
+ }
898
+ handleOHLCVUnsubscription(client, subscription) {
899
+ const coin = this.safeString(subscription, 'coin');
900
+ const marketId = this.coinToMarketId(coin);
901
+ const symbol = this.safeSymbol(marketId);
902
+ const interval = this.safeString(subscription, 'interval');
903
+ const timeframe = this.findTimeframe(interval);
904
+ const subMessageHash = 'candles:' + timeframe + ':' + symbol;
905
+ const messageHash = 'unsubscribe:' + subMessageHash;
906
+ if (messageHash in client.subscriptions) {
907
+ delete client.subscriptions[messageHash];
908
+ }
909
+ if (subMessageHash in client.subscriptions) {
910
+ delete client.subscriptions[subMessageHash];
911
+ }
912
+ const error = new UnsubscribeError(this.id + ' ' + subMessageHash);
913
+ client.reject(error, subMessageHash);
914
+ client.resolve(true, messageHash);
915
+ if (symbol in this.ohlcvs) {
916
+ if (timeframe in this.ohlcvs[symbol]) {
917
+ delete this.ohlcvs[symbol][timeframe];
918
+ }
919
+ }
920
+ }
921
+ handleSubscriptionResponse(client, message) {
922
+ // {
923
+ // "channel":"subscriptionResponse",
924
+ // "data":{
925
+ // "method":"unsubscribe",
926
+ // "subscription":{
927
+ // "type":"l2Book",
928
+ // "coin":"BTC",
929
+ // "nSigFigs":5,
930
+ // "mantissa":null
931
+ // }
932
+ // }
933
+ // }
934
+ //
935
+ // {
936
+ // "channel":"subscriptionResponse",
937
+ // "data":{
938
+ // "method":"unsubscribe",
939
+ // "subscription":{
940
+ // "type":"trades",
941
+ // "coin":"PURR/USDC"
942
+ // }
943
+ // }
944
+ // }
945
+ //
946
+ const data = this.safeDict(message, 'data', {});
947
+ const method = this.safeString(data, 'method');
948
+ if (method === 'unsubscribe') {
949
+ const subscription = this.safeDict(data, 'subscription', {});
950
+ const type = this.safeString(subscription, 'type');
951
+ if (type === 'l2Book') {
952
+ this.handleOrderBookUnsubscription(client, subscription);
953
+ }
954
+ else if (type === 'trades') {
955
+ this.handleTradesUnsubscription(client, subscription);
956
+ }
957
+ else if (type === 'webData2') {
958
+ this.handleTickersUnsubscription(client, subscription);
959
+ }
960
+ else if (type === 'candle') {
961
+ this.handleOHLCVUnsubscription(client, subscription);
962
+ }
963
+ }
964
+ }
727
965
  handleMessage(client, message) {
966
+ //
967
+ // {
968
+ // "channel":"subscriptionResponse",
969
+ // "data":{
970
+ // "method":"unsubscribe",
971
+ // "subscription":{
972
+ // "type":"l2Book",
973
+ // "coin":"BTC",
974
+ // "nSigFigs":5,
975
+ // "mantissa":null
976
+ // }
977
+ // }
978
+ // }
979
+ //
728
980
  if (this.handleErrorMessage(client, message)) {
729
981
  return;
730
982
  }
@@ -738,6 +990,7 @@ export default class hyperliquid extends hyperliquidRest {
738
990
  'userFills': this.handleMyTrades,
739
991
  'webData2': this.handleWsTickers,
740
992
  'post': this.handleWsPost,
993
+ 'subscriptionResponse': this.handleSubscriptionResponse,
741
994
  };
742
995
  const exacMethod = this.safeValue(methods, topic);
743
996
  if (exacMethod !== undefined) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ccxt",
3
- "version": "4.3.98",
3
+ "version": "4.4.1",
4
4
  "description": "A JavaScript / TypeScript / Python / C# / PHP cryptocurrency trading library with support for 100+ exchanges",
5
5
  "unpkg": "dist/ccxt.browser.min.js",
6
6
  "type": "module",