ccxt 4.4.21 → 4.4.22

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 (52) hide show
  1. package/README.md +4 -4
  2. package/dist/ccxt.browser.min.js +4 -4
  3. package/dist/cjs/ccxt.js +1 -1
  4. package/dist/cjs/src/alpaca.js +1 -0
  5. package/dist/cjs/src/base/Exchange.js +21 -0
  6. package/dist/cjs/src/bigone.js +3 -0
  7. package/dist/cjs/src/binance.js +103 -0
  8. package/dist/cjs/src/bitflyer.js +57 -0
  9. package/dist/cjs/src/bitget.js +77 -0
  10. package/dist/cjs/src/bybit.js +78 -0
  11. package/dist/cjs/src/cex.js +1307 -1385
  12. package/dist/cjs/src/cryptocom.js +1 -1
  13. package/dist/cjs/src/gate.js +103 -3
  14. package/dist/cjs/src/htx.js +1 -7
  15. package/dist/cjs/src/hyperliquid.js +10 -8
  16. package/dist/cjs/src/kucoin.js +27 -59
  17. package/dist/cjs/src/okx.js +74 -0
  18. package/js/ccxt.d.ts +3 -3
  19. package/js/ccxt.js +1 -1
  20. package/js/src/abstract/bitflyer.d.ts +1 -0
  21. package/js/src/abstract/bitget.d.ts +3 -0
  22. package/js/src/abstract/cex.d.ts +28 -29
  23. package/js/src/abstract/gate.d.ts +5 -0
  24. package/js/src/abstract/gateio.d.ts +5 -0
  25. package/js/src/abstract/kucoin.d.ts +1 -0
  26. package/js/src/abstract/kucoinfutures.d.ts +1 -0
  27. package/js/src/abstract/okx.d.ts +1 -0
  28. package/js/src/alpaca.js +1 -0
  29. package/js/src/base/Exchange.d.ts +8 -2
  30. package/js/src/base/Exchange.js +21 -0
  31. package/js/src/base/types.d.ts +8 -0
  32. package/js/src/bigone.js +3 -0
  33. package/js/src/binance.d.ts +3 -1
  34. package/js/src/binance.js +103 -0
  35. package/js/src/bitflyer.d.ts +3 -1
  36. package/js/src/bitflyer.js +57 -0
  37. package/js/src/bitget.d.ts +3 -1
  38. package/js/src/bitget.js +77 -0
  39. package/js/src/bybit.d.ts +3 -1
  40. package/js/src/bybit.js +78 -0
  41. package/js/src/cex.d.ts +34 -20
  42. package/js/src/cex.js +1308 -1386
  43. package/js/src/cryptocom.js +1 -1
  44. package/js/src/gate.d.ts +2 -0
  45. package/js/src/gate.js +103 -3
  46. package/js/src/htx.js +1 -7
  47. package/js/src/hyperliquid.js +10 -8
  48. package/js/src/kucoin.d.ts +0 -1
  49. package/js/src/kucoin.js +27 -59
  50. package/js/src/okx.d.ts +3 -1
  51. package/js/src/okx.js +74 -0
  52. package/package.json +1 -1
@@ -1615,7 +1615,7 @@ class cryptocom extends cryptocom$1 {
1615
1615
  let paginate = false;
1616
1616
  [paginate, params] = this.handleOptionAndParams(params, 'fetchMyTrades', 'paginate');
1617
1617
  if (paginate) {
1618
- return await this.fetchPaginatedCallDynamic('fetchMyTrades', symbol, since, limit, params);
1618
+ return await this.fetchPaginatedCallDynamic('fetchMyTrades', symbol, since, limit, params, 100);
1619
1619
  }
1620
1620
  const request = {};
1621
1621
  let market = undefined;
@@ -321,10 +321,17 @@ class gate extends gate$1 {
321
321
  'interest_records': 20 / 15,
322
322
  'estimate_rate': 20 / 15,
323
323
  'currency_discount_tiers': 20 / 15,
324
+ 'risk_units': 20 / 15,
325
+ 'unified_mode': 20 / 15,
326
+ 'loan_margin_tiers': 20 / 15,
324
327
  },
325
328
  'post': {
326
329
  'account_mode': 20 / 15,
327
- 'loans': 200 / 15, // 15r/10s cost = 20 / 1.5 = 13.33
330
+ 'loans': 200 / 15,
331
+ 'portfolio_calculator': 20 / 15,
332
+ },
333
+ 'put': {
334
+ 'unified_mode': 20 / 15,
328
335
  },
329
336
  },
