ccxt 4.2.63 → 4.2.65

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 (60) hide show
  1. package/README.md +3 -3
  2. package/build.sh +2 -2
  3. package/dist/ccxt.browser.js +565 -178
  4. package/dist/ccxt.browser.min.js +3 -3
  5. package/dist/cjs/ccxt.js +1 -1
  6. package/dist/cjs/src/base/Exchange.js +12 -0
  7. package/dist/cjs/src/binance.js +33 -12
  8. package/dist/cjs/src/bingx.js +58 -49
  9. package/dist/cjs/src/bitget.js +69 -1
  10. package/dist/cjs/src/bitmex.js +3 -1
  11. package/dist/cjs/src/blofin.js +46 -11
  12. package/dist/cjs/src/btcmarkets.js +12 -0
  13. package/dist/cjs/src/bybit.js +100 -7
  14. package/dist/cjs/src/coinbase.js +12 -2
  15. package/dist/cjs/src/delta.js +95 -1
  16. package/dist/cjs/src/gemini.js +9 -4
  17. package/dist/cjs/src/hitbtc.js +1 -1
  18. package/dist/cjs/src/krakenfutures.js +1 -0
  19. package/dist/cjs/src/kucoin.js +87 -62
  20. package/dist/cjs/src/pro/bitget.js +5 -5
  21. package/dist/cjs/src/pro/coinex.js +4 -4
  22. package/dist/cjs/src/pro/currencycom.js +1 -1
  23. package/dist/cjs/src/pro/lbank.js +1 -1
  24. package/dist/cjs/src/yobit.js +15 -15
  25. package/js/ccxt.d.ts +1 -1
  26. package/js/ccxt.js +1 -1
  27. package/js/src/abstract/blofin.d.ts +1 -0
  28. package/js/src/abstract/krakenfutures.d.ts +1 -0
  29. package/js/src/abstract/kucoin.d.ts +10 -0
  30. package/js/src/abstract/kucoinfutures.d.ts +10 -0
  31. package/js/src/base/Exchange.js +12 -0
  32. package/js/src/binance.d.ts +1 -1
  33. package/js/src/binance.js +33 -12
  34. package/js/src/bingx.js +58 -49
  35. package/js/src/bitget.d.ts +3 -1
  36. package/js/src/bitget.js +69 -1
  37. package/js/src/bitmex.js +3 -1
  38. package/js/src/blofin.d.ts +3 -1
  39. package/js/src/blofin.js +46 -11
  40. package/js/src/btcmarkets.js +12 -0
  41. package/js/src/bybit.d.ts +1 -0
  42. package/js/src/bybit.js +100 -7
  43. package/js/src/coinbase.js +12 -2
  44. package/js/src/delta.d.ts +3 -1
  45. package/js/src/delta.js +95 -1
  46. package/js/src/gate.d.ts +1 -1
  47. package/js/src/gemini.js +9 -4
  48. package/js/src/hitbtc.js +1 -1
  49. package/js/src/krakenfutures.js +1 -0
  50. package/js/src/kucoin.js +87 -62
  51. package/js/src/okx.d.ts +1 -1
  52. package/js/src/pro/bitget.js +5 -5
  53. package/js/src/pro/coinex.js +4 -4
  54. package/js/src/pro/currencycom.d.ts +1 -1
  55. package/js/src/pro/currencycom.js +1 -1
  56. package/js/src/pro/lbank.js +1 -1
  57. package/js/src/woo.d.ts +1 -1
  58. package/js/src/yobit.js +15 -15
  59. package/package.json +2 -2
  60. package/skip-tests.json +47 -22
package/dist/cjs/ccxt.js CHANGED
@@ -177,7 +177,7 @@ var woo$1 = require('./src/pro/woo.js');
177
177
 
178
178
  //-----------------------------------------------------------------------------
179
179
  // this is updated by vss.js when building
180
- const version = '4.2.63';
180
+ const version = '4.2.65';
181
181
  Exchange["default"].ccxtVersion = version;
