ccxt 4.1.82 → 4.1.83

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.83/dist/ccxt.browser.js
213
+ * unpkg: https://unpkg.com/ccxt@4.1.83/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.83/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 = {}) {
@@ -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;
@@ -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;
@@ -103705,6 +103723,8 @@ class cryptocom extends _abstract_cryptocom_js__WEBPACK_IMPORTED_MODULE_0__/* ["
103705
103723
  'cancelAllOrders': true,
103706
103724
  'cancelOrder': true,
103707
103725
  'cancelOrders': true,
103726
+ 'closeAllPositions': false,
103727
+ 'closePosition': true,
103708
103728
  'createOrder': true,
103709
103729
  'createOrders': true,
103710
103730
  'fetchAccounts': true,
@@ -106560,6 +106580,51 @@ class cryptocom extends _abstract_cryptocom_js__WEBPACK_IMPORTED_MODULE_0__/* ["
106560
106580
  }
106561
106581
  return returnString;
106562
106582
  }
106583
+ async closePosition(symbol, side = undefined, params = {}) {
106584
+ /**
106585
+ * @method
106586
+ * @name cryptocom#closePositions
106587
+ * @description closes open positions for a market
106588
+ * @see https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html#private-close-position
106589
+ * @param {string} symbol Unified CCXT market symbol
106590
+ * @param {string} [marginMode] not used by cryptocom.closePositions
106591
+ * @param {string} [side] not used by cryptocom.closePositions
106592
+ * @param {object} [params] extra parameters specific to the okx api endpoint
106593
+ *
106594
+ * EXCHANGE SPECIFIC PARAMETERS
106595
+ * @param {string} [params.type] LIMIT or MARKET
106596
+ * @param {number} [params.price] for limit orders only
106597
+ * @returns {object[]} [A list of position structures]{@link https://docs.ccxt.com/#/?id=position-structure}
106598
+ */
106599
+ await this.loadMarkets();
106600
+ const market = this.market(symbol);
106601
+ const request = {
106602
+ 'instrument_name': market['id'],
106603
+ 'type': 'MARKET',
106604
+ };
106605
+ const type = this.safeStringUpper(params, 'type');
106606
+ const price = this.safeString(params, 'price');
106607
+ if (type !== undefined) {
106608
+ request['type'] = type;
106609
+ }
106610
+ if (price !== undefined) {
106611
+ request['price'] = this.priceToPrecision(market['symbol'], price);
106612
+ }
106613
+ const response = await this.v1PrivatePostPrivateClosePosition(this.extend(request, params));
106614
+ //
106615
+ // {
106616
+ // "id" : 1700830813298,
106617
+ // "method" : "private/close-position",
106618
+ // "code" : 0,
106619
+ // "result" : {
106620
+ // "client_oid" : "179a909d-5614-655b-0d0e-9e85c9a25c85",
106621
+ // "order_id" : "6142909897021751347"
106622
+ // }
106623
+ // }
106624
+ //
106625
+ const result = this.safeValue(response, 'result');
106626
+ return this.parseOrder(result, market);
106627
+ }
106563
106628
  sign(path, api = 'public', method = 'GET', params = {}, headers = undefined, body = undefined) {
106564
106629
  const type = this.safeString(api, 0);
106565
106630
  const access = this.safeString(api, 1);
@@ -186175,6 +186240,8 @@ class okx extends _abstract_okx_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */
186175
186240
  'cancelAllOrders': false,
186176
186241
  'cancelOrder': true,
186177
186242
  'cancelOrders': true,
186243
+ 'closeAllPositions': false,
186244
+ 'closePosition': true,
186178
186245
  'createDepositAddress': false,
186179
186246
  'createMarketBuyOrderWithCost': true,
186180
186247
  'createMarketSellOrderWithCost': true,
@@ -193305,6 +193372,74 @@ class okx extends _abstract_okx_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */
193305
193372
  'info': greeks,
193306
193373
  };
193307
193374
  }
