ccxt 4.5.2 → 4.5.4

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 (66) hide show
  1. package/README.md +4 -4
  2. package/dist/ccxt.browser.min.js +2 -2
  3. package/dist/cjs/ccxt.js +1 -1
  4. package/dist/cjs/src/base/Exchange.js +78 -5
  5. package/dist/cjs/src/base/functions/encode.js +8 -0
  6. package/dist/cjs/src/base/functions/rsa.js +14 -1
  7. package/dist/cjs/src/base/functions.js +1 -0
  8. package/dist/cjs/src/binance.js +12 -15
  9. package/dist/cjs/src/bitget.js +1 -1
  10. package/dist/cjs/src/bitvavo.js +8 -0
  11. package/dist/cjs/src/bybit.js +20 -6
  12. package/dist/cjs/src/coinbase.js +28 -10
  13. package/dist/cjs/src/coincatch.js +34 -21
  14. package/dist/cjs/src/delta.js +1 -0
  15. package/dist/cjs/src/gate.js +27 -12
  16. package/dist/cjs/src/gemini.js +3 -3
  17. package/dist/cjs/src/htx.js +4 -4
  18. package/dist/cjs/src/kucoinfutures.js +11 -10
  19. package/dist/cjs/src/mexc.js +30 -1
  20. package/dist/cjs/src/okx.js +19 -4
  21. package/dist/cjs/src/pro/binance.js +3 -3
  22. package/dist/cjs/src/pro/bitfinex.js +140 -0
  23. package/dist/cjs/src/pro/bitget.js +168 -26
  24. package/dist/cjs/src/pro/bybit.js +67 -11
  25. package/dist/cjs/src/pro/coinex.js +10 -11
  26. package/dist/cjs/src/pro/kucoin.js +64 -0
  27. package/dist/cjs/src/pro/mexc.js +7 -3
  28. package/js/ccxt.d.ts +1 -1
  29. package/js/ccxt.js +1 -1
  30. package/js/src/abstract/myokx.d.ts +1 -0
  31. package/js/src/abstract/okx.d.ts +1 -0
  32. package/js/src/abstract/okxus.d.ts +1 -0
  33. package/js/src/base/Exchange.d.ts +6 -0
  34. package/js/src/base/Exchange.js +78 -5
  35. package/js/src/base/functions/encode.d.ts +2 -1
  36. package/js/src/base/functions/encode.js +8 -1
  37. package/js/src/base/functions/rsa.js +16 -3
  38. package/js/src/binance.js +12 -15
  39. package/js/src/bitget.js +1 -1
  40. package/js/src/bitvavo.js +8 -0
  41. package/js/src/bybit.js +20 -6
  42. package/js/src/coinbase.d.ts +1 -1
  43. package/js/src/coinbase.js +28 -10
  44. package/js/src/coincatch.d.ts +2 -0
  45. package/js/src/coincatch.js +34 -21
  46. package/js/src/delta.js +1 -0
  47. package/js/src/gate.js +27 -12
  48. package/js/src/gemini.js +3 -3
  49. package/js/src/htx.js +4 -4
  50. package/js/src/kucoinfutures.js +11 -10
  51. package/js/src/mexc.d.ts +3 -0
  52. package/js/src/mexc.js +30 -1
  53. package/js/src/okx.d.ts +4 -2
  54. package/js/src/okx.js +19 -4
  55. package/js/src/pro/binance.js +3 -3
  56. package/js/src/pro/bitfinex.d.ts +30 -0
  57. package/js/src/pro/bitfinex.js +140 -0
  58. package/js/src/pro/bitget.d.ts +9 -1
  59. package/js/src/pro/bitget.js +168 -26
  60. package/js/src/pro/bybit.d.ts +6 -2
  61. package/js/src/pro/bybit.js +67 -11
  62. package/js/src/pro/coinex.js +11 -12
  63. package/js/src/pro/kucoin.d.ts +22 -0
  64. package/js/src/pro/kucoin.js +64 -0
  65. package/js/src/pro/mexc.js +7 -3
  66. package/package.json +3 -3
