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/README.md CHANGED
@@ -209,13 +209,13 @@ console.log(version, Object.keys(exchanges));
209
209
 
210
210
  All-in-one browser bundle (dependencies included), served from a CDN of your choice:
211
211
 
212
- * jsDelivr: https://cdn.jsdelivr.net/npm/ccxt@4.1.82/dist/ccxt.browser.js
213
- * unpkg: https://unpkg.com/ccxt@4.1.82/dist/ccxt.browser.js
212
+ * jsDelivr: https://cdn.jsdelivr.net/npm/ccxt@4.1.84/dist/ccxt.browser.js
213
+ * unpkg: https://unpkg.com/ccxt@4.1.84/dist/ccxt.browser.js
214
214
 
215
215
  CDNs are not updated in real-time and may have delays. Defaulting to the most recent version without specifying the version number is not recommended. Please, keep in mind that we are not responsible for the correct operation of those CDN servers.
216
216
 
217
217
  ```HTML
218
- <script type="text/javascript" src="https://cdn.jsdelivr.net/npm/ccxt@4.1.82/dist/ccxt.browser.js"></script>
218
+ <script type="text/javascript" src="https://cdn.jsdelivr.net/npm/ccxt@4.1.84/dist/ccxt.browser.js"></script>
219
219
  ```
220
220
 
221
221
  Creates a global `ccxt` object:
