ccxt 4.5.2 → 4.5.3

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 (45) hide show
  1. package/README.md +3 -3
  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 +11 -0
  5. package/dist/cjs/src/binance.js +5 -11
  6. package/dist/cjs/src/bitget.js +1 -1
  7. package/dist/cjs/src/coincatch.js +2 -2
  8. package/dist/cjs/src/gate.js +27 -12
  9. package/dist/cjs/src/gemini.js +3 -3
  10. package/dist/cjs/src/htx.js +4 -4
  11. package/dist/cjs/src/kucoinfutures.js +8 -8
  12. package/dist/cjs/src/mexc.js +30 -1
  13. package/dist/cjs/src/okx.js +17 -3
  14. package/dist/cjs/src/pro/binance.js +3 -3
  15. package/dist/cjs/src/pro/bitfinex.js +140 -0
  16. package/dist/cjs/src/pro/bitget.js +61 -16
  17. package/dist/cjs/src/pro/bybit.js +3 -3
  18. package/dist/cjs/src/pro/kucoin.js +64 -0
  19. package/dist/cjs/src/pro/mexc.js +7 -3
  20. package/js/ccxt.d.ts +1 -1
  21. package/js/ccxt.js +1 -1
  22. package/js/src/base/Exchange.d.ts +2 -0
  23. package/js/src/base/Exchange.js +11 -0
  24. package/js/src/binance.js +5 -11
  25. package/js/src/bitget.js +1 -1
  26. package/js/src/coincatch.js +2 -2
  27. package/js/src/gate.js +27 -12
  28. package/js/src/gemini.js +3 -3
  29. package/js/src/htx.js +4 -4
  30. package/js/src/kucoinfutures.js +8 -8
  31. package/js/src/mexc.d.ts +3 -0
  32. package/js/src/mexc.js +30 -1
  33. package/js/src/okx.d.ts +4 -2
  34. package/js/src/okx.js +17 -3
  35. package/js/src/pro/binance.js +3 -3
  36. package/js/src/pro/bitfinex.d.ts +30 -0
  37. package/js/src/pro/bitfinex.js +140 -0
  38. package/js/src/pro/bitget.d.ts +6 -0
  39. package/js/src/pro/bitget.js +61 -16
  40. package/js/src/pro/bybit.d.ts +2 -2
  41. package/js/src/pro/bybit.js +3 -3
  42. package/js/src/pro/kucoin.d.ts +22 -0
  43. package/js/src/pro/kucoin.js +64 -0
  44. package/js/src/pro/mexc.js +7 -3
  45. package/package.json +1 -1