182
182
  const exchanges = {
183
183
  'ace': ace,
@@ -2705,6 +2705,18 @@ class Exchange {
2705
2705
  return this.filterBySymbolSinceLimit(results, symbol, since, limit);
2706
2706
  }
2707
2707
  calculateFee(symbol, type, side, amount, price, takerOrMaker = 'taker', params = {}) {
2708
+ /**
2709
+ * @method
2710
+ * @description calculates the presumptive fee that would be charged for an order
2711
+ * @param {string} symbol unified market symbol
2712
+ * @param {string} type 'market' or 'limit'
2713
+ * @param {string} side 'buy' or 'sell'
2714
+ * @param {float} amount how much you want to trade, in units of the base currency on most exchanges, or number of contracts
2715
+ * @param {float} price the price for the order to be filled at, in units of the quote currency
2716
+ * @param {string} takerOrMaker 'taker' or 'maker'
2717
+ * @param {object} params
2718
+ * @returns {object} contains the rate, the percentage multiplied to the order amount to obtain the fee amount, and cost, the total value of the fee in units of the quote currency, for the order
2719
+ */
2708
2720
  if (type === 'market' && takerOrMaker === 'maker') {
2709
2721
  throw new errors.ArgumentsRequired(this.id + ' calculateFee() - you have provided incompatible arguments - "market" type order can not be "maker". Change either the "type" or the "takerOrMaker" argument to calculate the fee.');
2710
2722
  }
@@ -2525,6 +2525,7 @@ class binance extends binance$1 {
2525
2525
  * @see https://binance-docs.github.io/apidocs/futures/en/#check-server-time // swap
2526
2526
  * @see https://binance-docs.github.io/apidocs/delivery/en/#check-server-time // future
2527
2527
  * @param {object} [params] extra parameters specific to the exchange API endpoint
2528
+ * @param {string} [params.subType] "linear" or "inverse"
2528
2529
  * @returns {int} the current integer timestamp in milliseconds from the exchange server
2529
2530
  */
2530
2531
  const defaultType = this.safeString2(this.options, 'fetchTime', 'defaultType', 'spot');
@@ -2785,14 +2786,12 @@ class binance extends binance$1 {
2785
2786
  }
2786
2787
  }
2787
2788
  const promises = await Promise.all(promisesRaw);
2788
- const spotMarkets = this.safeValue(this.safeValue(promises, 0), 'symbols', []);
2789
- const futureMarkets = this.safeValue(this.safeValue(promises, 1), 'symbols', []);
2790
- const deliveryMarkets = this.safeValue(this.safeValue(promises, 2), 'symbols', []);
2791
- const optionMarkets = this.safeValue(this.safeValue(promises, 3), 'optionSymbols', []);
2792
- let markets = spotMarkets;
2793
- markets = this.arrayConcat(markets, futureMarkets);
2794
- markets = this.arrayConcat(markets, deliveryMarkets);
2795
- markets = this.arrayConcat(markets, optionMarkets);
2789
+ let markets = [];
2790
+ for (let i = 0; i < fetchMarkets.length; i++) {
2791
+ const promise = this.safeDict(promises, i);
2792
+ const promiseMarkets = this.safeList2(promise, 'symbols', 'optionSymbols', []);
2793
+ markets = this.arrayConcat(markets, promiseMarkets);
2794
+ }
2796
2795
  //
2797
2796
  // spot / margin
2798
2797
  //
@@ -3322,6 +3321,7 @@ class binance extends binance$1 {
3322
3321
  * @param {string} [params.marginMode] 'cross' or 'isolated', for margin trading, uses this.options.defaultMarginMode if not passed, defaults to undefined/None/null
3323
3322
  * @param {string[]|undefined} [params.symbols] unified market symbols, only used in isolated margin mode
3324
3323
  * @param {boolean} [params.portfolioMargin] set to true if you would like to fetch the balance for a portfolio margin account
3324
+ * @param {string} [params.subType] "linear" or "inverse"
3325
3325
  * @returns {object} a [balance structure]{@link https://docs.ccxt.com/#/?id=balance-structure}
3326
3326
  */
3327
3327
  await this.loadMarkets();
@@ -3900,6 +3900,7 @@ class binance extends binance$1 {
3900
3900
  * @see https://binance-docs.github.io/apidocs/delivery/en/#symbol-order-book-ticker // future
3901
3901
  * @param {string[]|undefined} symbols unified symbols of the markets to fetch the bids and asks for, all markets are returned if not assigned
3902
3902
  * @param {object} [params] extra parameters specific to the exchange API endpoint
3903
+ * @param {string} [params.subType] "linear" or "inverse"
3903
3904
  * @returns {object} a dictionary of [ticker structures]{@link https://docs.ccxt.com/#/?id=ticker-structure}
3904
3905
  */
3905
3906
  await this.loadMarkets();
@@ -3940,6 +3941,7 @@ class binance extends binance$1 {
3940
3941
  * @see https://binance-docs.github.io/apidocs/delivery/en/#symbol-price-ticker // future
3941
3942
  * @param {string[]|undefined} symbols unified symbols of the markets to fetch the last prices
3942
3943
  * @param {object} [params] extra parameters specific to the exchange API endpoint
3944
+ * @param {string} [params.subType] "linear" or "inverse"
3943
3945
  * @returns {object} a dictionary of lastprices structures
3944
3946
  */
3945
3947
  await this.loadMarkets();
@@ -4045,6 +4047,7 @@ class binance extends binance$1 {
4045
4047
  * @see https://binance-docs.github.io/apidocs/voptions/en/#24hr-ticker-price-change-statistics // option
4046
4048
  * @param {string[]} [symbols] unified symbols of the markets to fetch the ticker for, all market tickers are returned if not assigned
4047
4049
  * @param {object} [params] extra parameters specific to the exchange API endpoint
4050
+ * @param {string} [params.subType] "linear" or "inverse"
4048
4051
  * @returns {object} a dictionary of [ticker structures]{@link https://docs.ccxt.com/#/?id=ticker-structure}
4049
4052
  */
4050
4053
  await this.loadMarkets();
@@ -6471,6 +6474,7 @@ class binance extends binance$1 {
6471
6474
  * @param {string} [params.marginMode] 'cross' or 'isolated', for spot margin trading
6472
6475
  * @param {boolean} [params.portfolioMargin] set to true if you would like to fetch open orders in the portfolio margin account
6473
6476
  * @param {boolean} [params.stop] set to true if you would like to fetch portfolio margin account conditional orders
6477
+ * @param {string} [params.subType] "linear" or "inverse"
6474
6478
  * @returns {Order[]} a list of [order structures]{@link https://docs.ccxt.com/#/?id=order-structure}
6475
6479
  */
6476
6480
  await this.loadMarkets();
@@ -8614,6 +8618,7 @@ class binance extends binance$1 {
8614
8618
  * @param {string} symbol unified market symbol
8615
8619
  * @param {object} [params] extra parameters specific to the exchange API endpoint
8616
8620
  * @param {boolean} [params.portfolioMargin] set to true if you would like to fetch trading fees in a portfolio margin account
8621
+ * @param {string} [params.subType] "linear" or "inverse"
8617
8622
  * @returns {object} a [fee structure]{@link https://docs.ccxt.com/#/?id=fee-structure}
8618
8623
  */
8619
8624
  await this.loadMarkets();
@@ -8682,6 +8687,7 @@ class binance extends binance$1 {
8682
8687
  * @see https://binance-docs.github.io/apidocs/futures/en/#account-information-v2-user_data
8683
8688
  * @see https://binance-docs.github.io/apidocs/delivery/en/#account-information-user_data
8684
8689
  * @param {object} [params] extra parameters specific to the exchange API endpoint
8690
+ * @param {string} [params.subType] "linear" or "inverse"
8685
8691
  * @returns {object} a dictionary of [fee structures]{@link https://docs.ccxt.com/#/?id=fee-structure} indexed by market symbols
8686
8692
  */
8687
8693
  await this.loadMarkets();
@@ -8939,6 +8945,7 @@ class binance extends binance$1 {
8939
8945
  * @param {object} [params] extra parameters specific to the exchange API endpoint
8940
8946
  * @param {int} [params.until] timestamp in ms of the latest funding rate
8941
8947
  * @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)
8948
+ * @param {string} [params.subType] "linear" or "inverse"
8942
8949
  * @returns {object[]} a list of [funding rate structures]{@link https://docs.ccxt.com/#/?id=funding-rate-history-structure}
8943
8950
  */
8944
8951
  await this.loadMarkets();
@@ -9012,6 +9019,7 @@ class binance extends binance$1 {
9012
9019
  * @see https://binance-docs.github.io/apidocs/delivery/en/#index-price-and-mark-price
9013
9020
  * @param {string[]|undefined} symbols list of unified market symbols
9014
9021
  * @param {object} [params] extra parameters specific to the exchange API endpoint
9022
+ * @param {string} [params.subType] "linear" or "inverse"
9015
9023
  * @returns {object} a dictionary of [funding rates structures]{@link https://docs.ccxt.com/#/?id=funding-rates-structure}, indexe by market symbols
9016
9024
  */
9017
9025
  await this.loadMarkets();
@@ -9635,6 +9643,7 @@ class binance extends binance$1 {
9635
9643
  * @param {string[]|undefined} symbols list of unified market symbols
9636
9644
  * @param {object} [params] extra parameters specific to the exchange API endpoint
9637
9645
  * @param {boolean} [params.portfolioMargin] set to true if you would like to fetch the leverage tiers for a portfolio margin account
9646
+ * @param {string} [params.subType] "linear" or "inverse"
9638
9647
  * @returns {object} a dictionary of [leverage tiers structures]{@link https://docs.ccxt.com/#/?id=leverage-tiers-structure}, indexed by market symbols
9639
9648
  */
9640
9649
  await this.loadMarkets();
@@ -9949,6 +9958,7 @@ class binance extends binance$1 {
9949
9958
  * @param {string[]|undefined} symbols list of unified market symbols
9950
9959
  * @param {object} [params] extra parameters specific to the exchange API endpoint
9951
9960
  * @param {boolean} [params.portfolioMargin] set to true if you would like to fetch positions in a portfolio margin account
9961
+ * @param {string} [params.subType] "linear" or "inverse"
9952
9962
  * @returns {object} data on account positions
9953
9963
  */
9954
9964
  if (symbols !== undefined) {
@@ -10002,6 +10012,7 @@ class binance extends binance$1 {
10002
10012
  * @param {string[]|undefined} symbols list of unified market symbols
10003
10013
  * @param {object} [params] extra parameters specific to the exchange API endpoint
10004
10014
  * @param {boolean} [params.portfolioMargin] set to true if you would like to fetch positions for a portfolio margin account
10015
+ * @param {string} [params.subType] "linear" or "inverse"
10005
10016
  * @returns {object} data on the positions risk
10006
10017
  */
10007
10018
  if (symbols !== undefined) {
@@ -10161,6 +10172,7 @@ class binance extends binance$1 {
10161
10172
  * @param {object} [params] extra parameters specific to the exchange API endpoint
10162
10173
  * @param {int} [params.until] timestamp in ms of the latest funding history entry
10163
10174
  * @param {boolean} [params.portfolioMargin] set to true if you would like to fetch the funding history for a portfolio margin account
10175
+ * @param {string} [params.subType] "linear" or "inverse"
10164
10176
  * @returns {object} a [funding history structure]{@link https://docs.ccxt.com/#/?id=funding-history-structure}
10165
10177
  */
10166
10178
  await this.loadMarkets();
@@ -10345,6 +10357,7 @@ class binance extends binance$1 {
10345
10357
  * @param {string} symbol not used by binance setPositionMode ()
10346
10358
  * @param {object} [params] extra parameters specific to the exchange API endpoint
10347
10359
  * @param {boolean} [params.portfolioMargin] set to true if you would like to set the position mode for a portfolio margin account
10360
+ * @param {string} [params.subType] "linear" or "inverse"
10348
10361
  * @returns {object} response from the exchange
10349
10362
  */
10350
10363
  const defaultType = this.safeString(this.options, 'defaultType', 'future');
@@ -10373,7 +10386,7 @@ class binance extends binance$1 {
10373
10386
  response = await this.dapiPrivatePostPositionSideDual(this.extend(request, params));
10374
10387
  }
10375
10388
  }
10376
- else {
10389
+ else if (this.isLinear(type, subType)) {
10377
10390
  if (isPortfolioMargin) {
10378
10391
  response = await this.papiPostUmPositionSideDual(this.extend(request, params));
10379
10392
  }
@@ -10381,6 +10394,9 @@ class binance extends binance$1 {
10381
10394
  response = await this.fapiPrivatePostPositionSideDual(this.extend(request, params));
10382
10395
  }
10383
10396
  }
10397
+ else {
10398
+ throw new errors.BadRequest(this.id + ' setPositionMode() supports linear and inverse contracts only');
10399
+ }
10384
10400
  //
10385
10401
  // {
10386
10402
  // "code": 200,
@@ -10400,6 +10416,7 @@ class binance extends binance$1 {
10400
10416
  * @see https://binance-docs.github.io/apidocs/pm/en/#get-cm-account-detail-user_data
10401
10417
  * @param {string[]} [symbols] a list of unified market symbols
10402
10418
  * @param {object} [params] extra parameters specific to the exchange API endpoint
10419
+ * @param {string} [params.subType] "linear" or "inverse"
10403
10420
  * @returns {object} a list of [leverage structures]{@link https://docs.ccxt.com/#/?id=leverage-structure}
10404
10421
  */
10405
10422
  await this.loadMarkets();
@@ -10674,6 +10691,7 @@ class binance extends binance$1 {
10674
10691
  * @param {int} [params.until] timestamp in ms of the latest ledger entry
10675
10692
  * @param {boolean} [params.paginate] default false, when true will automatically paginate by calling this endpoint multiple times. See in the docs all the [available parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
10676
10693
  * @param {boolean} [params.portfolioMargin] set to true if you would like to fetch the ledger for a portfolio margin account
10694
+ * @param {string} [params.subType] "linear" or "inverse"
10677
10695
  * @returns {object} a [ledger structure]{@link https://docs.ccxt.com/#/?id=ledger-structure}
10678
10696
  */
10679
10697
  await this.loadMarkets();
@@ -11817,6 +11835,8 @@ class binance extends binance$1 {
11817
11835
  * @param {int} [params.until] timestamp in ms of the latest liquidation
11818
11836
  * @param {boolean} [params.paginate] *spot only* default false, when true will automatically paginate by calling this endpoint multiple times. See in the docs all the [available parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
11819
11837
  * @param {boolean} [params.portfolioMargin] set to true if you would like to fetch liquidations in a portfolio margin account
11838
+ * @param {string} [params.type] "spot"
11839
+ * @param {string} [params.subType] "linear" or "inverse"
11820
11840
  * @returns {object} an array of [liquidation structures]{@link https://docs.ccxt.com/#/?id=liquidation-structure}
11821
11841
  */
11822
11842
  await this.loadMarkets();
@@ -12142,8 +12162,8 @@ class binance extends binance$1 {
12142
12162
  * @name binance#fetchPositionMode
12143
12163
  * @description fetchs the position mode, hedged or one way, hedged for binance is set identically for all linear markets or all inverse markets
12144
12164
  * @param {string} symbol unified symbol of the market to fetch the order book for
12145
- * @param {object} params extra parameters specific to the exchange API endpoint
12146
- * @param {string} params.subType "linear" or "inverse"
12165
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
12166
+ * @param {string} [params.subType] "linear" or "inverse"
12147
12167
  * @returns {object} an object detailing whether the market is in hedged or one-way mode
12148
12168
  */
12149
12169
  let market = undefined;
@@ -12181,7 +12201,8 @@ class binance extends binance$1 {
12181
12201
  * @see https://binance-docs.github.io/apidocs/futures/en/#account-information-v2-user_data
12182
12202
  * @param {string} symbol unified symbol of the market the order was made in
12183
12203
  * @param {object} [params] extra parameters specific to the exchange API endpoint
12184
- * @returns {object} struct of marginMode
12204
+ * @param {string} [params.subType] "linear" or "inverse"
12205
+ * @returns {object} a list of [margin mode structures]{@link https://docs.ccxt.com/#/?id=margin-mode-structure}
12185
12206
  */
12186
12207
  await this.loadMarkets();
12187
12208
  let market = undefined;
@@ -435,7 +435,7 @@ class bingx extends bingx$1 {
435
435
  // }
436
436
  // }
437
437
  //
438
- const data = this.safeValue(response, 'data');
438
+ const data = this.safeDict(response, 'data');
439
439
  return this.safeInteger(data, 'serverTime');
440
440
  }
441
441
  async fetchCurrencies(params = {}) {
@@ -490,14 +490,14 @@ class bingx extends bingx$1 {
490
490
  // ],
491
491
  // }
492
492
  //
493
- const data = this.safeValue(response, 'data', []);
493
+ const data = this.safeList(response, 'data', []);
494
494
  const result = {};
495
495
  for (let i = 0; i < data.length; i++) {
496
496
  const entry = data[i];
497
497
  const currencyId = this.safeString(entry, 'coin');
498
498
  const code = this.safeCurrencyCode(currencyId);
499
499
  const name = this.safeString(entry, 'name');
500
- const networkList = this.safeValue(entry, 'networkList');
500
+ const networkList = this.safeList(entry, 'networkList');
501
501
  const networks = {};
502
502
  let fee = undefined;
503
503
  let active = undefined;
@@ -507,8 +507,8 @@ class bingx extends bingx$1 {
507
507
  const rawNetwork = networkList[j];
508
508
  const network = this.safeString(rawNetwork, 'network');
509
509
  const networkCode = this.networkIdToCode(network);
510
- const isDefault = this.safeValue(rawNetwork, 'isDefault');
511
- withdrawEnabled = this.safeValue(rawNetwork, 'withdrawEnable');
510
+ const isDefault = this.safeBool(rawNetwork, 'isDefault');
511
+ withdrawEnabled = this.safeBool(rawNetwork, 'withdrawEnable');
512
512
  const limits = {
513
513
  'amounts': { 'min': this.safeNumber(rawNetwork, 'withdrawMin'), 'max': this.safeNumber(rawNetwork, 'withdrawMax') },
514
514
  };
@@ -569,8 +569,8 @@ class bingx extends bingx$1 {
569
569
  // }
570
570
  // }
571
571
  //
572
- const data = this.safeValue(response, 'data');
573
- const markets = this.safeValue(data, 'symbols', []);
572
+ const data = this.safeDict(response, 'data');
573
+ const markets = this.safeList(data, 'symbols', []);
574
574
  return this.parseMarkets(markets);
575
575
  }
576
576
  async fetchSwapMarkets(params) {
@@ -598,7 +598,7 @@ class bingx extends bingx$1 {
598
598
  // ]
599
599
  // }
600
600
  //
601
- const markets = this.safeValue(response, 'data', []);
601
+ const markets = this.safeList(response, 'data', []);
602
602
  return this.parseMarkets(markets);
603
603
  }
604
604
  parseMarket(market) {
@@ -625,7 +625,7 @@ class bingx extends bingx$1 {
625
625
  if (settle !== undefined) {
626
626
  symbol += ':' + settle;
627
627
  }
628
- const fees = this.safeValue(this.fees, type, {});
628
+ const fees = this.safeDict(this.fees, type, {});
629
629
  const contractSize = this.safeNumber(market, 'size');
630
630
  const isActive = this.safeString(market, 'status') === '1';
631
631
  const isInverse = (spot) ? undefined : false;
@@ -699,8 +699,8 @@ class bingx extends bingx$1 {
699
699
  requests.push(this.fetchSpotMarkets(params)); // sandbox is swap only
700
700
  }
701
701
  const promises = await Promise.all(requests);
702
- const spotMarkets = this.safeValue(promises, 0, []);
703
- const swapMarkets = this.safeValue(promises, 1, []);
702
+ const spotMarkets = this.safeList(promises, 0, []);
703
+ const swapMarkets = this.safeList(promises, 1, []);
704
704
  return this.arrayConcat(spotMarkets, swapMarkets);
705
705
  }
706
706
  async fetchOHLCV(symbol, timeframe = '1m', since = undefined, limit = undefined, params = {}) {
@@ -914,7 +914,7 @@ class bingx extends bingx$1 {
914
914
  // ]
915
915
  // }
916
916
  //
917
- const trades = this.safeValue(response, 'data', []);
917
+ const trades = this.safeList(response, 'data', []);
918
918
  return this.parseTrades(trades, market, since, limit);
919
919
  }
920
920
  parseTrade(trade, market = undefined) {
@@ -1010,9 +1010,9 @@ class bingx extends bingx$1 {
1010
1010
  const type = (cost === undefined) ? 'spot' : 'swap';
1011
1011
  const currencyId = this.safeStringN(trade, ['currency', 'N', 'commissionAsset']);
1012
1012
  const currencyCode = this.safeCurrencyCode(currencyId);
1013
- const m = this.safeValue(trade, 'm');
1013
+ const m = this.safeBool(trade, 'm');
1014
1014
  const marketId = this.safeString(trade, 's');
1015
- const isBuyerMaker = this.safeValue2(trade, 'buyerMaker', 'isBuyerMaker');
1015
+ const isBuyerMaker = this.safeBool2(trade, 'buyerMaker', 'isBuyerMaker');
1016
1016
  let takeOrMaker = undefined;
1017
1017
  if ((isBuyerMaker !== undefined) || (m !== undefined)) {
1018
1018
  takeOrMaker = (isBuyerMaker || m) ? 'maker' : 'taker';
@@ -1024,11 +1024,11 @@ class bingx extends bingx$1 {
1024
1024
  takeOrMaker = 'taker';
1025
1025
  }
1026
1026
  }
1027
- const isBuyer = this.safeValue(trade, 'isBuyer');
1027
+ const isBuyer = this.safeBool(trade, 'isBuyer');
1028
1028
  if (isBuyer !== undefined) {
1029
1029
  side = isBuyer ? 'buy' : 'sell';
1030
1030
  }
1031
- const isMaker = this.safeValue(trade, 'isMaker');
1031
+ const isMaker = this.safeBool(trade, 'isMaker');
1032
1032
  if (isMaker !== undefined) {
1033
1033
  takeOrMaker = isMaker ? 'maker' : 'taker';
1034
1034
  }
@@ -1138,7 +1138,7 @@ class bingx extends bingx$1 {
1138
1138
  // ]}
1139
1139
  // }
1140
1140
  //
1141
- const orderbook = this.safeValue(response, 'data', {});
1141
+ const orderbook = this.safeDict(response, 'data', {});
1142
1142
  const timestamp = this.safeInteger2(orderbook, 'T', 'ts');
1143
1143
  return this.parseOrderBook(orderbook, market['symbol'], timestamp, 'bids', 'asks', 0, 1);
1144
1144
  }
@@ -1174,7 +1174,7 @@ class bingx extends bingx$1 {
1174
1174
  // ]
1175
1175
  // }
1176
1176
  //
1177
- const data = this.safeValue(response, 'data', {});
1177
+ const data = this.safeList(response, 'data', []);
1178
1178
  return this.parseFundingRate(data, market);
1179
1179
  }
1180
1180
  async fetchFundingRates(symbols = undefined, params = {}) {
@@ -1190,7 +1190,7 @@ class bingx extends bingx$1 {
1190
1190
  await this.loadMarkets();
1191
1191
  symbols = this.marketSymbols(symbols, 'swap', true);
1192
1192
  const response = await this.swapV2PublicGetQuotePremiumIndex(this.extend(params));
1193
- const data = this.safeValue(response, 'data', []);
1193
+ const data = this.safeList(response, 'data', []);
1194
1194
  const filteredResponse = [];
1195
1195
  for (let i = 0; i < data.length; i++) {
1196
1196
  const item = data[i];
@@ -1287,7 +1287,7 @@ class bingx extends bingx$1 {
1287
1287
  // ]
1288
1288
  // }
1289
1289
  //
1290
- const data = this.safeValue(response, 'data', []);
1290
+ const data = this.safeList(response, 'data', []);
1291
1291
  const rates = [];
1292
1292
  for (let i = 0; i < data.length; i++) {
1293
1293
  const entry = data[i];
@@ -1332,7 +1332,7 @@ class bingx extends bingx$1 {
1332
1332
  // }
1333
1333
  // }
1334
1334
  //
1335
- const data = this.safeValue(response, 'data', {});
1335
+ const data = this.safeDict(response, 'data', {});
1336
1336
  return this.parseOpenInterest(data, market);
1337
1337
  }
1338
1338
  parseOpenInterest(interest, market = undefined) {
@@ -1666,7 +1666,7 @@ class bingx extends bingx$1 {
1666
1666
  // ]
1667
1667
  // }
1668
1668
  //
1669
- const positions = this.safeValue(response, 'data', []);
1669
+ const positions = this.safeList(response, 'data', []);
1670
1670
  return this.parsePositions(positions, symbols);
1671
1671
  }
1672
1672
  parsePosition(position, market = undefined) {
@@ -1701,7 +1701,7 @@ class bingx extends bingx$1 {
1701
1701
  //
1702
1702
  let marketId = this.safeString(position, 'symbol', '');
1703
1703
  marketId = marketId.replace('/', '-'); // standard return different format
1704
- const isolated = this.safeValue(position, 'isolated');
1704
+ const isolated = this.safeBool(position, 'isolated');
1705
1705
  let marginMode = undefined;
1706
1706
  if (isolated !== undefined) {
1707
1707
  marginMode = isolated ? 'isolated' : 'cross';
@@ -1864,6 +1864,7 @@ class bingx extends bingx$1 {
1864
1864
  const takeProfitPrice = this.safeString(params, 'takeProfitPrice');
1865
1865
  const trailingAmount = this.safeString(params, 'trailingAmount');
1866
1866
  const trailingPercent = this.safeString2(params, 'trailingPercent', 'priceRate');
1867
+ const trailingType = this.safeString(params, 'trailingType', 'TRAILING_STOP_MARKET');
1867
1868
  const isTriggerOrder = triggerPrice !== undefined;
1868
1869
  const isStopLossPriceOrder = stopLossPrice !== undefined;
1869
1870
  const isTakeProfitPriceOrder = takeProfitPrice !== undefined;
@@ -1910,7 +1911,7 @@ class bingx extends bingx$1 {
1910
1911
  }
1911
1912
  }
1912
1913
  else if (isTrailing) {
1913
- request['type'] = 'TRAILING_STOP_MARKET';
1914
+ request['type'] = trailingType;
1914
1915
  if (isTrailingAmountOrder) {
1915
1916
  request['price'] = this.parseToNumeric(trailingAmount);
1916
1917
  }
@@ -1965,7 +1966,7 @@ class bingx extends bingx$1 {
1965
1966
  }
1966
1967
  request['positionSide'] = positionSide;
1967
1968
  request['quantity'] = this.parseToNumeric(this.amountToPrecision(symbol, amount));
1968
- params = this.omit(params, ['reduceOnly', 'triggerPrice', 'stopLossPrice', 'takeProfitPrice', 'trailingAmount', 'trailingPercent', 'takeProfit', 'stopLoss', 'clientOrderId']);
1969
+ params = this.omit(params, ['reduceOnly', 'triggerPrice', 'stopLossPrice', 'takeProfitPrice', 'trailingAmount', 'trailingPercent', 'trailingType', 'takeProfit', 'stopLoss', 'clientOrderId']);
1969
1970
  }
1970
1971
  return this.extend(request, params);
1971
1972
  }
@@ -1996,14 +1997,22 @@ class bingx extends bingx$1 {
1996
1997
  * @param {float} [params.takeProfit.triggerPrice] take profit trigger price
1997
1998
  * @param {object} [params.stopLoss] *stopLoss object in params* containing the triggerPrice at which the attached stop loss order will be triggered
1998
1999
  * @param {float} [params.stopLoss.triggerPrice] stop loss trigger price
2000
+ * @param {boolean} [params.test] *swap only* whether to use the test endpoint or not, default is false
1999
2001
  * @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
2000
2002
  */
2001
2003
  await this.loadMarkets();
2002
2004
  const market = this.market(symbol);
2005
+ const test = this.safeBool(params, 'test', false);
2006
+ params = this.omit(params, 'test');
2003
2007
  const request = this.createOrderRequest(symbol, type, side, amount, price, params);
2004
2008
  let response = undefined;
2005
2009
  if (market['swap']) {
2006
- response = await this.swapV2PrivatePostTradeOrder(request);
2010
+ if (test) {
2011
+ response = await this.swapV2PrivatePostTradeOrderTest(request);
2012
+ }
2013
+ else {
2014
+ response = await this.swapV2PrivatePostTradeOrder(request);
2015
+ }
2007
2016
  }
2008
2017
  else {
2009
2018
  response = await this.spotV1PrivatePostTradeOrder(request);
@@ -2086,7 +2095,7 @@ class bingx extends bingx$1 {
2086
2095
  const side = this.safeString(rawOrder, 'side');
2087
2096
  const amount = this.safeNumber(rawOrder, 'amount');
2088
2097
  const price = this.safeNumber(rawOrder, 'price');
2089
- const orderParams = this.safeValue(rawOrder, 'params', {});
2098
+ const orderParams = this.safeDict(rawOrder, 'params', {});
2090
2099
  const orderRequest = this.createOrderRequest(marketId, type, side, amount, price, orderParams);
2091
2100
  ordersRequests.push(orderRequest);
2092
2101
  }
@@ -2146,8 +2155,8 @@ class bingx extends bingx$1 {
2146
2155
  // }
2147
2156
  // }
2148
2157
  //
2149
- const data = this.safeValue(response, 'data', {});
2150
- const result = this.safeValue(data, 'orders', []);
2158
+ const data = this.safeDict(response, 'data', {});
2159
+ const result = this.safeList(data, 'orders', []);
2151
2160
  return this.parseOrders(result, market);
2152
2161
  }
2153
2162
  parseOrderSide(side) {
@@ -2880,8 +2889,8 @@ class bingx extends bingx$1 {
2880
2889
  // }
2881
2890
  // }
2882
2891
  //
2883
- const data = this.safeValue(response, 'data', []);
2884
- const orders = this.safeValue(data, 'orders', []);
2892
+ const data = this.safeDict(response, 'data', {});
2893
+ const orders = this.safeList(data, 'orders', []);
2885
2894
  return this.parseOrders(orders, market, since, limit);
2886
2895
  }
2887
2896
  async fetchClosedOrders(symbol = undefined, since = undefined, limit = undefined, params = {}) {
@@ -2995,7 +3004,7 @@ class bingx extends bingx$1 {
2995
3004
  */
2996
3005
  await this.loadMarkets();
2997
3006
  const currency = this.currency(code);
2998
- const accountsByType = this.safeValue(this.options, 'accountsByType', {});
3007
+ const accountsByType = this.safeDict(this.options, 'accountsByType', {});
2999
3008
  const fromId = this.safeString(accountsByType, fromAccount, fromAccount);
3000
3009
  const toId = this.safeString(accountsByType, toAccount, toAccount);
3001
3010
  const request = {
@@ -3038,7 +3047,7 @@ class bingx extends bingx$1 {
3038
3047
  if (code !== undefined) {
3039
3048
  currency = this.currency(code);
3040
3049
  }
3041
- const accountsByType = this.safeValue(this.options, 'accountsByType', {});
3050
+ const accountsByType = this.safeDict(this.options, 'accountsByType', {});
3042
3051
  const fromAccount = this.safeString(params, 'fromAccount');
3043
3052
  const toAccount = this.safeString(params, 'toAccount');
3044
3053
  const fromId = this.safeString(accountsByType, fromAccount, fromAccount);
@@ -3071,7 +3080,7 @@ class bingx extends bingx$1 {
3071
3080
  // ]
3072
3081
  // }
3073
3082
  //
3074
- const rows = this.safeValue(response, 'rows', []);
3083
+ const rows = this.safeList(response, 'rows', []);
3075
3084
  return this.parseTransfers(rows, currency, since, limit);
3076
3085
  }
3077
3086
  parseTransfer(transfer, currency = undefined) {
@@ -3079,7 +3088,7 @@ class bingx extends bingx$1 {
3079
3088
  const timestamp = this.safeInteger(transfer, 'timestamp');
3080
3089
  const currencyCode = this.safeCurrencyCode(undefined, currency);
3081
3090
  const status = this.safeString(transfer, 'status');
3082
- const accountsById = this.safeValue(this.options, 'accountsById', {});
3091
+ const accountsById = this.safeDict(this.options, 'accountsById', {});
3083
3092
  const typeId = this.safeString(transfer, 'type');
3084
3093
  const typeIdSplit = typeId.split('_');
3085
3094
  const fromId = this.safeString(typeIdSplit, 0);
@@ -3137,7 +3146,7 @@ class bingx extends bingx$1 {
3137
3146
  // }
3138
3147
  // }
3139
3148
  //
3140
- const data = this.safeValue(this.safeValue(response, 'data'), 'data');
3149
+ const data = this.safeList(this.safeDict(response, 'data'), 'data');
3141
3150
  const parsed = this.parseDepositAddresses(data, [currency['code']], false);
3142
3151
  return this.indexBy(parsed, 'network');
3143
3152
  }
@@ -3590,8 +3599,8 @@ class bingx extends bingx$1 {
3590
3599
  let fills = undefined;
3591
3600
  if (market['spot']) {
3592
3601
  response = await this.spotV1PrivateGetTradeMyTrades(this.extend(request, params));
3593
- const data = this.safeValue(response, 'data', []);
3594
- fills = this.safeValue(data, 'fills', []);
3602
+ const data = this.safeDict(response, 'data', {});
3603
+ fills = this.safeList(data, 'fills', []);
3595
3604
  //
3596
3605
  // {
3597
3606
  // "code": 0,
@@ -3622,8 +3631,8 @@ class bingx extends bingx$1 {
3622
3631
  params = this.omit(params, 'tradingUnit');
3623
3632
  request['tradingUnit'] = tradingUnit;
3624
3633
  response = await this.swapV2PrivateGetTradeAllFillOrders(this.extend(request, params));
3625
- const data = this.safeValue(response, 'data', []);
3626
- fills = this.safeValue(data, 'fill_orders', []);
3634
+ const data = this.safeDict(response, 'data', {});
3635
+ fills = this.safeList(data, 'fill_orders', []);
3627
3636
  //
3628
3637
  // {
3629
3638
  // "code": "0",
@@ -3676,7 +3685,7 @@ class bingx extends bingx$1 {
3676
3685
  // ]
3677
3686
  // }
3678
3687
  //
3679
- const networkList = this.safeValue(fee, 'networkList', []);
3688
+ const networkList = this.safeList(fee, 'networkList', []);
3680
3689
  const networkListLength = networkList.length;
3681
3690
  const result = {
3682
3691
  'info': fee,
@@ -3694,7 +3703,7 @@ class bingx extends bingx$1 {
3694
3703
  for (let i = 0; i < networkListLength; i++) {
3695
3704
  const network = networkList[i];
3696
3705
  const networkId = this.safeString(network, 'network');
3697
- const isDefault = this.safeValue(network, 'isDefault');
3706
+ const isDefault = this.safeBool(network, 'isDefault');
3698
3707
  const currencyCode = this.safeString(currency, 'code');
3699
3708
  const networkCode = this.networkIdToCode(networkId, currencyCode);
3700
3709
  result['networks'][networkCode] = {
@@ -3849,8 +3858,8 @@ class bingx extends bingx$1 {
3849
3858
  // }
3850
3859
  // }
3851
3860
  //
3852
- const data = this.safeValue(response, 'data', {});
3853
- const liquidations = this.safeValue(data, 'orders', []);
3861
+ const data = this.safeDict(response, 'data', {});
3862
+ const liquidations = this.safeList(data, 'orders', []);
3854
3863
  return this.parseLiquidations(liquidations, market, since, limit);
3855
3864
  }
3856
3865
  parseLiquidation(liquidation, market = undefined) {
@@ -3923,7 +3932,7 @@ class bingx extends bingx$1 {
3923
3932
  // }
3924
3933
  // }
3925
3934
  //
3926
- const data = this.safeValue(response, 'data');
3935
+ const data = this.safeDict(response, 'data');
3927
3936
  return this.parseOrder(data);
3928
3937
  }
3929
3938
  async closeAllPositions(params = {}) {
@@ -3961,8 +3970,8 @@ class bingx extends bingx$1 {
3961
3970
  // }
3962
3971
  // }
3963
3972
  //
3964
- const data = this.safeValue(response, 'data', {});
3965
- const success = this.safeValue(data, 'success', []);
3973
+ const data = this.safeDict(response, 'data', {});
3974
+ const success = this.safeList(data, 'success', []);
3966
3975
  const positions = [];
3967
3976
  for (let i = 0; i < success.length; i++) {
3968
3977
  const position = this.parsePosition({ 'positionId': success[i] });
@@ -4057,7 +4066,7 @@ class bingx extends bingx$1 {
4057
4066
  * @param {string} [params.newClientOrderId] custom order id consisting of letters, numbers, and _, 1-40 characters, different orders cannot use the same newClientOrderId.
4058
4067
  * @param {string} [params.positionSide] *contract only* position direction, required for single position as BOTH, for both long and short positions only LONG or SHORT can be chosen, defaults to LONG if empty
4059
4068
  * @param {string} [params.reduceOnly] *contract only* true or false, default=false for single position mode. this parameter is not accepted for both long and short positions mode
4060
- * @param {float} [params.priceRate] *contract only* for type TRAILING_STOP_Market, Max = 1
4069
+ * @param {float} [params.priceRate] *contract only* for type TRAILING_STOP_Market or TRAILING_TP_SL, Max = 1
4061
4070
  * @param {string} [params.workingType] *contract only* StopPrice trigger price types, MARK_PRICE (default), CONTRACT_PRICE, or INDEX_PRICE
4062
4071
  * @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
4063
4072
  */
@@ -4175,7 +4184,7 @@ class bingx extends bingx$1 {
4175
4184
  * @see https://bingx-api.github.io/docs/#/en-us/swapV2/trade-api.html#Query%20Margin%20Mode
4176
4185
  * @param {string} symbol unified symbol of the market to fetch the margin mode for
4177
4186
  * @param {object} [params] extra parameters specific to the exchange API endpoint
4178
- * @returns {object} Struct of MarginMode
4187
+ * @returns {object} a [margin mode structure]{@link https://docs.ccxt.com/#/?id=margin-mode-structure}
4179
4188
  */
4180
4189
  await this.loadMarkets();
4181
4190
  const market = this.market(symbol);