@@ -10683,7 +10683,7 @@ class Exchange {
10683
10683
  async fetchFundingHistory(symbol = undefined, since = undefined, limit = undefined, params = {}) {
10684
10684
  throw new _errors_js__WEBPACK_IMPORTED_MODULE_3__.NotSupported(this.id + ' fetchFundingHistory() is not supported yet');
10685
10685
  }
10686
- async closePosition(symbol, side = undefined, marginMode = undefined, params = {}) {
10686
+ async closePosition(symbol, side = undefined, params = {}) {
10687
10687
  throw new _errors_js__WEBPACK_IMPORTED_MODULE_3__.NotSupported(this.id + ' closePositions() is not supported yet');
10688
10688
  }
10689
10689
  async closeAllPositions(params = {}) {
@@ -25587,7 +25587,7 @@ class binance extends _abstract_binance_js__WEBPACK_IMPORTED_MODULE_0__/* ["defa
25587
25587
  extendedParams = this.omit(extendedParams, ['orderidlist', 'origclientorderidlist']);
25588
25588
  query = this.rawencode(extendedParams);
25589
25589
  const orderidlistLength = orderidlist.length;
25590
- const origclientorderidlistLength = orderidlist.length;
25590
+ const origclientorderidlistLength = origclientorderidlist.length;
25591
25591
  if (orderidlistLength > 0) {
25592
25592
  query = query + '&' + 'orderidlist=[' + orderidlist.join(',') + ']';
25593
25593
  }
@@ -30279,7 +30279,7 @@ class bingx extends _abstract_bingx_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"
30279
30279
  * @see https://bitgetlimited.github.io/apidoc/en/mix/#close-all-position
30280
30280
  * @param {object} [params] extra parameters specific to the okx api endpoint
30281
30281
  * @param {string} [params.recvWindow] request valid time window value
30282
- * @returns {[object]} [A list of position structures]{@link https://docs.ccxt.com/#/?id=position-structure}
30282
+ * @returns {object[]} [A list of position structures]{@link https://docs.ccxt.com/#/?id=position-structure}
30283
30283
  */
30284
30284
  await this.loadMarkets();
30285
30285
  const defaultRecvWindow = this.safeInteger(this.options, 'recvWindow');
@@ -47223,7 +47223,7 @@ class bitget extends _abstract_bitget_js__WEBPACK_IMPORTED_MODULE_0__/* ["defaul
47223
47223
  * @param {object} [params] extra parameters specific to the okx api endpoint
47224
47224
  * @param {string} [params.subType] 'linear' or 'inverse'
47225
47225
  * @param {string} [params.settle] *required and only valid when params.subType === "linear"* 'USDT' or 'USDC'
47226
- * @returns {[object]} [A list of position structures]{@link https://docs.ccxt.com/#/?id=position-structure}
47226
+ * @returns {object[]} [A list of position structures]{@link https://docs.ccxt.com/#/?id=position-structure}
47227
47227
  */
47228
47228
  await this.loadMarkets();
47229
47229
  let subType = undefined;
@@ -81908,9 +81908,11 @@ class bybit extends _abstract_bybit_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"
81908
81908
  else if (symbolsLength === 1) {
81909
81909
  symbol = symbols[0];
81910
81910
  }
81911
+ symbols = this.marketSymbols(symbols);
81911
81912
  }
81912
81913
  else if (symbols !== undefined) {
81913
81914
  symbol = symbols;
81915
+ symbols = [this.symbol(symbol)];
81914
81916
  }
81915
81917
  await this.loadMarkets();
81916
81918
  const [enableUnifiedMargin, enableUnifiedAccount] = await this.isUnifiedEnabled();
@@ -81920,14 +81922,12 @@ class bybit extends _abstract_bybit_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"
81920
81922
  let isUsdcSettled = false;
81921
81923
  if (symbol !== undefined) {
81922
81924
  market = this.market(symbol);
81925
+ symbol = market['symbol'];
81923
81926
  request['symbol'] = market['id'];
81924
81927
  isUsdcSettled = market['settle'] === 'USDC';
81925
81928
  }
81926
81929
  let type = undefined;
81927
81930
  [type, params] = this.getBybitType('fetchPositions', market, params);
81928
- if (type === 'spot') {
81929
- throw new _base_errors_js__WEBPACK_IMPORTED_MODULE_1__.NotSupported(this.id + ' fetchPositions() not support spot market');
81930
- }
81931
81931
  if (type === 'linear' || type === 'inverse') {
81932
81932
  const baseCoin = this.safeString(params, 'baseCoin');
81933
81933
  if (type === 'linear') {
@@ -83818,6 +83818,9 @@ class cex extends _abstract_cex_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */
83818
83818
  'cancelOrder': true,
83819
83819
  'cancelOrders': false,
83820
83820
  'createDepositAddress': false,
83821
+ 'createMarketBuyOrderWithCost': true,
83822
+ 'createMarketOrderWithCost': false,
83823
+ 'createMarketSellOrderWithCost': false,
83821
83824
  'createOrder': true,
83822
83825
  'createStopLimitOrder': false,
83823
83826
  'createStopMarketOrder': false,
@@ -84536,31 +84539,46 @@ class cex extends _abstract_cex_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */
84536
84539
  * @param {float} amount how much of currency you want to trade in units of base currency
84537
84540
  * @param {float} [price] the price at which the order is to be fullfilled, in units of the quote currency, ignored in market orders
84538
84541
  * @param {object} [params] extra parameters specific to the exchange API endpoint
84542
+ * @param {float} [params.cost] the quote quantity that can be used as an alternative for the amount for market buy orders
84539
84543
  * @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
84540
84544
  */
84545
+ await this.loadMarkets();
84546
+ const market = this.market(symbol);
84547
+ const request = {
84548
+ 'pair': market['id'],
84549
+ 'type': side,
84550
+ };
84541
84551
  // for market buy it requires the amount of quote currency to spend
84542
84552
  if ((type === 'market') && (side === 'buy')) {
84543
- if (this.options['createMarketBuyOrderRequiresPrice']) {
84553
+ let quoteAmount = undefined;
84554
+ let createMarketBuyOrderRequiresPrice = true;
84555
+ [createMarketBuyOrderRequiresPrice, params] = this.handleOptionAndParams(params, 'createOrder', 'createMarketBuyOrderRequiresPrice', true);
84556
+ const cost = this.safeString(params, 'cost');
84557
+ params = this.omit(params, 'cost');
84558
+ if (cost !== undefined) {
84559
+ quoteAmount = this.costToPrecision(symbol, cost);
84560
+ }
84561
+ else if (createMarketBuyOrderRequiresPrice) {
84544
84562
  if (price === undefined) {
84545
- throw new _base_errors_js__WEBPACK_IMPORTED_MODULE_2__.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)");
84563
+ throw new _base_errors_js__WEBPACK_IMPORTED_MODULE_2__.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');
84546
84564
  }
84547
84565
  else {
84548
84566
  const amountString = this.numberToString(amount);
84549
84567
  const priceString = this.numberToString(price);
84550
- const baseAmount = _base_Precise_js__WEBPACK_IMPORTED_MODULE_3__/* .Precise */ .O.stringMul(amountString, priceString);
84551
- amount = this.parseNumber(baseAmount);
84568
+ const costRequest = _base_Precise_js__WEBPACK_IMPORTED_MODULE_3__/* .Precise */ .O.stringMul(amountString, priceString);
84569
+ quoteAmount = this.costToPrecision(symbol, costRequest);
84552
84570
  }
84553
84571
  }
84572
+ else {
84573
+ quoteAmount = this.costToPrecision(symbol, amount);
84574
+ }
84575
+ request['amount'] = quoteAmount;
84576
+ }
84577
+ else {
84578
+ request['amount'] = this.amountToPrecision(symbol, amount);
84554
84579
  }
84555
- await this.loadMarkets();
84556
- const market = this.market(symbol);
84557
- const request = {
84558
- 'pair': market['id'],
84559
- 'type': side,
84560
- 'amount': amount,
84561
- };
84562
84580
  if (type === 'limit') {
84563
- request['price'] = price;
84581
+ request['price'] = this.numberToString(price);
84564
84582
  }
84565
84583
  else {
84566
84584
  request['order_type'] = type;
@@ -101204,6 +101222,9 @@ class coinsph extends _abstract_coinsph_js__WEBPACK_IMPORTED_MODULE_0__/* ["defa
101204
101222
  'closeAllPositions': false,
101205
101223
  'closePosition': false,
101206
101224
  'createDepositAddress': false,
101225
+ 'createMarketBuyOrderWithCost': true,
101226
+ 'createMarketOrderWithCost': false,
101227
+ 'createMarketSellOrderWithCost': false,
101207
101228
  'createOrder': true,
101208
101229
  'createPostOnlyOrder': false,
101209
101230
  'createReduceOnlyOrder': false,
@@ -102231,12 +102252,14 @@ class coinsph extends _abstract_coinsph_js__WEBPACK_IMPORTED_MODULE_0__/* ["defa
102231
102252
  * @method
102232
102253
  * @name coinsph#createOrder
102233
102254
  * @description create a trade order
102255
+ * @see https://coins-docs.github.io/rest-api/#new-order--trade
102234
102256
  * @param {string} symbol unified symbol of the market to create an order in
102235
102257
  * @param {string} type 'market', 'limit', 'stop_loss', 'take_profit', 'stop_loss_limit', 'take_profit_limit' or 'limit_maker'
102236
102258
  * @param {string} side 'buy' or 'sell'
102237
102259
  * @param {float} amount how much of currency you want to trade in units of base currency
102238
102260
  * @param {float} [price] the price at which the order is to be fullfilled, in units of the quote currency, ignored in market orders
102239
102261
  * @param {object} [params] extra parameters specific to the exchange API endpoint
102262
+ * @param {float} [params.cost] the quote quantity that can be used as an alternative for the amount for market buy orders
102240
102263
  * @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
102241
102264
  */
102242
102265
  // todo: add test order low priority
@@ -102272,24 +102295,29 @@ class coinsph extends _abstract_coinsph_js__WEBPACK_IMPORTED_MODULE_0__/* ["defa
102272
102295
  request['quantity'] = this.amountToPrecision(symbol, amount);
102273
102296
  }
102274
102297
  else if (orderSide === 'BUY') {
102275
- const quoteOrderQty = this.safeNumber2(params, 'cost', 'quoteOrderQty');
102276
- const createMarketBuyOrderRequiresPrice = this.safeValue(this.options, 'createMarketBuyOrderRequiresPrice', true);
102277
- if (quoteOrderQty !== undefined) {
102278
- amount = quoteOrderQty;
102298
+ let quoteAmount = undefined;
102299
+ let createMarketBuyOrderRequiresPrice = true;
102300
+ [createMarketBuyOrderRequiresPrice, params] = this.handleOptionAndParams(params, 'createOrder', 'createMarketBuyOrderRequiresPrice', true);
102301
+ const cost = this.safeNumber2(params, 'cost', 'quoteOrderQty');
102302
+ params = this.omit(params, 'cost');
102303
+ if (cost !== undefined) {
102304
+ quoteAmount = this.costToPrecision(symbol, cost);
102279
102305
  }
102280
102306
  else if (createMarketBuyOrderRequiresPrice) {
102281
102307
  if (price === undefined) {
102282
- throw new _base_errors_js__WEBPACK_IMPORTED_MODULE_2__.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)");
102308
+ throw new _base_errors_js__WEBPACK_IMPORTED_MODULE_2__.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');
102283
102309
  }
102284
102310
  else {
102285
102311
  const amountString = this.numberToString(amount);
102286
102312
  const priceString = this.numberToString(price);
102287
- const quoteAmount = _base_Precise_js__WEBPACK_IMPORTED_MODULE_3__/* .Precise */ .O.stringMul(amountString, priceString);
102288
- amount = this.parseNumber(quoteAmount);
102313
+ const costRequest = _base_Precise_js__WEBPACK_IMPORTED_MODULE_3__/* .Precise */ .O.stringMul(amountString, priceString);
102314
+ quoteAmount = this.costToPrecision(symbol, costRequest);
102289
102315
  }
102290
102316
  }
102291
- request['quoteOrderQty'] = this.costToPrecision(symbol, amount);
102292
- params = this.omit(params, 'cost', 'quoteOrderQty');
102317
+ else {
102318
+ quoteAmount = this.costToPrecision(symbol, amount);
102319
+ }
102320
+ request['quoteOrderQty'] = quoteAmount;
102293
102321
  }
102294
102322
  }
102295
102323
  if (orderType === 'STOP_LOSS' || orderType === 'STOP_LOSS_LIMIT' || orderType === 'TAKE_PROFIT' || orderType === 'TAKE_PROFIT_LIMIT') {
@@ -103705,6 +103733,8 @@ class cryptocom extends _abstract_cryptocom_js__WEBPACK_IMPORTED_MODULE_0__/* ["
103705
103733
  'cancelAllOrders': true,
103706
103734
  'cancelOrder': true,
103707
103735
  'cancelOrders': true,
103736
+ 'closeAllPositions': false,
103737
+ 'closePosition': true,
103708
103738
  'createOrder': true,
103709
103739
  'createOrders': true,
103710
103740
  'fetchAccounts': true,
@@ -106560,6 +106590,51 @@ class cryptocom extends _abstract_cryptocom_js__WEBPACK_IMPORTED_MODULE_0__/* ["
106560
106590
  }
106561
106591
  return returnString;
106562
106592
  }
106593
+ async closePosition(symbol, side = undefined, params = {}) {
106594
+ /**
106595
+ * @method
106596
+ * @name cryptocom#closePositions
106597
+ * @description closes open positions for a market
106598
+ * @see https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html#private-close-position
106599
+ * @param {string} symbol Unified CCXT market symbol
106600
+ * @param {string} [marginMode] not used by cryptocom.closePositions
106601
+ * @param {string} [side] not used by cryptocom.closePositions
106602
+ * @param {object} [params] extra parameters specific to the okx api endpoint
106603
+ *
106604
+ * EXCHANGE SPECIFIC PARAMETERS
106605
+ * @param {string} [params.type] LIMIT or MARKET
106606
+ * @param {number} [params.price] for limit orders only
106607
+ * @returns {object[]} [A list of position structures]{@link https://docs.ccxt.com/#/?id=position-structure}
106608
+ */
106609
+ await this.loadMarkets();
106610
+ const market = this.market(symbol);
106611
+ const request = {
106612
+ 'instrument_name': market['id'],
106613
+ 'type': 'MARKET',
106614
+ };
106615
+ const type = this.safeStringUpper(params, 'type');
106616
+ const price = this.safeString(params, 'price');
106617
+ if (type !== undefined) {
106618
+ request['type'] = type;
106619
+ }
106620
+ if (price !== undefined) {
106621
+ request['price'] = this.priceToPrecision(market['symbol'], price);
106622
+ }
106623
+ const response = await this.v1PrivatePostPrivateClosePosition(this.extend(request, params));
106624
+ //
106625
+ // {
106626
+ // "id" : 1700830813298,
106627
+ // "method" : "private/close-position",
106628
+ // "code" : 0,
106629
+ // "result" : {
106630
+ // "client_oid" : "179a909d-5614-655b-0d0e-9e85c9a25c85",
106631
+ // "order_id" : "6142909897021751347"
106632
+ // }
106633
+ // }
106634
+ //
106635
+ const result = this.safeValue(response, 'result');
106636
+ return this.parseOrder(result, market);
106637
+ }
106563
106638
  sign(path, api = 'public', method = 'GET', params = {}, headers = undefined, body = undefined) {
106564
106639
  const type = this.safeString(api, 0);
106565
106640
  const access = this.safeString(api, 1);
@@ -136580,6 +136655,9 @@ class htx extends _abstract_htx_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */
136580
136655
  'cancelOrder': true,
136581
136656
  'cancelOrders': true,
136582
136657
  'createDepositAddress': undefined,
136658
+ 'createMarketBuyOrderWithCost': true,
136659
+ 'createMarketOrderWithCost': false,
136660
+ 'createMarketSellOrderWithCost': false,
136583
136661
  'createOrder': true,
136584
136662
  'createOrders': true,
136585
136663
  'createReduceOnlyOrder': false,
@@ -141382,6 +141460,25 @@ class htx extends _abstract_htx_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */
141382
141460
  'trades': trades,
141383
141461
  }, market);