330
337
  'spot': {
@@ -626,6 +633,7 @@ class gate extends gate$1 {
626
633
  },
627
634
  'options': {
628
635
  'sandboxMode': false,
636
+ 'unifiedAccount': undefined,
629
637
  'createOrder': {
630
638
  'expiration': 86400, // for conditional orders
631
639
  },
@@ -887,6 +895,37 @@ class gate extends gate$1 {
887
895
  super.setSandboxMode(enable);
888
896
  this.options['sandboxMode'] = enable;
889
897
  }
898
+ async loadUnifiedStatus(params = {}) {
899
+ /**
900
+ * @method
901
+ * @name gate#isUnifiedEnabled
902
+ * @description returns unifiedAccount so the user can check if the unified account is enabled
903
+ * @see https://www.gate.io/docs/developers/apiv4/#get-account-detail
904
+ * @returns {boolean} true or false if the enabled unified account is enabled or not and sets the unifiedAccount option if it is undefined
905
+ */
906
+ const unifiedAccount = this.safeBool(this.options, 'unifiedAccount');
907
+ if (unifiedAccount === undefined) {
908
+ const response = await this.privateAccountGetDetail(params);
909
+ //
910
+ // {
911
+ // "user_id": 10406147,
912
+ // "ip_whitelist": [],
913
+ // "currency_pairs": [],
914
+ // "key": {
915
+ // "mode": 1
916
+ // },
917
+ // "tier": 0,
918
+ // "tier_expire_time": "0001-01-01T00:00:00Z",
919
+ // "copy_trading_role": 0
920
+ // }
921
+ //
922
+ const result = this.safeDict(response, 'key', {});
923
+ this.options['unifiedAccount'] = this.safeInteger(result, 'mode') === 2;
924
+ }
925
+ }
926
+ async upgradeUnifiedTradeAccount(params = {}) {
927
+ return await this.privateUnifiedPutUnifiedMode(params);
928
+ }
890
929
  createExpiredOptionMarket(symbol) {
891
930
  // support expired option contracts
892
931
  const quote = 'USDT';
@@ -1576,6 +1615,9 @@ class gate extends gate$1 {
1576
1615
  if (apiBackup !== undefined) {
1577
1616
  return undefined;
1578
1617
  }
1618
+ if (this.checkRequiredCredentials(false)) {
1619
+ await this.loadUnifiedStatus();
1620
+ }
1579
1621
  const response = await this.publicSpotGetCurrencies(params);
1580
1622
  //
1581
1623
  // {
@@ -2678,10 +2720,14 @@ class gate extends gate$1 {
2678
2720
  * @param {string} [params.settle] 'btc' or 'usdt' - settle currency for perpetual swap and future - default="usdt" for swap and "btc" for future
2679
2721
  * @param {string} [params.marginMode] 'cross' or 'isolated' - marginMode for margin trading if not provided this.options['defaultMarginMode'] is used
2680
2722
  * @param {string} [params.symbol] margin only - unified ccxt symbol
2723
+ * @param {boolean} [params.unifiedAccount] default false, set to true for fetching the unified account balance
2681
2724
  */
2682
2725
  await this.loadMarkets();
2726
+ await this.loadUnifiedStatus();
2683
2727
  const symbol = this.safeString(params, 'symbol');
2684
2728
  params = this.omit(params, 'symbol');
2729
+ let isUnifiedAccount = false;
2730
+ [isUnifiedAccount, params] = this.handleOptionAndParams(params, 'fetchBalance', 'unifiedAccount');
2685
2731
  const [type, query] = this.handleMarketTypeAndParams('fetchBalance', undefined, params);
2686
2732
  const [request, requestParams] = this.prepareRequest(undefined, type, query);
2687
2733
  const [marginMode, requestQuery] = this.getMarginMode(false, requestParams);
@@ -2690,7 +2736,10 @@ class gate extends gate$1 {
2690
2736
  request['currency_pair'] = market['id'];
2691
2737
  }
2692
2738
  let response = undefined;
2693
- if (type === 'spot') {
2739
+ if (isUnifiedAccount) {
2740
+ response = await this.privateUnifiedGetAccounts(this.extend(request, params));
2741
+ }
2742
+ else if (type === 'spot') {
2694
2743
  if (marginMode === 'spot') {
2695
2744
  response = await this.privateSpotGetAccounts(this.extend(request, requestQuery));
2696
2745
  }
@@ -2864,12 +2913,63 @@ class gate extends gate$1 {
2864
2913
  // "orders_limit": 10
2865
2914
  // }
2866
2915
  //
2916
+ // unified
2917
+ //
2918
+ // {
2919
+ // "user_id": 10001,
2920
+ // "locked": false,
2921
+ // "balances": {
2922
+ // "ETH": {
2923
+ // "available": "0",
2924
+ // "freeze": "0",
2925
+ // "borrowed": "0.075393666654",
2926
+ // "negative_liab": "0",
2927
+ // "futures_pos_liab": "0",
2928
+ // "equity": "1016.1",
2929
+ // "total_freeze": "0",
2930
+ // "total_liab": "0"
2931
+ // },
2932
+ // "POINT": {
2933
+ // "available": "9999999999.017023138734",
2934
+ // "freeze": "0",
2935
+ // "borrowed": "0",
2936
+ // "negative_liab": "0",
2937
+ // "futures_pos_liab": "0",
2938
+ // "equity": "12016.1",
2939
+ // "total_freeze": "0",
2940
+ // "total_liab": "0"
2941
+ // },
2942
+ // "USDT": {
2943
+ // "available": "0.00000062023",
2944
+ // "freeze": "0",
2945
+ // "borrowed": "0",
2946
+ // "negative_liab": "0",
2947
+ // "futures_pos_liab": "0",
2948
+ // "equity": "16.1",
2949
+ // "total_freeze": "0",
2950
+ // "total_liab": "0"
2951
+ // }
2952
+ // },
2953
+ // "total": "230.94621713",
2954
+ // "borrowed": "161.66395521",
2955
+ // "total_initial_margin": "1025.0524665088",
2956
+ // "total_margin_balance": "3382495.944473949183",
2957
+ // "total_maintenance_margin": "205.01049330176",
2958
+ // "total_initial_margin_rate": "3299.827135672679",
2959
+ // "total_maintenance_margin_rate": "16499.135678363399",
2960
+ // "total_available_margin": "3381470.892007440383",
2961
+ // "unified_account_total": "3381470.892007440383",
2962
+ // "unified_account_total_liab": "0",
2963
+ // "unified_account_total_equity": "100016.1",
2964
+ // "leverage": "2"
2965
+ // }
2966
+ //
2867
2967
  const result = {
2868
2968
  'info': response,
2869
2969
  };
2870
2970
  const isolated = marginMode === 'margin';
2871
2971
  let data = response;
2872
- if ('balances' in data) { // True for cross_margin
2972
+ if ('balances' in data) { // True for cross_margin and unified
2873
2973
  const flatBalances = [];
2874
2974
  const balances = this.safeValue(data, 'balances', []);
2875
2975
  // inject currency and create an artificial balance object
@@ -5113,13 +5113,7 @@ class htx extends htx$1 {
5113
5113
  let cost = undefined;
5114
5114
  let amount = undefined;
5115
5115
  if ((type !== undefined) && (type.indexOf('market') >= 0)) {
5116
- // for market orders amount is in quote currency, meaning it is the cost
5117
- if (side === 'sell') {
5118
- cost = this.safeString(order, 'field-cash-amount');
5119
- }
5120
- else {
5121
- cost = this.safeString(order, 'amount');
5122
- }
5116
+ cost = this.safeString(order, 'field-cash-amount');
5123
5117
  }
5124
5118
  else {
5125
5119
  amount = this.safeString2(order, 'volume', 'amount');
@@ -2227,15 +2227,17 @@ class hyperliquid extends hyperliquid$1 {
2227
2227
  const leverage = this.safeDict(entry, 'leverage', {});
2228
2228
  const marginMode = this.safeString(leverage, 'type');
2229
2229
  const isIsolated = (marginMode === 'isolated');
2230
- let size = this.safeString(entry, 'szi');
2230
+ const rawSize = this.safeString(entry, 'szi');
2231
+ let size = rawSize;
2231
2232
  let side = undefined;
2232
2233
  if (size !== undefined) {
2233
- side = Precise["default"].stringGt(size, '0') ? 'long' : 'short';
2234
+ side = Precise["default"].stringGt(rawSize, '0') ? 'long' : 'short';
2234
2235
  size = Precise["default"].stringAbs(size);
2235
2236
  }
2236
- const unrealizedPnl = this.safeNumber(entry, 'unrealizedPnl');
2237
- const initialMargin = this.safeNumber(entry, 'marginUsed');
2238
- const percentage = unrealizedPnl / initialMargin * 100;
2237
+ const rawUnrealizedPnl = this.safeString(entry, 'unrealizedPnl');
2238
+ const absRawUnrealizedPnl = Precise["default"].stringAbs(rawUnrealizedPnl);
2239
+ const initialMargin = this.safeString(entry, 'marginUsed');
2240
+ const percentage = Precise["default"].stringMul(Precise["default"].stringDiv(absRawUnrealizedPnl, initialMargin), '100');
2239
2241
  return this.safePosition({
2240
2242
  'info': position,
2241
2243
  'id': undefined,
@@ -2245,7 +2247,7 @@ class hyperliquid extends hyperliquid$1 {
2245
2247
  'isolated': isIsolated,
2246
2248
  'hedged': undefined,
2247
2249
  'side': side,
2248
- 'contracts': size,
2250
+ 'contracts': this.parseNumber(size),
2249
2251
  'contractSize': undefined,
2250
2252
  'entryPrice': this.safeNumber(entry, 'entryPx'),
2251
2253
  'markPrice': undefined,
@@ -2256,10 +2258,10 @@ class hyperliquid extends hyperliquid$1 {
2256
2258
  'maintenanceMargin': undefined,
2257
2259
  'initialMarginPercentage': undefined,
2258
2260
  'maintenanceMarginPercentage': undefined,
2259
- 'unrealizedPnl': unrealizedPnl,
2261
+ 'unrealizedPnl': this.parseNumber(rawUnrealizedPnl),
2260
2262
  'liquidationPrice': this.safeNumber(entry, 'liquidationPx'),
2261
2263
  'marginMode': marginMode,
2262
- 'percentage': percentage,
2264
+ 'percentage': this.parseNumber(percentage),
2263
2265
  });
2264
2266
  }
2265
2267
  async setMarginMode(marginMode, symbol = undefined, params = {}) {
@@ -288,6 +288,7 @@ class kucoin extends kucoin$1 {
288
288
  // ws
289
289
  'bullet-private': 10,
290
290
  'position/update-user-leverage': 5,
291
+ 'deposit-address/create': 20,
291
292
  },
292
293
  'delete': {
293
294
  // account
@@ -707,6 +708,7 @@ class kucoin extends kucoin$1 {
707
708
  'accounts/sub-transfer': 'v2',
708
709
  'accounts/inner-transfer': 'v2',
709
710
  'transfer-out': 'v3',
711
+ 'deposit-address/create': 'v3',
710
712
  // spot trading
711
713
  'oco/order': 'v3',
712
714
  // margin trading
@@ -718,6 +720,7 @@ class kucoin extends kucoin$1 {
718
720
  'redeem': 'v3',
719
721
  'lend/purchase/update': 'v3',
720
722
  'position/update-user-leverage': 'v3',
723
+ 'withdrawals': 'v3',
721
724
  },
722
725
  'DELETE': {
723
726
  // account
@@ -783,7 +786,7 @@ class kucoin extends kucoin$1 {
783
786
  'TLOS': 'tlos',
784
787
  'CFX': 'cfx',
785
788
  'ACA': 'aca',
786
- 'OPTIMISM': 'optimism',
789
+ 'OP': 'optimism',
787
790
  'ONT': 'ont',
788
791
  'GLMR': 'glmr',
789
792
  'CSPR': 'cspr',
@@ -1894,7 +1897,7 @@ class kucoin extends kucoin$1 {
1894
1897
  /**
1895
1898
  * @method
1896
1899
  * @name kucoin#createDepositAddress
1897
- * @see https://docs.kucoin.com/#create-deposit-address
1900
+ * @see https://www.kucoin.com/docs/rest/funding/deposit/create-deposit-address-v3-
1898
1901
  * @description create a currency deposit address
1899
1902
  * @param {string} code unified currency code of the currency for the deposit address
1900
1903
  * @param {object} [params] extra parameters specific to the exchange API endpoint
@@ -1909,12 +1912,24 @@ class kucoin extends kucoin$1 {
1909
1912
  let networkCode = undefined;
1910
1913
  [networkCode, params] = this.handleNetworkCodeAndParams(params);
1911
1914
  if (networkCode !== undefined) {
1912
- request['chain'] = this.networkCodeToId(networkCode).toLowerCase();
1915
+ request['chain'] = this.networkCodeToId(networkCode); // docs mention "chain-name", but seems "chain-id" is used, like in "fetchDepositAddress"
1913
1916
  }
1914
- const response = await this.privatePostDepositAddresses(this.extend(request, params));
1917
+ const response = await this.privatePostDepositAddressCreate(this.extend(request, params));
1915
1918
  // {"code":"260000","msg":"Deposit address already exists."}
1916
- // BCH {"code":"200000","data":{"address":"bitcoincash:qza3m4nj9rx7l9r0cdadfqxts6f92shvhvr5ls4q7z","memo":""}}
1917
- // BTC {"code":"200000","data":{"address":"36SjucKqQpQSvsak9A7h6qzFjrVXpRNZhE","memo":""}}
1919
+ //
1920
+ // {
1921
+ // "code": "200000",
1922
+ // "data": {
1923
+ // "address": "0x2336d1834faab10b2dac44e468f2627138417431",
1924
+ // "memo": null,
1925
+ // "chainId": "bsc",
1926
+ // "to": "MAIN",
1927
+ // "expirationDate": 0,
1928
+ // "currency": "BNB",
1929
+ // "chainName": "BEP20"
1930
+ // }
1931
+ // }
1932
+ //
1918
1933
  const data = this.safeDict(response, 'data', {});
1919
1934
  return this.parseDepositAddress(data, currency);
1920
1935
  }
@@ -1971,7 +1986,7 @@ class kucoin extends kucoin$1 {
1971
1986
  return {
1972
1987
  'info': depositAddress,
1973
1988
  'currency': code,
1974
- 'network': this.networkIdToCode(this.safeString(depositAddress, 'chain')),
1989
+ 'network': this.networkIdToCode(this.safeString(depositAddress, 'chainId')),
1975
1990
  'address': address,
1976
1991
  'tag': this.safeString(depositAddress, 'memo'),
1977
1992
  };
@@ -3433,7 +3448,7 @@ class kucoin extends kucoin$1 {
3433
3448
  * @method
3434
3449
  * @name kucoin#withdraw
3435
3450
  * @description make a withdrawal
3436
- * @see https://www.kucoin.com/docs/rest/funding/withdrawals/apply-withdraw
3451
+ * @see https://www.kucoin.com/docs/rest/funding/withdrawals/apply-withdraw-v3-
3437
3452
  * @param {string} code unified currency code
3438
3453
  * @param {float} amount the amount to withdraw
3439
3454
  * @param {string} address the address to withdraw to
@@ -3447,7 +3462,8 @@ class kucoin extends kucoin$1 {
3447
3462
  const currency = this.currency(code);
3448
3463
  const request = {
3449
3464
  'currency': currency['id'],
3450
- 'address': address,
3465
+ 'toAddress': address,
3466
+ 'withdrawType': 'ADDRESS',
3451
3467
  // 'memo': tag,
3452
3468
  // 'isInner': false, // internal transfer or external withdrawal
3453
3469
  // 'remark': 'optional',
@@ -3461,8 +3477,7 @@ class kucoin extends kucoin$1 {
3461
3477
  if (networkCode !== undefined) {
3462
3478
  request['chain'] = this.networkCodeToId(networkCode).toLowerCase();
3463
3479
  }
3464
- await this.loadCurrencyPrecision(currency, networkCode);
3465
- request['amount'] = this.currencyToPrecision(code, amount, networkCode);
3480
+ request['amount'] = parseFloat(this.currencyToPrecision(code, amount, networkCode));
3466
3481
  let includeFee = undefined;
3467
3482
  [includeFee, params] = this.handleOptionAndParams(params, 'withdraw', 'includeFee', false);
3468
3483
  if (includeFee) {
@@ -3470,7 +3485,7 @@ class kucoin extends kucoin$1 {
3470
3485
  }
3471
3486
  const response = await this.privatePostWithdrawals(this.extend(request, params));
3472
3487
  //
3473
- // https://github.com/ccxt/ccxt/issues/5558
3488
+ // the id is inside "data"
3474
3489
  //
3475
3490
  // {
3476
3491
  // "code": 200000,
@@ -3482,53 +3497,6 @@ class kucoin extends kucoin$1 {
3482
3497
  const data = this.safeDict(response, 'data', {});
3483
3498
  return this.parseTransaction(data, currency);
3484
3499
  }
3485
- async loadCurrencyPrecision(currency, networkCode = undefined) {
3486
- // as kucoin might not have network specific precisions defined in fetchCurrencies (because of webapi failure)
3487
- // we should check and refetch precision once-per-instance for that specific currency & network
3488
- // so avoids thorwing exceptions and burden to users
3489
- // Note: this needs to be executed only if networkCode was provided
3490
- if (networkCode !== undefined) {
3491
- const networks = currency['networks'];
3492
- const network = this.safeDict(networks, networkCode);
3493
- if (this.safeNumber(network, 'precision') !== undefined) {
3494
- // if precision exists, no need to refetch
3495
- return;
3496
- }
3497
- // otherwise try to fetch and store in instance
3498
- const request = {
3499
- 'currency': currency['id'],
3500
- 'chain': this.networkCodeToId(networkCode).toLowerCase(),
3501
- };
3502
- const response = await this.privateGetWithdrawalsQuotas(request);
3503
- //
3504
- // {
3505
- // "code": "200000",
3506
- // "data": {
3507
- // "currency": "USDT",
3508
- // "limitBTCAmount": "14.24094850",
3509
- // "usedBTCAmount": "0.00000000",
3510
- // "quotaCurrency": "USDT",
3511
- // "limitQuotaCurrencyAmount": "999999.00000000",
3512
- // "usedQuotaCurrencyAmount": "0",
3513
- // "remainAmount": "999999.0000",
3514
- // "availableAmount": "10.77545071",
3515
- // "withdrawMinFee": "1",
3516
- // "innerWithdrawMinFee": "0",
3517
- // "withdrawMinSize": "10",
3518
- // "isWithdrawEnabled": true,
3519
- // "precision": 4,
3520
- // "chain": "EOS",
3521
- // "reason": null,
3522
- // "lockedAmount": "0"
3523
- // }
3524
- // }
3525
- //
3526
- const data = this.safeDict(response, 'data', {});
3527
- const precision = this.parseNumber(this.parsePrecision(this.safeString(data, 'precision')));
3528
- const code = currency['code'];
3529
- this.currencies[code]['networks'][networkCode]['precision'] = precision;
3530
- }
3531
- }
3532
3500
  parseTransactionStatus(status) {
3533
3501
  const statuses = {
3534
3502
  'SUCCESS': 'ok',
@@ -93,6 +93,8 @@ class okx extends okx$1 {
93
93
  'fetchLedgerEntry': undefined,
94
94
  'fetchLeverage': true,
95
95
  'fetchLeverageTiers': false,
96
+ 'fetchLongShortRatio': false,
97
+ 'fetchLongShortRatioHistory': true,
96
98
  'fetchMarginAdjustmentHistory': true,
97
99
  'fetchMarketLeverageTiers': true,
98
100
  'fetchMarkets': true,
@@ -235,6 +237,7 @@ class okx extends okx$1 {
235
237
  'rubik/stat/margin/loan-ratio': 4,
236
238
  // long/short
237
239
  'rubik/stat/contracts/long-short-account-ratio': 4,
240
+ 'rubik/stat/contracts/long-short-account-ratio-contract': 4,
238
241
  'rubik/stat/contracts/open-interest-volume': 4,
239
242
  'rubik/stat/option/open-interest-volume': 4,
240
243
  // put/call
@@ -8497,6 +8500,77 @@ class okx extends okx$1 {
8497
8500
  const positions = this.parsePositions(data, symbols, params);
8498
8501
  return this.filterBySinceLimit(positions, since, limit);
8499
8502
  }
8503
+ async fetchLongShortRatioHistory(symbol = undefined, timeframe = undefined, since = undefined, limit = undefined, params = {}) {
8504
+ /**
8505
+ * @method
8506
+ * @name okx#fetchLongShortRatioHistory
8507
+ * @description fetches the long short ratio history for a unified market symbol
8508
+ * @see https://www.okx.com/docs-v5/en/#trading-statistics-rest-api-get-contract-long-short-ratio
8509
+ * @param {string} symbol unified symbol of the market to fetch the long short ratio for
8510
+ * @param {string} [timeframe] the period for the ratio
8511
+ * @param {int} [since] the earliest time in ms to fetch ratios for
8512
+ * @param {int} [limit] the maximum number of long short ratio structures to retrieve
8513
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
8514
+ * @param {int} [params.until] timestamp in ms of the latest ratio to fetch
8515
+ * @returns {object[]} an array of [long short ratio structures]{@link https://docs.ccxt.com/#/?id=long-short-ratio-structure}
8516
+ */
8517
+ await this.loadMarkets();
8518
+ const market = this.market(symbol);
8519
+ const request = {
8520
+ 'instId': market['id'],
8521
+ };
8522
+ const until = this.safeString2(params, 'until', 'end');
8523
+ params = this.omit(params, 'until');
8524
+ if (until !== undefined) {
8525
+ request['end'] = until;
8526
+ }
8527
+ if (timeframe !== undefined) {
8528
+ request['period'] = timeframe;
8529
+ }
8530
+ if (since !== undefined) {
8531
+ request['begin'] = since;
8532
+ }
8533
+ if (limit !== undefined) {
8534
+ request['limit'] = limit;
8535
+ }
8536
+ const response = await this.publicGetRubikStatContractsLongShortAccountRatioContract(this.extend(request, params));
8537
+ //
8538
+ // {
8539
+ // "code": "0",
8540
+ // "data": [
8541
+ // ["1729323600000", "0.9398602814619824"],
8542
+ // ["1729323300000", "0.9398602814619824"],
8543
+ // ["1729323000000", "0.9398602814619824"],
8544
+ // ],
8545
+ // "msg": ""
8546
+ // }
8547
+ //
8548
+ const data = this.safeList(response, 'data', []);
8549
+ const result = [];
8550
+ for (let i = 0; i < data.length; i++) {
8551
+ const entry = data[i];
8552
+ result.push({
8553
+ 'timestamp': this.safeString(entry, 0),
8554
+ 'longShortRatio': this.safeString(entry, 1),
8555
+ });
8556
+ }
8557
+ return this.parseLongShortRatioHistory(result, market);
8558
+ }
8559
+ parseLongShortRatio(info, market = undefined) {
8560
+ const timestamp = this.safeInteger(info, 'timestamp');
8561
+ let symbol = undefined;
8562
+ if (market !== undefined) {
8563
+ symbol = market['symbol'];
8564
+ }
8565
+ return {
8566
+ 'info': info,
8567
+ 'symbol': symbol,
8568
+ 'timestamp': timestamp,
8569
+ 'datetime': this.iso8601(timestamp),
8570
+ 'timeframe': undefined,
8571
+ 'longShortRatio': this.safeNumber(info, 'longShortRatio'),
8572
+ };
8573
+ }
8500
8574
  }
8501
8575
 
8502
8576
  module.exports = okx;
package/js/ccxt.d.ts CHANGED
@@ -2,9 +2,9 @@ import { Exchange } from './src/base/Exchange.js';
2
2
  import { Precise } from './src/base/Precise.js';
3
3
  import * as functions from './src/base/functions.js';
4
4
  import * as errors from './src/base/errors.js';
5
- import type { Int, int, Str, Strings, Num, Bool, IndexType, OrderSide, OrderType, MarketType, SubType, Dict, NullableDict, List, NullableList, Fee, OHLCV, OHLCVC, implicitReturnType, Market, Currency, Dictionary, MinMax, FeeInterface, TradingFeeInterface, MarketInterface, Trade, Order, OrderBook, Ticker, Transaction, Tickers, CurrencyInterface, Balance, BalanceAccount, Account, PartialBalances, Balances, DepositAddress, WithdrawalResponse, DepositAddressResponse, FundingRate, FundingRates, Position, BorrowInterest, LeverageTier, LedgerEntry, DepositWithdrawFeeNetwork, DepositWithdrawFee, TransferEntry, CrossBorrowRate, IsolatedBorrowRate, FundingRateHistory, OpenInterest, Liquidation, OrderRequest, CancellationRequest, FundingHistory, MarketMarginModes, MarginMode, Greeks, Conversion, Option, LastPrice, Leverage, MarginModification, Leverages, LastPrices, Currencies, TradingFees, MarginModes, OptionChain, IsolatedBorrowRates, CrossBorrowRates, LeverageTiers } from './src/base/types.js';
5
+ import type { Int, int, Str, Strings, Num, Bool, IndexType, OrderSide, OrderType, MarketType, SubType, Dict, NullableDict, List, NullableList, Fee, OHLCV, OHLCVC, implicitReturnType, Market, Currency, Dictionary, MinMax, FeeInterface, TradingFeeInterface, MarketInterface, Trade, Order, OrderBook, Ticker, Transaction, Tickers, CurrencyInterface, Balance, BalanceAccount, Account, PartialBalances, Balances, DepositAddress, WithdrawalResponse, DepositAddressResponse, FundingRate, FundingRates, Position, BorrowInterest, LeverageTier, LedgerEntry, DepositWithdrawFeeNetwork, DepositWithdrawFee, TransferEntry, CrossBorrowRate, IsolatedBorrowRate, FundingRateHistory, OpenInterest, Liquidation, OrderRequest, CancellationRequest, FundingHistory, MarketMarginModes, MarginMode, Greeks, Conversion, Option, LastPrice, Leverage, MarginModification, Leverages, LastPrices, Currencies, TradingFees, MarginModes, OptionChain, IsolatedBorrowRates, CrossBorrowRates, LeverageTiers, LongShortRatio } from './src/base/types.js';
6
6
  import { BaseError, ExchangeError, AuthenticationError, PermissionDenied, AccountNotEnabled, AccountSuspended, ArgumentsRequired, BadRequest, BadSymbol, OperationRejected, NoChange, MarginModeAlreadySet, MarketClosed, ManualInteractionNeeded, InsufficientFunds, InvalidAddress, AddressPending, InvalidOrder, OrderNotFound, OrderNotCached, OrderImmediatelyFillable, OrderNotFillable, DuplicateOrderId, ContractUnavailable, NotSupported, InvalidProxySettings, ExchangeClosedByUser, OperationFailed, NetworkError, DDoSProtection, RateLimitExceeded, ExchangeNotAvailable, OnMaintenance, InvalidNonce, ChecksumError, RequestTimeout, BadResponse, NullResponse, CancelPending, UnsubscribeError } from './src/base/errors.js';
7
- declare const version = "4.4.20";
7
+ declare const version = "4.4.21";
8
8
  import ace from './src/ace.js';
9
9
  import alpaca from './src/alpaca.js';
10
10
  import ascendex from './src/ascendex.js';
@@ -558,5 +558,5 @@ declare const ccxt: {
558
558
  zaif: typeof zaif;
559
559
  zonda: typeof zonda;
560
560
  } & typeof functions & typeof errors;
561
- export { version, Exchange, exchanges, pro, Precise, functions, errors, BaseError, ExchangeError, AuthenticationError, PermissionDenied, AccountNotEnabled, AccountSuspended, ArgumentsRequired, BadRequest, BadSymbol, OperationRejected, NoChange, MarginModeAlreadySet, MarketClosed, ManualInteractionNeeded, InsufficientFunds, InvalidAddress, AddressPending, InvalidOrder, OrderNotFound, OrderNotCached, OrderImmediatelyFillable, OrderNotFillable, DuplicateOrderId, ContractUnavailable, NotSupported, InvalidProxySettings, ExchangeClosedByUser, OperationFailed, NetworkError, DDoSProtection, RateLimitExceeded, ExchangeNotAvailable, OnMaintenance, InvalidNonce, ChecksumError, RequestTimeout, BadResponse, NullResponse, CancelPending, UnsubscribeError, Int, int, Str, Strings, Num, Bool, IndexType, OrderSide, OrderType, MarketType, SubType, Dict, NullableDict, List, NullableList, Fee, OHLCV, OHLCVC, implicitReturnType, Market, Currency, Dictionary, MinMax, FeeInterface, TradingFeeInterface, MarketMarginModes, MarketInterface, Trade, Order, OrderBook, Ticker, Transaction, Tickers, CurrencyInterface, Balance, BalanceAccount, Account, PartialBalances, Balances, DepositAddress, WithdrawalResponse, DepositAddressResponse, FundingRate, FundingRates, Position, BorrowInterest, LeverageTier, LedgerEntry, DepositWithdrawFeeNetwork, DepositWithdrawFee, TransferEntry, CrossBorrowRate, IsolatedBorrowRate, FundingRateHistory, OpenInterest, Liquidation, OrderRequest, CancellationRequest, FundingHistory, MarginMode, Greeks, Conversion, Option, LastPrice, Leverage, MarginModification, Leverages, LastPrices, Currencies, TradingFees, MarginModes, OptionChain, IsolatedBorrowRates, CrossBorrowRates, LeverageTiers, ace, alpaca, ascendex, bequant, bigone, binance, binancecoinm, binanceus, binanceusdm, bingx, bit2c, bitbank, bitbns, bitcoincom, bitfinex, bitfinex2, bitflyer, bitget, bithumb, bitmart, bitmex, bitopro, bitpanda, bitrue, bitso, bitstamp, bitteam, bitvavo, bl3p, blockchaincom, blofin, btcalpha, btcbox, btcmarkets, btcturk, bybit, cex, coinbase, coinbaseadvanced, coinbaseexchange, coinbaseinternational, coincheck, coinex, coinlist, coinmate, coinmetro, coinone, coinsph, coinspot, cryptocom, currencycom, delta, deribit, digifinex, exmo, fmfwio, gate, gateio, gemini, hashkey, hitbtc, hollaex, htx, huobi, huobijp, hyperliquid, idex, independentreserve, indodax, kraken, krakenfutures, kucoin, kucoinfutures, kuna, latoken, lbank, luno, lykke, mercado, mexc, ndax, novadax, oceanex, okcoin, okx, onetrading, oxfun, p2b, paradex, paymium, phemex, poloniex, poloniexfutures, probit, timex, tokocrypto, tradeogre, upbit, vertex, wavesexchange, wazirx, whitebit, woo, woofipro, xt, yobit, zaif, zonda, };
561
+ export { version, Exchange, exchanges, pro, Precise, functions, errors, BaseError, ExchangeError, AuthenticationError, PermissionDenied, AccountNotEnabled, AccountSuspended, ArgumentsRequired, BadRequest, BadSymbol, OperationRejected, NoChange, MarginModeAlreadySet, MarketClosed, ManualInteractionNeeded, InsufficientFunds, InvalidAddress, AddressPending, InvalidOrder, OrderNotFound, OrderNotCached, OrderImmediatelyFillable, OrderNotFillable, DuplicateOrderId, ContractUnavailable, NotSupported, InvalidProxySettings, ExchangeClosedByUser, OperationFailed, NetworkError, DDoSProtection, RateLimitExceeded, ExchangeNotAvailable, OnMaintenance, InvalidNonce, ChecksumError, RequestTimeout, BadResponse, NullResponse, CancelPending, UnsubscribeError, Int, int, Str, Strings, Num, Bool, IndexType, OrderSide, OrderType, MarketType, SubType, Dict, NullableDict, List, NullableList, Fee, OHLCV, OHLCVC, implicitReturnType, Market, Currency, Dictionary, MinMax, FeeInterface, TradingFeeInterface, MarketMarginModes, MarketInterface, Trade, Order, OrderBook, Ticker, Transaction, Tickers, CurrencyInterface, Balance, BalanceAccount, Account, PartialBalances, Balances, DepositAddress, WithdrawalResponse, DepositAddressResponse, FundingRate, FundingRates, Position, BorrowInterest, LeverageTier, LedgerEntry, DepositWithdrawFeeNetwork, DepositWithdrawFee, TransferEntry, CrossBorrowRate, IsolatedBorrowRate, FundingRateHistory, OpenInterest, Liquidation, OrderRequest, CancellationRequest, FundingHistory, MarginMode, Greeks, Conversion, Option, LastPrice, Leverage, LongShortRatio, MarginModification, Leverages, LastPrices, Currencies, TradingFees, MarginModes, OptionChain, IsolatedBorrowRates, CrossBorrowRates, LeverageTiers, ace, alpaca, ascendex, bequant, bigone, binance, binancecoinm, binanceus, binanceusdm, bingx, bit2c, bitbank, bitbns, bitcoincom, bitfinex, bitfinex2, bitflyer, bitget, bithumb, bitmart, bitmex, bitopro, bitpanda, bitrue, bitso, bitstamp, bitteam, bitvavo, bl3p, blockchaincom, blofin, btcalpha, btcbox, btcmarkets, btcturk, bybit, cex, coinbase, coinbaseadvanced, coinbaseexchange, coinbaseinternational, coincheck, coinex, coinlist, coinmate, coinmetro, coinone, coinsph, coinspot, cryptocom, currencycom, delta, deribit, digifinex, exmo, fmfwio, gate, gateio, gemini, hashkey, hitbtc, hollaex, htx, huobi, huobijp, hyperliquid, idex, independentreserve, indodax, kraken, krakenfutures, kucoin, kucoinfutures, kuna, latoken, lbank, luno, lykke, mercado, mexc, ndax, novadax, oceanex, okcoin, okx, onetrading, oxfun, p2b, paradex, paymium, phemex, poloniex, poloniexfutures, probit, timex, tokocrypto, tradeogre, upbit, vertex, wavesexchange, wazirx, whitebit, woo, woofipro, xt, yobit, zaif, zonda, };
562
562
  export default ccxt;
package/js/ccxt.js CHANGED
@@ -38,7 +38,7 @@ import * as errors from './src/base/errors.js';
38
38
  import { BaseError, ExchangeError, AuthenticationError, PermissionDenied, AccountNotEnabled, AccountSuspended, ArgumentsRequired, BadRequest, BadSymbol, OperationRejected, NoChange, MarginModeAlreadySet, MarketClosed, ManualInteractionNeeded, InsufficientFunds, InvalidAddress, AddressPending, InvalidOrder, OrderNotFound, OrderNotCached, OrderImmediatelyFillable, OrderNotFillable, DuplicateOrderId, ContractUnavailable, NotSupported, InvalidProxySettings, ExchangeClosedByUser, OperationFailed, NetworkError, DDoSProtection, RateLimitExceeded, ExchangeNotAvailable, OnMaintenance, InvalidNonce, ChecksumError, RequestTimeout, BadResponse, NullResponse, CancelPending, UnsubscribeError } from './src/base/errors.js';
39
39
  //-----------------------------------------------------------------------------
40
40
  // this is updated by vss.js when building
41
- const version = '4.4.21';
41
+ const version = '4.4.22';
42
42
  Exchange.ccxtVersion = version;
43
43
  //-----------------------------------------------------------------------------
44
44
  import ace from './src/ace.js';
@@ -10,6 +10,7 @@ interface Exchange {
10
10
  publicGetGethealth(params?: {}): Promise<implicitReturnType>;
11
11
  publicGetGetboardstate(params?: {}): Promise<implicitReturnType>;
12
12
  publicGetGetchats(params?: {}): Promise<implicitReturnType>;
13
+ publicGetGetfundingrate(params?: {}): Promise<implicitReturnType>;
13
14
  privateGetGetpermissions(params?: {}): Promise<implicitReturnType>;
14
15
  privateGetGetbalance(params?: {}): Promise<implicitReturnType>;
15
16
  privateGetGetbalancehistory(params?: {}): Promise<implicitReturnType>;
@@ -67,12 +67,14 @@ interface Exchange {
67
67
  publicMixGetV2MixMarketCurrentFundRate(params?: {}): Promise<implicitReturnType>;
68
68
  publicMixGetV2MixMarketContracts(params?: {}): Promise<implicitReturnType>;
69
69
  publicMixGetV2MixMarketQueryPositionLever(params?: {}): Promise<implicitReturnType>;
70
+ publicMixGetV2MixMarketAccountLongShort(params?: {}): Promise<implicitReturnType>;
70
71
  publicMarginGetMarginV1CrossPublicInterestRateAndLimit(params?: {}): Promise<implicitReturnType>;
71
72
  publicMarginGetMarginV1IsolatedPublicInterestRateAndLimit(params?: {}): Promise<implicitReturnType>;
72
73
  publicMarginGetMarginV1CrossPublicTierData(params?: {}): Promise<implicitReturnType>;
73
74
  publicMarginGetMarginV1IsolatedPublicTierData(params?: {}): Promise<implicitReturnType>;
74
75
  publicMarginGetMarginV1PublicCurrencies(params?: {}): Promise<implicitReturnType>;
75
76
  publicMarginGetV2MarginCurrencies(params?: {}): Promise<implicitReturnType>;
77
+ publicMarginGetV2MarginMarketLongShortRatio(params?: {}): Promise<implicitReturnType>;
76
78
  publicEarnGetV2EarnLoanPublicCoinInfos(params?: {}): Promise<implicitReturnType>;
77
79
  publicEarnGetV2EarnLoanPublicHourInterest(params?: {}): Promise<implicitReturnType>;
78
80
  privateSpotGetSpotV1WalletDepositAddress(params?: {}): Promise<implicitReturnType>;
@@ -219,6 +221,7 @@ interface Exchange {
219
221
  privateMixGetV2MixOrderOrdersHistory(params?: {}): Promise<implicitReturnType>;
220
222
  privateMixGetV2MixOrderOrdersPlanPending(params?: {}): Promise<implicitReturnType>;
221
223
  privateMixGetV2MixOrderOrdersPlanHistory(params?: {}): Promise<implicitReturnType>;
224
+ privateMixGetV2MixMarketPositionLongShort(params?: {}): Promise<implicitReturnType>;
222
225
  privateMixPostMixV1AccountSubAccountContractAssets(params?: {}): Promise<implicitReturnType>;
223
226
  privateMixPostMixV1AccountOpenCount(params?: {}): Promise<implicitReturnType>;
224
227
  privateMixPostMixV1AccountSetLeverage(params?: {}): Promise<implicitReturnType>;