ccxt 4.1.81 → 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.
Files changed (53) hide show
  1. package/README.md +4 -4
  2. package/dist/ccxt.browser.js +488 -154
  3. package/dist/ccxt.browser.min.js +2 -2
  4. package/dist/cjs/ccxt.js +1 -1
  5. package/dist/cjs/src/base/Exchange.js +1 -1
  6. package/dist/cjs/src/bingx.js +1 -1
  7. package/dist/cjs/src/bitget.js +1 -1
  8. package/dist/cjs/src/bybit.js +1 -1
  9. package/dist/cjs/src/cex.js +30 -12
  10. package/dist/cjs/src/coinex.js +191 -71
  11. package/dist/cjs/src/cryptocom.js +47 -0
  12. package/dist/cjs/src/htx.js +12 -10
  13. package/dist/cjs/src/lbank.js +70 -38
  14. package/dist/cjs/src/okx.js +122 -7
  15. package/dist/cjs/src/pro/binance.js +1 -1
  16. package/dist/cjs/src/pro/bingx.js +1 -1
  17. package/dist/cjs/src/pro/bitget.js +1 -1
  18. package/dist/cjs/src/pro/bybit.js +1 -1
  19. package/dist/cjs/src/pro/cex.js +1 -1
  20. package/dist/cjs/src/pro/coinbasepro.js +1 -1
  21. package/dist/cjs/src/pro/cryptocom.js +1 -1
  22. package/dist/cjs/src/pro/gate.js +1 -1
  23. package/dist/cjs/src/pro/kucoin.js +1 -1
  24. package/dist/cjs/src/pro/kucoinfutures.js +1 -1
  25. package/dist/cjs/src/pro/okx.js +1 -1
  26. package/js/ccxt.d.ts +1 -1
  27. package/js/ccxt.js +1 -1
  28. package/js/src/base/Exchange.d.ts +1 -1
  29. package/js/src/base/Exchange.js +1 -1
  30. package/js/src/bingx.js +1 -1
  31. package/js/src/bitget.js +1 -1
  32. package/js/src/bybit.js +1 -1
  33. package/js/src/cex.js +30 -12
  34. package/js/src/coinex.js +191 -71
  35. package/js/src/cryptocom.d.ts +1 -0
  36. package/js/src/cryptocom.js +47 -0
  37. package/js/src/htx.js +12 -10
  38. package/js/src/lbank.d.ts +1 -0
  39. package/js/src/lbank.js +71 -39
  40. package/js/src/okx.d.ts +1 -0
  41. package/js/src/okx.js +122 -7
  42. package/js/src/pro/binance.js +1 -1
  43. package/js/src/pro/bingx.js +1 -1
  44. package/js/src/pro/bitget.js +1 -1
  45. package/js/src/pro/bybit.js +1 -1
  46. package/js/src/pro/cex.js +1 -1
  47. package/js/src/pro/coinbasepro.js +1 -1
  48. package/js/src/pro/cryptocom.js +1 -1
  49. package/js/src/pro/gate.js +1 -1
  50. package/js/src/pro/kucoin.js +1 -1
  51. package/js/src/pro/kucoinfutures.js +1 -1
  52. package/js/src/pro/okx.js +1 -1
  53. package/package.json +1 -1