141384
141462
  }
141463
+ async createMarketBuyOrderWithCost(symbol, cost, params = {}) {
141464
+ /**
141465
+ * @method
141466
+ * @name htx#createMarketBuyOrderWithCost
141467
+ * @description create a market buy order by providing the symbol and cost
141468
+ * @see https://www.htx.com/en-us/opend/newApiPages/?id=7ec4ee16-7773-11ed-9966-0242ac110003
141469
+ * @param {string} symbol unified symbol of the market to create an order in
141470
+ * @param {float} cost how much you want to trade in units of the quote currency
141471
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
141472
+ * @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
141473
+ */
141474
+ await this.loadMarkets();
141475
+ const market = this.market(symbol);
141476
+ if (!market['spot']) {
141477
+ throw new _base_errors_js__WEBPACK_IMPORTED_MODULE_1__.NotSupported(this.id + ' createMarketBuyOrderWithCost() supports spot orders only');
141478
+ }
141479
+ params['createMarketBuyOrderRequiresPrice'] = false;
141480
+ return await this.createOrder(symbol, 'market', 'buy', cost, undefined, params);
141481
+ }
141385
141482
  async createSpotOrderRequest(symbol, type, side, amount, price = undefined, params = {}) {
141386
141483
  /**
141387
141484
  * @method
@@ -141395,6 +141492,7 @@ class htx extends _abstract_htx_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */
141395
141492
  * @param {float} [price] the price at which the order is to be fullfilled, in units of the quote currency, ignored in market orders
141396
141493
  * @param {object} [params] extra parameters specific to the exchange API endpoint
141397
141494
  * @param {string} [params.timeInForce] supports 'IOC' and 'FOK'
141495
+ * @param {float} [params.cost] the quote quantity that can be used as an alternative for the amount for market buy orders
141398
141496
  * @returns {object} request to be sent to the exchange
141399
141497
  */
141400
141498
  await this.loadMarkets();
@@ -141469,9 +141567,17 @@ class htx extends _abstract_htx_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */
141469
141567
  request['source'] = 'c2c-margin-api';
141470
141568
  }
