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/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;
package/js/src/coinsph.js CHANGED
@@ -38,6 +38,9 @@ export default class coinsph extends Exchange {
38
38
  'closeAllPositions': false,
39
39
  'closePosition': false,
40
40
  'createDepositAddress': false,
41
+ 'createMarketBuyOrderWithCost': true,
42
+ 'createMarketOrderWithCost': false,
43
+ 'createMarketSellOrderWithCost': false,
41
44
  'createOrder': true,
42
45
  'createPostOnlyOrder': false,
43
46
  'createReduceOnlyOrder': false,
@@ -1065,12 +1068,14 @@ export default class coinsph extends Exchange {
1065
1068
  * @method
1066
1069
  * @name coinsph#createOrder
1067
1070
  * @description create a trade order
1071
+ * @see https://coins-docs.github.io/rest-api/#new-order--trade
1068
1072
  * @param {string} symbol unified symbol of the market to create an order in
1069
1073
  * @param {string} type 'market', 'limit', 'stop_loss', 'take_profit', 'stop_loss_limit', 'take_profit_limit' or 'limit_maker'
1070
1074
  * @param {string} side 'buy' or 'sell'
1071
1075
  * @param {float} amount how much of currency you want to trade in units of base currency
1072
1076
  * @param {float} [price] the price at which the order is to be fullfilled, in units of the quote currency, ignored in market orders
1073
1077
  * @param {object} [params] extra parameters specific to the exchange API endpoint
1078
+ * @param {float} [params.cost] the quote quantity that can be used as an alternative for the amount for market buy orders
1074
1079
  * @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
1075
1080
  */
1076
1081
  // todo: add test order low priority
@@ -1106,24 +1111,29 @@ export default class coinsph extends Exchange {
1106
1111
  request['quantity'] = this.amountToPrecision(symbol, amount);
1107
1112
  }
1108
1113
  else if (orderSide === 'BUY') {
1109
- const quoteOrderQty = this.safeNumber2(params, 'cost', 'quoteOrderQty');
1110
- const createMarketBuyOrderRequiresPrice = this.safeValue(this.options, 'createMarketBuyOrderRequiresPrice', true);
1111
- if (quoteOrderQty !== undefined) {
1112
- amount = quoteOrderQty;
1114
+ let quoteAmount = undefined;
1115
+ let createMarketBuyOrderRequiresPrice = true;
1116
+ [createMarketBuyOrderRequiresPrice, params] = this.handleOptionAndParams(params, 'createOrder', 'createMarketBuyOrderRequiresPrice', true);
1117
+ const cost = this.safeNumber2(params, 'cost', 'quoteOrderQty');
1118
+ params = this.omit(params, 'cost');
1119
+ if (cost !== undefined) {
1120
+ quoteAmount = this.costToPrecision(symbol, cost);
1113
1121
  }
1114
1122
  else if (createMarketBuyOrderRequiresPrice) {
1115
1123
  if (price === undefined) {
1116
- 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)");
1124
+ 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');
1117
1125
  }
1118
1126
  else {
1119
1127
  const amountString = this.numberToString(amount);
1120
1128
  const priceString = this.numberToString(price);
1121
- const quoteAmount = Precise.stringMul(amountString, priceString);
1122
- amount = this.parseNumber(quoteAmount);
1129
+ const costRequest = Precise.stringMul(amountString, priceString);
1130
+ quoteAmount = this.costToPrecision(symbol, costRequest);
1123
1131
  }
1124
1132
  }
1125
- request['quoteOrderQty'] = this.costToPrecision(symbol, amount);
1126
- params = this.omit(params, 'cost', 'quoteOrderQty');
1133
+ else {
1134
+ quoteAmount = this.costToPrecision(symbol, amount);
1135
+ }
1136
+ request['quoteOrderQty'] = quoteAmount;
1127
1137
  }
1128
1138
  }
1129
1139
  if (orderType === 'STOP_LOSS' || orderType === 'STOP_LOSS_LIMIT' || orderType === 'TAKE_PROFIT' || orderType === 'TAKE_PROFIT_LIMIT') {
@@ -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/htx.d.ts CHANGED
@@ -83,6 +83,7 @@ export default class htx extends Exchange {
83
83
  fetchOpenOrders(symbol?: Str, since?: Int, limit?: Int, params?: {}): Promise<Order[]>;
84
84
  parseOrderStatus(status: any): string;
85
85
  parseOrder(order: any, market?: Market): Order;
86
+ createMarketBuyOrderWithCost(symbol: string, cost: any, params?: {}): Promise<Order>;
86
87
  createSpotOrderRequest(symbol: string, type: OrderType, side: OrderSide, amount: any, price?: any, params?: {}): Promise<any>;
87
88
  createContractOrderRequest(symbol: string, type: OrderType, side: OrderSide, amount: any, price?: any, params?: {}): any;
88
89
  createOrder(symbol: string, type: OrderType, side: OrderSide, amount: any, price?: any, params?: {}): Promise<Order>;
package/js/src/htx.js CHANGED
@@ -41,6 +41,9 @@ export default class htx extends Exchange {
41
41
  'cancelOrder': true,
42
42
  'cancelOrders': true,
43
43
  'createDepositAddress': undefined,
44
+ 'createMarketBuyOrderWithCost': true,
45
+ 'createMarketOrderWithCost': false,
46
+ 'createMarketSellOrderWithCost': false,
44
47
  'createOrder': true,
45
48
  'createOrders': true,
46
49
  'createReduceOnlyOrder': false,
@@ -4843,6 +4846,25 @@ export default class htx extends Exchange {
4843
4846
  'trades': trades,
4844
4847
  }, market);
4845
4848
  }
4849
+ async createMarketBuyOrderWithCost(symbol, cost, params = {}) {
4850
+ /**
4851
+ * @method
4852
+ * @name htx#createMarketBuyOrderWithCost
4853
+ * @description create a market buy order by providing the symbol and cost
4854
+ * @see https://www.htx.com/en-us/opend/newApiPages/?id=7ec4ee16-7773-11ed-9966-0242ac110003
4855
+ * @param {string} symbol unified symbol of the market to create an order in
4856
+ * @param {float} cost how much you want to trade in units of the quote currency
4857
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
4858
+ * @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
4859
+ */
4860
+ await this.loadMarkets();
4861
+ const market = this.market(symbol);
4862
+ if (!market['spot']) {
4863
+ throw new NotSupported(this.id + ' createMarketBuyOrderWithCost() supports spot orders only');
4864
+ }
4865
+ params['createMarketBuyOrderRequiresPrice'] = false;
4866
+ return await this.createOrder(symbol, 'market', 'buy', cost, undefined, params);
4867
+ }
4846
4868
  async createSpotOrderRequest(symbol, type, side, amount, price = undefined, params = {}) {
4847
4869
  /**
4848
4870
  * @method
@@ -4856,6 +4878,7 @@ export default class htx extends Exchange {
4856
4878
  * @param {float} [price] the price at which the order is to be fullfilled, in units of the quote currency, ignored in market orders
4857
4879
  * @param {object} [params] extra parameters specific to the exchange API endpoint
4858
4880
  * @param {string} [params.timeInForce] supports 'IOC' and 'FOK'
4881
+ * @param {float} [params.cost] the quote quantity that can be used as an alternative for the amount for market buy orders
4859
4882
  * @returns {object} request to be sent to the exchange
4860
4883
  */
4861
4884
  await this.loadMarkets();
@@ -4930,9 +4953,17 @@ export default class htx extends Exchange {
4930
4953
  request['source'] = 'c2c-margin-api';
4931
4954
  }
4932
4955
  if ((orderType === 'market') && (side === 'buy')) {
4933
- if (this.options['createMarketBuyOrderRequiresPrice']) {
4956
+ let quoteAmount = undefined;
4957
+ let createMarketBuyOrderRequiresPrice = true;
4958
+ [createMarketBuyOrderRequiresPrice, params] = this.handleOptionAndParams(params, 'createOrder', 'createMarketBuyOrderRequiresPrice', true);
4959
+ const cost = this.safeNumber(params, 'cost');
4960
+ params = this.omit(params, 'cost');
4961
+ if (cost !== undefined) {
4962
+ quoteAmount = this.amountToPrecision(symbol, cost);
4963
+ }
4964
+ else if (createMarketBuyOrderRequiresPrice) {
4934
4965
  if (price === undefined) {
4935
- throw new 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.");
4966
+ 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');
4936
4967
  }
4937
4968
  else {
4938
4969
  // despite that cost = amount * price is in quote currency and should have quote precision
@@ -4943,12 +4974,13 @@ export default class htx extends Exchange {
4943
4974
  // we use amountToPrecision here because the exchange requires cost in base precision
4944
4975
  const amountString = this.numberToString(amount);
4945
4976
  const priceString = this.numberToString(price);
4946
- request['amount'] = this.costToPrecision(symbol, Precise.stringMul(amountString, priceString));
4977
+ quoteAmount = this.amountToPrecision(symbol, Precise.stringMul(amountString, priceString));
4947
4978
  }
4948
4979
  }
4949
4980
  else {
4950
- request['amount'] = this.costToPrecision(symbol, amount);
4981
+ quoteAmount = this.amountToPrecision(symbol, amount);
4951
4982
  }
4983
+ request['amount'] = quoteAmount;
4952
4984
  }
4953
4985
  else {
4954
4986
  request['amount'] = this.amountToPrecision(symbol, amount);
@@ -5080,6 +5112,7 @@ export default class htx extends Exchange {
5080
5112
  * @param {bool} [params.postOnly] *contract only* true or false
5081
5113
  * @param {int} [params.leverRate] *contract only* required for all contract orders except tpsl, leverage greater than 20x requires prior approval of high-leverage agreement
5082
5114
  * @param {string} [params.timeInForce] supports 'IOC' and 'FOK'
5115
+ * @param {float} [params.cost] *spot market buy only* the quote quantity that can be used as an alternative for the amount
5083
5116
  * @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
5084
5117
  */
5085
5118
  await this.loadMarkets();
@@ -51,6 +51,7 @@ export default class huobijp extends Exchange {
51
51
  fetchOpenOrdersV2(symbol?: Str, since?: Int, limit?: Int, params?: {}): Promise<Order[]>;
52
52
  parseOrderStatus(status: any): string;
53
53
  parseOrder(order: any, market?: Market): Order;
54
+ createMarketBuyOrderWithCost(symbol: string, cost: any, params?: {}): Promise<Order>;
54
55
  createOrder(symbol: string, type: OrderType, side: OrderSide, amount: any, price?: any, params?: {}): Promise<Order>;
55
56
  cancelOrder(id: string, symbol?: Str, params?: {}): Promise<any>;
56
57
  cancelOrders(ids: any, symbol?: Str, params?: {}): Promise<any>;
package/js/src/huobijp.js CHANGED
@@ -6,7 +6,7 @@
6
6
 
7
7
  // ---------------------------------------------------------------------------
8
8
  import Exchange from './abstract/huobijp.js';
9
- import { AuthenticationError, ExchangeError, PermissionDenied, ExchangeNotAvailable, OnMaintenance, InvalidOrder, OrderNotFound, InsufficientFunds, BadSymbol, BadRequest, RequestTimeout, NetworkError, ArgumentsRequired } from './base/errors.js';
9
+ import { AuthenticationError, ExchangeError, PermissionDenied, ExchangeNotAvailable, OnMaintenance, InvalidOrder, OrderNotFound, InsufficientFunds, BadSymbol, BadRequest, RequestTimeout, NetworkError, ArgumentsRequired, NotSupported } from './base/errors.js';
10
10
  import { Precise } from './base/Precise.js';
11
11
  import { TRUNCATE, TICK_SIZE } from './base/functions/number.js';
12
12
  import { sha256 } from './static_dependencies/noble-hashes/sha256.js';
@@ -37,6 +37,9 @@ export default class huobijp extends Exchange {
37
37
  'cancelAllOrders': true,
38
38
  'cancelOrder': true,
39
39
  'cancelOrders': true,
40
+ 'createMarketBuyOrderWithCost': true,
41
+ 'createMarketOrderWithCost': false,
42
+ 'createMarketSellOrderWithCost': false,
40
43
  'createOrder': true,
41
44
  'createStopLimitOrder': false,
42
45
  'createStopMarketOrder': false,
@@ -1361,6 +1364,24 @@ export default class huobijp extends Exchange {
1361
1364
  'trades': undefined,
1362
1365
  }, market);
1363
1366
  }
1367
+ async createMarketBuyOrderWithCost(symbol, cost, params = {}) {
1368
+ /**
1369
+ * @method
1370
+ * @name huobijp#createMarketBuyOrderWithCost
1371
+ * @description create a market buy order by providing the symbol and cost
1372
+ * @param {string} symbol unified symbol of the market to create an order in
1373
+ * @param {float} cost how much you want to trade in units of the quote currency
1374
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
1375
+ * @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
1376
+ */
1377
+ await this.loadMarkets();
1378
+ const market = this.market(symbol);
1379
+ if (!market['spot']) {
1380
+ throw new NotSupported(this.id + ' createMarketBuyOrderWithCost() supports spot orders only');
1381
+ }
1382
+ params['createMarketBuyOrderRequiresPrice'] = false;
1383
+ return await this.createOrder(symbol, 'market', 'buy', cost, undefined, params);
1384
+ }
1364
1385
  async createOrder(symbol, type, side, amount, price = undefined, params = {}) {
1365
1386
  /**
1366
1387
  * @method
@@ -1393,9 +1414,17 @@ export default class huobijp extends Exchange {
1393
1414
  }
1394
1415
  params = this.omit(params, ['clientOrderId', 'client-order-id']);
1395
1416
  if ((type === 'market') && (side === 'buy')) {
1396
- if (this.options['createMarketBuyOrderRequiresPrice']) {
1417
+ let quoteAmount = undefined;
1418
+ let createMarketBuyOrderRequiresPrice = true;
1419
+ [createMarketBuyOrderRequiresPrice, params] = this.handleOptionAndParams(params, 'createOrder', 'createMarketBuyOrderRequiresPrice', true);
1420
+ const cost = this.safeNumber(params, 'cost');
1421
+ params = this.omit(params, 'cost');
1422
+ if (cost !== undefined) {
1423
+ quoteAmount = this.amountToPrecision(symbol, cost);
1424
+ }
1425
+ else if (createMarketBuyOrderRequiresPrice) {
1397
1426
  if (price === undefined) {
1398
- throw new 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.");
1427
+ 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');
1399
1428
  }
1400
1429
  else {
1401
1430
  // despite that cost = amount * price is in quote currency and should have quote precision
@@ -1406,13 +1435,13 @@ export default class huobijp extends Exchange {
1406
1435
  // we use amountToPrecision here because the exchange requires cost in base precision
1407
1436
  const amountString = this.numberToString(amount);
1408
1437
  const priceString = this.numberToString(price);
1409
- const baseAmount = Precise.stringMul(amountString, priceString);
1410
- request['amount'] = this.costToPrecision(symbol, baseAmount);
1438
+ quoteAmount = this.amountToPrecision(symbol, Precise.stringMul(amountString, priceString));
1411
1439
  }
1412
1440
  }
1413
1441
  else {
1414
- request['amount'] = this.costToPrecision(symbol, amount);
1442
+ quoteAmount = this.amountToPrecision(symbol, amount);
1415
1443
  }
1444
+ request['amount'] = quoteAmount;
1416
1445
  }
1417
1446
  else {
1418
1447
  request['amount'] = this.amountToPrecision(symbol, amount);
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.84",
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",