@@ -469,7 +469,7 @@ export default class kucoinfutures extends kucoin {
469
469
  // }
470
470
  // }
471
471
  //
472
- const data = this.safeValue(response, 'data', {});
472
+ const data = this.safeDict(response, 'data', {});
473
473
  const status = this.safeString(data, 'status');
474
474
  return {
475
475
  'status': (status === 'open') ? 'ok' : 'maintenance',
@@ -552,7 +552,7 @@ export default class kucoinfutures extends kucoin {
552
552
  // }
553
553
  //
554
554
  const result = [];
555
- const data = this.safeValue(response, 'data', []);
555
+ const data = this.safeList(response, 'data', []);
556
556
  for (let i = 0; i < data.length; i++) {
557
557
  const market = data[i];
558
558
  const id = this.safeString(market, 'symbol');
@@ -769,7 +769,7 @@ export default class kucoinfutures extends kucoin {
769
769
  // }
770
770
  // }
771
771
  //
772
- const data = this.safeValue(response, 'data', {});
772
+ const data = this.safeDict(response, 'data', {});
773
773
  const address = this.safeString(data, 'address');
774
774
  if (currencyId !== 'NIM') {
775
775
  // contains spaces
@@ -833,7 +833,7 @@ export default class kucoinfutures extends kucoin {
833
833
  // }
834
834
  // }
835
835
  //
836
- const data = this.safeValue(response, 'data', {});
836
+ const data = this.safeDict(response, 'data', {});
837
837
  const timestamp = this.parseToInt(this.safeInteger(data, 'ts') / 1000000);
838
838
  const orderbook = this.parseOrderBook(data, market['symbol'], timestamp, 'bids', 'asks', 0, 1);
839
839
  orderbook['nonce'] = this.safeInteger(data, 'sequence');
@@ -1163,7 +1163,7 @@ export default class kucoinfutures extends kucoin {
1163
1163
  // }
1164
1164
  //
1165
1165
  const data = this.safeValue(response, 'data');
1166
- const dataList = this.safeValue(data, 'dataList', []);
1166
+ const dataList = this.safeList(data, 'dataList', []);
1167
1167
  const fees = [];
1168
1168
  for (let i = 0; i < dataList.length; i++) {
1169
1169
  const listItem = dataList[i];
@@ -2124,7 +2124,7 @@ export default class kucoinfutures extends kucoin {
2124
2124
  // }
2125
2125
  // }
2126
2126
  //
2127
- const responseData = this.safeValue(response, 'data', {});
2127
+ const responseData = this.safeDict(response, 'data', {});
2128
2128
  const orders = this.safeList(responseData, 'items', []);
2129
2129
  return this.parseOrders(orders, market, since, limit);
2130
2130
  }
@@ -3052,7 +3052,7 @@ export default class kucoinfutures extends kucoin {
3052
3052
  // ]
3053
3053
  // }
3054
3054
  //
3055
- const data = this.safeValue(response, 'data');
3055
+ const data = this.safeList(response, 'data', []);
3056
3056
  return this.parseMarketLeverageTiers(data, market);
3057
3057
  }
3058
3058
  parseMarketLeverageTiers(info, market = undefined) {
@@ -3141,7 +3141,7 @@ export default class kucoinfutures extends kucoin {
3141
3141
  // ]
3142
3142
  // }
3143
3143
  //
3144
- const data = this.safeValue(response, 'data');
3144
+ const data = this.safeList(response, 'data', []);
3145
3145
  return this.parseFundingRateHistories(data, market, since, limit);
3146
3146
  }
3147
3147
  parseFundingRateHistory(info, market = undefined) {
package/js/src/mexc.d.ts CHANGED
@@ -653,11 +653,14 @@ export default class mexc extends Exchange {
653
653
  * @name mexc#withdraw
654
654
  * @description make a withdrawal
655
655
  * @see https://mexcdevelop.github.io/apidocs/spot_v3_en/#withdraw-new
656
+ * @see https://www.mexc.com/api-docs/spot-v3/wallet-endpoints#internal-transfer
656
657
  * @param {string} code unified currency code
657
658
  * @param {float} amount the amount to withdraw
658
659
  * @param {string} address the address to withdraw to
659
660
  * @param {string} tag
660
661
  * @param {object} [params] extra parameters specific to the exchange API endpoint
662
+ * @param {object} [params.internal] false by default, set to true for an "internal transfer"
663
+ * @param {object} [params.toAccountType] skipped by default, set to 'EMAIL|UID|MOBILE' when making an "internal transfer"
661
664
  * @returns {object} a [transaction structure]{@link https://docs.ccxt.com/#/?id=transaction-structure}
662
665
  */
663
666
  withdraw(code: string, amount: number, address: string, tag?: Str, params?: {}): Promise<Transaction>;
package/js/src/mexc.js CHANGED
@@ -4998,7 +4998,13 @@ export default class mexc extends Exchange {
4998
4998
  // "id":"25fb2831fb6d4fc7aa4094612a26c81d"
4999
4999
  // }
5000
5000
  //
5001
- const id = this.safeString(transaction, 'id');
5001
+ // internal withdraw (aka internal-transfer)
5002
+ //
5003
+ // {
5004
+ // "tranId":"ad36f0e9c9a24ae794b36fa4f152e471"
5005
+ // }
5006
+ //
5007
+ const id = this.safeString2(transaction, 'id', 'tranId');
5002
5008
  const type = (id === undefined) ? 'deposit' : 'withdrawal';
5003
5009
  const timestamp = this.safeInteger2(transaction, 'insertTime', 'applyTime');
5004
5010
  const updated = this.safeInteger(transaction, 'updateTime');
@@ -5511,17 +5517,40 @@ export default class mexc extends Exchange {
5511
5517
  * @name mexc#withdraw
5512
5518
  * @description make a withdrawal
5513
5519
  * @see https://mexcdevelop.github.io/apidocs/spot_v3_en/#withdraw-new
5520
+ * @see https://www.mexc.com/api-docs/spot-v3/wallet-endpoints#internal-transfer
5514
5521
  * @param {string} code unified currency code
5515
5522
  * @param {float} amount the amount to withdraw
5516
5523
  * @param {string} address the address to withdraw to
5517
5524
  * @param {string} tag
5518
5525
  * @param {object} [params] extra parameters specific to the exchange API endpoint
5526
+ * @param {object} [params.internal] false by default, set to true for an "internal transfer"
5527
+ * @param {object} [params.toAccountType] skipped by default, set to 'EMAIL|UID|MOBILE' when making an "internal transfer"
5519
5528
  * @returns {object} a [transaction structure]{@link https://docs.ccxt.com/#/?id=transaction-structure}
5520
5529
  */
5521
5530
  async withdraw(code, amount, address, tag = undefined, params = {}) {
5522
5531
  await this.loadMarkets();
5523
5532
  const currency = this.currency(code);
5524
5533
  [tag, params] = this.handleWithdrawTagAndParams(tag, params);
5534
+ const internal = this.safeBool(params, 'internal', false);
5535
+ if (internal) {
5536
+ params = this.omit(params, 'internal');
5537
+ const requestForInternal = {
5538
+ 'asset': currency['id'],
5539
+ 'amount': amount,
5540
+ 'toAccount': address,
5541
+ };
5542
+ const toAccountType = this.safeString(params, 'toAccountType');
5543
+ if (toAccountType === undefined) {
5544
+ throw new ArgumentsRequired(this.id + ' withdraw() requires a toAccountType parameter for internal transfer to be of: EMAIL | UID | MOBILE');
5545
+ }
5546
+ const responseForInternal = await this.spotPrivatePostCapitalTransferInternal(this.extend(requestForInternal, params));
5547
+ //
5548
+ // {
5549
+ // "id":"7213fea8e94b4a5593d507237e5a555b"
5550
+ // }
5551
+ //
5552
+ return this.parseTransaction(responseForInternal, currency);
5553
+ }
5525
5554
  const networks = this.safeDict(this.options, 'networks', {});
5526
5555
  let network = this.safeString2(params, 'network', 'netWork'); // this line allows the user to specify either ERC20 or ETH
5527
5556
  network = this.safeString(networks, network, network); // handle ETH > ERC-20 alias
package/js/src/okx.d.ts CHANGED
@@ -138,6 +138,7 @@ export default class okx extends Exchange {
138
138
  * @see https://www.okx.com/docs-v5/en/#rest-api-market-data-get-mark-price-candlesticks-history
139
139
  * @see https://www.okx.com/docs-v5/en/#rest-api-market-data-get-index-candlesticks
140
140
  * @see https://www.okx.com/docs-v5/en/#rest-api-market-data-get-index-candlesticks-history
141
+ * @see https://www.okx.com/docs-v5/en/#order-book-trading-market-data-get-candlesticks-history
141
142
  * @param {string} symbol unified symbol of the market to fetch OHLCV data for
142
143
  * @param {string} timeframe the length of time each candle represents
143
144
  * @param {int} [since] timestamp in ms of the earliest candle to fetch
@@ -145,6 +146,7 @@ export default class okx extends Exchange {
145
146
  * @param {object} [params] extra parameters specific to the exchange API endpoint
146
147
  * @param {string} [params.price] "mark" or "index" for mark price and index price candles
147
148
  * @param {int} [params.until] timestamp in ms of the latest candle to fetch
149
+ * @param {string} [params.type] "Candles" or "HistoryCandles", default is "Candles" for recent candles, "HistoryCandles" for older candles
148
150
  * @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)
149
151
  * @returns {int[][]} A list of candles ordered as timestamp, open, high, low, close, volume
150
152
  */
@@ -190,8 +192,8 @@ export default class okx extends Exchange {
190
192
  /**
191
193
  * @method
192
194
  * @name okx#createMarketBuyOrderWithCost
193
- * @see https://www.okx.com/docs-v5/en/#order-book-trading-trade-post-place-order
194
195
  * @description create a market buy order by providing the symbol and cost
196
+ * @see https://www.okx.com/docs-v5/en/#order-book-trading-trade-post-place-order
195
197
  * @param {string} symbol unified symbol of the market to create an order in
196
198
  * @param {float} cost how much you want to trade in units of the quote currency
197
199
  * @param {object} [params] extra parameters specific to the exchange API endpoint
@@ -201,8 +203,8 @@ export default class okx extends Exchange {
201
203
  /**
202
204
  * @method
203
205
  * @name okx#createMarketSellOrderWithCost
204
- * @see https://www.okx.com/docs-v5/en/#order-book-trading-trade-post-place-order
205
206
  * @description create a market buy order by providing the symbol and cost
207
+ * @see https://www.okx.com/docs-v5/en/#order-book-trading-trade-post-place-order
206
208
  * @param {string} symbol unified symbol of the market to create an order in
207
209
  * @param {float} cost how much you want to trade in units of the quote currency
208
210
  * @param {object} [params] extra parameters specific to the exchange API endpoint
package/js/src/okx.js CHANGED
@@ -2420,6 +2420,7 @@ export default class okx extends Exchange {
2420
2420
  * @see https://www.okx.com/docs-v5/en/#rest-api-market-data-get-mark-price-candlesticks-history
2421
2421
  * @see https://www.okx.com/docs-v5/en/#rest-api-market-data-get-index-candlesticks
2422
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
2423
2424
  * @param {string} symbol unified symbol of the market to fetch OHLCV data for
2424
2425
  * @param {string} timeframe the length of time each candle represents
2425
2426
  * @param {int} [since] timestamp in ms of the earliest candle to fetch
@@ -2427,6 +2428,7 @@ export default class okx extends Exchange {
2427
2428
  * @param {object} [params] extra parameters specific to the exchange API endpoint
2428
2429
  * @param {string} [params.price] "mark" or "index" for mark price and index price candles
2429
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
2430
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)
2431
2433
  * @returns {int[][]} A list of candles ordered as timestamp, open, high, low, close, volume
2432
2434
  */
@@ -2442,6 +2444,7 @@ export default class okx extends Exchange {
2442
2444
  params = this.omit(params, 'price');
2443
2445
  const options = this.safeDict(this.options, 'fetchOHLCV', {});
2444
2446
  const timezone = this.safeString(options, 'timezone', 'UTC');
2447
+ const limitIsUndefined = (limit === undefined);
2445
2448
  if (limit === undefined) {
2446
2449
  limit = 100; // default 100, max 100
2447
2450
  }
@@ -2466,7 +2469,8 @@ export default class okx extends Exchange {
2466
2469
  const historyBorder = now - ((1440 - 1) * durationInMilliseconds);
2467
2470
  if (since < historyBorder) {
2468
2471
  defaultType = 'HistoryCandles';
2469
- 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
2470
2474
  }
2471
2475
  const startTime = Math.max(since - 1, 0);
2472
2476
  request['before'] = startTime;
@@ -2501,6 +2505,10 @@ export default class okx extends Exchange {
2501
2505
  }
2502
2506
  else {
2503
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
+ }
2504
2512
  response = await this.publicGetMarketHistoryCandles(this.extend(request, params));
2505
2513
  }
2506
2514
  else {
@@ -2848,8 +2856,8 @@ export default class okx extends Exchange {
2848
2856
  /**
2849
2857
  * @method
2850
2858
  * @name okx#createMarketBuyOrderWithCost
2851
- * @see https://www.okx.com/docs-v5/en/#order-book-trading-trade-post-place-order
2852
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
2853
2861
  * @param {string} symbol unified symbol of the market to create an order in
2854
2862
  * @param {float} cost how much you want to trade in units of the quote currency
2855
2863
  * @param {object} [params] extra parameters specific to the exchange API endpoint
@@ -2870,8 +2878,8 @@ export default class okx extends Exchange {
2870
2878
  /**
2871
2879
  * @method
2872
2880
  * @name okx#createMarketSellOrderWithCost
2873
- * @see https://www.okx.com/docs-v5/en/#order-book-trading-trade-post-place-order
2874
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
2875
2883
  * @param {string} symbol unified symbol of the market to create an order in
2876
2884
  * @param {float} cost how much you want to trade in units of the quote currency
2877
2885
  * @param {object} [params] extra parameters specific to the exchange API endpoint
@@ -2934,6 +2942,8 @@ export default class okx extends Exchange {
2934
2942
  const takeProfitDefined = (takeProfit !== undefined);
2935
2943
  const trailingPercent = this.safeString2(params, 'trailingPercent', 'callbackRatio');
2936
2944
  const isTrailingPercentOrder = trailingPercent !== undefined;
2945
+ const trailingPrice = this.safeString2(params, 'trailingPrice', 'callbackSpread');
2946
+ const isTrailingPriceOrder = trailingPrice !== undefined;
2937
2947
  const trigger = (triggerPrice !== undefined) || (type === 'trigger');
2938
2948
  const isReduceOnly = this.safeValue(params, 'reduceOnly', false);
2939
2949
  const defaultMarginMode = this.safeString2(this.options, 'defaultMarginMode', 'marginMode', 'cross');
@@ -3050,6 +3060,10 @@ export default class okx extends Exchange {
3050
3060
  request['callbackRatio'] = convertedTrailingPercent;
3051
3061
  request['ordType'] = 'move_order_stop';
3052
3062
  }
3063
+ else if (isTrailingPriceOrder) {
3064
+ request['callbackSpread'] = trailingPrice;
3065
+ request['ordType'] = 'move_order_stop';
3066
+ }
3053
3067
  else if (stopLossDefined || takeProfitDefined) {
3054
3068
  if (stopLossDefined) {
3055
3069
  const stopLossTriggerPrice = this.safeValueN(stopLoss, ['triggerPrice', 'stopPrice', 'slTriggerPx']);
@@ -3244,8 +3244,8 @@ export default class binance extends binanceRest {
3244
3244
  await this.loadMarkets();
3245
3245
  const market = this.market(symbol);
3246
3246
  const type = this.getMarketType('cancelAllOrdersWs', market, params);
3247
- if (type !== 'spot' && type !== 'future') {
3248
- throw new BadRequest(this.id + ' cancelAllOrdersWs only supports spot or swap markets');
3247
+ if (type !== 'spot') {
3248
+ throw new BadRequest(this.id + ' cancelAllOrdersWs only supports spot markets');
3249
3249
  }
3250
3250
  const url = this.urls['api']['ws']['ws-api'][type];
3251
3251
  const requestId = this.requestId(url);
@@ -3258,7 +3258,7 @@ export default class binance extends binanceRest {
3258
3258
  };
3259
3259
  const message = {
3260
3260
  'id': messageHash,
3261
- 'method': 'order.cancel',
3261
+ 'method': 'openOrders.cancelAll',
3262
3262
  'params': this.signParams(this.extend(payload, params)),
3263
3263
  };
3264
3264
  const subscription = {
@@ -4,6 +4,7 @@ import Client from '../base/ws/Client.js';
4
4
  export default class bitfinex extends bitfinexRest {
5
5
  describe(): any;
6
6
  subscribe(channel: any, symbol: any, params?: {}): Promise<any>;
7
+ unSubscribe(channel: any, topic: any, symbol: any, params?: {}): Promise<any>;
7
8
  subscribePrivate(messageHash: any): Promise<any>;
8
9
  /**
9
10
  * @method
@@ -17,6 +18,16 @@ export default class bitfinex extends bitfinexRest {
17
18
  * @returns {int[][]} A list of candles ordered as timestamp, open, high, low, close, volume
18
19
  */
19
20
  watchOHLCV(symbol: string, timeframe?: string, since?: Int, limit?: Int, params?: {}): Promise<OHLCV[]>;
21
+ /**
22
+ * @method
23
+ * @name bitfinex#unWatchOHLCV
24
+ * @description unWatches historical candlestick data containing the open, high, low, and close price, and the volume of a market
25
+ * @param {string} symbol unified symbol of the market to fetch OHLCV data for
26
+ * @param {string} timeframe the length of time each candle represents
27
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
28
+ * @returns {bool} true if successfully unsubscribed, false otherwise
29
+ */
30
+ unWatchOHLCV(symbol: string, timeframe?: string, params?: {}): Promise<any>;
20
31
  handleOHLCV(client: Client, message: any, subscription: any): void;
21
32
  /**
22
33
  * @method
@@ -29,6 +40,15 @@ export default class bitfinex extends bitfinexRest {
29
40
  * @returns {object[]} a list of [trade structures]{@link https://docs.ccxt.com/#/?id=public-trades}
30
41
  */
31
42
  watchTrades(symbol: string, since?: Int, limit?: Int, params?: {}): Promise<Trade[]>;
43
+ /**
44
+ * @method
45
+ * @name bitfinex#unWatchTrades
46
+ * @description unWatches the list of most recent trades for a particular symbol
47
+ * @param {string} symbol unified symbol of the market to fetch trades for
48
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
49
+ * @returns {object[]} a list of [trade structures]{@link https://docs.ccxt.com/#/?id=public-trades}
50
+ */
51
+ unWatchTrades(symbol: string, params?: {}): Promise<any>;
32
52
  /**
33
53
  * @method
34
54
  * @name bitfinex#watchMyTrades
@@ -49,6 +69,15 @@ export default class bitfinex extends bitfinexRest {
49
69
  * @returns {object} a [ticker structure]{@link https://docs.ccxt.com/#/?id=ticker-structure}
50
70
  */
51
71
  watchTicker(symbol: string, params?: {}): Promise<Ticker>;
72
+ /**
73
+ * @method
74
+ * @name bitfinex#unWatchTicker
75
+ * @description unWatches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market
76
+ * @param {string} symbol unified symbol of the market to fetch the ticker for
77
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
78
+ * @returns {object} a [ticker structure]{@link https://docs.ccxt.com/#/?id=ticker-structure}
79
+ */
80
+ unWatchTicker(symbol: string, params?: {}): Promise<any>;
52
81
  handleMyTrade(client: Client, message: any, subscription?: {}): void;
53
82
  handleTrades(client: Client, message: any, subscription: any): void;
54
83
  parseWsTrade(trade: any, market?: any): Trade;
@@ -78,6 +107,7 @@ export default class bitfinex extends bitfinexRest {
78
107
  handleBalance(client: Client, message: any, subscription: any): void;
79
108
  parseWsBalance(balance: any): import("../base/types.js").BalanceAccount;
80
109
  handleSystemStatus(client: Client, message: any): any;
110
+ handleUnsubscriptionStatus(client: Client, message: any): boolean;
81
111
  handleSubscriptionStatus(client: Client, message: any): any;
82
112
  authenticate(params?: {}): Promise<any>;
83
113
  handleAuthenticationMessage(client: Client, message: any): void;
@@ -25,6 +25,10 @@ export default class bitfinex extends bitfinexRest {
25
25
  'watchBalance': true,
26
26
  'watchOHLCV': true,
27
27
  'watchOrders': true,
28
+ 'unWatchTicker': true,
29
+ 'unWatchTrades': true,
30
+ 'unWatchOHLCV': true,
31
+ 'unWatchOrderBook': true,
28
32
  },
29
33
  'urls': {
30
34
  'api': {
@@ -67,6 +71,31 @@ export default class bitfinex extends bitfinexRest {
67
71
  }
68
72
  return result;
69
73
  }
74
+ async unSubscribe(channel, topic, symbol, params = {}) {
75
+ await this.loadMarkets();
76
+ const market = this.market(symbol);
77
+ const marketId = market['id'];
78
+ const url = this.urls['api']['ws']['public'];
79
+ const client = this.client(url);
80
+ const subMessageHash = channel + ':' + marketId;
81
+ const messageHash = 'unsubscribe:' + channel + ':' + marketId;
82
+ const unSubTopic = 'unsubscribe' + ':' + topic + ':' + symbol;
83
+ const channelId = this.safeString(client.subscriptions, unSubTopic);
84
+ const request = {
85
+ 'event': 'unsubscribe',
86
+ 'chanId': channelId,
87
+ };
88
+ const unSubChanMsg = 'unsubscribe:' + channelId;
89
+ client.subscriptions[unSubChanMsg] = subMessageHash;
90
+ const subscription = {
91
+ 'messageHashes': [messageHash],
92
+ 'subMessageHashes': [subMessageHash],
93
+ 'topic': topic,
94
+ 'unsubscribe': true,
95
+ 'symbols': [symbol],
96
+ };
97
+ return await this.watch(url, messageHash, this.deepExtend(request, params), messageHash, subscription);
98
+ }
70
99
  async subscribePrivate(messageHash) {
71
100
  await this.loadMarkets();
72
101
  await this.authenticate();
@@ -105,6 +134,42 @@ export default class bitfinex extends bitfinexRest {
105
134
  }
106
135
  return this.filterBySinceLimit(ohlcv, since, limit, 0, true);
107
136
  }
137
+ /**
138
+ * @method
139
+ * @name bitfinex#unWatchOHLCV
140
+ * @description unWatches historical candlestick data containing the open, high, low, and close price, and the volume of a market
141
+ * @param {string} symbol unified symbol of the market to fetch OHLCV data for
142
+ * @param {string} timeframe the length of time each candle represents
143
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
144
+ * @returns {bool} true if successfully unsubscribed, false otherwise
145
+ */
146
+ async unWatchOHLCV(symbol, timeframe = '1m', params = {}) {
147
+ await this.loadMarkets();
148
+ const market = this.market(symbol);
149
+ symbol = market['symbol'];
150
+ const interval = this.safeString(this.timeframes, timeframe, timeframe);
151
+ const channel = 'candles';
152
+ const subMessageHash = channel + ':' + interval + ':' + market['id'];
153
+ const messageHash = 'unsubscribe:' + subMessageHash;
154
+ const url = this.urls['api']['ws']['public'];
155
+ const client = this.client(url);
156
+ const subId = 'unsubscribe:trade:' + interval + ':' + market['id']; // trade here because we use the key
157
+ const channelId = this.safeString(client.subscriptions, subId);
158
+ const request = {
159
+ 'event': 'unsubscribe',
160
+ 'chanId': channelId,
161
+ };
162
+ const unSubChanMsg = 'unsubscribe:' + channelId;
163
+ client.subscriptions[unSubChanMsg] = subMessageHash;
164
+ const subscription = {
165
+ 'messageHashes': [messageHash],
166
+ 'subMessageHashes': [subMessageHash],
167
+ 'topic': 'ohlcv',
168
+ 'unsubscribe': true,
169
+ 'symbols': [symbol],
170
+ };
171
+ return await this.watch(url, messageHash, this.deepExtend(request, params), messageHash, subscription);
172
+ }
108
173
  handleOHLCV(client, message, subscription) {
109
174
  //
110
175
  // initial snapshot
@@ -205,6 +270,17 @@ export default class bitfinex extends bitfinexRest {
205
270
  }
206
271
  return this.filterBySinceLimit(trades, since, limit, 'timestamp', true);
207
272
  }
273
+ /**
274
+ * @method
275
+ * @name bitfinex#unWatchTrades
276
+ * @description unWatches the list of most recent trades for a particular symbol
277
+ * @param {string} symbol unified symbol of the market to fetch trades for
278
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
279
+ * @returns {object[]} a list of [trade structures]{@link https://docs.ccxt.com/#/?id=public-trades}
280
+ */
281
+ async unWatchTrades(symbol, params = {}) {
282
+ return await this.unSubscribe('trades', 'trades', symbol, params);
283
+ }
208
284
  /**
209
285
  * @method
210
286
  * @name bitfinex#watchMyTrades
@@ -239,6 +315,17 @@ export default class bitfinex extends bitfinexRest {
239
315
  async watchTicker(symbol, params = {}) {
240
316
  return await this.subscribe('ticker', symbol, params);
241
317
  }
318
+ /**
319
+ * @method
320
+ * @name bitfinex#unWatchTicker
321
+ * @description unWatches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market
322
+ * @param {string} symbol unified symbol of the market to fetch the ticker for
323
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
324
+ * @returns {object} a [ticker structure]{@link https://docs.ccxt.com/#/?id=ticker-structure}
325
+ */
326
+ async unWatchTicker(symbol, params = {}) {
327
+ return await this.unSubscribe('ticker', 'ticker', symbol, params);
328
+ }
242
329
  handleMyTrade(client, message, subscription = {}) {
243
330
  //
244
331
  // trade execution
@@ -832,6 +919,29 @@ export default class bitfinex extends bitfinexRest {
832
919
  //
833
920
  return message;
834
921
  }
922
+ handleUnsubscriptionStatus(client, message) {
923
+ //
924
+ // {
925
+ // "event": "unsubscribed",
926
+ // "status": "OK",
927
+ // "chanId": CHANNEL_ID
928
+ // }
929
+ //
930
+ const channelId = this.safeString(message, 'chanId');
931
+ const unSubChannel = 'unsubscribe:' + channelId;
932
+ const subMessageHash = this.safeString(client.subscriptions, unSubChannel);
933
+ const subscription = this.safeDict(client.subscriptions, 'unsubscribe:' + subMessageHash);
934
+ delete client.subscriptions[unSubChannel];
935
+ const messageHashes = this.safeList(subscription, 'messageHashes', []);
936
+ const subMessageHashes = this.safeList(subscription, 'subMessageHashes', []);
937
+ for (let i = 0; i < messageHashes.length; i++) {
938
+ const messageHash = messageHashes[i];
939
+ const subHash = subMessageHashes[i];
940
+ this.cleanUnsubscription(client, subHash, messageHash);
941
+ }
942
+ this.cleanCache(subscription);
943
+ return true;
944
+ }
835
945
  handleSubscriptionStatus(client, message) {
836
946
  //
837
947
  // {
@@ -845,8 +955,37 @@ export default class bitfinex extends bitfinexRest {
845
955
  // "pair": "BTCUSD"
846
956
  // }
847
957
  //
958
+ // {
959
+ // event: 'subscribed',
960
+ // channel: 'candles',
961
+ // chanId: 128306,
962
+ // key: 'trade:1m:tBTCUST'
963
+ // }
964
+ //
848
965
  const channelId = this.safeString(message, 'chanId');
849
966
  client.subscriptions[channelId] = message;
967
+ // store the opposite direction too for unWatch
968
+ const mappings = {
969
+ 'book': 'orderbook',
970
+ 'candles': 'ohlcv',
971
+ 'ticker': 'ticker',
972
+ 'trades': 'trades',
973
+ };
974
+ const unifiedChannel = this.safeString(mappings, this.safeString(message, 'channel'));
975
+ if ('key' in message) {
976
+ // handle ohlcv differently because the message is different
977
+ const key = this.safeString(message, 'key');
978
+ const subKeyId = 'unsubscribe:' + key;
979
+ client.subscriptions[subKeyId] = channelId;
980
+ }
981
+ else {
982
+ const marketId = this.safeString(message, 'symbol');
983
+ const symbol = this.safeSymbol(marketId);
984
+ if (unifiedChannel !== undefined) {
985
+ const subId = 'unsubscribe:' + unifiedChannel + ':' + symbol;
986
+ client.subscriptions[subId] = channelId;
987
+ }
988
+ }
850
989
  return message;
851
990
  }
852
991
  async authenticate(params = {}) {
@@ -1153,6 +1292,7 @@ export default class bitfinex extends bitfinexRest {
1153
1292
  const methods = {
1154
1293
  'info': this.handleSystemStatus,
1155
1294
  'subscribed': this.handleSubscriptionStatus,
1295
+ 'unsubscribed': this.handleUnsubscriptionStatus,
1156
1296
  'auth': this.handleAuthenticationMessage,
1157
1297
  };
1158
1298
  const method = this.safeValue(methods, event);
@@ -142,10 +142,12 @@ export default class bitget extends bitgetRest {
142
142
  * @description get the list of most recent trades for a particular symbol
143
143
  * @see https://www.bitget.com/api-doc/spot/websocket/public/Trades-Channel
144
144
  * @see https://www.bitget.com/api-doc/contract/websocket/public/New-Trades-Channel
145
+ * @see https://www.bitget.com/api-doc/uta/websocket/public/New-Trades-Channel
145
146
  * @param {string} symbol unified symbol of the market to fetch trades for
146
147
  * @param {int} [since] timestamp in ms of the earliest trade to fetch
147
148
  * @param {int} [limit] the maximum amount of trades to fetch
148
149
  * @param {object} [params] extra parameters specific to the exchange API endpoint
150
+ * @param {boolean} [params.uta] set to true for the unified trading account (uta), defaults to false
149
151
  * @returns {object[]} a list of [trade structures]{@link https://docs.ccxt.com/#/?id=public-trades}
150
152
  */
151
153
  watchTrades(symbol: string, since?: Int, limit?: Int, params?: {}): Promise<Trade[]>;
@@ -155,10 +157,12 @@ export default class bitget extends bitgetRest {
155
157
  * @description get the list of most recent trades for a particular symbol
156
158
  * @see https://www.bitget.com/api-doc/spot/websocket/public/Trades-Channel
157
159
  * @see https://www.bitget.com/api-doc/contract/websocket/public/New-Trades-Channel
160
+ * @see https://www.bitget.com/api-doc/uta/websocket/public/New-Trades-Channel
158
161
  * @param {string[]} symbols unified symbol of the market to fetch trades for
159
162
  * @param {int} [since] timestamp in ms of the earliest trade to fetch
160
163
  * @param {int} [limit] the maximum amount of trades to fetch
161
164
  * @param {object} [params] extra parameters specific to the exchange API endpoint
165
+ * @param {boolean} [params.uta] set to true for the unified trading account (uta), defaults to false
162
166
  * @returns {object[]} a list of [trade structures]{@link https://docs.ccxt.com/#/?id=public-trades}
163
167
  */
164
168
  watchTradesForSymbols(symbols: string[], since?: Int, limit?: Int, params?: {}): Promise<Trade[]>;
@@ -168,8 +172,10 @@ export default class bitget extends bitgetRest {
168
172
  * @description unsubscribe from the trades channel
169
173
  * @see https://www.bitget.com/api-doc/spot/websocket/public/Trades-Channel
170
174
  * @see https://www.bitget.com/api-doc/contract/websocket/public/New-Trades-Channel
175
+ * @see https://www.bitget.com/api-doc/uta/websocket/public/New-Trades-Channel
171
176
  * @param {string} symbol unified symbol of the market to unwatch the trades for
172
177
  * @param {object} [params] extra parameters specific to the exchange API endpoint
178
+ * @param {boolean} [params.uta] set to true for the unified trading account (uta), defaults to false
173
179
  * @returns {any} status of the unwatch request
174
180
  */
175
181
  unWatchTrades(symbol: string, params?: {}): Promise<any>;