@@ -663,7 +663,7 @@ class htx extends htx$1["default"] {
663
663
  'api/v1/contract_batchorder': 1,
664
664
  'api/v1/contract_cancel': 1,
665
665
  'api/v1/contract_cancelall': 1,
666
- 'api/v1/contract_switch_lever_rate': 1,
666
+ 'api/v1/contract_switch_lever_rate': 30,
667
667
  'api/v1/lightning_close_position': 1,
668
668
  'api/v1/contract_order_info': 1,
669
669
  'api/v1/contract_order_detail': 1,
@@ -722,7 +722,7 @@ class htx extends htx$1["default"] {
722
722
  'swap-api/v1/swap_cancel': 1,
723
723
  'swap-api/v1/swap_cancelall': 1,
724
724
  'swap-api/v1/swap_lightning_close_position': 1,
725
- 'swap-api/v1/swap_switch_lever_rate': 1,
725
+ 'swap-api/v1/swap_switch_lever_rate': 30,
726
726
  'swap-api/v1/swap_order_info': 1,
727
727
  'swap-api/v1/swap_order_detail': 1,
728
728
  'swap-api/v1/swap_openorders': 1,
@@ -796,8 +796,8 @@ class htx extends htx$1["default"] {
796
796
  'linear-swap-api/v1/swap_cross_cancel': 1,
797
797
  'linear-swap-api/v1/swap_cancelall': 1,
798
798
  'linear-swap-api/v1/swap_cross_cancelall': 1,
799
- 'linear-swap-api/v1/swap_switch_lever_rate': 1,
800
- 'linear-swap-api/v1/swap_cross_switch_lever_rate': 1,
799
+ 'linear-swap-api/v1/swap_switch_lever_rate': 30,
800
+ 'linear-swap-api/v1/swap_cross_switch_lever_rate': 30,
801
801
  'linear-swap-api/v1/swap_lightning_close_position': 1,
802
802
  'linear-swap-api/v1/swap_cross_lightning_close_position': 1,
803
803
  'linear-swap-api/v1/swap_order_info': 1,
@@ -228,7 +228,7 @@ class kucoinfutures extends kucoinfutures$1["default"] {
228
228
  '429': errors.RateLimitExceeded,
229
229
  '500': errors.ExchangeNotAvailable,
230
230
  '503': errors.ExchangeNotAvailable,
231
- '100001': errors.InvalidOrder,
231
+ '100001': errors.OrderNotFound,
232
232
  '100004': errors.BadRequest,
233
233
  '101030': errors.PermissionDenied,
234
234
  '200004': errors.InsufficientFunds,
@@ -247,7 +247,8 @@ class kucoinfutures extends kucoinfutures$1["default"] {
247
247
  '400100': errors.BadRequest,
248
248
  '411100': errors.AccountSuspended,
249
249
  '500000': errors.ExchangeNotAvailable,
250
- '300009': errors.InvalidOrder, // {"msg":"No open positions to close.","code":"300009"}
250
+ '300009': errors.InvalidOrder,
251
+ '330008': errors.InsufficientFunds, // {"msg":"Your current margin and leverage have reached the maximum open limit. Please increase your margin or raise your leverage to open larger positions.","code":"330008"}
251
252
  },
252
253
  'broad': {
253
254
  'Position does not exist': errors.OrderNotFound, // { "code":"200000", "msg":"Position does not exist" }
@@ -468,7 +469,7 @@ class kucoinfutures extends kucoinfutures$1["default"] {
468
469
  // }
469
470
  // }
470
471
  //
471
- const data = this.safeValue(response, 'data', {});
472
+ const data = this.safeDict(response, 'data', {});
472
473
  const status = this.safeString(data, 'status');
473
474
  return {
474
475
  'status': (status === 'open') ? 'ok' : 'maintenance',
@@ -551,7 +552,7 @@ class kucoinfutures extends kucoinfutures$1["default"] {
551
552
  // }
552
553
  //
553
554
  const result = [];
554
- const data = this.safeValue(response, 'data', []);
555
+ const data = this.safeList(response, 'data', []);
555
556
  for (let i = 0; i < data.length; i++) {
556
557
  const market = data[i];
557
558
  const id = this.safeString(market, 'symbol');
@@ -768,7 +769,7 @@ class kucoinfutures extends kucoinfutures$1["default"] {
768
769
  // }
769
770
  // }
770
771
  //
771
- const data = this.safeValue(response, 'data', {});
772
+ const data = this.safeDict(response, 'data', {});
772
773
  const address = this.safeString(data, 'address');
773
774
  if (currencyId !== 'NIM') {
774
775
  // contains spaces
@@ -832,7 +833,7 @@ class kucoinfutures extends kucoinfutures$1["default"] {
832
833
  // }
833
834
  // }
834
835
  //
835
- const data = this.safeValue(response, 'data', {});
836
+ const data = this.safeDict(response, 'data', {});
836
837
  const timestamp = this.parseToInt(this.safeInteger(data, 'ts') / 1000000);
837
838
  const orderbook = this.parseOrderBook(data, market['symbol'], timestamp, 'bids', 'asks', 0, 1);
838
839
  orderbook['nonce'] = this.safeInteger(data, 'sequence');
@@ -1162,7 +1163,7 @@ class kucoinfutures extends kucoinfutures$1["default"] {
1162
1163
  // }
1163
1164
  //
1164
1165
  const data = this.safeValue(response, 'data');
1165
- const dataList = this.safeValue(data, 'dataList', []);
1166
+ const dataList = this.safeList(data, 'dataList', []);
1166
1167
  const fees = [];
1167
1168
  for (let i = 0; i < dataList.length; i++) {
1168
1169
  const listItem = dataList[i];
@@ -2123,7 +2124,7 @@ class kucoinfutures extends kucoinfutures$1["default"] {
2123
2124
  // }
2124
2125
  // }
2125
2126
  //
2126
- const responseData = this.safeValue(response, 'data', {});
2127
+ const responseData = this.safeDict(response, 'data', {});
2127
2128
  const orders = this.safeList(responseData, 'items', []);
2128
2129
  return this.parseOrders(orders, market, since, limit);
2129
2130
  }
@@ -3051,7 +3052,7 @@ class kucoinfutures extends kucoinfutures$1["default"] {
3051
3052
  // ]
3052
3053
  // }
3053
3054
  //
3054
- const data = this.safeValue(response, 'data');
3055
+ const data = this.safeList(response, 'data', []);
3055
3056
  return this.parseMarketLeverageTiers(data, market);
3056
3057
  }
3057
3058
  parseMarketLeverageTiers(info, market = undefined) {
@@ -3140,7 +3141,7 @@ class kucoinfutures extends kucoinfutures$1["default"] {
3140
3141
  // ]
3141
3142
  // }
3142
3143
  //
3143
- const data = this.safeValue(response, 'data');
3144
+ const data = this.safeList(response, 'data', []);
3144
3145
  return this.parseFundingRateHistories(data, market, since, limit);
3145
3146
  }
3146
3147
  parseFundingRateHistory(info, market = undefined) {
@@ -4996,7 +4996,13 @@ class mexc extends mexc$1["default"] {
4996
4996
  // "id":"25fb2831fb6d4fc7aa4094612a26c81d"
4997
4997
  // }
4998
4998
  //
4999
- const id = this.safeString(transaction, 'id');
4999
+ // internal withdraw (aka internal-transfer)
5000
+ //
5001
+ // {
5002
+ // "tranId":"ad36f0e9c9a24ae794b36fa4f152e471"
5003
+ // }
5004
+ //
5005
+ const id = this.safeString2(transaction, 'id', 'tranId');
5000
5006
  const type = (id === undefined) ? 'deposit' : 'withdrawal';
5001
5007
  const timestamp = this.safeInteger2(transaction, 'insertTime', 'applyTime');
5002
5008
  const updated = this.safeInteger(transaction, 'updateTime');
@@ -5509,17 +5515,40 @@ class mexc extends mexc$1["default"] {
5509
5515
  * @name mexc#withdraw
5510
5516
  * @description make a withdrawal
5511
5517
  * @see https://mexcdevelop.github.io/apidocs/spot_v3_en/#withdraw-new
5518
+ * @see https://www.mexc.com/api-docs/spot-v3/wallet-endpoints#internal-transfer
5512
5519
  * @param {string} code unified currency code
5513
5520
  * @param {float} amount the amount to withdraw
5514
5521
  * @param {string} address the address to withdraw to
5515
5522
  * @param {string} tag
5516
5523
  * @param {object} [params] extra parameters specific to the exchange API endpoint
5524
+ * @param {object} [params.internal] false by default, set to true for an "internal transfer"
5525
+ * @param {object} [params.toAccountType] skipped by default, set to 'EMAIL|UID|MOBILE' when making an "internal transfer"
5517
5526
  * @returns {object} a [transaction structure]{@link https://docs.ccxt.com/#/?id=transaction-structure}
5518
5527
  */
5519
5528
  async withdraw(code, amount, address, tag = undefined, params = {}) {
5520
5529
  await this.loadMarkets();
5521
5530
  const currency = this.currency(code);
5522
5531
  [tag, params] = this.handleWithdrawTagAndParams(tag, params);
5532
+ const internal = this.safeBool(params, 'internal', false);
5533
+ if (internal) {
5534
+ params = this.omit(params, 'internal');
5535
+ const requestForInternal = {
5536
+ 'asset': currency['id'],
5537
+ 'amount': amount,
5538
+ 'toAccount': address,
5539
+ };
5540
+ const toAccountType = this.safeString(params, 'toAccountType');
5541
+ if (toAccountType === undefined) {
5542
+ throw new errors.ArgumentsRequired(this.id + ' withdraw() requires a toAccountType parameter for internal transfer to be of: EMAIL | UID | MOBILE');
5543
+ }
5544
+ const responseForInternal = await this.spotPrivatePostCapitalTransferInternal(this.extend(requestForInternal, params));
5545
+ //
5546
+ // {
5547
+ // "id":"7213fea8e94b4a5593d507237e5a555b"
5548
+ // }
5549
+ //
5550
+ return this.parseTransaction(responseForInternal, currency);
5551
+ }
5523
5552
  const networks = this.safeDict(this.options, 'networks', {});
5524
5553
  let network = this.safeString2(params, 'network', 'netWork'); // this line allows the user to specify either ERC20 or ETH
5525
5554
  network = this.safeString(networks, network, network); // handle ETH > ERC-20 alias
@@ -213,6 +213,7 @@ class okx extends okx$1["default"] {
213
213
  'market/open-oracle': 50,
214
214
  'market/exchange-rate': 20,
215
215
  'market/index-components': 1,
216
+ 'public/market-data-history': 4,
216
217
  'public/economic-calendar': 50,
217
218
  'market/block-tickers': 1,
218
219
  'market/block-ticker': 1,
@@ -364,7 +365,7 @@ class okx extends okx$1["default"] {
364
365
  'account/fixed-loan/borrowing-limit': 4,
365
366
  'account/fixed-loan/borrowing-quote': 5,
366
367
  'account/fixed-loan/borrowing-orders-list': 5,
367
- 'account/spot-manual-borrow-repay': 10,
368
+ 'account/spot-manual-borrow-repay': 30,
368
369
  'account/set-auto-repay': 4,
369
370
  'account/spot-borrow-repay-history': 4,
370
371
  'account/move-positions-history': 10,
@@ -2419,6 +2420,7 @@ class okx extends okx$1["default"] {
2419
2420
  * @see https://www.okx.com/docs-v5/en/#rest-api-market-data-get-mark-price-candlesticks-history
2420
2421
  * @see https://www.okx.com/docs-v5/en/#rest-api-market-data-get-index-candlesticks
2421
2422
  * @see https://www.okx.com/docs-v5/en/#rest-api-market-data-get-index-candlesticks-history
2423
+ * @see https://www.okx.com/docs-v5/en/#order-book-trading-market-data-get-candlesticks-history
2422
2424
  * @param {string} symbol unified symbol of the market to fetch OHLCV data for
2423
2425
  * @param {string} timeframe the length of time each candle represents
2424
2426
  * @param {int} [since] timestamp in ms of the earliest candle to fetch
@@ -2426,6 +2428,7 @@ class okx extends okx$1["default"] {
2426
2428
  * @param {object} [params] extra parameters specific to the exchange API endpoint
2427
2429
  * @param {string} [params.price] "mark" or "index" for mark price and index price candles
2428
2430
  * @param {int} [params.until] timestamp in ms of the latest candle to fetch
2431
+ * @param {string} [params.type] "Candles" or "HistoryCandles", default is "Candles" for recent candles, "HistoryCandles" for older candles
2429
2432
  * @param {boolean} [params.paginate] default false, when true will automatically paginate by calling this endpoint multiple times. See in the docs all the [availble parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
2430
2433
  * @returns {int[][]} A list of candles ordered as timestamp, open, high, low, close, volume
2431
2434
  */
@@ -2441,6 +2444,7 @@ class okx extends okx$1["default"] {
2441
2444
  params = this.omit(params, 'price');
2442
2445
  const options = this.safeDict(this.options, 'fetchOHLCV', {});
2443
2446
  const timezone = this.safeString(options, 'timezone', 'UTC');
2447
+ const limitIsUndefined = (limit === undefined);
2444
2448
  if (limit === undefined) {
2445
2449
  limit = 100; // default 100, max 100
2446
2450
  }
@@ -2465,7 +2469,8 @@ class okx extends okx$1["default"] {
2465
2469
  const historyBorder = now - ((1440 - 1) * durationInMilliseconds);
2466
2470
  if (since < historyBorder) {
2467
2471
  defaultType = 'HistoryCandles';
2468
- limit = Math.min(limit, 100); // max 100 for historical endpoint
2472
+ const maxLimit = (price !== undefined) ? 100 : 300;
2473
+ limit = Math.min(limit, maxLimit); // max 300 for historical endpoint
2469
2474
  }
2470
2475
  const startTime = Math.max(since - 1, 0);
2471
2476
  request['before'] = startTime;
@@ -2500,6 +2505,10 @@ class okx extends okx$1["default"] {
2500
2505
  }
2501
2506
  else {
2502
2507
  if (isHistoryCandles) {
2508
+ if (limitIsUndefined && (limit === 100)) {
2509
+ limit = 300;
2510
+ request['limit'] = 300; // reassign to 300, but this whole logic needs to be simplified...
2511
+ }
2503
2512
  response = await this.publicGetMarketHistoryCandles(this.extend(request, params));
2504
2513
  }
2505
2514
  else {
@@ -2847,8 +2856,8 @@ class okx extends okx$1["default"] {
2847
2856
  /**
2848
2857
  * @method
2849
2858
  * @name okx#createMarketBuyOrderWithCost
2850
- * @see https://www.okx.com/docs-v5/en/#order-book-trading-trade-post-place-order
2851
2859
  * @description create a market buy order by providing the symbol and cost
2860
+ * @see https://www.okx.com/docs-v5/en/#order-book-trading-trade-post-place-order
2852
2861
  * @param {string} symbol unified symbol of the market to create an order in
2853
2862
  * @param {float} cost how much you want to trade in units of the quote currency
2854
2863
  * @param {object} [params] extra parameters specific to the exchange API endpoint
@@ -2869,8 +2878,8 @@ class okx extends okx$1["default"] {
2869
2878
  /**
2870
2879
  * @method
2871
2880
  * @name okx#createMarketSellOrderWithCost
2872
- * @see https://www.okx.com/docs-v5/en/#order-book-trading-trade-post-place-order
2873
2881
  * @description create a market buy order by providing the symbol and cost
2882
+ * @see https://www.okx.com/docs-v5/en/#order-book-trading-trade-post-place-order
2874
2883
  * @param {string} symbol unified symbol of the market to create an order in
2875
2884
  * @param {float} cost how much you want to trade in units of the quote currency
2876
2885
  * @param {object} [params] extra parameters specific to the exchange API endpoint
@@ -2933,6 +2942,8 @@ class okx extends okx$1["default"] {
2933
2942
  const takeProfitDefined = (takeProfit !== undefined);
2934
2943
  const trailingPercent = this.safeString2(params, 'trailingPercent', 'callbackRatio');
2935
2944
  const isTrailingPercentOrder = trailingPercent !== undefined;
2945
+ const trailingPrice = this.safeString2(params, 'trailingPrice', 'callbackSpread');
2946
+ const isTrailingPriceOrder = trailingPrice !== undefined;
2936
2947
  const trigger = (triggerPrice !== undefined) || (type === 'trigger');
2937
2948
  const isReduceOnly = this.safeValue(params, 'reduceOnly', false);
2938
2949
  const defaultMarginMode = this.safeString2(this.options, 'defaultMarginMode', 'marginMode', 'cross');
@@ -3049,6 +3060,10 @@ class okx extends okx$1["default"] {
3049
3060
  request['callbackRatio'] = convertedTrailingPercent;
3050
3061
  request['ordType'] = 'move_order_stop';
3051
3062
  }
3063
+ else if (isTrailingPriceOrder) {
3064
+ request['callbackSpread'] = trailingPrice;
3065
+ request['ordType'] = 'move_order_stop';
3066
+ }
3052
3067
  else if (stopLossDefined || takeProfitDefined) {
3053
3068
  if (stopLossDefined) {
3054
3069
  const stopLossTriggerPrice = this.safeValueN(stopLoss, ['triggerPrice', 'stopPrice', 'slTriggerPx']);
@@ -3240,8 +3240,8 @@ class binance extends binance$1["default"] {
3240
3240
  await this.loadMarkets();
3241
3241
  const market = this.market(symbol);
3242
3242
  const type = this.getMarketType('cancelAllOrdersWs', market, params);
3243
- if (type !== 'spot' && type !== 'future') {
3244
- throw new errors.BadRequest(this.id + ' cancelAllOrdersWs only supports spot or swap markets');
3243
+ if (type !== 'spot') {
3244
+ throw new errors.BadRequest(this.id + ' cancelAllOrdersWs only supports spot markets');
3245
3245
  }
3246
3246
  const url = this.urls['api']['ws']['ws-api'][type];
3247
3247
  const requestId = this.requestId(url);
@@ -3254,7 +3254,7 @@ class binance extends binance$1["default"] {
3254
3254
  };
3255
3255
  const message = {
3256
3256
  'id': messageHash,
3257
- 'method': 'order.cancel',
3257
+ 'method': 'openOrders.cancelAll',
3258
3258
  'params': this.signParams(this.extend(payload, params)),
3259
3259
  };
3260
3260
  const subscription = {
@@ -24,6 +24,10 @@ class bitfinex extends bitfinex$1["default"] {
24
24
  'watchBalance': true,
25
25
  'watchOHLCV': true,
26
26
  'watchOrders': true,
27
+ 'unWatchTicker': true,
28
+ 'unWatchTrades': true,
29
+ 'unWatchOHLCV': true,
30
+ 'unWatchOrderBook': true,
27
31
  },
28
32
  'urls': {
29
33
  'api': {
@@ -66,6 +70,31 @@ class bitfinex extends bitfinex$1["default"] {
66
70
  }
67
71
  return result;
68
72
  }
73
+ async unSubscribe(channel, topic, symbol, params = {}) {
74
+ await this.loadMarkets();
75
+ const market = this.market(symbol);
76
+ const marketId = market['id'];
77
+ const url = this.urls['api']['ws']['public'];
78
+ const client = this.client(url);
79
+ const subMessageHash = channel + ':' + marketId;
80
+ const messageHash = 'unsubscribe:' + channel + ':' + marketId;
81
+ const unSubTopic = 'unsubscribe' + ':' + topic + ':' + symbol;
82
+ const channelId = this.safeString(client.subscriptions, unSubTopic);
83
+ const request = {
84
+ 'event': 'unsubscribe',
85
+ 'chanId': channelId,
86
+ };
87
+ const unSubChanMsg = 'unsubscribe:' + channelId;
88
+ client.subscriptions[unSubChanMsg] = subMessageHash;
89
+ const subscription = {
90
+ 'messageHashes': [messageHash],
91
+ 'subMessageHashes': [subMessageHash],
92
+ 'topic': topic,
93
+ 'unsubscribe': true,
94
+ 'symbols': [symbol],
95
+ };
96
+ return await this.watch(url, messageHash, this.deepExtend(request, params), messageHash, subscription);
97
+ }
69
98
  async subscribePrivate(messageHash) {
70
99
  await this.loadMarkets();
71
100
  await this.authenticate();
@@ -104,6 +133,42 @@ class bitfinex extends bitfinex$1["default"] {
104
133
  }
105
134
  return this.filterBySinceLimit(ohlcv, since, limit, 0, true);
106
135
  }
136
+ /**
137
+ * @method
138
+ * @name bitfinex#unWatchOHLCV
139
+ * @description unWatches historical candlestick data containing the open, high, low, and close price, and the volume of a market
140
+ * @param {string} symbol unified symbol of the market to fetch OHLCV data for
141
+ * @param {string} timeframe the length of time each candle represents
142
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
143
+ * @returns {bool} true if successfully unsubscribed, false otherwise
144
+ */
145
+ async unWatchOHLCV(symbol, timeframe = '1m', params = {}) {
146
+ await this.loadMarkets();
147
+ const market = this.market(symbol);
148
+ symbol = market['symbol'];
149
+ const interval = this.safeString(this.timeframes, timeframe, timeframe);
150
+ const channel = 'candles';
151
+ const subMessageHash = channel + ':' + interval + ':' + market['id'];
152
+ const messageHash = 'unsubscribe:' + subMessageHash;
153
+ const url = this.urls['api']['ws']['public'];
154
+ const client = this.client(url);
155
+ const subId = 'unsubscribe:trade:' + interval + ':' + market['id']; // trade here because we use the key
156
+ const channelId = this.safeString(client.subscriptions, subId);
157
+ const request = {
158
+ 'event': 'unsubscribe',
159
+ 'chanId': channelId,
160
+ };
161
+ const unSubChanMsg = 'unsubscribe:' + channelId;
162
+ client.subscriptions[unSubChanMsg] = subMessageHash;
163
+ const subscription = {
164
+ 'messageHashes': [messageHash],
165
+ 'subMessageHashes': [subMessageHash],
166
+ 'topic': 'ohlcv',
167
+ 'unsubscribe': true,
168
+ 'symbols': [symbol],
169
+ };
170
+ return await this.watch(url, messageHash, this.deepExtend(request, params), messageHash, subscription);
171
+ }
107
172
  handleOHLCV(client, message, subscription) {
108
173
  //
109
174
  // initial snapshot
@@ -204,6 +269,17 @@ class bitfinex extends bitfinex$1["default"] {
204
269
  }
205
270
  return this.filterBySinceLimit(trades, since, limit, 'timestamp', true);
206
271
  }
272
+ /**
273
+ * @method
274
+ * @name bitfinex#unWatchTrades
275
+ * @description unWatches the list of most recent trades for a particular symbol
276
+ * @param {string} symbol unified symbol of the market to fetch trades for
277
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
278
+ * @returns {object[]} a list of [trade structures]{@link https://docs.ccxt.com/#/?id=public-trades}
279
+ */
280
+ async unWatchTrades(symbol, params = {}) {
281
+ return await this.unSubscribe('trades', 'trades', symbol, params);
282
+ }
207
283
  /**
208
284
  * @method
209
285
  * @name bitfinex#watchMyTrades
@@ -238,6 +314,17 @@ class bitfinex extends bitfinex$1["default"] {
238
314
  async watchTicker(symbol, params = {}) {
239
315
  return await this.subscribe('ticker', symbol, params);
240
316
  }
317
+ /**
318
+ * @method
319
+ * @name bitfinex#unWatchTicker
320
+ * @description unWatches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market
321
+ * @param {string} symbol unified symbol of the market to fetch the ticker for
322
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
323
+ * @returns {object} a [ticker structure]{@link https://docs.ccxt.com/#/?id=ticker-structure}
324
+ */
325
+ async unWatchTicker(symbol, params = {}) {
326
+ return await this.unSubscribe('ticker', 'ticker', symbol, params);
327
+ }
241
328
  handleMyTrade(client, message, subscription = {}) {
242
329
  //
243
330
  // trade execution
@@ -831,6 +918,29 @@ class bitfinex extends bitfinex$1["default"] {
831
918
  //
832
919
  return message;
833
920
  }
921
+ handleUnsubscriptionStatus(client, message) {
922
+ //
923
+ // {
924
+ // "event": "unsubscribed",
925
+ // "status": "OK",
926
+ // "chanId": CHANNEL_ID
927
+ // }
928
+ //
929
+ const channelId = this.safeString(message, 'chanId');
930
+ const unSubChannel = 'unsubscribe:' + channelId;
931
+ const subMessageHash = this.safeString(client.subscriptions, unSubChannel);
932
+ const subscription = this.safeDict(client.subscriptions, 'unsubscribe:' + subMessageHash);
933
+ delete client.subscriptions[unSubChannel];
934
+ const messageHashes = this.safeList(subscription, 'messageHashes', []);
935
+ const subMessageHashes = this.safeList(subscription, 'subMessageHashes', []);
936
+ for (let i = 0; i < messageHashes.length; i++) {
937
+ const messageHash = messageHashes[i];
938
+ const subHash = subMessageHashes[i];
939
+ this.cleanUnsubscription(client, subHash, messageHash);
940
+ }
941
+ this.cleanCache(subscription);
942
+ return true;
943
+ }
834
944
  handleSubscriptionStatus(client, message) {
835
945
  //
836
946
  // {
@@ -844,8 +954,37 @@ class bitfinex extends bitfinex$1["default"] {
844
954
  // "pair": "BTCUSD"
845
955
  // }
846
956
  //
957
+ // {
958
+ // event: 'subscribed',
959
+ // channel: 'candles',
960
+ // chanId: 128306,
961
+ // key: 'trade:1m:tBTCUST'
962
+ // }
963
+ //
847
964
  const channelId = this.safeString(message, 'chanId');
848
965
  client.subscriptions[channelId] = message;
966
+ // store the opposite direction too for unWatch
967
+ const mappings = {
968
+ 'book': 'orderbook',
969
+ 'candles': 'ohlcv',
970
+ 'ticker': 'ticker',
971
+ 'trades': 'trades',
972
+ };
973
+ const unifiedChannel = this.safeString(mappings, this.safeString(message, 'channel'));
974
+ if ('key' in message) {
975
+ // handle ohlcv differently because the message is different
976
+ const key = this.safeString(message, 'key');
977
+ const subKeyId = 'unsubscribe:' + key;
978
+ client.subscriptions[subKeyId] = channelId;
979
+ }
980
+ else {
981
+ const marketId = this.safeString(message, 'symbol');
982
+ const symbol = this.safeSymbol(marketId);
983
+ if (unifiedChannel !== undefined) {
984
+ const subId = 'unsubscribe:' + unifiedChannel + ':' + symbol;
985
+ client.subscriptions[subId] = channelId;
986
+ }
987
+ }
849
988
  return message;
850
989
  }
851
990
  async authenticate(params = {}) {
@@ -1152,6 +1291,7 @@ class bitfinex extends bitfinex$1["default"] {
1152
1291
  const methods = {
1153
1292
  'info': this.handleSystemStatus,
1154
1293
  'subscribed': this.handleSubscriptionStatus,
1294
+ 'unsubscribed': this.handleUnsubscriptionStatus,
1155
1295
  'auth': this.handleAuthenticationMessage,
1156
1296
  };
1157
1297
  const method = this.safeValue(methods, event);