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/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.83';
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 = {}) {
@@ -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;
@@ -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;
@@ -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);
@@ -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.82";
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.83';
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/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/cex.js CHANGED
@@ -35,6 +35,9 @@ export default class cex extends Exchange {
35
35
  'cancelOrder': true,
36
36
  'cancelOrders': false,
37
37
  'createDepositAddress': false,
38
+ 'createMarketBuyOrderWithCost': true,
39
+ 'createMarketOrderWithCost': false,
40
+ 'createMarketSellOrderWithCost': false,
38
41
  'createOrder': true,
39
42
  'createStopLimitOrder': false,
40
43
  'createStopMarketOrder': false,
@@ -753,31 +756,46 @@ export default class cex extends Exchange {
753
756
  * @param {float} amount how much of currency you want to trade in units of base currency
754
757
  * @param {float} [price] the price at which the order is to be fullfilled, in units of the quote currency, ignored in market orders
755
758
  * @param {object} [params] extra parameters specific to the exchange API endpoint
759
+ * @param {float} [params.cost] the quote quantity that can be used as an alternative for the amount for market buy orders
756
760
  * @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
757
761
  */
762
+ await this.loadMarkets();
763
+ const market = this.market(symbol);
764
+ const request = {
765
+ 'pair': market['id'],
766
+ 'type': side,
767
+ };
758
768
  // for market buy it requires the amount of quote currency to spend
759
769
  if ((type === 'market') && (side === 'buy')) {
760
- if (this.options['createMarketBuyOrderRequiresPrice']) {
770
+ let quoteAmount = undefined;
771
+ let createMarketBuyOrderRequiresPrice = true;
772
+ [createMarketBuyOrderRequiresPrice, params] = this.handleOptionAndParams(params, 'createOrder', 'createMarketBuyOrderRequiresPrice', true);
773
+ const cost = this.safeString(params, 'cost');
774
+ params = this.omit(params, 'cost');
775
+ if (cost !== undefined) {
776
+ quoteAmount = this.costToPrecision(symbol, cost);
777
+ }
778
+ else if (createMarketBuyOrderRequiresPrice) {
761
779
  if (price === undefined) {
762
- throw new 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)");
780
+ throw new 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');
763
781
  }
764
782
  else {
765
783
  const amountString = this.numberToString(amount);
766
784
  const priceString = this.numberToString(price);
767
- const baseAmount = Precise.stringMul(amountString, priceString);
768
- amount = this.parseNumber(baseAmount);
785
+ const costRequest = Precise.stringMul(amountString, priceString);
786
+ quoteAmount = this.costToPrecision(symbol, costRequest);
769
787
  }
770
788
  }
789
+ else {
790
+ quoteAmount = this.costToPrecision(symbol, amount);
791
+ }
792
+ request['amount'] = quoteAmount;
793
+ }
794
+ else {
795
+ request['amount'] = this.amountToPrecision(symbol, amount);
771
796
  }
772
- await this.loadMarkets();
773
- const market = this.market(symbol);
774
- const request = {
775
- 'pair': market['id'],
776
- 'type': side,
777
- 'amount': amount,
778
- };
779
797
  if (type === 'limit') {
780
- request['price'] = price;
798
+ request['price'] = this.numberToString(price);
781
799
  }
782
800
  else {
783
801
  request['order_type'] = type;
@@ -99,6 +99,7 @@ export default class cryptocom extends Exchange {
99
99
  parsePosition(position: any, market?: Market): import("./base/types.js").Position;
100
100
  nonce(): number;
101
101
  paramsToString(object: any, level: any): any;
102
+ closePosition(symbol: string, side?: OrderSide, params?: {}): Promise<Order>;
102
103
  sign(path: any, api?: string, method?: string, params?: {}, headers?: any, body?: any): {
103
104
  url: string;
104
105
  method: string;
@@ -36,6 +36,8 @@ export default class cryptocom extends Exchange {
36
36
  'cancelAllOrders': true,
37
37
  'cancelOrder': true,
38
38
  'cancelOrders': true,
39
+ 'closeAllPositions': false,
40
+ 'closePosition': true,
39
41
  'createOrder': true,
40
42
  'createOrders': true,
41
43
  'fetchAccounts': true,
@@ -2891,6 +2893,51 @@ export default class cryptocom extends Exchange {
2891
2893
  }
2892
2894
  return returnString;
2893
2895
  }
2896
+ async closePosition(symbol, side = undefined, params = {}) {
2897
+ /**
2898
+ * @method
2899
+ * @name cryptocom#closePositions
2900
+ * @description closes open positions for a market
2901
+ * @see https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html#private-close-position
2902
+ * @param {string} symbol Unified CCXT market symbol
2903
+ * @param {string} [marginMode] not used by cryptocom.closePositions
2904
+ * @param {string} [side] not used by cryptocom.closePositions
2905
+ * @param {object} [params] extra parameters specific to the okx api endpoint
2906
+ *
2907
+ * EXCHANGE SPECIFIC PARAMETERS
2908
+ * @param {string} [params.type] LIMIT or MARKET
2909
+ * @param {number} [params.price] for limit orders only
2910
+ * @returns {object[]} [A list of position structures]{@link https://docs.ccxt.com/#/?id=position-structure}
2911
+ */
2912
+ await this.loadMarkets();
2913
+ const market = this.market(symbol);
2914
+ const request = {
2915
+ 'instrument_name': market['id'],
2916
+ 'type': 'MARKET',
2917
+ };
2918
+ const type = this.safeStringUpper(params, 'type');
2919
+ const price = this.safeString(params, 'price');
2920
+ if (type !== undefined) {
2921
+ request['type'] = type;
2922
+ }
2923
+ if (price !== undefined) {
2924
+ request['price'] = this.priceToPrecision(market['symbol'], price);
2925
+ }
2926
+ const response = await this.v1PrivatePostPrivateClosePosition(this.extend(request, params));
2927
+ //
2928
+ // {
2929
+ // "id" : 1700830813298,
2930
+ // "method" : "private/close-position",
2931
+ // "code" : 0,
2932
+ // "result" : {
2933
+ // "client_oid" : "179a909d-5614-655b-0d0e-9e85c9a25c85",
2934
+ // "order_id" : "6142909897021751347"
2935
+ // }
2936
+ // }
2937
+ //
2938
+ const result = this.safeValue(response, 'result');
2939
+ return this.parseOrder(result, market);
2940
+ }
2894
2941
  sign(path, api = 'public', method = 'GET', params = {}, headers = undefined, body = undefined) {
2895
2942
  const type = this.safeString(api, 0);
2896
2943
  const access = this.safeString(api, 1);
package/js/src/okx.d.ts CHANGED
@@ -325,5 +325,6 @@ export default class okx extends Exchange {
325
325
  underlyingPrice: any;
326
326
  info: any;
327
327
  };
328
+ closePosition(symbol: string, side?: OrderSide, params?: {}): Promise<Order>;
328
329
  handleErrors(httpCode: any, reason: any, url: any, method: any, headers: any, body: any, response: any, requestHeaders: any, requestBody: any): any;
329
330
  }
package/js/src/okx.js CHANGED
@@ -37,6 +37,8 @@ export default class okx extends Exchange {
37
37
  'cancelAllOrders': false,
38
38
  'cancelOrder': true,
39
39
  'cancelOrders': true,
40
+ 'closeAllPositions': false,
41
+ 'closePosition': true,
40
42
  'createDepositAddress': false,
41
43
  'createMarketBuyOrderWithCost': true,
42
44
  'createMarketSellOrderWithCost': true,
@@ -7167,6 +7169,74 @@ export default class okx extends Exchange {
7167
7169
  'info': greeks,
7168
7170
  };
7169
7171
  }
7172
+ async closePosition(symbol, side = undefined, params = {}) {
7173
+ /**
7174
+ * @method
7175
+ * @name okx#closePosition
7176
+ * @description closes open positions for a market
7177
+ * @see https://www.okx.com/docs-v5/en/#order-book-trading-trade-post-close-positions
7178
+ * @param {string} symbol Unified CCXT market symbol
7179
+ * @param {string} [side] 'buy' or 'sell', leave as undefined in net mode
7180
+ * @param {object} [params] extra parameters specific to the okx api endpoint
7181
+ * @param {string} [params.clientOrderId] a unique identifier for the order
7182
+ * @param {string} [params.marginMode] 'cross' or 'isolated', default is 'cross;
7183
+ * @param {string} [params.code] *required in the case of closing cross MARGIN position for Single-currency margin* margin currency
7184
+ *
7185
+ * EXCHANGE SPECIFIC PARAMETERS
7186
+ * @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
7187
+ * @param {string} [params.tag] order tag a combination of case-sensitive alphanumerics, all numbers, or all letters of up to 16 characters
7188
+ * @returns {[object]} [A list of position structures]{@link https://docs.ccxt.com/#/?id=position-structure}
7189
+ */
7190
+ await this.loadMarkets();
7191
+ const market = this.market(symbol);
7192
+ const clientOrderId = this.safeString(params, 'clientOrderId');
7193
+ const code = this.safeString(params, 'code');
7194
+ let marginMode = undefined;
7195
+ [marginMode, params] = this.handleMarginModeAndParams('closePosition', params, 'cross');
7196
+ const request = {
7197
+ 'instId': market['id'],
7198
+ 'mgnMode': marginMode,
7199
+ };
7200
+ if (side !== undefined) {
7201
+ if ((side === 'buy')) {
7202
+ request['posSide'] = 'long';
7203
+ }
7204
+ else if (side === 'sell') {
7205
+ request['posSide'] = 'short';
7206
+ }
7207
+ else {
7208
+ request['posSide'] = side;
7209
+ }
7210
+ }
7211
+ if (clientOrderId !== undefined) {
7212
+ request['clOrdId'] = clientOrderId;
7213
+ }
7214
+ if (code !== undefined) {
7215
+ const currency = this.currency(code);
7216
+ request['ccy'] = currency['id'];
7217
+ }
7218
+ const response = await this.privatePostTradeClosePosition(this.extend(request, params));
7219
+ //
7220
+ // {
7221
+ // "code": "1",
7222
+ // "data": [
7223
+ // {
7224
+ // "clOrdId":"e847386590ce4dBCe903bbc394dc88bf",
7225
+ // "ordId":"",
7226
+ // "sCode":"51000",
7227
+ // "sMsg":"Parameter posSide error ",
7228
+ // "tag":"e847386590ce4dBC"
7229
+ // }
7230
+ // ],
7231
+ // "inTime": "1701877077101064",
7232
+ // "msg": "All operations failed",
7233
+ // "outTime": "1701877077102579"
7234
+ // }
7235
+ //
7236
+ const data = this.safeValue(response, 'data');
7237
+ const order = this.safeValue(data, 0);
7238
+ return this.parseOrder(order, market);
7239
+ }
7170
7240
  handleErrors(httpCode, reason, url, method, headers, body, response, requestHeaders, requestBody) {
7171
7241
  if (!response) {
7172
7242
  return undefined; // fallback to default error handler
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ccxt",
3
- "version": "4.1.82",
3
+ "version": "4.1.83",
4
4
  "description": "A JavaScript / TypeScript / Python / C# / PHP cryptocurrency trading library with support for 130+ exchanges",
5
5
  "unpkg": "dist/ccxt.browser.js",
6
6
  "type": "module",