141471
141569
  if ((orderType === 'market') && (side === 'buy')) {
141472
- if (this.options['createMarketBuyOrderRequiresPrice']) {
141570
+ let quoteAmount = undefined;
141571
+ let createMarketBuyOrderRequiresPrice = true;
141572
+ [createMarketBuyOrderRequiresPrice, params] = this.handleOptionAndParams(params, 'createOrder', 'createMarketBuyOrderRequiresPrice', true);
141573
+ const cost = this.safeNumber(params, 'cost');
141574
+ params = this.omit(params, 'cost');
141575
+ if (cost !== undefined) {
141576
+ quoteAmount = this.amountToPrecision(symbol, cost);
141577
+ }
141578
+ else if (createMarketBuyOrderRequiresPrice) {
141473
141579
  if (price === undefined) {
141474
- throw new _base_errors_js__WEBPACK_IMPORTED_MODULE_1__.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.");
141580
+ throw new _base_errors_js__WEBPACK_IMPORTED_MODULE_1__.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');
141475
141581
  }
141476
141582
  else {
141477
141583
  // despite that cost = amount * price is in quote currency and should have quote precision
@@ -141482,12 +141588,13 @@ class htx extends _abstract_htx_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */
141482
141588
  // we use amountToPrecision here because the exchange requires cost in base precision
141483
141589
  const amountString = this.numberToString(amount);
141484
141590
  const priceString = this.numberToString(price);
141485
- request['amount'] = this.costToPrecision(symbol, _base_Precise_js__WEBPACK_IMPORTED_MODULE_3__/* .Precise */ .O.stringMul(amountString, priceString));
141591
+ quoteAmount = this.amountToPrecision(symbol, _base_Precise_js__WEBPACK_IMPORTED_MODULE_3__/* .Precise */ .O.stringMul(amountString, priceString));
141486
141592
  }
141487
141593
  }
141488
141594
  else {
141489
- request['amount'] = this.costToPrecision(symbol, amount);
141595
+ quoteAmount = this.amountToPrecision(symbol, amount);
141490
141596
  }
141597
+ request['amount'] = quoteAmount;
141491
141598
  }
141492
141599
  else {
141493
141600
  request['amount'] = this.amountToPrecision(symbol, amount);
@@ -141619,6 +141726,7 @@ class htx extends _abstract_htx_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */
141619
141726
  * @param {bool} [params.postOnly] *contract only* true or false
141620
141727
  * @param {int} [params.leverRate] *contract only* required for all contract orders except tpsl, leverage greater than 20x requires prior approval of high-leverage agreement
141621
141728
  * @param {string} [params.timeInForce] supports 'IOC' and 'FOK'
141729
+ * @param {float} [params.cost] *spot market buy only* the quote quantity that can be used as an alternative for the amount
141622
141730
  * @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
141623
141731
  */
141624
141732
  await this.loadMarkets();
@@ -145338,6 +145446,9 @@ class huobijp extends _abstract_huobijp_js__WEBPACK_IMPORTED_MODULE_0__/* ["defa
145338
145446
  'cancelAllOrders': true,
145339
145447
  'cancelOrder': true,
145340
145448
  'cancelOrders': true,
145449
+ 'createMarketBuyOrderWithCost': true,
145450
+ 'createMarketOrderWithCost': false,
145451
+ 'createMarketSellOrderWithCost': false,
145341
145452
  'createOrder': true,
145342
145453
  'createStopLimitOrder': false,
145343
145454
  'createStopMarketOrder': false,
@@ -146662,6 +146773,24 @@ class huobijp extends _abstract_huobijp_js__WEBPACK_IMPORTED_MODULE_0__/* ["defa
146662
146773
  'trades': undefined,
146663
146774
  }, market);
146664
146775
  }
146776
+ async createMarketBuyOrderWithCost(symbol, cost, params = {}) {
146777
+ /**
146778
+ * @method
146779
+ * @name huobijp#createMarketBuyOrderWithCost
146780
+ * @description create a market buy order by providing the symbol and cost
146781
+ * @param {string} symbol unified symbol of the market to create an order in
146782
+ * @param {float} cost how much you want to trade in units of the quote currency
146783
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
146784
+ * @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
146785
+ */
146786
+ await this.loadMarkets();
146787
+ const market = this.market(symbol);
146788
+ if (!market['spot']) {
146789
+ throw new _base_errors_js__WEBPACK_IMPORTED_MODULE_2__.NotSupported(this.id + ' createMarketBuyOrderWithCost() supports spot orders only');
146790
+ }
146791
+ params['createMarketBuyOrderRequiresPrice'] = false;
146792
+ return await this.createOrder(symbol, 'market', 'buy', cost, undefined, params);
146793
+ }
146665
146794
  async createOrder(symbol, type, side, amount, price = undefined, params = {}) {
146666
146795
  /**
146667
146796
  * @method
@@ -146694,9 +146823,17 @@ class huobijp extends _abstract_huobijp_js__WEBPACK_IMPORTED_MODULE_0__/* ["defa
146694
146823
  }
146695
146824
  params = this.omit(params, ['clientOrderId', 'client-order-id']);
146696
146825
  if ((type === 'market') && (side === 'buy')) {
146697
- if (this.options['createMarketBuyOrderRequiresPrice']) {
146826
+ let quoteAmount = undefined;
146827
+ let createMarketBuyOrderRequiresPrice = true;
146828
+ [createMarketBuyOrderRequiresPrice, params] = this.handleOptionAndParams(params, 'createOrder', 'createMarketBuyOrderRequiresPrice', true);
146829
+ const cost = this.safeNumber(params, 'cost');
146830
+ params = this.omit(params, 'cost');
146831
+ if (cost !== undefined) {
146832
+ quoteAmount = this.amountToPrecision(symbol, cost);
146833
+ }
146834
+ else if (createMarketBuyOrderRequiresPrice) {
146698
146835
  if (price === undefined) {
146699
- throw new _base_errors_js__WEBPACK_IMPORTED_MODULE_2__.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.");
146836
+ throw new _base_errors_js__WEBPACK_IMPORTED_MODULE_2__.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');
146700
146837
  }
146701
146838
  else {
146702
146839
  // despite that cost = amount * price is in quote currency and should have quote precision
@@ -146707,13 +146844,13 @@ class huobijp extends _abstract_huobijp_js__WEBPACK_IMPORTED_MODULE_0__/* ["defa
146707
146844
  // we use amountToPrecision here because the exchange requires cost in base precision
146708
146845
  const amountString = this.numberToString(amount);
146709
146846
  const priceString = this.numberToString(price);
146710
- const baseAmount = _base_Precise_js__WEBPACK_IMPORTED_MODULE_3__/* .Precise */ .O.stringMul(amountString, priceString);
146711
- request['amount'] = this.costToPrecision(symbol, baseAmount);
146847
+ quoteAmount = this.amountToPrecision(symbol, _base_Precise_js__WEBPACK_IMPORTED_MODULE_3__/* .Precise */ .O.stringMul(amountString, priceString));
146712
146848
  }
146713
146849
  }