193375
+ async closePosition(symbol, side = undefined, params = {}) {
193376
+ /**
193377
+ * @method
193378
+ * @name okx#closePosition
193379
+ * @description closes open positions for a market
193380
+ * @see https://www.okx.com/docs-v5/en/#order-book-trading-trade-post-close-positions
193381
+ * @param {string} symbol Unified CCXT market symbol
193382
+ * @param {string} [side] 'buy' or 'sell', leave as undefined in net mode
193383
+ * @param {object} [params] extra parameters specific to the okx api endpoint
193384
+ * @param {string} [params.clientOrderId] a unique identifier for the order
193385
+ * @param {string} [params.marginMode] 'cross' or 'isolated', default is 'cross;
193386
+ * @param {string} [params.code] *required in the case of closing cross MARGIN position for Single-currency margin* margin currency
193387
+ *
193388
+ * EXCHANGE SPECIFIC PARAMETERS
193389
+ * @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
193390
+ * @param {string} [params.tag] order tag a combination of case-sensitive alphanumerics, all numbers, or all letters of up to 16 characters
193391
+ * @returns {[object]} [A list of position structures]{@link https://docs.ccxt.com/#/?id=position-structure}
193392
+ */
193393
+ await this.loadMarkets();
193394
+ const market = this.market(symbol);
193395
+ const clientOrderId = this.safeString(params, 'clientOrderId');
193396
+ const code = this.safeString(params, 'code');
193397
+ let marginMode = undefined;
193398
+ [marginMode, params] = this.handleMarginModeAndParams('closePosition', params, 'cross');
193399
+ const request = {
193400
+ 'instId': market['id'],
193401
+ 'mgnMode': marginMode,
193402
+ };
193403
+ if (side !== undefined) {
193404
+ if ((side === 'buy')) {
193405
+ request['posSide'] = 'long';
193406
+ }
193407
+ else if (side === 'sell') {
193408
+ request['posSide'] = 'short';
193409
+ }
193410
+ else {
193411
+ request['posSide'] = side;
193412
+ }
193413
+ }
193414
+ if (clientOrderId !== undefined) {
193415
+ request['clOrdId'] = clientOrderId;
193416
+ }
193417
+ if (code !== undefined) {
193418
+ const currency = this.currency(code);
193419
+ request['ccy'] = currency['id'];
193420
+ }
193421
+ const response = await this.privatePostTradeClosePosition(this.extend(request, params));
193422
+ //
193423
+ // {
193424
+ // "code": "1",
193425
+ // "data": [
193426
+ // {
193427
+ // "clOrdId":"e847386590ce4dBCe903bbc394dc88bf",
193428
+ // "ordId":"",
193429
+ // "sCode":"51000",
193430
+ // "sMsg":"Parameter posSide error ",
193431
+ // "tag":"e847386590ce4dBC"
193432
+ // }
193433
+ // ],
193434
+ // "inTime": "1701877077101064",
193435
+ // "msg": "All operations failed",
193436
+ // "outTime": "1701877077102579"
193437
+ // }
193438
+ //
193439
+ const data = this.safeValue(response, 'data');
193440
+ const order = this.safeValue(data, 0);
193441
+ return this.parseOrder(order, market);
193442
+ }
193308
193443
  handleErrors(httpCode, reason, url, method, headers, body, response, requestHeaders, requestBody) {
193309
193444
  if (!response) {
193310
193445
  return undefined; // fallback to default error handler
@@ -288832,7 +288967,7 @@ SOFTWARE.
288832
288967
 
288833
288968
  //-----------------------------------------------------------------------------
288834
288969
  // this is updated by vss.js when building
288835
- const version = '4.1.82';
288970
+ const version = '4.1.83';
288836
288971
  _src_base_Exchange_js__WEBPACK_IMPORTED_MODULE_0__/* .Exchange */ .e.ccxtVersion = version;
288837
288972
  //-----------------------------------------------------------------------------
288838
288973