ccxt 4.1.82 → 4.1.84

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cjs/ccxt.js CHANGED
@@ -172,7 +172,7 @@ var woo$1 = require('./src/pro/woo.js');
172
172
 
173
173
  //-----------------------------------------------------------------------------
174
174
  // this is updated by vss.js when building
175
- const version = '4.1.82';
175
+ const version = '4.1.84';
176
176
  Exchange["default"].ccxtVersion = version;
177
177
  const exchanges = {
178
178
  'ace': ace,
@@ -3700,7 +3700,7 @@ class Exchange {
3700
3700
  async fetchFundingHistory(symbol = undefined, since = undefined, limit = undefined, params = {}) {
3701
3701
  throw new errors.NotSupported(this.id + ' fetchFundingHistory() is not supported yet');
3702
3702
  }
3703
- async closePosition(symbol, side = undefined, marginMode = undefined, params = {}) {
3703
+ async closePosition(symbol, side = undefined, params = {}) {
3704
3704
  throw new errors.NotSupported(this.id + ' closePositions() is not supported yet');
3705
3705
  }
3706
3706
  async closeAllPositions(params = {}) {
@@ -8604,7 +8604,7 @@ class binance extends binance$1 {
8604
8604
  extendedParams = this.omit(extendedParams, ['orderidlist', 'origclientorderidlist']);
8605
8605
  query = this.rawencode(extendedParams);
8606
8606
  const orderidlistLength = orderidlist.length;
8607
- const origclientorderidlistLength = orderidlist.length;
8607
+ const origclientorderidlistLength = origclientorderidlist.length;
8608
8608
  if (orderidlistLength > 0) {
8609
8609
  query = query + '&' + 'orderidlist=[' + orderidlist.join(',') + ']';
8610
8610
  }
@@ -3369,7 +3369,7 @@ class bingx extends bingx$1 {
3369
3369
  * @see https://bitgetlimited.github.io/apidoc/en/mix/#close-all-position
3370
3370
  * @param {object} [params] extra parameters specific to the okx api endpoint
3371
3371
  * @param {string} [params.recvWindow] request valid time window value
3372
- * @returns {[object]} [A list of position structures]{@link https://docs.ccxt.com/#/?id=position-structure}
3372
+ * @returns {object[]} [A list of position structures]{@link https://docs.ccxt.com/#/?id=position-structure}
3373
3373
  */
3374
3374
  await this.loadMarkets();
3375
3375
  const defaultRecvWindow = this.safeInteger(this.options, 'recvWindow');
@@ -7020,7 +7020,7 @@ class bitget extends bitget$1 {
7020
7020
  * @param {object} [params] extra parameters specific to the okx api endpoint
7021
7021
  * @param {string} [params.subType] 'linear' or 'inverse'
7022
7022
  * @param {string} [params.settle] *required and only valid when params.subType === "linear"* 'USDT' or 'USDC'
7023
- * @returns {[object]} [A list of position structures]{@link https://docs.ccxt.com/#/?id=position-structure}
7023
+ * @returns {object[]} [A list of position structures]{@link https://docs.ccxt.com/#/?id=position-structure}
7024
7024
  */
7025
7025
  await this.loadMarkets();
7026
7026
  let subType = undefined;
@@ -5742,9 +5742,11 @@ class bybit extends bybit$1 {
5742
5742
  else if (symbolsLength === 1) {
5743
5743
  symbol = symbols[0];
5744
5744
  }
5745
+ symbols = this.marketSymbols(symbols);
5745
5746
  }
5746
5747
  else if (symbols !== undefined) {
5747
5748
  symbol = symbols;
5749
+ symbols = [this.symbol(symbol)];
5748
5750
  }
5749
5751
  await this.loadMarkets();
5750
5752
  const [enableUnifiedMargin, enableUnifiedAccount] = await this.isUnifiedEnabled();
@@ -5754,14 +5756,12 @@ class bybit extends bybit$1 {
5754
5756
  let isUsdcSettled = false;
5755
5757
  if (symbol !== undefined) {
5756
5758
  market = this.market(symbol);
5759
+ symbol = market['symbol'];
5757
5760
  request['symbol'] = market['id'];
5758
5761
  isUsdcSettled = market['settle'] === 'USDC';
5759
5762
  }
5760
5763
  let type = undefined;
5761
5764
  [type, params] = this.getBybitType('fetchPositions', market, params);
5762
- if (type === 'spot') {
5763
- throw new errors.NotSupported(this.id + ' fetchPositions() not support spot market');
5764
- }
5765
5765
  if (type === 'linear' || type === 'inverse') {
5766
5766
  const baseCoin = this.safeString(params, 'baseCoin');
5767
5767
  if (type === 'linear') {
@@ -32,6 +32,9 @@ class cex extends cex$1 {
32
32
  'cancelOrder': true,
33
33
  'cancelOrders': false,
34
34
  'createDepositAddress': false,
35
+ 'createMarketBuyOrderWithCost': true,
36
+ 'createMarketOrderWithCost': false,
37
+ 'createMarketSellOrderWithCost': false,
35
38
  'createOrder': true,
36
39
  'createStopLimitOrder': false,
37
40
  'createStopMarketOrder': false,
@@ -750,31 +753,46 @@ class cex extends cex$1 {
750
753
  * @param {float} amount how much of currency you want to trade in units of base currency
751
754
  * @param {float} [price] the price at which the order is to be fullfilled, in units of the quote currency, ignored in market orders
752
755
  * @param {object} [params] extra parameters specific to the exchange API endpoint
756
+ * @param {float} [params.cost] the quote quantity that can be used as an alternative for the amount for market buy orders
753
757
  * @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
754
758
  */
759
+ await this.loadMarkets();
760
+ const market = this.market(symbol);
761
+ const request = {
762
+ 'pair': market['id'],
763
+ 'type': side,
764
+ };
755
765
  // for market buy it requires the amount of quote currency to spend
756
766
  if ((type === 'market') && (side === 'buy')) {
757
- if (this.options['createMarketBuyOrderRequiresPrice']) {
767
+ let quoteAmount = undefined;
768
+ let createMarketBuyOrderRequiresPrice = true;
769
+ [createMarketBuyOrderRequiresPrice, params] = this.handleOptionAndParams(params, 'createOrder', 'createMarketBuyOrderRequiresPrice', true);
770
+ const cost = this.safeString(params, 'cost');
771
+ params = this.omit(params, 'cost');
772
+ if (cost !== undefined) {
773
+ quoteAmount = this.costToPrecision(symbol, cost);
774
+ }
775
+ else if (createMarketBuyOrderRequiresPrice) {
758
776
  if (price === undefined) {
759
- throw new errors.InvalidOrder(this.id + " createOrder() requires the price argument with market buy orders to calculate total order cost (amount to spend), where cost = amount * price. Supply a price argument to createOrder() call if you want the cost to be calculated for you from price and amount, or, alternatively, add .options['createMarketBuyOrderRequiresPrice'] = false to supply the cost in the amount argument (the exchange-specific behaviour)");
777
+ throw new errors.InvalidOrder(this.id + ' createOrder() requires the price argument for market buy orders to calculate the total cost to spend (amount * price), alternatively set the createMarketBuyOrderRequiresPrice option or param to false and pass the cost to spend in the amount argument');
760
778
  }
761
779
  else {
762
780
  const amountString = this.numberToString(amount);
763
781
  const priceString = this.numberToString(price);
764
- const baseAmount = Precise["default"].stringMul(amountString, priceString);
765
- amount = this.parseNumber(baseAmount);
782
+ const costRequest = Precise["default"].stringMul(amountString, priceString);
783
+ quoteAmount = this.costToPrecision(symbol, costRequest);
766
784
  }
767
785
  }
786
+ else {
787
+ quoteAmount = this.costToPrecision(symbol, amount);
788
+ }
789
+ request['amount'] = quoteAmount;
790
+ }
791
+ else {
792
+ request['amount'] = this.amountToPrecision(symbol, amount);
768
793
  }
769
- await this.loadMarkets();
770
- const market = this.market(symbol);
771
- const request = {
772
- 'pair': market['id'],
773
- 'type': side,
774
- 'amount': amount,
775
- };
776
794
  if (type === 'limit') {
777
- request['price'] = price;
795
+ request['price'] = this.numberToString(price);
778
796
  }
779
797
  else {
780
798
  request['order_type'] = type;
@@ -35,6 +35,9 @@ class coinsph extends coinsph$1 {
35
35
  'closeAllPositions': false,
36
36
  'closePosition': false,
37
37
  'createDepositAddress': false,
38
+ 'createMarketBuyOrderWithCost': true,
39
+ 'createMarketOrderWithCost': false,
40
+ 'createMarketSellOrderWithCost': false,
38
41
  'createOrder': true,
39
42
  'createPostOnlyOrder': false,
40
43
  'createReduceOnlyOrder': false,
@@ -1062,12 +1065,14 @@ class coinsph extends coinsph$1 {
1062
1065
  * @method
1063
1066
  * @name coinsph#createOrder
1064
1067
  * @description create a trade order
1068
+ * @see https://coins-docs.github.io/rest-api/#new-order--trade
1065
1069
  * @param {string} symbol unified symbol of the market to create an order in
1066
1070
  * @param {string} type 'market', 'limit', 'stop_loss', 'take_profit', 'stop_loss_limit', 'take_profit_limit' or 'limit_maker'
1067
1071
  * @param {string} side 'buy' or 'sell'
1068
1072
  * @param {float} amount how much of currency you want to trade in units of base currency
1069
1073
  * @param {float} [price] the price at which the order is to be fullfilled, in units of the quote currency, ignored in market orders
1070
1074
  * @param {object} [params] extra parameters specific to the exchange API endpoint
1075
+ * @param {float} [params.cost] the quote quantity that can be used as an alternative for the amount for market buy orders
1071
1076
  * @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
1072
1077
  */
1073
1078
  // todo: add test order low priority
@@ -1103,24 +1108,29 @@ class coinsph extends coinsph$1 {
1103
1108
  request['quantity'] = this.amountToPrecision(symbol, amount);
1104
1109
  }
1105
1110
  else if (orderSide === 'BUY') {
1106
- const quoteOrderQty = this.safeNumber2(params, 'cost', 'quoteOrderQty');
1107
- const createMarketBuyOrderRequiresPrice = this.safeValue(this.options, 'createMarketBuyOrderRequiresPrice', true);
1108
- if (quoteOrderQty !== undefined) {
1109
- amount = quoteOrderQty;
1111
+ let quoteAmount = undefined;
1112
+ let createMarketBuyOrderRequiresPrice = true;
1113
+ [createMarketBuyOrderRequiresPrice, params] = this.handleOptionAndParams(params, 'createOrder', 'createMarketBuyOrderRequiresPrice', true);
1114
+ const cost = this.safeNumber2(params, 'cost', 'quoteOrderQty');
1115
+ params = this.omit(params, 'cost');
1116
+ if (cost !== undefined) {
1117
+ quoteAmount = this.costToPrecision(symbol, cost);
1110
1118
  }
1111
1119
  else if (createMarketBuyOrderRequiresPrice) {
1112
1120
  if (price === undefined) {
1113
- throw new errors.InvalidOrder(this.id + " createOrder() requires the price argument with market buy orders to calculate total order cost (amount to spend), where cost = amount * price. Supply a price argument to createOrder() call if you want the cost to be calculated for you from price and amount, or, alternatively, add .options['createMarketBuyOrderRequiresPrice'] = false to supply the cost in the amount argument (the exchange-specific behaviour)");
1121
+ throw new errors.InvalidOrder(this.id + ' createOrder() requires the price argument for market buy orders to calculate the total cost to spend (amount * price), alternatively set the createMarketBuyOrderRequiresPrice option or param to false and pass the cost to spend in the amount argument');
1114
1122
  }
1115
1123
  else {
1116
1124
  const amountString = this.numberToString(amount);
1117
1125
  const priceString = this.numberToString(price);
1118
- const quoteAmount = Precise["default"].stringMul(amountString, priceString);
1119
- amount = this.parseNumber(quoteAmount);
1126
+ const costRequest = Precise["default"].stringMul(amountString, priceString);
1127
+ quoteAmount = this.costToPrecision(symbol, costRequest);
1120
1128
  }
1121
1129
  }
1122
- request['quoteOrderQty'] = this.costToPrecision(symbol, amount);
1123
- params = this.omit(params, 'cost', 'quoteOrderQty');
1130
+ else {
1131
+ quoteAmount = this.costToPrecision(symbol, amount);
1132
+ }
1133
+ request['quoteOrderQty'] = quoteAmount;
1124
1134
  }
1125
1135
  }
1126
1136
  if (orderType === 'STOP_LOSS' || orderType === 'STOP_LOSS_LIMIT' || orderType === 'TAKE_PROFIT' || orderType === 'TAKE_PROFIT_LIMIT') {
@@ -33,6 +33,8 @@ class cryptocom extends cryptocom$1 {
33
33
  'cancelAllOrders': true,
34
34
  'cancelOrder': true,
35
35
  'cancelOrders': true,
36
+ 'closeAllPositions': false,
37
+ 'closePosition': true,
36
38
  'createOrder': true,
37
39
  'createOrders': true,
38
40
  'fetchAccounts': true,
@@ -2888,6 +2890,51 @@ class cryptocom extends cryptocom$1 {
2888
2890
  }
2889
2891
  return returnString;
2890
2892
  }
2893
+ async closePosition(symbol, side = undefined, params = {}) {
2894
+ /**
2895
+ * @method
2896
+ * @name cryptocom#closePositions
2897
+ * @description closes open positions for a market
2898
+ * @see https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html#private-close-position
2899
+ * @param {string} symbol Unified CCXT market symbol
2900
+ * @param {string} [marginMode] not used by cryptocom.closePositions
2901
+ * @param {string} [side] not used by cryptocom.closePositions
2902
+ * @param {object} [params] extra parameters specific to the okx api endpoint
2903
+ *
2904
+ * EXCHANGE SPECIFIC PARAMETERS
2905
+ * @param {string} [params.type] LIMIT or MARKET
2906
+ * @param {number} [params.price] for limit orders only
2907
+ * @returns {object[]} [A list of position structures]{@link https://docs.ccxt.com/#/?id=position-structure}
2908
+ */
2909
+ await this.loadMarkets();
2910
+ const market = this.market(symbol);
2911
+ const request = {
2912
+ 'instrument_name': market['id'],
2913
+ 'type': 'MARKET',
2914
+ };
2915
+ const type = this.safeStringUpper(params, 'type');
2916
+ const price = this.safeString(params, 'price');
2917
+ if (type !== undefined) {
2918
+ request['type'] = type;
2919
+ }
2920
+ if (price !== undefined) {
2921
+ request['price'] = this.priceToPrecision(market['symbol'], price);
2922
+ }
2923
+ const response = await this.v1PrivatePostPrivateClosePosition(this.extend(request, params));
2924
+ //
2925
+ // {
2926
+ // "id" : 1700830813298,
2927
+ // "method" : "private/close-position",
2928
+ // "code" : 0,
2929
+ // "result" : {
2930
+ // "client_oid" : "179a909d-5614-655b-0d0e-9e85c9a25c85",
2931
+ // "order_id" : "6142909897021751347"
2932
+ // }
2933
+ // }
2934
+ //
2935
+ const result = this.safeValue(response, 'result');
2936
+ return this.parseOrder(result, market);
2937
+ }
2891
2938
  sign(path, api = 'public', method = 'GET', params = {}, headers = undefined, body = undefined) {
2892
2939
  const type = this.safeString(api, 0);
2893
2940
  const access = this.safeString(api, 1);
@@ -38,6 +38,9 @@ class htx extends htx$1 {
38
38
  'cancelOrder': true,
39
39
  'cancelOrders': true,
40
40
  'createDepositAddress': undefined,
41
+ 'createMarketBuyOrderWithCost': true,
42
+ 'createMarketOrderWithCost': false,
43
+ 'createMarketSellOrderWithCost': false,
41
44
  'createOrder': true,
42
45
  'createOrders': true,
43
46
  'createReduceOnlyOrder': false,
@@ -4840,6 +4843,25 @@ class htx extends htx$1 {
4840
4843
  'trades': trades,
4841
4844
  }, market);
4842
4845
  }
4846
+ async createMarketBuyOrderWithCost(symbol, cost, params = {}) {
4847
+ /**
4848
+ * @method
4849
+ * @name htx#createMarketBuyOrderWithCost
4850
+ * @description create a market buy order by providing the symbol and cost
4851
+ * @see https://www.htx.com/en-us/opend/newApiPages/?id=7ec4ee16-7773-11ed-9966-0242ac110003
4852
+ * @param {string} symbol unified symbol of the market to create an order in
4853
+ * @param {float} cost how much you want to trade in units of the quote currency
4854
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
4855
+ * @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
4856
+ */
4857
+ await this.loadMarkets();
4858
+ const market = this.market(symbol);
4859
+ if (!market['spot']) {
4860
+ throw new errors.NotSupported(this.id + ' createMarketBuyOrderWithCost() supports spot orders only');
4861
+ }
4862
+ params['createMarketBuyOrderRequiresPrice'] = false;
4863
+ return await this.createOrder(symbol, 'market', 'buy', cost, undefined, params);
4864
+ }
4843
4865
  async createSpotOrderRequest(symbol, type, side, amount, price = undefined, params = {}) {
4844
4866
  /**
4845
4867
  * @method
@@ -4853,6 +4875,7 @@ class htx extends htx$1 {
4853
4875
  * @param {float} [price] the price at which the order is to be fullfilled, in units of the quote currency, ignored in market orders
4854
4876
  * @param {object} [params] extra parameters specific to the exchange API endpoint
4855
4877
  * @param {string} [params.timeInForce] supports 'IOC' and 'FOK'
4878
+ * @param {float} [params.cost] the quote quantity that can be used as an alternative for the amount for market buy orders
4856
4879
  * @returns {object} request to be sent to the exchange
4857
4880
  */
4858
4881
  await this.loadMarkets();
@@ -4927,9 +4950,17 @@ class htx extends htx$1 {
4927
4950
  request['source'] = 'c2c-margin-api';
4928
4951
  }
4929
4952
  if ((orderType === 'market') && (side === 'buy')) {
4930
- if (this.options['createMarketBuyOrderRequiresPrice']) {
4953
+ let quoteAmount = undefined;
4954
+ let createMarketBuyOrderRequiresPrice = true;
4955
+ [createMarketBuyOrderRequiresPrice, params] = this.handleOptionAndParams(params, 'createOrder', 'createMarketBuyOrderRequiresPrice', true);
4956
+ const cost = this.safeNumber(params, 'cost');
4957
+ params = this.omit(params, 'cost');
4958
+ if (cost !== undefined) {
4959
+ quoteAmount = this.amountToPrecision(symbol, cost);
4960
+ }
4961
+ else if (createMarketBuyOrderRequiresPrice) {
4931
4962
  if (price === undefined) {
4932
- throw new errors.InvalidOrder(this.id + " market buy order requires price argument to calculate cost (total amount of quote currency to spend for buying, amount * price). To switch off this warning exception and specify cost in the amount argument, set .options['createMarketBuyOrderRequiresPrice'] = false. Make sure you know what you're doing.");
4963
+ throw new errors.InvalidOrder(this.id + ' createOrder() requires the price argument for market buy orders to calculate the total cost to spend (amount * price), alternatively set the createMarketBuyOrderRequiresPrice option or param to false and pass the cost to spend in the amount argument');
4933
4964
  }
4934
4965
  else {
4935
4966
  // despite that cost = amount * price is in quote currency and should have quote precision
@@ -4940,12 +4971,13 @@ class htx extends htx$1 {
4940
4971
  // we use amountToPrecision here because the exchange requires cost in base precision
4941
4972
  const amountString = this.numberToString(amount);
4942
4973
  const priceString = this.numberToString(price);
4943
- request['amount'] = this.costToPrecision(symbol, Precise["default"].stringMul(amountString, priceString));
4974
+ quoteAmount = this.amountToPrecision(symbol, Precise["default"].stringMul(amountString, priceString));
4944
4975
  }
4945
4976
  }
4946
4977
  else {
4947
- request['amount'] = this.costToPrecision(symbol, amount);
4978
+ quoteAmount = this.amountToPrecision(symbol, amount);
4948
4979
  }
4980
+ request['amount'] = quoteAmount;
4949
4981
  }
4950
4982
  else {
4951
4983
  request['amount'] = this.amountToPrecision(symbol, amount);
@@ -5077,6 +5109,7 @@ class htx extends htx$1 {
5077
5109
  * @param {bool} [params.postOnly] *contract only* true or false
5078
5110
  * @param {int} [params.leverRate] *contract only* required for all contract orders except tpsl, leverage greater than 20x requires prior approval of high-leverage agreement
5079
5111
  * @param {string} [params.timeInForce] supports 'IOC' and 'FOK'
5112
+ * @param {float} [params.cost] *spot market buy only* the quote quantity that can be used as an alternative for the amount
5080
5113
  * @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
5081
5114
  */
5082
5115
  await this.loadMarkets();
@@ -34,6 +34,9 @@ class huobijp extends huobijp$1 {
34
34
  'cancelAllOrders': true,
35
35
  'cancelOrder': true,
36
36
  'cancelOrders': true,
37
+ 'createMarketBuyOrderWithCost': true,
38
+ 'createMarketOrderWithCost': false,
39
+ 'createMarketSellOrderWithCost': false,
37
40
  'createOrder': true,
38
41
  'createStopLimitOrder': false,
39
42
  'createStopMarketOrder': false,
@@ -1358,6 +1361,24 @@ class huobijp extends huobijp$1 {
1358
1361
  'trades': undefined,
1359
1362
  }, market);
1360
1363
  }
1364
+ async createMarketBuyOrderWithCost(symbol, cost, params = {}) {
1365
+ /**
1366
+ * @method
1367
+ * @name huobijp#createMarketBuyOrderWithCost
1368
+ * @description create a market buy order by providing the symbol and cost
1369
+ * @param {string} symbol unified symbol of the market to create an order in
1370
+ * @param {float} cost how much you want to trade in units of the quote currency
1371
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
1372
+ * @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
1373
+ */
1374
+ await this.loadMarkets();
1375
+ const market = this.market(symbol);
1376
+ if (!market['spot']) {
1377
+ throw new errors.NotSupported(this.id + ' createMarketBuyOrderWithCost() supports spot orders only');
1378
+ }
1379
+ params['createMarketBuyOrderRequiresPrice'] = false;
1380
+ return await this.createOrder(symbol, 'market', 'buy', cost, undefined, params);
1381
+ }
1361
1382
  async createOrder(symbol, type, side, amount, price = undefined, params = {}) {
1362
1383
  /**
1363
1384
  * @method
@@ -1390,9 +1411,17 @@ class huobijp extends huobijp$1 {
1390
1411
  }
1391
1412
  params = this.omit(params, ['clientOrderId', 'client-order-id']);
1392
1413
  if ((type === 'market') && (side === 'buy')) {
1393
- if (this.options['createMarketBuyOrderRequiresPrice']) {
1414
+ let quoteAmount = undefined;
1415
+ let createMarketBuyOrderRequiresPrice = true;
1416
+ [createMarketBuyOrderRequiresPrice, params] = this.handleOptionAndParams(params, 'createOrder', 'createMarketBuyOrderRequiresPrice', true);
1417
+ const cost = this.safeNumber(params, 'cost');
1418
+ params = this.omit(params, 'cost');
1419
+ if (cost !== undefined) {
1420
+ quoteAmount = this.amountToPrecision(symbol, cost);
1421
+ }
1422
+ else if (createMarketBuyOrderRequiresPrice) {
1394
1423
  if (price === undefined) {
1395
- throw new errors.InvalidOrder(this.id + " market buy order requires price argument to calculate cost (total amount of quote currency to spend for buying, amount * price). To switch off this warning exception and specify cost in the amount argument, set .options['createMarketBuyOrderRequiresPrice'] = false. Make sure you know what you're doing.");
1424
+ throw new errors.InvalidOrder(this.id + ' createOrder() requires the price argument for market buy orders to calculate the total cost to spend (amount * price), alternatively set the createMarketBuyOrderRequiresPrice option or param to false and pass the cost to spend in the amount argument');
1396
1425
  }
1397
1426
  else {
1398
1427
  // despite that cost = amount * price is in quote currency and should have quote precision
@@ -1403,13 +1432,13 @@ class huobijp extends huobijp$1 {
1403
1432
  // we use amountToPrecision here because the exchange requires cost in base precision
1404
1433
  const amountString = this.numberToString(amount);
1405
1434
  const priceString = this.numberToString(price);
1406
- const baseAmount = Precise["default"].stringMul(amountString, priceString);
1407
- request['amount'] = this.costToPrecision(symbol, baseAmount);
1435
+ quoteAmount = this.amountToPrecision(symbol, Precise["default"].stringMul(amountString, priceString));
1408
1436
  }
1409
1437
  }
1410
1438
  else {
1411
- request['amount'] = this.costToPrecision(symbol, amount);
1439
+ quoteAmount = this.amountToPrecision(symbol, amount);
1412
1440
  }
1441
+ request['amount'] = quoteAmount;
1413
1442
  }
1414
1443
  else {
1415
1444
  request['amount'] = this.amountToPrecision(symbol, amount);
@@ -34,6 +34,8 @@ class okx extends okx$1 {
34
34
  'cancelAllOrders': false,
35
35
  'cancelOrder': true,
36
36
  'cancelOrders': true,
37
+ 'closeAllPositions': false,
38
+ 'closePosition': true,
37
39
  'createDepositAddress': false,
38
40
  'createMarketBuyOrderWithCost': true,
39
41
  'createMarketSellOrderWithCost': true,
@@ -7164,6 +7166,74 @@ class okx extends okx$1 {
7164
7166
  'info': greeks,
7165
7167
  };
7166
7168
  }
7169
+ async closePosition(symbol, side = undefined, params = {}) {
7170
+ /**
7171
+ * @method
7172
+ * @name okx#closePosition
7173
+ * @description closes open positions for a market
7174
+ * @see https://www.okx.com/docs-v5/en/#order-book-trading-trade-post-close-positions
7175
+ * @param {string} symbol Unified CCXT market symbol
7176
+ * @param {string} [side] 'buy' or 'sell', leave as undefined in net mode
7177
+ * @param {object} [params] extra parameters specific to the okx api endpoint
7178
+ * @param {string} [params.clientOrderId] a unique identifier for the order
7179
+ * @param {string} [params.marginMode] 'cross' or 'isolated', default is 'cross;
7180
+ * @param {string} [params.code] *required in the case of closing cross MARGIN position for Single-currency margin* margin currency
7181
+ *
7182
+ * EXCHANGE SPECIFIC PARAMETERS
7183
+ * @param {boolean} [params.autoCxl] whether any pending orders for closing out needs to be automatically canceled when close position via a market order. false or true, the default is false
7184
+ * @param {string} [params.tag] order tag a combination of case-sensitive alphanumerics, all numbers, or all letters of up to 16 characters
7185
+ * @returns {[object]} [A list of position structures]{@link https://docs.ccxt.com/#/?id=position-structure}
7186
+ */
7187
+ await this.loadMarkets();
7188
+ const market = this.market(symbol);
7189
+ const clientOrderId = this.safeString(params, 'clientOrderId');
7190
+ const code = this.safeString(params, 'code');
7191
+ let marginMode = undefined;
7192
+ [marginMode, params] = this.handleMarginModeAndParams('closePosition', params, 'cross');
7193
+ const request = {
7194
+ 'instId': market['id'],
7195
+ 'mgnMode': marginMode,
7196
+ };
7197
+ if (side !== undefined) {
7198
+ if ((side === 'buy')) {
7199
+ request['posSide'] = 'long';
7200
+ }
7201
+ else if (side === 'sell') {
7202
+ request['posSide'] = 'short';
7203
+ }
7204
+ else {
7205
+ request['posSide'] = side;
7206
+ }
7207
+ }
7208
+ if (clientOrderId !== undefined) {
7209
+ request['clOrdId'] = clientOrderId;
7210
+ }
7211
+ if (code !== undefined) {
7212
+ const currency = this.currency(code);
7213
+ request['ccy'] = currency['id'];
7214
+ }
7215
+ const response = await this.privatePostTradeClosePosition(this.extend(request, params));
7216
+ //
7217
+ // {
7218
+ // "code": "1",
7219
+ // "data": [
7220
+ // {
7221
+ // "clOrdId":"e847386590ce4dBCe903bbc394dc88bf",
7222
+ // "ordId":"",
7223
+ // "sCode":"51000",
7224
+ // "sMsg":"Parameter posSide error ",
7225
+ // "tag":"e847386590ce4dBC"
7226
+ // }
7227
+ // ],
7228
+ // "inTime": "1701877077101064",
7229
+ // "msg": "All operations failed",
7230
+ // "outTime": "1701877077102579"
7231
+ // }
7232
+ //
7233
+ const data = this.safeValue(response, 'data');
7234
+ const order = this.safeValue(data, 0);
7235
+ return this.parseOrder(order, market);
7236
+ }
7167
7237
  handleErrors(httpCode, reason, url, method, headers, body, response, requestHeaders, requestBody) {
7168
7238
  if (!response) {
7169
7239
  return undefined; // fallback to default error handler
package/js/ccxt.d.ts CHANGED
@@ -4,7 +4,7 @@ import * as functions from './src/base/functions.js';
4
4
  import * as errors from './src/base/errors.js';
5
5
  import { Market, Trade, Fee, Ticker, OrderBook, Order, Transaction, Tickers, Currency, Balance, DepositAddress, WithdrawalResponse, DepositAddressResponse, OHLCV, Balances, PartialBalances, Dictionary, MinMax, Position, FundingRateHistory, Liquidation, FundingHistory, MarginMode, Greeks } from './src/base/types.js';
6
6
  import { BaseError, ExchangeError, PermissionDenied, AccountNotEnabled, AccountSuspended, ArgumentsRequired, BadRequest, BadSymbol, MarginModeAlreadySet, BadResponse, NullResponse, InsufficientFunds, InvalidAddress, InvalidOrder, OrderNotFound, OrderNotCached, CancelPending, OrderImmediatelyFillable, OrderNotFillable, DuplicateOrderId, NotSupported, NetworkError, DDoSProtection, RateLimitExceeded, ExchangeNotAvailable, OnMaintenance, InvalidNonce, RequestTimeout, AuthenticationError, AddressPending, NoChange } from './src/base/errors.js';
7
- declare const version = "4.1.81";
7
+ declare const version = "4.1.83";
8
8
  import ace from './src/ace.js';
9
9
  import alpaca from './src/alpaca.js';
10
10
  import ascendex from './src/ascendex.js';
package/js/ccxt.js CHANGED
@@ -38,7 +38,7 @@ import * as errors from './src/base/errors.js';
38
38
  import { BaseError, ExchangeError, PermissionDenied, AccountNotEnabled, AccountSuspended, ArgumentsRequired, BadRequest, BadSymbol, MarginModeAlreadySet, BadResponse, NullResponse, InsufficientFunds, InvalidAddress, InvalidOrder, OrderNotFound, OrderNotCached, CancelPending, OrderImmediatelyFillable, OrderNotFillable, DuplicateOrderId, NotSupported, NetworkError, DDoSProtection, RateLimitExceeded, ExchangeNotAvailable, OnMaintenance, InvalidNonce, RequestTimeout, AuthenticationError, AddressPending, NoChange } from './src/base/errors.js';
39
39
  //-----------------------------------------------------------------------------
40
40
  // this is updated by vss.js when building
41
- const version = '4.1.82';
41
+ const version = '4.1.84';
42
42
  Exchange.ccxtVersion = version;
43
43
  //-----------------------------------------------------------------------------
44
44
  import ace from './src/ace.js';
@@ -792,7 +792,7 @@ export default class Exchange {
792
792
  fetchOpenInterest(symbol: string, params?: {}): Promise<OpenInterest>;
793
793
  fetchFundingRateHistory(symbol?: string, since?: Int, limit?: Int, params?: {}): Promise<FundingRateHistory[]>;
794
794
  fetchFundingHistory(symbol?: string, since?: Int, limit?: Int, params?: {}): Promise<FundingHistory[]>;
795
- closePosition(symbol: string, side?: OrderSide, marginMode?: string, params?: {}): Promise<Order>;
795
+ closePosition(symbol: string, side?: OrderSide, params?: {}): Promise<Order>;
796
796
  closeAllPositions(params?: {}): Promise<Position[]>;
797
797
  parseLastPrice(price: any, market?: Market): any;
798
798
  fetchDepositAddress(code: string, params?: {}): Promise<any>;
@@ -3696,7 +3696,7 @@ export default class Exchange {
3696
3696
  async fetchFundingHistory(symbol = undefined, since = undefined, limit = undefined, params = {}) {
3697
3697
  throw new NotSupported(this.id + ' fetchFundingHistory() is not supported yet');
3698
3698
  }
3699
- async closePosition(symbol, side = undefined, marginMode = undefined, params = {}) {
3699
+ async closePosition(symbol, side = undefined, params = {}) {
3700
3700
  throw new NotSupported(this.id + ' closePositions() is not supported yet');
3701
3701
  }
3702
3702
  async closeAllPositions(params = {}) {
package/js/src/binance.js CHANGED
@@ -8607,7 +8607,7 @@ export default class binance extends Exchange {
8607
8607
  extendedParams = this.omit(extendedParams, ['orderidlist', 'origclientorderidlist']);
8608
8608
  query = this.rawencode(extendedParams);
8609
8609
  const orderidlistLength = orderidlist.length;
8610
- const origclientorderidlistLength = orderidlist.length;
8610
+ const origclientorderidlistLength = origclientorderidlist.length;
8611
8611
  if (orderidlistLength > 0) {
8612
8612
  query = query + '&' + 'orderidlist=[' + orderidlist.join(',') + ']';
8613
8613
  }
package/js/src/bingx.js CHANGED
@@ -3372,7 +3372,7 @@ export default class bingx extends Exchange {
3372
3372
  * @see https://bitgetlimited.github.io/apidoc/en/mix/#close-all-position
3373
3373
  * @param {object} [params] extra parameters specific to the okx api endpoint
3374
3374
  * @param {string} [params.recvWindow] request valid time window value
3375
- * @returns {[object]} [A list of position structures]{@link https://docs.ccxt.com/#/?id=position-structure}
3375
+ * @returns {object[]} [A list of position structures]{@link https://docs.ccxt.com/#/?id=position-structure}
3376
3376
  */
3377
3377
  await this.loadMarkets();
3378
3378
  const defaultRecvWindow = this.safeInteger(this.options, 'recvWindow');
package/js/src/bitget.js CHANGED
@@ -7023,7 +7023,7 @@ export default class bitget extends Exchange {
7023
7023
  * @param {object} [params] extra parameters specific to the okx api endpoint
7024
7024
  * @param {string} [params.subType] 'linear' or 'inverse'
7025
7025
  * @param {string} [params.settle] *required and only valid when params.subType === "linear"* 'USDT' or 'USDC'
7026
- * @returns {[object]} [A list of position structures]{@link https://docs.ccxt.com/#/?id=position-structure}
7026
+ * @returns {object[]} [A list of position structures]{@link https://docs.ccxt.com/#/?id=position-structure}
7027
7027
  */
7028
7028
  await this.loadMarkets();
7029
7029
  let subType = undefined;
package/js/src/bybit.js CHANGED
@@ -5745,9 +5745,11 @@ export default class bybit extends Exchange {
5745
5745
  else if (symbolsLength === 1) {
5746
5746
  symbol = symbols[0];
5747
5747
  }
5748
+ symbols = this.marketSymbols(symbols);
5748
5749
  }
5749
5750
  else if (symbols !== undefined) {
5750
5751
  symbol = symbols;
5752
+ symbols = [this.symbol(symbol)];
5751
5753
  }
5752
5754
  await this.loadMarkets();
5753
5755
  const [enableUnifiedMargin, enableUnifiedAccount] = await this.isUnifiedEnabled();
@@ -5757,14 +5759,12 @@ export default class bybit extends Exchange {
5757
5759
  let isUsdcSettled = false;
5758
5760
  if (symbol !== undefined) {
5759
5761
  market = this.market(symbol);
5762
+ symbol = market['symbol'];
5760
5763
  request['symbol'] = market['id'];
5761
5764
  isUsdcSettled = market['settle'] === 'USDC';
5762
5765
  }
5763
5766
  let type = undefined;
5764
5767
  [type, params] = this.getBybitType('fetchPositions', market, params);
5765
- if (type === 'spot') {
5766
- throw new NotSupported(this.id + ' fetchPositions() not support spot market');
5767
- }
5768
5768
  if (type === 'linear' || type === 'inverse') {
5769
5769
  const baseCoin = this.safeString(params, 'baseCoin');
5770
5770
  if (type === 'linear') {