146714
146850
  else {
146715
- request['amount'] = this.costToPrecision(symbol, amount);
146851
+ quoteAmount = this.amountToPrecision(symbol, amount);
146716
146852
  }
146853
+ request['amount'] = quoteAmount;
146717
146854
  }
146718
146855
  else {
146719
146856
  request['amount'] = this.amountToPrecision(symbol, amount);
@@ -186175,6 +186312,8 @@ class okx extends _abstract_okx_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */
186175
186312
  'cancelAllOrders': false,
186176
186313
  'cancelOrder': true,
186177
186314
  'cancelOrders': true,
186315
+ 'closeAllPositions': false,
186316
+ 'closePosition': true,
186178
186317
  'createDepositAddress': false,
186179
186318
  'createMarketBuyOrderWithCost': true,
186180
186319
  'createMarketSellOrderWithCost': true,
@@ -193305,6 +193444,74 @@ class okx extends _abstract_okx_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */
193305
193444
  'info': greeks,
193306
193445
  };
193307
193446
  }
193447
+ async closePosition(symbol, side = undefined, params = {}) {
193448
+ /**
193449
+ * @method
193450
+ * @name okx#closePosition
193451
+ * @description closes open positions for a market
193452
+ * @see https://www.okx.com/docs-v5/en/#order-book-trading-trade-post-close-positions
193453
+ * @param {string} symbol Unified CCXT market symbol
193454
+ * @param {string} [side] 'buy' or 'sell', leave as undefined in net mode
193455
+ * @param {object} [params] extra parameters specific to the okx api endpoint
193456
+ * @param {string} [params.clientOrderId] a unique identifier for the order
193457
+ * @param {string} [params.marginMode] 'cross' or 'isolated', default is 'cross;
193458
+ * @param {string} [params.code] *required in the case of closing cross MARGIN position for Single-currency margin* margin currency
193459
+ *
193460
+ * EXCHANGE SPECIFIC PARAMETERS
193461
+ * @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
193462
+ * @param {string} [params.tag] order tag a combination of case-sensitive alphanumerics, all numbers, or all letters of up to 16 characters
193463
+ * @returns {[object]} [A list of position structures]{@link https://docs.ccxt.com/#/?id=position-structure}
193464
+ */
193465
+ await this.loadMarkets();
193466
+ const market = this.market(symbol);
193467
+ const clientOrderId = this.safeString(params, 'clientOrderId');
193468
+ const code = this.safeString(params, 'code');
193469
+ let marginMode = undefined;
193470
+ [marginMode, params] = this.handleMarginModeAndParams('closePosition', params, 'cross');
193471
+ const request = {
193472
+ 'instId': market['id'],
193473
+ 'mgnMode': marginMode,
193474
+ };
193475
+ if (side !== undefined) {
193476
+ if ((side === 'buy')) {
193477
+ request['posSide'] = 'long';
193478
+ }
193479
+ else if (side === 'sell') {
193480
+ request['posSide'] = 'short';
193481
+ }
193482
+ else {
193483
+ request['posSide'] = side;
193484
+ }
193485
+ }
193486
+ if (clientOrderId !== undefined) {
193487
+ request['clOrdId'] = clientOrderId;
193488
+ }
193489
+ if (code !== undefined) {
193490
+ const currency = this.currency(code);
193491
+ request['ccy'] = currency['id'];
193492
+ }
193493
+ const response = await this.privatePostTradeClosePosition(this.extend(request, params));
193494
+ //
193495
+ // {
193496
+ // "code": "1",
193497
+ // "data": [
193498
+ // {
193499
+ // "clOrdId":"e847386590ce4dBCe903bbc394dc88bf",
193500
+ // "ordId":"",
193501
+ // "sCode":"51000",
193502
+ // "sMsg":"Parameter posSide error ",
193503
+ // "tag":"e847386590ce4dBC"
193504
+ // }
193505
+ // ],
193506
+ // "inTime": "1701877077101064",
193507
+ // "msg": "All operations failed",
193508
+ // "outTime": "1701877077102579"
193509
+ // }
193510
+ //
193511
+ const data = this.safeValue(response, 'data');
193512
+ const order = this.safeValue(data, 0);
193513
+ return this.parseOrder(order, market);
193514
+ }
193308
193515
  handleErrors(httpCode, reason, url, method, headers, body, response, requestHeaders, requestBody) {
193309
193516
  if (!response) {
193310
193517
  return undefined; // fallback to default error handler
@@ -288832,7 +289039,7 @@ SOFTWARE.
288832
289039
 
288833
289040
  //-----------------------------------------------------------------------------
288834
289041
  // this is updated by vss.js when building
288835
- const version = '4.1.82';
289042
+ const version = '4.1.84';
288836
289043
  _src_base_Exchange_js__WEBPACK_IMPORTED_MODULE_0__/* .Exchange */ .e.ccxtVersion = version;
288837
289044
  //-----------------------------------------------------------------------------
288838
289045