@@ -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.js CHANGED
@@ -3375,14 +3375,16 @@ export default class htx extends Exchange {
3375
3375
  // "margin_mode": "cross",
3376
3376
  // "margin_account": "USDT",
3377
3377
  // "margin_asset": "USDT",
3378
- // "margin_balance": 200.000000000000000000,
3379
- // "margin_static": 200.000000000000000000,
3380
- // "margin_position": 0,
3381
- // "margin_frozen": 0,
3382
- // "profit_real": 0E-18,
3383
- // "profit_unreal": 0,
3384
- // "withdraw_available": 2E+2,
3385
- // "risk_rate": null,
3378
+ // "margin_balance": 49.874186030200000000,
3379
+ // "money_in": 50,
3380
+ // "money_out": 0,
3381
+ // "margin_static": 49.872786030200000000,
3382
+ // "margin_position": 6.180000000000000000,
3383
+ // "margin_frozen": 6.000000000000000000,
3384
+ // "profit_unreal": 0.001400000000000000,
3385
+ // "withdraw_available": 37.6927860302,
3386
+ // "risk_rate": 271.984050521072796934,
3387
+ // "new_risk_rate": 0.001858676950514399,
3386
3388
  // "contract_detail": [
3387
3389
  // {
3388
3390
  // "symbol": "MANA",
@@ -3489,8 +3491,8 @@ export default class htx extends Exchange {
3489
3491
  }
3490
3492
  else {
3491
3493
  const account = this.account();
3492
- account['free'] = this.safeString(first, 'margin_balance', 'margin_available');
3493
- account['used'] = this.safeString(first, 'margin_frozen');
3494
+ account['free'] = this.safeString(first, 'withdraw_available');
3495
+ account['total'] = this.safeString(first, 'margin_balance');
3494
3496
  const currencyId = this.safeString2(first, 'margin_asset', 'symbol');
3495
3497
  const code = this.safeCurrencyCode(currencyId);
3496
3498
  result[code] = account;
package/js/src/lbank.d.ts CHANGED
@@ -28,6 +28,7 @@ export default class lbank extends Exchange {
28
28
  };
29
29
  fetchTradingFee(symbol: string, params?: {}): Promise<{}>;
30
30
  fetchTradingFees(params?: {}): Promise<{}>;
31
+ createMarketBuyOrderWithCost(symbol: string, cost: any, params?: {}): Promise<Order>;
31
32
  createOrder(symbol: string, type: OrderType, side: OrderSide, amount: any, price?: any, params?: {}): Promise<Order>;
32
33
  parseOrderStatus(status: any): string;
33
34
  parseOrder(order: any, market?: Market): Order;
package/js/src/lbank.js CHANGED
@@ -6,7 +6,7 @@
6
6
 
7
7
  // ---------------------------------------------------------------------------
8
8
  import Exchange from './abstract/lbank.js';
9
- import { ExchangeError, InvalidAddress, DuplicateOrderId, InsufficientFunds, InvalidOrder, InvalidNonce, AuthenticationError, RateLimitExceeded, PermissionDenied, BadRequest, BadSymbol, ArgumentsRequired } from './base/errors.js';
9
+ import { ExchangeError, InvalidAddress, DuplicateOrderId, InsufficientFunds, InvalidOrder, InvalidNonce, AuthenticationError, RateLimitExceeded, PermissionDenied, BadRequest, BadSymbol, ArgumentsRequired, NotSupported } from './base/errors.js';
10
10
  import { TICK_SIZE } from './base/functions/number.js';
11
11
  import { Precise } from './base/Precise.js';
12
12
  import { md5 } from './static_dependencies/noble-hashes/md5.js';
@@ -37,6 +37,9 @@ export default class lbank extends Exchange {
37
37
  'addMargin': false,
38
38
  'cancelAllOrders': true,
39
39
  'cancelOrder': true,
40
+ 'createMarketBuyOrderWithCost': true,
41
+ 'createMarketOrderWithCost': false,
42
+ 'createMarketSellOrderWithCost': false,
40
43
  'createOrder': true,
41
44
  'createReduceOnlyOrder': false,
42
45
  'createStopLimitOrder': false,
@@ -107,10 +110,10 @@ export default class lbank extends Exchange {
107
110
  'contract': 'https://lbkperp.lbank.com',
108
111
  },
109
112
  'api2': 'https://api.lbkex.com',
110
- 'www': 'https://www.lbank.info',
111
- 'doc': 'https://www.lbank.info/en-US/docs/index.html',
112
- 'fees': 'https://lbankinfo.zendesk.com/hc/en-gb/articles/360012072873-Trading-Fees',
113
- 'referral': 'https://www.lbank.info/invitevip?icode=7QCY',
113
+ 'www': 'https://www.lbank.com',
114
+ 'doc': 'https://www.lbank.com/en-US/docs/index.html',
115
+ 'fees': 'https://support.lbank.site/hc/en-gb/articles/900000535703-Trading-Fees-From-14-00-on-April-7-2020-UTC-8-',
116
+ 'referral': 'https://www.lbank.com/login/?icode=7QCY',
114
117
  },
115
118
  'api': {
116
119
  'spot': {
@@ -298,7 +301,7 @@ export default class lbank extends Exchange {
298
301
  * @method
299
302
  * @name lbank2#fetchTime
300
303
  * @description fetches the current integer timestamp in milliseconds from the exchange server
301
- * @see https://www.lbank.info/en-US/docs/index.html#get-timestamp
304
+ * @see https://www.lbank.com/en-US/docs/index.html#get-timestamp
302
305
  * @see https://www.lbank.com/en-US/docs/contract.html#get-the-current-time
303
306
  * @param {object} [params] extra parameters specific to the exchange API endpoint
304
307
  * @returns {int} the current integer timestamp in milliseconds from the exchange server
@@ -593,7 +596,7 @@ export default class lbank extends Exchange {
593
596
  * @method
594
597
  * @name lbank2#fetchTicker
595
598
  * @description fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market
596
- * @see https://www.lbank.info/en-US/docs/index.html#query-current-market-data-new
599
+ * @see https://www.lbank.com/en-US/docs/index.html#query-current-market-data-new
597
600
  * @param {string} symbol unified symbol of the market to fetch the ticker for
598
601
  * @param {object} [params] extra parameters specific to the exchange API endpoint
599
602
  * @returns {object} a [ticker structure]{@link https://docs.ccxt.com/#/?id=ticker-structure}
@@ -638,7 +641,7 @@ export default class lbank extends Exchange {
638
641
  * @method
639
642
  * @name lbank2#fetchTickers
640
643
  * @description fetches price tickers for multiple markets, statistical information calculated over the past 24 hours for each market
641
- * @see https://www.lbank.info/en-US/docs/index.html#query-current-market-data-new
644
+ * @see https://www.lbank.com/en-US/docs/index.html#query-current-market-data-new
642
645
  * @see https://www.lbank.com/en-US/docs/contract.html#query-contract-market-list
643
646
  * @param {string[]|undefined} symbols unified symbols of the markets to fetch the ticker for, all market tickers are returned if not assigned
644
647
  * @param {object} [params] extra parameters specific to the exchange API endpoint
@@ -718,7 +721,7 @@ export default class lbank extends Exchange {
718
721
  * @method
719
722
  * @name lbank2#fetchOrderBook
720
723
  * @description fetches information on open orders with bid (buy) and ask (sell) prices, volumes and other data
721
- * @see https://www.lbank.info/en-US/docs/index.html#query-market-depth
724
+ * @see https://www.lbank.com/en-US/docs/index.html#query-market-depth
722
725
  * @see https://www.lbank.com/en-US/docs/contract.html#get-handicap
723
726
  * @param {string} symbol unified symbol of the market to fetch the order book for
724
727
  * @param {int} [limit] the maximum amount of order book entries to return
@@ -907,8 +910,8 @@ export default class lbank extends Exchange {
907
910
  * @method
908
911
  * @name lbank2#fetchTrades
909
912
  * @description get the list of most recent trades for a particular symbol
910
- * @see https://www.lbank.info/en-US/docs/index.html#query-historical-transactions
911
- * @see https://www.lbank.info/en-US/docs/index.html#recent-transactions-list
913
+ * @see https://www.lbank.com/en-US/docs/index.html#query-historical-transactions
914
+ * @see https://www.lbank.com/en-US/docs/index.html#recent-transactions-list
912
915
  * @param {string} symbol unified symbol of the market to fetch trades for
913
916
  * @param {int} [since] timestamp in ms of the earliest trade to fetch
914
917
  * @param {int} [limit] the maximum amount of trades to fetch
@@ -980,7 +983,7 @@ export default class lbank extends Exchange {
980
983
  * @method
981
984
  * @name lbank2#fetchOHLCV
982
985
  * @description fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market
983
- * @see https://www.lbank.info/en-US/docs/index.html#query-k-bar-data
986
+ * @see https://www.lbank.com/en-US/docs/index.html#query-k-bar-data
984
987
  * @param {string} symbol unified symbol of the market to fetch OHLCV data for
985
988
  * @param {string} timeframe the length of time each candle represents
986
989
  * @param {int} [since] timestamp in ms of the earliest candle to fetch
@@ -1165,9 +1168,9 @@ export default class lbank extends Exchange {
1165
1168
  * @method
1166
1169
  * @name lbank2#fetchBalance
1167
1170
  * @description query for balance and get the amount of funds available for trading or funds locked in orders
1168
- * @see https://www.lbank.info/en-US/docs/index.html#asset-information
1169
- * @see https://www.lbank.info/en-US/docs/index.html#account-information
1170
- * @see https://www.lbank.info/en-US/docs/index.html#get-all-coins-information
1171
+ * @see https://www.lbank.com/en-US/docs/index.html#asset-information
1172
+ * @see https://www.lbank.com/en-US/docs/index.html#account-information
1173
+ * @see https://www.lbank.com/en-US/docs/index.html#get-all-coins-information
1171
1174
  * @param {object} [params] extra parameters specific to the exchange API endpoint
1172
1175
  * @returns {object} a [balance structure]{@link https://docs.ccxt.com/#/?id=balance-structure}
1173
1176
  */
@@ -1232,7 +1235,7 @@ export default class lbank extends Exchange {
1232
1235
  * @method
1233
1236
  * @name lbank2#fetchTradingFee
1234
1237
  * @description fetch the trading fees for a market
1235
- * @see https://www.lbank.info/en-US/docs/index.html#transaction-fee-rate-query
1238
+ * @see https://www.lbank.com/en-US/docs/index.html#transaction-fee-rate-query
1236
1239
  * @param {string} symbol unified market symbol
1237
1240
  * @param {object} [params] extra parameters specific to the exchange API endpoint
1238
1241
  * @returns {object} a [fee structure]{@link https://docs.ccxt.com/#/?id=fee-structure}
@@ -1246,7 +1249,7 @@ export default class lbank extends Exchange {
1246
1249
  * @method
1247
1250
  * @name lbank2#fetchTradingFees
1248
1251
  * @description fetch the trading fees for multiple markets
1249
- * @see https://www.lbank.info/en-US/docs/index.html#transaction-fee-rate-query
1252
+ * @see https://www.lbank.com/en-US/docs/index.html#transaction-fee-rate-query
1250
1253
  * @param {object} [params] extra parameters specific to the exchange API endpoint
1251
1254
  * @returns {object} a dictionary of [fee structures]{@link https://docs.ccxt.com/#/?id=fee-structure} indexed by market symbols
1252
1255
  */
@@ -1262,13 +1265,33 @@ export default class lbank extends Exchange {
1262
1265
  }
1263
1266
  return result;
1264
1267
  }
1268
+ async createMarketBuyOrderWithCost(symbol, cost, params = {}) {
1269
+ /**
1270
+ * @method
1271
+ * @name lbank#createMarketBuyOrderWithCost
1272
+ * @description create a market buy order by providing the symbol and cost
1273
+ * @see https://www.lbank.com/en-US/docs/index.html#place-order
1274
+ * @see https://www.lbank.com/en-US/docs/index.html#place-an-order
1275
+ * @param {string} symbol unified symbol of the market to create an order in
1276
+ * @param {float} cost how much you want to trade in units of the quote currency
1277
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
1278
+ * @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
1279
+ */
1280
+ await this.loadMarkets();
1281
+ const market = this.market(symbol);
1282
+ if (!market['spot']) {
1283
+ throw new NotSupported(this.id + ' createMarketBuyOrderWithCost() supports spot orders only');
1284
+ }
1285
+ params['createMarketBuyOrderRequiresPrice'] = false;
1286
+ return await this.createOrder(symbol, 'market', 'buy', cost, undefined, params);
1287
+ }
1265
1288
  async createOrder(symbol, type, side, amount, price = undefined, params = {}) {
1266
1289
  /**
1267
1290
  * @method
1268
1291
  * @name lbank2#createOrder
1269
1292
  * @description create a trade order
1270
- * @see https://www.lbank.info/en-US/docs/index.html#place-order
1271
- * @see https://www.lbank.info/en-US/docs/index.html#place-an-order
1293
+ * @see https://www.lbank.com/en-US/docs/index.html#place-order
1294
+ * @see https://www.lbank.com/en-US/docs/index.html#place-an-order
1272
1295
  * @param {string} symbol unified symbol of the market to create an order in
1273
1296
  * @param {string} type 'market' or 'limit'
1274
1297
  * @param {string} side 'buy' or 'sell'
@@ -1313,21 +1336,30 @@ export default class lbank extends Exchange {
1313
1336
  }
1314
1337
  else if (side === 'buy') {
1315
1338
  request['type'] = side + '_' + 'market';
1316
- if (this.options['createMarketBuyOrderRequiresPrice']) {
1339
+ let quoteAmount = undefined;
1340
+ let createMarketBuyOrderRequiresPrice = true;
1341
+ [createMarketBuyOrderRequiresPrice, params] = this.handleOptionAndParams(params, 'createOrder', 'createMarketBuyOrderRequiresPrice', true);
1342
+ const cost = this.safeNumber(params, 'cost');
1343
+ params = this.omit(params, 'cost');
1344
+ if (cost !== undefined) {
1345
+ quoteAmount = this.costToPrecision(symbol, cost);
1346
+ }
1347
+ else if (createMarketBuyOrderRequiresPrice) {
1317
1348
  if (price === undefined) {
1318
- 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 the 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)");
1349
+ 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');
1319
1350
  }
1320
1351
  else {
1321
1352
  const amountString = this.numberToString(amount);
1322
1353
  const priceString = this.numberToString(price);
1323
- const quoteAmount = Precise.stringMul(amountString, priceString);
1324
- const cost = this.parseNumber(quoteAmount);
1325
- request['price'] = this.priceToPrecision(symbol, cost);
1354
+ const costRequest = Precise.stringMul(amountString, priceString);
1355
+ quoteAmount = this.costToPrecision(symbol, costRequest);
1326
1356
  }
1327
1357
  }
1328
1358
  else {
1329
- request['price'] = amount;
1359
+ quoteAmount = this.costToPrecision(symbol, amount);
1330
1360
  }
1361
+ // market buys require filling the price param instead of the amount param, for market buys the price is treated as the cost by lbank
1362
+ request['price'] = quoteAmount;
1331
1363
  }
1332
1364
  }
1333
1365
  if (clientOrderId !== undefined) {
@@ -1499,8 +1531,8 @@ export default class lbank extends Exchange {
1499
1531
  * @method
1500
1532
  * @name lbank2#fetchOrder
1501
1533
  * @description fetches information on an order made by the user
1502
- * @see https://www.lbank.info/en-US/docs/index.html#query-order
1503
- * @see https://www.lbank.info/en-US/docs/index.html#query-order-new
1534
+ * @see https://www.lbank.com/en-US/docs/index.html#query-order
1535
+ * @see https://www.lbank.com/en-US/docs/index.html#query-order-new
1504
1536
  * @param {string} symbol unified symbol of the market the order was made in
1505
1537
  * @param {object} [params] extra parameters specific to the exchange API endpoint
1506
1538
  * @returns {object} An [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
@@ -1603,7 +1635,7 @@ export default class lbank extends Exchange {
1603
1635
  * @method
1604
1636
  * @name lbank2#fetchMyTrades
1605
1637
  * @description fetch all trades made by the user
1606
- * @see https://www.lbank.info/en-US/docs/index.html#past-transaction-details
1638
+ * @see https://www.lbank.com/en-US/docs/index.html#past-transaction-details
1607
1639
  * @param {string} symbol unified market symbol
1608
1640
  * @param {int} [since] the earliest time in ms to fetch trades for
1609
1641
  * @param {int} [limit] the maximum number of trade structures to retrieve
@@ -1662,7 +1694,7 @@ export default class lbank extends Exchange {
1662
1694
  * @method
1663
1695
  * @name lbank2#fetchOrders
1664
1696
  * @description fetches information on multiple orders made by the user
1665
- * @see https://www.lbank.info/en-US/docs/index.html#query-all-orders
1697
+ * @see https://www.lbank.com/en-US/docs/index.html#query-all-orders
1666
1698
  * @param {string} symbol unified market symbol of the market orders were made in
1667
1699
  * @param {int} [since] the earliest time in ms to fetch orders for
1668
1700
  * @param {int} [limit] the maximum number of order structures to retrieve
@@ -1722,7 +1754,7 @@ export default class lbank extends Exchange {
1722
1754
  * @method
1723
1755
  * @name lbank2#fetchOpenOrders
1724
1756
  * @description fetch all unfilled currently open orders
1725
- * @see https://www.lbank.info/en-US/docs/index.html#current-pending-order
1757
+ * @see https://www.lbank.com/en-US/docs/index.html#current-pending-order
1726
1758
  * @param {string} symbol unified market symbol
1727
1759
  * @param {int} [since] the earliest time in ms to fetch open orders for
1728
1760
  * @param {int} [limit] the maximum number of open order structures to retrieve
@@ -1779,7 +1811,7 @@ export default class lbank extends Exchange {
1779
1811
  * @method
1780
1812
  * @name lbank2#cancelOrder
1781
1813
  * @description cancels an open order
1782
- * @see https://www.lbank.info/en-US/docs/index.html#cancel-order-new
1814
+ * @see https://www.lbank.com/en-US/docs/index.html#cancel-order-new
1783
1815
  * @param {string} id order id
1784
1816
  * @param {string} symbol unified symbol of the market the order was made in
1785
1817
  * @param {object} [params] extra parameters specific to the exchange API endpoint
@@ -1821,7 +1853,7 @@ export default class lbank extends Exchange {
1821
1853
  * @method
1822
1854
  * @name lbank2#cancelAllOrders
1823
1855
  * @description cancel all open orders in a market
1824
- * @see https://www.lbank.info/en-US/docs/index.html#cancel-all-pending-orders-for-a-single-trading-pair
1856
+ * @see https://www.lbank.com/en-US/docs/index.html#cancel-all-pending-orders-for-a-single-trading-pair
1825
1857
  * @param {string} symbol unified market symbol of the market to cancel orders in
1826
1858
  * @param {object} [params] extra parameters specific to the exchange API endpoint
1827
1859
  * @returns {object[]} a list of [order structures]{@link https://docs.ccxt.com/#/?id=order-structure}
@@ -1868,8 +1900,8 @@ export default class lbank extends Exchange {
1868
1900
  * @method
1869
1901
  * @name lbank2#fetchDepositAddress
1870
1902
  * @description fetch the deposit address for a currency associated with this account
1871
- * @see https://www.lbank.info/en-US/docs/index.html#get-deposit-address
1872
- * @see https://www.lbank.info/en-US/docs/index.html#the-user-obtains-the-deposit-address
1903
+ * @see https://www.lbank.com/en-US/docs/index.html#get-deposit-address
1904
+ * @see https://www.lbank.com/en-US/docs/index.html#the-user-obtains-the-deposit-address
1873
1905
  * @param {string} code unified currency code
1874
1906
  * @param {object} [params] extra parameters specific to the exchange API endpoint
1875
1907
  * @returns {object} an [address structure]{@link https://docs.ccxt.com/#/?id=address-structure}
@@ -1967,7 +1999,7 @@ export default class lbank extends Exchange {
1967
1999
  * @method
1968
2000
  * @name lbank2#withdraw
1969
2001
  * @description make a withdrawal
1970
- * @see https://www.lbank.info/en-US/docs/index.html#withdrawal
2002
+ * @see https://www.lbank.com/en-US/docs/index.html#withdrawal
1971
2003
  * @param {string} code unified currency code
1972
2004
  * @param {float} amount the amount to withdraw
1973
2005
  * @param {string} address the address to withdraw to
@@ -2133,7 +2165,7 @@ export default class lbank extends Exchange {
2133
2165
  * @method
2134
2166
  * @name lbank2#fetchDeposits
2135
2167
  * @description fetch all deposits made to an account
2136
- * @see https://www.lbank.info/en-US/docs/index.html#get-recharge-history
2168
+ * @see https://www.lbank.com/en-US/docs/index.html#get-recharge-history
2137
2169
  * @param {string} code unified currency code
2138
2170
  * @param {int} [since] the earliest time in ms to fetch deposits for
2139
2171
  * @param {int} [limit] the maximum number of deposits structures to retrieve
@@ -2186,7 +2218,7 @@ export default class lbank extends Exchange {
2186
2218
  * @method
2187
2219
  * @name lbank2#fetchWithdrawals
2188
2220
  * @description fetch all withdrawals made from an account
2189
- * @see https://www.lbank.info/en-US/docs/index.html#get-withdrawal-history
2221
+ * @see https://www.lbank.com/en-US/docs/index.html#get-withdrawal-history
2190
2222
  * @param {string} code unified currency code
2191
2223
  * @param {int} [since] the earliest time in ms to fetch withdrawals for
2192
2224
  * @param {int} [limit] the maximum number of withdrawals structures to retrieve
@@ -2389,8 +2421,8 @@ export default class lbank extends Exchange {
2389
2421
  * @method
2390
2422
  * @name lbank2#fetchDepositWithdrawFees
2391
2423
  * @description when using private endpoint, only returns information for currencies with non-zero balance, use public method by specifying this.options['fetchDepositWithdrawFees']['method'] = 'fetchPublicDepositWithdrawFees'
2392
- * @see https://www.lbank.info/en-US/docs/index.html#get-all-coins-information
2393
- * @see https://www.lbank.info/en-US/docs/index.html#withdrawal-configurations
2424
+ * @see https://www.lbank.com/en-US/docs/index.html#get-all-coins-information
2425
+ * @see https://www.lbank.com/en-US/docs/index.html#withdrawal-configurations
2394
2426
  * @param {string[]|undefined} codes array of unified currency codes
2395
2427
  * @param {object} [params] extra parameters specific to the exchange API endpoint
2396
2428
  * @returns {object} a list of [fee structures]{@link https://docs.ccxt.com/#/?id=fee-structure}
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,
@@ -3137,7 +3139,13 @@ export default class okx extends Exchange {
3137
3139
  });
3138
3140
  }
3139
3141
  }
3140
- const response = await this[method](request); // * dont extend with params, otherwise ARRAY will be turned into OBJECT
3142
+ let response = undefined;
3143
+ if (method === 'privatePostTradeCancelAlgos') {
3144
+ response = await this.privatePostTradeCancelAlgos(request); // * dont extend with params, otherwise ARRAY will be turned into OBJECT
3145
+ }
3146
+ else {
3147
+ response = await this.privatePostTradeCancelBatchOrders(request); // * dont extend with params, otherwise ARRAY will be turned into OBJECT
3148
+ }
3141
3149
  //
3142
3150
  // {
3143
3151
  // "code": "0",
@@ -3436,7 +3444,13 @@ export default class okx extends Exchange {
3436
3444
  }
3437
3445
  }
3438
3446
  const query = this.omit(params, ['method', 'clOrdId', 'clientOrderId', 'stop']);
3439
- const response = await this[method](this.extend(request, query));
3447
+ let response = undefined;
3448
+ if (method === 'privateGetTradeOrderAlgo') {
3449
+ response = await this.privateGetTradeOrderAlgo(this.extend(request, query));
3450
+ }
3451
+ else {
3452
+ response = await this.privateGetTradeOrder(this.extend(request, query));
3453
+ }
3440
3454
  //
3441
3455
  // Spot and Swap
3442
3456
  //
@@ -3595,7 +3609,13 @@ export default class okx extends Exchange {
3595
3609
  }
3596
3610
  }
3597
3611
  const query = this.omit(params, ['method', 'stop']);
3598
- const response = await this[method](this.extend(request, query));
3612
+ let response = undefined;
3613
+ if (method === 'privateGetTradeOrdersAlgoPending') {
3614
+ response = await this.privateGetTradeOrdersAlgoPending(this.extend(request, query));
3615
+ }
3616
+ else {
3617
+ response = await this.privateGetTradeOrdersPending(this.extend(request, query));
3618
+ }
3599
3619
  //
3600
3620
  // {
3601
3621
  // "code": "0",
@@ -3767,7 +3787,13 @@ export default class okx extends Exchange {
3767
3787
  }
3768
3788
  }
3769
3789
  const send = this.omit(query, ['method', 'stop', 'ordType']);
3770
- const response = await this[method](this.extend(request, send));
3790
+ let response = undefined;
3791
+ if (method === 'privateGetTradeOrdersAlgoHistory') {
3792
+ response = await this.privateGetTradeOrdersAlgoHistory(this.extend(request, send));
3793
+ }
3794
+ else {
3795
+ response = await this.privateGetTradeOrdersHistory(this.extend(request, send));
3796
+ }
3771
3797
  //
3772
3798
  // {
3773
3799
  // "code": "0",
@@ -3944,7 +3970,13 @@ export default class okx extends Exchange {
3944
3970
  request['state'] = 'filled';
3945
3971
  }
3946
3972
  const send = this.omit(query, ['method', 'stop']);
3947
- const response = await this[method](this.extend(request, send));
3973
+ let response = undefined;
3974
+ if (method === 'privateGetTradeOrdersAlgoHistory') {
3975
+ response = await this.privateGetTradeOrdersAlgoHistory(this.extend(request, send));
3976
+ }
3977
+ else {
3978
+ response = await this.privateGetTradeOrdersHistory(this.extend(request, send));
3979
+ }
3948
3980
  //
3949
3981
  // {
3950
3982
  // "code": "0",
@@ -4197,7 +4229,16 @@ export default class okx extends Exchange {
4197
4229
  request['ccy'] = currency['id'];
4198
4230
  }
4199
4231
  [request, params] = this.handleUntilOption('end', request, params);
4200
- const response = await this[method](this.extend(request, query));
4232
+ let response = undefined;
4233
+ if (method === 'privateGetAccountBillsArchive') {
4234
+ response = await this.privateGetAccountBillsArchive(this.extend(request, query));
4235
+ }
4236
+ else if (method === 'privateGetAssetBills') {
4237
+ response = await this.privateGetAssetBills(this.extend(request, query));
4238
+ }
4239
+ else {
4240
+ response = await this.privateGetAccountBills(this.extend(request, query));
4241
+ }
4201
4242
  //
4202
4243
  // privateGetAccountBills, privateGetAccountBillsArchive
4203
4244
  //
@@ -5109,7 +5150,13 @@ export default class okx extends Exchange {
5109
5150
  }
5110
5151
  const fetchPositionsOptions = this.safeValue(this.options, 'fetchPositions', {});
5111
5152
  const method = this.safeString(fetchPositionsOptions, 'method', 'privateGetAccountPositions');
5112
- const response = await this[method](this.extend(request, params));
5153
+ let response = undefined;
5154
+ if (method === 'privateGetAccountPositionsHistory') {
5155
+ response = await this.privateGetAccountPositionsHistory(this.extend(request, params));
5156
+ }
5157
+ else {
5158
+ response = await this.privateGetAccountPositions(this.extend(request, params));
5159
+ }
5113
5160
  //
5114
5161
  // {
5115
5162
  // "code": "0",
@@ -7122,6 +7169,74 @@ export default class okx extends Exchange {
7122
7169
  'info': greeks,
7123
7170
  };
7124
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
+ }
7125
7240
  handleErrors(httpCode, reason, url, method, headers, body, response, requestHeaders, requestBody) {
7126
7241
  if (!response) {
7127
7242
  return undefined; // fallback to default error handler
@@ -499,7 +499,7 @@ export default class binance extends binanceRest {
499
499
  * @param {int} [since] timestamp in ms of the earliest trade to fetch
500
500
  * @param {int} [limit] the maximum amount of trades to fetch
501
501
  * @param {object} [params] extra parameters specific to the exchange API endpoint
502
- * @returns {object[]} a list of [trade structures]{@link https://docs.ccxt.com/en/latest/manual.html?#public-trades}
502
+ * @returns {object[]} a list of [trade structures]{@link https://docs.ccxt.com/#/?id=public-trades}
503
503
  */
504
504
  await this.loadMarkets();
505
505
  symbols = this.marketSymbols(symbols, undefined, false, true, true);
@@ -528,7 +528,7 @@ export default class bingx extends bingxRest {
528
528
  * @see https://bingx-api.github.io/docs/#/swapV2/socket/account.html#Account%20balance%20and%20position%20update%20push
529
529
  * @description query for balance and get the amount of funds available for trading or funds locked in orders
530
530
  * @param {object} [params] extra parameters specific to the exchange API endpoint
531
- * @returns {object} a [balance structure]{@link https://docs.ccxt.com/en/latest/manual.html?#balance-structure}
531
+ * @returns {object} a [balance structure]{@link https://docs.ccxt.com/#/?id=balance-structure}
532
532
  */
533
533
  await this.loadMarkets();
534
534
  await this.authenticate();
@@ -664,7 +664,7 @@ export default class bitget extends bitgetRest {
664
664
  * @param {int} [since] timestamp in ms of the earliest trade to fetch
665
665
  * @param {int} [limit] the maximum amount of trades to fetch
666
666
  * @param {object} [params] extra parameters specific to the exchange API endpoint
667
- * @returns {object[]} a list of [trade structures]{@link https://docs.ccxt.com/en/latest/manual.html?#public-trades}
667
+ * @returns {object[]} a list of [trade structures]{@link https://docs.ccxt.com/#/?id=public-trades}
668
668
  */
669
669
  const symbolsLength = symbols.length;
670
670
  if (symbolsLength === 0) {
@@ -704,7 +704,7 @@ export default class bybit extends bybitRest {
704
704
  * @param {int} [since] timestamp in ms of the earliest trade to fetch
705
705
  * @param {int} [limit] the maximum amount of trades to fetch
706
706
  * @param {object} [params] extra parameters specific to the exchange API endpoint
707
- * @returns {object[]} a list of [trade structures]{@link https://docs.ccxt.com/en/latest/manual.html?#public-trades}
707
+ * @returns {object[]} a list of [trade structures]{@link https://docs.ccxt.com/#/?id=public-trades}
708
708
  */
709
709
  await this.loadMarkets();
710
710
  symbols = this.marketSymbols(symbols);