ccxt 4.5.18 → 4.5.20

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 (152) hide show
  1. package/README.md +7 -6
  2. package/dist/ccxt.browser.min.js +40 -16
  3. package/dist/cjs/_virtual/index.cjs.js +1459 -9
  4. package/dist/cjs/ccxt.js +8 -2
  5. package/dist/cjs/src/abstract/dydx.js +11 -0
  6. package/dist/cjs/src/base/Exchange.js +164 -10
  7. package/dist/cjs/src/base/ws/Client.js +3 -1
  8. package/dist/cjs/src/binance.js +8 -1
  9. package/dist/cjs/src/bingx.js +20 -0
  10. package/dist/cjs/src/bitget.js +43 -41
  11. package/dist/cjs/src/bybit.js +21 -23
  12. package/dist/cjs/src/deribit.js +6 -0
  13. package/dist/cjs/src/dydx.js +2454 -0
  14. package/dist/cjs/src/gate.js +4 -4
  15. package/dist/cjs/src/hibachi.js +1 -1
  16. package/dist/cjs/src/hyperliquid.js +207 -9
  17. package/dist/cjs/src/kucoin.js +711 -109
  18. package/dist/cjs/src/mexc.js +2 -3
  19. package/dist/cjs/src/pro/binance.js +59 -144
  20. package/dist/cjs/src/pro/dydx.js +418 -0
  21. package/dist/cjs/src/pro/kraken.js +4 -3
  22. package/dist/cjs/src/pro/xt.js +218 -4
  23. package/dist/cjs/src/protobuf/mexc/compiled.cjs.js +1 -0
  24. package/dist/cjs/src/static_dependencies/dydx-v4-client/cosmos/base/v1beta1/coin.js +56 -0
  25. package/dist/cjs/src/static_dependencies/dydx-v4-client/cosmos/crypto/multisig/v1beta1/multisig.js +56 -0
  26. package/dist/cjs/src/static_dependencies/dydx-v4-client/cosmos/crypto/secp256k1/keys.js +48 -0
  27. package/dist/cjs/src/static_dependencies/dydx-v4-client/cosmos/tx/signing/v1beta1/signing.js +343 -0
  28. package/dist/cjs/src/static_dependencies/dydx-v4-client/cosmos/tx/v1beta1/tx.js +717 -0
  29. package/dist/cjs/src/static_dependencies/dydx-v4-client/dydxprotocol/accountplus/tx.js +60 -0
  30. package/dist/cjs/src/static_dependencies/dydx-v4-client/dydxprotocol/clob/clob_pair.js +45 -0
  31. package/dist/cjs/src/static_dependencies/dydx-v4-client/dydxprotocol/clob/order.js +380 -0
  32. package/dist/cjs/src/static_dependencies/dydx-v4-client/dydxprotocol/clob/order_removals.js +72 -0
  33. package/dist/cjs/src/static_dependencies/dydx-v4-client/dydxprotocol/clob/tx.js +211 -0
  34. package/dist/cjs/src/static_dependencies/dydx-v4-client/dydxprotocol/sending/transfer.js +195 -0
  35. package/dist/cjs/src/static_dependencies/dydx-v4-client/dydxprotocol/sending/tx.js +49 -0
  36. package/dist/cjs/src/static_dependencies/dydx-v4-client/dydxprotocol/subaccounts/subaccount.js +57 -0
  37. package/dist/cjs/src/static_dependencies/dydx-v4-client/google/protobuf/any.js +56 -0
  38. package/dist/cjs/src/static_dependencies/dydx-v4-client/helpers.js +79 -0
  39. package/dist/cjs/src/static_dependencies/dydx-v4-client/long/index.cjs.js +9 -0
  40. package/dist/cjs/src/static_dependencies/dydx-v4-client/onboarding.js +59 -0
  41. package/dist/cjs/src/static_dependencies/dydx-v4-client/registry.js +39 -0
  42. package/dist/cjs/src/static_dependencies/noble-hashes/pbkdf2.js +69 -0
  43. package/dist/cjs/src/static_dependencies/noble-hashes/ripemd160.js +108 -0
  44. package/dist/cjs/src/static_dependencies/noble-hashes/utils.js +50 -1
  45. package/dist/cjs/src/static_dependencies/scure-base/index.js +29 -0
  46. package/dist/cjs/src/static_dependencies/scure-bip32/index.js +278 -0
  47. package/dist/cjs/src/static_dependencies/scure-bip39/index.js +97 -0
  48. package/dist/cjs/src/static_dependencies/scure-bip39/wordlists/english.js +2060 -0
  49. package/dist/cjs/src/static_dependencies/zklink/zklink-sdk-web.js +2 -0
  50. package/dist/cjs/src/toobit.js +2 -1
  51. package/js/ccxt.d.ts +8 -2
  52. package/js/ccxt.js +6 -2
  53. package/js/src/abstract/binance.d.ts +7 -0
  54. package/js/src/abstract/binancecoinm.d.ts +7 -0
  55. package/js/src/abstract/binanceus.d.ts +7 -0
  56. package/js/src/abstract/binanceusdm.d.ts +7 -0
  57. package/js/src/abstract/bitget.d.ts +1 -0
  58. package/js/src/abstract/dydx.d.ts +61 -0
  59. package/js/src/abstract/dydx.js +11 -0
  60. package/js/src/abstract/kucoin.d.ts +1 -1
  61. package/js/src/abstract/kucoinfutures.d.ts +1 -1
  62. package/js/src/base/Exchange.d.ts +7 -0
  63. package/js/src/base/Exchange.js +163 -10
  64. package/js/src/base/ws/Client.js +3 -1
  65. package/js/src/binance.js +8 -1
  66. package/js/src/bingx.js +20 -0
  67. package/js/src/bitget.d.ts +3 -3
  68. package/js/src/bitget.js +43 -41
  69. package/js/src/bybit.d.ts +3 -3
  70. package/js/src/bybit.js +21 -23
  71. package/js/src/deribit.js +6 -0
  72. package/js/src/dydx.d.ts +364 -0
  73. package/js/src/dydx.js +2453 -0
  74. package/js/src/gate.d.ts +2 -2
  75. package/js/src/gate.js +4 -4
  76. package/js/src/hibachi.js +1 -1
  77. package/js/src/hyperliquid.d.ts +17 -0
  78. package/js/src/hyperliquid.js +207 -9
  79. package/js/src/kucoin.d.ts +48 -1
  80. package/js/src/kucoin.js +711 -109
  81. package/js/src/mexc.js +2 -3
  82. package/js/src/pro/binance.d.ts +2 -2
  83. package/js/src/pro/binance.js +59 -144
  84. package/js/src/pro/dydx.d.ts +81 -0
  85. package/js/src/pro/dydx.js +417 -0
  86. package/js/src/pro/kraken.js +4 -3
  87. package/js/src/pro/xt.d.ts +85 -2
  88. package/js/src/pro/xt.js +218 -4
  89. package/js/src/static_dependencies/dydx-v4-client/cosmos/base/v1beta1/coin.d.ts +90 -0
  90. package/js/src/static_dependencies/dydx-v4-client/cosmos/base/v1beta1/coin.js +163 -0
  91. package/js/src/static_dependencies/dydx-v4-client/cosmos/crypto/multisig/keys.d.ts +26 -0
  92. package/js/src/static_dependencies/dydx-v4-client/cosmos/crypto/multisig/keys.js +51 -0
  93. package/js/src/static_dependencies/dydx-v4-client/cosmos/crypto/multisig/v1beta1/multisig.d.ts +48 -0
  94. package/js/src/static_dependencies/dydx-v4-client/cosmos/crypto/multisig/v1beta1/multisig.js +85 -0
  95. package/js/src/static_dependencies/dydx-v4-client/cosmos/crypto/secp256k1/keys.d.ts +40 -0
  96. package/js/src/static_dependencies/dydx-v4-client/cosmos/crypto/secp256k1/keys.js +77 -0
  97. package/js/src/static_dependencies/dydx-v4-client/cosmos/tx/signing/v1beta1/signing.d.ts +162 -0
  98. package/js/src/static_dependencies/dydx-v4-client/cosmos/tx/signing/v1beta1/signing.js +329 -0
  99. package/js/src/static_dependencies/dydx-v4-client/cosmos/tx/v1beta1/tx.d.ts +460 -0
  100. package/js/src/static_dependencies/dydx-v4-client/cosmos/tx/v1beta1/tx.js +698 -0
  101. package/js/src/static_dependencies/dydx-v4-client/dydxprotocol/accountplus/tx.d.ts +127 -0
  102. package/js/src/static_dependencies/dydx-v4-client/dydxprotocol/accountplus/tx.js +286 -0
  103. package/js/src/static_dependencies/dydx-v4-client/dydxprotocol/clob/block_rate_limit_config.d.ts +66 -0
  104. package/js/src/static_dependencies/dydx-v4-client/dydxprotocol/clob/block_rate_limit_config.js +109 -0
  105. package/js/src/static_dependencies/dydx-v4-client/dydxprotocol/clob/clob_pair.d.ts +127 -0
  106. package/js/src/static_dependencies/dydx-v4-client/dydxprotocol/clob/clob_pair.js +257 -0
  107. package/js/src/static_dependencies/dydx-v4-client/dydxprotocol/clob/equity_tier_limit_config.d.ts +48 -0
  108. package/js/src/static_dependencies/dydx-v4-client/dydxprotocol/clob/equity_tier_limit_config.js +93 -0
  109. package/js/src/static_dependencies/dydx-v4-client/dydxprotocol/clob/finalize_block.d.ts +23 -0
  110. package/js/src/static_dependencies/dydx-v4-client/dydxprotocol/clob/finalize_block.js +43 -0
  111. package/js/src/static_dependencies/dydx-v4-client/dydxprotocol/clob/liquidations.d.ts +92 -0
  112. package/js/src/static_dependencies/dydx-v4-client/dydxprotocol/clob/liquidations.js +164 -0
  113. package/js/src/static_dependencies/dydx-v4-client/dydxprotocol/clob/liquidations_config.d.ts +124 -0
  114. package/js/src/static_dependencies/dydx-v4-client/dydxprotocol/clob/liquidations_config.js +196 -0
  115. package/js/src/static_dependencies/dydx-v4-client/dydxprotocol/clob/matches.d.ts +159 -0
  116. package/js/src/static_dependencies/dydx-v4-client/dydxprotocol/clob/matches.js +324 -0
  117. package/js/src/static_dependencies/dydx-v4-client/dydxprotocol/clob/order.d.ts +546 -0
  118. package/js/src/static_dependencies/dydx-v4-client/dydxprotocol/clob/order.js +872 -0
  119. package/js/src/static_dependencies/dydx-v4-client/dydxprotocol/clob/order_removals.d.ts +84 -0
  120. package/js/src/static_dependencies/dydx-v4-client/dydxprotocol/clob/order_removals.js +181 -0
  121. package/js/src/static_dependencies/dydx-v4-client/dydxprotocol/clob/tx.d.ts +397 -0
  122. package/js/src/static_dependencies/dydx-v4-client/dydxprotocol/clob/tx.js +757 -0
  123. package/js/src/static_dependencies/dydx-v4-client/dydxprotocol/sending/transfer.d.ts +120 -0
  124. package/js/src/static_dependencies/dydx-v4-client/dydxprotocol/sending/transfer.js +246 -0
  125. package/js/src/static_dependencies/dydx-v4-client/dydxprotocol/sending/tx.d.ts +79 -0
  126. package/js/src/static_dependencies/dydx-v4-client/dydxprotocol/sending/tx.js +147 -0
  127. package/js/src/static_dependencies/dydx-v4-client/dydxprotocol/subaccounts/asset_position.d.ts +32 -0
  128. package/js/src/static_dependencies/dydx-v4-client/dydxprotocol/subaccounts/asset_position.js +59 -0
  129. package/js/src/static_dependencies/dydx-v4-client/dydxprotocol/subaccounts/perpetual_position.d.ts +34 -0
  130. package/js/src/static_dependencies/dydx-v4-client/dydxprotocol/subaccounts/perpetual_position.js +66 -0
  131. package/js/src/static_dependencies/dydx-v4-client/dydxprotocol/subaccounts/subaccount.d.ts +62 -0
  132. package/js/src/static_dependencies/dydx-v4-client/dydxprotocol/subaccounts/subaccount.js +111 -0
  133. package/js/src/static_dependencies/dydx-v4-client/google/protobuf/any.d.ts +207 -0
  134. package/js/src/static_dependencies/dydx-v4-client/google/protobuf/any.js +50 -0
  135. package/js/src/static_dependencies/dydx-v4-client/helpers.d.ts +82 -0
  136. package/js/src/static_dependencies/dydx-v4-client/helpers.js +172 -0
  137. package/js/src/static_dependencies/dydx-v4-client/long/index.cjs +1473 -0
  138. package/js/src/static_dependencies/dydx-v4-client/long/index.d.cts +2 -0
  139. package/js/src/static_dependencies/dydx-v4-client/onboarding.d.ts +35 -0
  140. package/js/src/static_dependencies/dydx-v4-client/onboarding.js +56 -0
  141. package/js/src/static_dependencies/dydx-v4-client/registry.d.ts +7 -0
  142. package/js/src/static_dependencies/dydx-v4-client/registry.js +36 -0
  143. package/js/src/static_dependencies/noble-hashes/utils.d.ts +1 -0
  144. package/js/src/static_dependencies/noble-hashes/utils.js +4 -0
  145. package/js/src/static_dependencies/scure-bip32/index.d.ts +49 -0
  146. package/js/src/static_dependencies/scure-bip32/index.js +295 -0
  147. package/js/src/static_dependencies/scure-bip39/index.d.ts +54 -0
  148. package/js/src/static_dependencies/scure-bip39/index.js +140 -0
  149. package/js/src/static_dependencies/scure-bip39/wordlists/english.d.ts +1 -0
  150. package/js/src/static_dependencies/scure-bip39/wordlists/english.js +2054 -0
  151. package/js/src/toobit.js +2 -1
  152. package/package.json +9 -3
package/js/src/kucoin.js CHANGED
@@ -68,8 +68,8 @@ export default class kucoin extends Exchange {
68
68
  'fetchDepositWithdrawFee': true,
69
69
  'fetchDepositWithdrawFees': true,
70
70
  'fetchFundingHistory': false,
71
- 'fetchFundingRate': false,
72
- 'fetchFundingRateHistory': false,
71
+ 'fetchFundingRate': true,
72
+ 'fetchFundingRateHistory': true,
73
73
  'fetchFundingRates': false,
74
74
  'fetchIndexOHLCV': false,
75
75
  'fetchIsolatedBorrowRate': false,
@@ -471,7 +471,7 @@ export default class kucoin extends Exchange {
471
471
  'market/funding-rate': 2,
472
472
  'market/funding-rate-history': 5,
473
473
  'market/cross-config': 25,
474
- 'market/server/status': 3,
474
+ 'server/status': 3,
475
475
  },
476
476
  },
477
477
  },
@@ -1129,22 +1129,49 @@ export default class kucoin extends Exchange {
1129
1129
  * @name kucoin#fetchStatus
1130
1130
  * @description the latest known information on the availability of the exchange API
1131
1131
  * @see https://docs.kucoin.com/#service-status
1132
+ * @see https://www.kucoin.com/docs-new/rest/ua/get-service-status
1132
1133
  * @param {object} [params] extra parameters specific to the exchange API endpoint
1134
+ * @param {boolean} [params.uta] set to true for the unified trading account (uta), defaults to false
1135
+ * @param {string} [params.tradeType] *uta only* set to SPOT or FUTURES
1133
1136
  * @returns {object} a [status structure]{@link https://docs.ccxt.com/#/?id=exchange-status-structure}
1134
1137
  */
1135
1138
  async fetchStatus(params = {}) {
1136
- const response = await this.publicGetStatus(params);
1137
- //
1138
- // {
1139
- // "code":"200000",
1140
- // "data":{
1141
- // "status":"open", //open, close, cancelonly
1142
- // "msg":"upgrade match engine" //remark for operation
1143
- // }
1144
- // }
1145
- //
1139
+ let uta = undefined;
1140
+ [uta, params] = this.handleOptionAndParams(params, 'fetchStatus', 'uta', false);
1141
+ let response = undefined;
1142
+ if (uta) {
1143
+ const defaultType = this.safeString(this.options, 'defaultType', 'spot');
1144
+ const defaultTradeType = (defaultType === 'spot') ? 'SPOT' : 'FUTURES';
1145
+ const tradeType = this.safeStringUpper(params, 'tradeType', defaultTradeType);
1146
+ const request = {
1147
+ 'tradeType': tradeType,
1148
+ };
1149
+ response = await this.utaGetServerStatus(this.extend(request, params));
1150
+ //
1151
+ // {
1152
+ // "code": "200000",
1153
+ // "data": {
1154
+ // "tradeType": "SPOT",
1155
+ // "serverStatus": "open",
1156
+ // "msg": ""
1157
+ // }
1158
+ // }
1159
+ //
1160
+ }
1161
+ else {
1162
+ response = await this.publicGetStatus(params);
1163
+ //
1164
+ // {
1165
+ // "code":"200000",
1166
+ // "data":{
1167
+ // "status":"open", //open, close, cancelonly
1168
+ // "msg":"upgrade match engine" //remark for operation
1169
+ // }
1170
+ // }
1171
+ //
1172
+ }
1146
1173
  const data = this.safeDict(response, 'data', {});
1147
- const status = this.safeString(data, 'status');
1174
+ const status = this.safeString2(data, 'status', 'serverStatus');
1148
1175
  return {
1149
1176
  'status': (status === 'open') ? 'ok' : 'maintenance',
1150
1177
  'updated': undefined,
@@ -1160,11 +1187,17 @@ export default class kucoin extends Exchange {
1160
1187
  * @see https://docs.kucoin.com/#get-symbols-list-deprecated
1161
1188
  * @see https://docs.kucoin.com/#get-all-tickers
1162
1189
  * @param {object} [params] extra parameters specific to the exchange API endpoint
1190
+ * @param {boolean} [params.uta] set to true for the unified trading account (uta), defaults to false
1163
1191
  * @returns {object[]} an array of objects representing market data
1164
1192
  */
1165
1193
  async fetchMarkets(params = {}) {
1166
1194
  let fetchTickersFees = undefined;
1167
1195
  [fetchTickersFees, params] = this.handleOptionAndParams(params, 'fetchMarkets', 'fetchTickersFees', true);
1196
+ let uta = undefined;
1197
+ [uta, params] = this.handleOptionAndParams(params, 'fetchMarkets', 'uta', false);
1198
+ if (uta) {
1199
+ return await this.fetchUtaMarkets(params);
1200
+ }
1168
1201
  const promises = [];
1169
1202
  promises.push(this.publicGetSymbols(params));
1170
1203
  //
@@ -1349,6 +1382,189 @@ export default class kucoin extends Exchange {
1349
1382
  }
1350
1383
  return result;
1351
1384
  }
1385
+ async fetchUtaMarkets(params = {}) {
1386
+ const promises = [];
1387
+ promises.push(this.utaGetMarketInstrument(this.extend(params, { 'tradeType': 'SPOT' })));
1388
+ //
1389
+ // {
1390
+ // "code": "200000",
1391
+ // "data": {
1392
+ // "tradeType": "SPOT",
1393
+ // "list": [
1394
+ // {
1395
+ // "symbol": "AVA-USDT",
1396
+ // "name": "AVA-USDT",
1397
+ // "baseCurrency": "AVA",
1398
+ // "quoteCurrency": "USDT",
1399
+ // "market": "USDS",
1400
+ // "minBaseOrderSize": "0.1",
1401
+ // "minQuoteOrderSize": "0.1",
1402
+ // "maxBaseOrderSize": "10000000000",
1403
+ // "maxQuoteOrderSize": "99999999",
1404
+ // "baseOrderStep": "0.01",
1405
+ // "quoteOrderStep": "0.0001",
1406
+ // "tickSize": "0.0001",
1407
+ // "feeCurrency": "USDT",
1408
+ // "tradingStatus": "1",
1409
+ // "marginMode": "2",
1410
+ // "priceLimitRatio": "0.05",
1411
+ // "feeCategory": 1,
1412
+ // "makerFeeCoefficient": "1.00",
1413
+ // "takerFeeCoefficient": "1.00",
1414
+ // "st": false
1415
+ // },
1416
+ // ]
1417
+ // }
1418
+ // }
1419
+ //
1420
+ promises.push(this.utaGetMarketInstrument(this.extend(params, { 'tradeType': 'FUTURES' })));
1421
+ //
1422
+ // {
1423
+ // "code": "200000",
1424
+ // "data": {
1425
+ // "tradeType": "FUTURES",
1426
+ // "list": [
1427
+ // {
1428
+ // "symbol": "XBTUSDTM",
1429
+ // "baseCurrency": "XBT",
1430
+ // "quoteCurrency": "USDT",
1431
+ // "maxBaseOrderSize": "1000000",
1432
+ // "tickSize": "0.1",
1433
+ // "tradingStatus": "1",
1434
+ // "settlementCurrency": "USDT",
1435
+ // "contractType": "0",
1436
+ // "isInverse": false,
1437
+ // "launchTime": 1585555200000,
1438
+ // "expiryTime": null,
1439
+ // "settlementTime": null,
1440
+ // "maxPrice": "1000000.0",
1441
+ // "lotSize": "1",
1442
+ // "unitSize": "0.001",
1443
+ // "makerFeeRate": "0.00020",
1444
+ // "takerFeeRate": "0.00060",
1445
+ // "settlementFeeRate": null,
1446
+ // "maxLeverage": 125,
1447
+ // "indexSourceExchanges": ["okex","binance","kucoin","bybit","bitmart","gateio"],
1448
+ // "k": "490.0",
1449
+ // "m": "300.0",
1450
+ // "f": "1.3",
1451
+ // "mmrLimit": "0.3",
1452
+ // "mmrLevConstant": "125.0"
1453
+ // },
1454
+ // ]
1455
+ // }
1456
+ // }
1457
+ //
1458
+ const responses = await Promise.all(promises);
1459
+ const data = this.safeDict(responses[0], 'data', {});
1460
+ const contractData = this.safeDict(responses[1], 'data', {});
1461
+ const spotData = this.safeList(data, 'list', []);
1462
+ const contractSymbolsData = this.safeList(contractData, 'list', []);
1463
+ const symbolsData = this.arrayConcat(spotData, contractSymbolsData);
1464
+ const result = [];
1465
+ for (let i = 0; i < symbolsData.length; i++) {
1466
+ const market = symbolsData[i];
1467
+ const id = this.safeString(market, 'symbol');
1468
+ const baseId = this.safeString(market, 'baseCurrency');
1469
+ const quoteId = this.safeString(market, 'quoteCurrency');
1470
+ const settleId = this.safeString(market, 'settlementCurrency');
1471
+ const base = this.safeCurrencyCode(baseId);
1472
+ const quote = this.safeCurrencyCode(quoteId);
1473
+ const settle = this.safeCurrencyCode(settleId);
1474
+ const hasMargin = this.safeString(market, 'marginMode');
1475
+ const isMarginable = (hasMargin === '1') ? true : false;
1476
+ let symbol = base + '/' + quote;
1477
+ if (settle !== undefined) {
1478
+ symbol += ':' + settle;
1479
+ }
1480
+ const contractType = this.safeString(market, 'contractType');
1481
+ const expiry = this.safeInteger(market, 'expiryTime');
1482
+ const active = this.safeString(market, 'tradingStatus');
1483
+ let type = undefined;
1484
+ let spot = false;
1485
+ let swap = false;
1486
+ let future = false;
1487
+ let contract = false;
1488
+ let linear = false;
1489
+ let inverse = false;
1490
+ if (contractType !== undefined) {
1491
+ contract = true;
1492
+ if (quote === settle) {
1493
+ linear = true;
1494
+ }
1495
+ else {
1496
+ inverse = true;
1497
+ }
1498
+ if (contractType === '0') {
1499
+ type = 'swap';
1500
+ swap = true;
1501
+ }
1502
+ else {
1503
+ type = 'future';
1504
+ future = true;
1505
+ }
1506
+ }
1507
+ else {
1508
+ type = 'spot';
1509
+ spot = true;
1510
+ }
1511
+ result.push({
1512
+ 'id': id,
1513
+ 'symbol': symbol,
1514
+ 'base': base,
1515
+ 'quote': quote,
1516
+ 'settle': settle,
1517
+ 'baseId': baseId,
1518
+ 'quoteId': quoteId,
1519
+ 'settleId': settleId,
1520
+ 'type': type,
1521
+ 'spot': spot,
1522
+ 'margin': isMarginable,
1523
+ 'swap': swap,
1524
+ 'future': future,
1525
+ 'option': false,
1526
+ 'active': (active === '1'),
1527
+ 'contract': contract,
1528
+ 'linear': linear,
1529
+ 'inverse': inverse,
1530
+ 'taker': this.safeNumber(market, 'makerFeeRate'),
1531
+ 'maker': this.safeNumber(market, 'takerFeeRate'),
1532
+ 'contractSize': this.safeNumber(market, 'unitSize'),
1533
+ 'expiry': expiry,
1534
+ 'expiryDatetime': this.iso8601(expiry),
1535
+ 'strike': undefined,
1536
+ 'optionType': undefined,
1537
+ 'precision': {
1538
+ 'amount': this.safeNumber(market, 'lotSize'),
1539
+ 'price': this.safeNumber(market, 'tickSize'),
1540
+ },
1541
+ 'limits': {
1542
+ 'leverage': {
1543
+ 'min': undefined,
1544
+ 'max': this.safeInteger(market, 'maxLeverage'),
1545
+ },
1546
+ 'amount': {
1547
+ 'min': this.safeNumber(market, 'minBaseOrderSize'),
1548
+ 'max': this.safeNumber(market, 'maxBaseOrderSize'),
1549
+ },
1550
+ 'price': {
1551
+ 'min': undefined,
1552
+ 'max': this.safeNumber(market, 'maxPrice'),
1553
+ },
1554
+ 'cost': {
1555
+ 'min': this.safeNumber(market, 'minQuoteOrderSize'),
1556
+ 'max': this.safeNumber(market, 'maxQuoteOrderSize'),
1557
+ },
1558
+ },
1559
+ 'created': this.safeInteger(market, 'launchTime'),
1560
+ 'info': market,
1561
+ });
1562
+ }
1563
+ if (this.options['adjustForTimeDifference']) {
1564
+ await this.loadTimeDifference();
1565
+ }
1566
+ return result;
1567
+ }
1352
1568
  /**
1353
1569
  * @method
1354
1570
  * @name kucoin#loadMigrationStatus
@@ -1755,17 +1971,35 @@ export default class kucoin extends Exchange {
1755
1971
  // "time": 1634641777363
1756
1972
  // }
1757
1973
  //
1974
+ // uta
1975
+ //
1976
+ // {
1977
+ // "symbol": "BTC-USDT",
1978
+ // "name": "BTC-USDT",
1979
+ // "bestBidSize": "0.69207954",
1980
+ // "bestBidPrice": "110417.5",
1981
+ // "bestAskSize": "0.08836606",
1982
+ // "bestAskPrice": "110417.6",
1983
+ // "lastPrice": "110417.5",
1984
+ // "size": "0.00016",
1985
+ // "open": "110105.1",
1986
+ // "high": "110838.9",
1987
+ // "low": "109705.5",
1988
+ // "baseVolume": "1882.10069442",
1989
+ // "quoteVolume": "207325626.822922498"
1990
+ // }
1991
+ //
1758
1992
  let percentage = this.safeString(ticker, 'changeRate');
1759
1993
  if (percentage !== undefined) {
1760
1994
  percentage = Precise.stringMul(percentage, '100');
1761
1995
  }
1762
- let last = this.safeString2(ticker, 'last', 'lastTradedPrice');
1996
+ let last = this.safeStringN(ticker, ['last', 'lastTradedPrice', 'lastPrice']);
1763
1997
  last = this.safeString(ticker, 'price', last);
1764
1998
  const marketId = this.safeString(ticker, 'symbol');
1765
1999
  market = this.safeMarket(marketId, market, '-');
1766
2000
  const symbol = market['symbol'];
1767
- const baseVolume = this.safeString(ticker, 'vol');
1768
- const quoteVolume = this.safeString(ticker, 'volValue');
2001
+ const baseVolume = this.safeString2(ticker, 'vol', 'baseVolume');
2002
+ const quoteVolume = this.safeString2(ticker, 'volValue', 'quoteVolume');
1769
2003
  const timestamp = this.safeIntegerN(ticker, ['time', 'datetime', 'timePoint']);
1770
2004
  return this.safeTicker({
1771
2005
  'symbol': symbol,
@@ -1773,9 +2007,9 @@ export default class kucoin extends Exchange {
1773
2007
  'datetime': this.iso8601(timestamp),
1774
2008
  'high': this.safeString(ticker, 'high'),
1775
2009
  'low': this.safeString(ticker, 'low'),
1776
- 'bid': this.safeString2(ticker, 'buy', 'bestBid'),
2010
+ 'bid': this.safeStringN(ticker, ['buy', 'bestBid', 'bestBidPrice']),
1777
2011
  'bidVolume': this.safeString(ticker, 'bestBidSize'),
1778
- 'ask': this.safeString2(ticker, 'sell', 'bestAsk'),
2012
+ 'ask': this.safeStringN(ticker, ['sell', 'bestAsk', 'bestAskPrice']),
1779
2013
  'askVolume': this.safeString(ticker, 'bestAskSize'),
1780
2014
  'vwap': undefined,
1781
2015
  'open': this.safeString(ticker, 'open'),
@@ -1796,45 +2030,103 @@ export default class kucoin extends Exchange {
1796
2030
  * @name kucoin#fetchTickers
1797
2031
  * @description fetches price tickers for multiple markets, statistical information calculated over the past 24 hours for each market
1798
2032
  * @see https://docs.kucoin.com/#get-all-tickers
2033
+ * @see https://www.kucoin.com/docs-new/rest/ua/get-ticker
1799
2034
  * @param {string[]|undefined} symbols unified symbols of the markets to fetch the ticker for, all market tickers are returned if not assigned
1800
2035
  * @param {object} [params] extra parameters specific to the exchange API endpoint
2036
+ * @param {boolean} [params.uta] set to true for the unified trading account (uta), defaults to false
2037
+ * @param {string} [params.tradeType] *uta only* set to SPOT or FUTURES
1801
2038
  * @returns {object} a dictionary of [ticker structures]{@link https://docs.ccxt.com/#/?id=ticker-structure}
1802
2039
  */
1803
2040
  async fetchTickers(symbols = undefined, params = {}) {
1804
2041
  await this.loadMarkets();
2042
+ const request = {};
1805
2043
  symbols = this.marketSymbols(symbols);
1806
- const response = await this.publicGetMarketAllTickers(params);
1807
- //
1808
- // {
1809
- // "code": "200000",
1810
- // "data": {
1811
- // "time":1602832092060,
1812
- // "ticker":[
1813
- // {
1814
- // "symbol": "BTC-USDT", // symbol
1815
- // "symbolName":"BTC-USDT", // Name of trading pairs, it would change after renaming
1816
- // "buy": "11328.9", // bestAsk
1817
- // "sell": "11329", // bestBid
1818
- // "changeRate": "-0.0055", // 24h change rate
1819
- // "changePrice": "-63.6", // 24h change price
1820
- // "high": "11610", // 24h highest price
1821
- // "low": "11200", // 24h lowest price
1822
- // "vol": "2282.70993217", // 24h volume,the aggregated trading volume in BTC
1823
- // "volValue": "25984946.157790431", // 24h total, the trading volume in quote currency of last 24 hours
1824
- // "last": "11328.9", // last price
1825
- // "averagePrice": "11360.66065903", // 24h average transaction price yesterday
1826
- // "takerFeeRate": "0.001", // Basic Taker Fee
1827
- // "makerFeeRate": "0.001", // Basic Maker Fee
1828
- // "takerCoefficient": "1", // Taker Fee Coefficient
1829
- // "makerCoefficient": "1" // Maker Fee Coefficient
1830
- // }
1831
- // ]
1832
- // }
1833
- // }
1834
- //
2044
+ let uta = undefined;
2045
+ [uta, params] = this.handleOptionAndParams(params, 'fetchTickers', 'uta', false);
2046
+ let response = undefined;
2047
+ if (uta) {
2048
+ if (symbols !== undefined) {
2049
+ const symbol = this.safeString(symbols, 0);
2050
+ const market = this.market(symbol);
2051
+ let type = undefined;
2052
+ [type, params] = this.handleMarketTypeAndParams('fetchTickers', market, params);
2053
+ if (type === 'spot') {
2054
+ request['tradeType'] = 'SPOT';
2055
+ }
2056
+ else {
2057
+ request['tradeType'] = 'FUTURES';
2058
+ }
2059
+ }
2060
+ else {
2061
+ const tradeType = this.safeStringUpper(params, 'tradeType');
2062
+ if (tradeType === undefined) {
2063
+ throw new ArgumentsRequired(this.id + ' fetchTickers() requires a tradeType parameter for uta, either SPOT or FUTURES');
2064
+ }
2065
+ request['tradeType'] = tradeType;
2066
+ params = this.omit(params, 'tradeType');
2067
+ }
2068
+ response = await this.utaGetMarketTicker(this.extend(request, params));
2069
+ //
2070
+ // {
2071
+ // "code": "200000",
2072
+ // "data": {
2073
+ // "tradeType": "SPOT",
2074
+ // "ts": 1762061290067,
2075
+ // "list": [
2076
+ // {
2077
+ // "symbol": "BTC-USDT",
2078
+ // "name": "BTC-USDT",
2079
+ // "bestBidSize": "0.69207954",
2080
+ // "bestBidPrice": "110417.5",
2081
+ // "bestAskSize": "0.08836606",
2082
+ // "bestAskPrice": "110417.6",
2083
+ // "lastPrice": "110417.5",
2084
+ // "size": "0.00016",
2085
+ // "open": "110105.1",
2086
+ // "high": "110838.9",
2087
+ // "low": "109705.5",
2088
+ // "baseVolume": "1882.10069442",
2089
+ // "quoteVolume": "207325626.822922498"
2090
+ // }
2091
+ // ]
2092
+ // }
2093
+ // }
2094
+ //
2095
+ }
2096
+ else {
2097
+ response = await this.publicGetMarketAllTickers(params);
2098
+ //
2099
+ // {
2100
+ // "code": "200000",
2101
+ // "data": {
2102
+ // "time":1602832092060,
2103
+ // "ticker":[
2104
+ // {
2105
+ // "symbol": "BTC-USDT", // symbol
2106
+ // "symbolName":"BTC-USDT", // Name of trading pairs, it would change after renaming
2107
+ // "buy": "11328.9", // bestAsk
2108
+ // "sell": "11329", // bestBid
2109
+ // "changeRate": "-0.0055", // 24h change rate
2110
+ // "changePrice": "-63.6", // 24h change price
2111
+ // "high": "11610", // 24h highest price
2112
+ // "low": "11200", // 24h lowest price
2113
+ // "vol": "2282.70993217", // 24h volume,the aggregated trading volume in BTC
2114
+ // "volValue": "25984946.157790431", // 24h total, the trading volume in quote currency of last 24 hours
2115
+ // "last": "11328.9", // last price
2116
+ // "averagePrice": "11360.66065903", // 24h average transaction price yesterday
2117
+ // "takerFeeRate": "0.001", // Basic Taker Fee
2118
+ // "makerFeeRate": "0.001", // Basic Maker Fee
2119
+ // "takerCoefficient": "1", // Taker Fee Coefficient
2120
+ // "makerCoefficient": "1" // Maker Fee Coefficient
2121
+ // }
2122
+ // ]
2123
+ // }
2124
+ // }
2125
+ //
2126
+ }
1835
2127
  const data = this.safeDict(response, 'data', {});
1836
- const tickers = this.safeList(data, 'ticker', []);
1837
- const time = this.safeInteger(data, 'time');
2128
+ const tickers = this.safeList2(data, 'ticker', 'list', []);
2129
+ const time = this.safeInteger2(data, 'time', 'ts');
1838
2130
  const result = {};
1839
2131
  for (let i = 0; i < tickers.length; i++) {
1840
2132
  tickers[i]['time'] = time;
@@ -1867,8 +2159,10 @@ export default class kucoin extends Exchange {
1867
2159
  * @name kucoin#fetchTicker
1868
2160
  * @description fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market
1869
2161
  * @see https://docs.kucoin.com/#get-24hr-stats
2162
+ * @see https://www.kucoin.com/docs-new/rest/ua/get-ticker
1870
2163
  * @param {string} symbol unified symbol of the market to fetch the ticker for
1871
2164
  * @param {object} [params] extra parameters specific to the exchange API endpoint
2165
+ * @param {boolean} [params.uta] set to true for the unified trading account (uta), defaults to false
1872
2166
  * @returns {object} a [ticker structure]{@link https://docs.ccxt.com/#/?id=ticker-structure}
1873
2167
  */
1874
2168
  async fetchTicker(symbol, params = {}) {
@@ -1877,32 +2171,78 @@ export default class kucoin extends Exchange {
1877
2171
  const request = {
1878
2172
  'symbol': market['id'],
1879
2173
  };
1880
- const response = await this.publicGetMarketStats(this.extend(request, params));
1881
- //
1882
- // {
1883
- // "code": "200000",
1884
- // "data": {
1885
- // "time": 1602832092060, // time
1886
- // "symbol": "BTC-USDT", // symbol
1887
- // "buy": "11328.9", // bestAsk
1888
- // "sell": "11329", // bestBid
1889
- // "changeRate": "-0.0055", // 24h change rate
1890
- // "changePrice": "-63.6", // 24h change price
1891
- // "high": "11610", // 24h highest price
1892
- // "low": "11200", // 24h lowest price
1893
- // "vol": "2282.70993217", // 24h volume,the aggregated trading volume in BTC
1894
- // "volValue": "25984946.157790431", // 24h total, the trading volume in quote currency of last 24 hours
1895
- // "last": "11328.9", // last price
1896
- // "averagePrice": "11360.66065903", // 24h average transaction price yesterday
1897
- // "takerFeeRate": "0.001", // Basic Taker Fee
1898
- // "makerFeeRate": "0.001", // Basic Maker Fee
1899
- // "takerCoefficient": "1", // Taker Fee Coefficient
1900
- // "makerCoefficient": "1" // Maker Fee Coefficient
1901
- // }
1902
- // }
1903
- //
1904
- const data = this.safeDict(response, 'data', {});
1905
- return this.parseTicker(data, market);
2174
+ let uta = undefined;
2175
+ [uta, params] = this.handleOptionAndParams(params, 'fetchTicker', 'uta', false);
2176
+ let response = undefined;
2177
+ let result = undefined;
2178
+ if (uta) {
2179
+ let type = undefined;
2180
+ [type, params] = this.handleMarketTypeAndParams('fetchTicker', market, params);
2181
+ if (type === 'spot') {
2182
+ request['tradeType'] = 'SPOT';
2183
+ }
2184
+ else {
2185
+ request['tradeType'] = 'FUTURES';
2186
+ }
2187
+ response = await this.utaGetMarketTicker(this.extend(request, params));
2188
+ //
2189
+ // {
2190
+ // "code": "200000",
2191
+ // "data": {
2192
+ // "tradeType": "SPOT",
2193
+ // "ts": 1762061290067,
2194
+ // "list": [
2195
+ // {
2196
+ // "symbol": "BTC-USDT",
2197
+ // "name": "BTC-USDT",
2198
+ // "bestBidSize": "0.69207954",
2199
+ // "bestBidPrice": "110417.5",
2200
+ // "bestAskSize": "0.08836606",
2201
+ // "bestAskPrice": "110417.6",
2202
+ // "lastPrice": "110417.5",
2203
+ // "size": "0.00016",
2204
+ // "open": "110105.1",
2205
+ // "high": "110838.9",
2206
+ // "low": "109705.5",
2207
+ // "baseVolume": "1882.10069442",
2208
+ // "quoteVolume": "207325626.822922498"
2209
+ // }
2210
+ // ]
2211
+ // }
2212
+ // }
2213
+ //
2214
+ const data = this.safeDict(response, 'data', {});
2215
+ const resultList = this.safeList(data, 'list', []);
2216
+ result = this.safeDict(resultList, 0, {});
2217
+ }
2218
+ else {
2219
+ response = await this.publicGetMarketStats(this.extend(request, params));
2220
+ //
2221
+ // {
2222
+ // "code": "200000",
2223
+ // "data": {
2224
+ // "time": 1602832092060, // time
2225
+ // "symbol": "BTC-USDT", // symbol
2226
+ // "buy": "11328.9", // bestAsk
2227
+ // "sell": "11329", // bestBid
2228
+ // "changeRate": "-0.0055", // 24h change rate
2229
+ // "changePrice": "-63.6", // 24h change price
2230
+ // "high": "11610", // 24h highest price
2231
+ // "low": "11200", // 24h lowest price
2232
+ // "vol": "2282.70993217", // 24h volume,the aggregated trading volume in BTC
2233
+ // "volValue": "25984946.157790431", // 24h total, the trading volume in quote currency of last 24 hours
2234
+ // "last": "11328.9", // last price
2235
+ // "averagePrice": "11360.66065903", // 24h average transaction price yesterday
2236
+ // "takerFeeRate": "0.001", // Basic Taker Fee
2237
+ // "makerFeeRate": "0.001", // Basic Maker Fee
2238
+ // "takerCoefficient": "1", // Taker Fee Coefficient
2239
+ // "makerCoefficient": "1" // Maker Fee Coefficient
2240
+ // }
2241
+ // }
2242
+ //
2243
+ result = this.safeDict(response, 'data', {});
2244
+ }
2245
+ return this.parseTicker(result, market);
1906
2246
  }
1907
2247
  /**
1908
2248
  * @method
@@ -1950,11 +2290,13 @@ export default class kucoin extends Exchange {
1950
2290
  * @name kucoin#fetchOHLCV
1951
2291
  * @description fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market
1952
2292
  * @see https://docs.kucoin.com/#get-klines
2293
+ * @see https://www.kucoin.com/docs-new/rest/ua/get-klines
1953
2294
  * @param {string} symbol unified symbol of the market to fetch OHLCV data for
1954
2295
  * @param {string} timeframe the length of time each candle represents
1955
2296
  * @param {int} [since] timestamp in ms of the earliest candle to fetch
1956
2297
  * @param {int} [limit] the maximum amount of candles to fetch
1957
2298
  * @param {object} [params] extra parameters specific to the exchange API endpoint
2299
+ * @param {boolean} [params.uta] set to true for the unified trading account (uta), defaults to false
1958
2300
  * @param {boolean} [params.paginate] default false, when true will automatically paginate by calling this endpoint multiple times. See in the docs all the [availble parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
1959
2301
  * @returns {int[][]} A list of candles ordered as timestamp, open, high, low, close, volume
1960
2302
  */
@@ -1969,7 +2311,6 @@ export default class kucoin extends Exchange {
1969
2311
  const marketId = market['id'];
1970
2312
  const request = {
1971
2313
  'symbol': marketId,
1972
- 'type': this.safeString(this.timeframes, timeframe, timeframe),
1973
2314
  };
1974
2315
  const duration = this.parseTimeframe(timeframe) * 1000;
1975
2316
  let endAt = this.milliseconds(); // required param
@@ -1989,19 +2330,54 @@ export default class kucoin extends Exchange {
1989
2330
  request['startAt'] = this.parseToInt(Math.floor(since / 1000));
1990
2331
  }
1991
2332
  request['endAt'] = this.parseToInt(Math.floor(endAt / 1000));
1992
- const response = await this.publicGetMarketCandles(this.extend(request, params));
1993
- //
1994
- // {
1995
- // "code":"200000",
1996
- // "data":[
1997
- // ["1591517700","0.025078","0.025069","0.025084","0.025064","18.9883256","0.4761861079404"],
1998
- // ["1591516800","0.025089","0.025079","0.025089","0.02506","99.4716622","2.494143499081"],
1999
- // ["1591515900","0.025079","0.02509","0.025091","0.025068","59.83701271","1.50060885172798"],
2000
- // ]
2001
- // }
2002
- //
2003
- const data = this.safeList(response, 'data', []);
2004
- return this.parseOHLCVs(data, market, timeframe, since, limit);
2333
+ let uta = undefined;
2334
+ [uta, params] = this.handleOptionAndParams(params, 'fetchOHLCV', 'uta', false);
2335
+ let response = undefined;
2336
+ let result = undefined;
2337
+ if (uta) {
2338
+ let type = undefined;
2339
+ [type, params] = this.handleMarketTypeAndParams('fetchOHLCV', market, params);
2340
+ if (type === 'spot') {
2341
+ request['tradeType'] = 'SPOT';
2342
+ }
2343
+ else {
2344
+ request['tradeType'] = 'FUTURES';
2345
+ }
2346
+ request['interval'] = this.safeString(this.timeframes, timeframe, timeframe);
2347
+ response = await this.utaGetMarketKline(this.extend(request, params));
2348
+ //
2349
+ // {
2350
+ // "code": "200000",
2351
+ // "data": {
2352
+ // "tradeType": "SPOT",
2353
+ // "symbol": "BTC-USDT",
2354
+ // "list": [
2355
+ // ["1762240200","104581.4","104527.1","104620.1","104526.4","5.57665554","583263.661804122"],
2356
+ // ["1762240140","104565.6","104581.3","104601.7","104511.3","6.48505114","677973.775916968"],
2357
+ // ["1762240080","104621.5","104571.3","104704.7","104571.3","14.51713618","1519468.954060838"]
2358
+ // ]
2359
+ // }
2360
+ // }
2361
+ //
2362
+ const data = this.safeDict(response, 'data', {});
2363
+ result = this.safeList(data, 'list', []);
2364
+ }
2365
+ else {
2366
+ request['type'] = this.safeString(this.timeframes, timeframe, timeframe);
2367
+ response = await this.publicGetMarketCandles(this.extend(request, params));
2368
+ //
2369
+ // {
2370
+ // "code":"200000",
2371
+ // "data":[
2372
+ // ["1591517700","0.025078","0.025069","0.025084","0.025064","18.9883256","0.4761861079404"],
2373
+ // ["1591516800","0.025089","0.025079","0.025089","0.02506","99.4716622","2.494143499081"],
2374
+ // ["1591515900","0.025079","0.02509","0.025091","0.025068","59.83701271","1.50060885172798"],
2375
+ // ]
2376
+ // }
2377
+ //
2378
+ result = this.safeList(response, 'data', []);
2379
+ }
2380
+ return this.parseOHLCVs(result, market, timeframe, since, limit);
2005
2381
  }
2006
2382
  /**
2007
2383
  * @method
@@ -2147,9 +2523,11 @@ export default class kucoin extends Exchange {
2147
2523
  * @description fetches information on open orders with bid (buy) and ask (sell) prices, volumes and other data
2148
2524
  * @see https://www.kucoin.com/docs/rest/spot-trading/market-data/get-part-order-book-aggregated-
2149
2525
  * @see https://www.kucoin.com/docs/rest/spot-trading/market-data/get-full-order-book-aggregated-
2526
+ * @see https://www.kucoin.com/docs-new/rest/ua/get-orderbook
2150
2527
  * @param {string} symbol unified symbol of the market to fetch the order book for
2151
2528
  * @param {int} [limit] the maximum amount of order book entries to return
2152
2529
  * @param {object} [params] extra parameters specific to the exchange API endpoint
2530
+ * @param {boolean} [params.uta] set to true for the unified trading account (uta), defaults to false
2153
2531
  * @returns {object} A dictionary of [order book structures]{@link https://docs.ccxt.com/#/?id=order-book-structure} indexed by market symbols
2154
2532
  */
2155
2533
  async fetchOrderBook(symbol, limit = undefined, params = {}) {
@@ -2158,8 +2536,44 @@ export default class kucoin extends Exchange {
2158
2536
  const level = this.safeInteger(params, 'level', 2);
2159
2537
  const request = { 'symbol': market['id'] };
2160
2538
  const isAuthenticated = this.checkRequiredCredentials(false);
2539
+ let uta = undefined;
2540
+ [uta, params] = this.handleOptionAndParams(params, 'fetchOrderBook', 'uta', false);
2161
2541
  let response = undefined;
2162
- if (!isAuthenticated || limit !== undefined) {
2542
+ if (uta) {
2543
+ if (limit === undefined) {
2544
+ throw new ArgumentsRequired(this.id + ' fetchOrderBook() requires a limit argument for uta, either 20, 50, 100 or FULL');
2545
+ }
2546
+ request['limit'] = limit;
2547
+ request['symbol'] = market['id'];
2548
+ let type = undefined;
2549
+ [type, params] = this.handleMarketTypeAndParams('fetchOrderBook', market, params);
2550
+ if (type === 'spot') {
2551
+ request['tradeType'] = 'SPOT';
2552
+ }
2553
+ else {
2554
+ request['tradeType'] = 'FUTURES';
2555
+ }
2556
+ response = await this.utaGetMarketOrderbook(this.extend(request, params));
2557
+ //
2558
+ // {
2559
+ // "code": "200000",
2560
+ // "data": {
2561
+ // "tradeType": "SPOT",
2562
+ // "symbol": "BTC-USDT",
2563
+ // "sequence": "23136002402",
2564
+ // "bids": [
2565
+ // ["104700","10.25940068"],
2566
+ // ["104698.9","0.00057076"],
2567
+ // ],
2568
+ // "asks": [
2569
+ // ["104700.1","1.4082106"],
2570
+ // ["104700.5","0.02866269"],
2571
+ // ]
2572
+ // }
2573
+ // }
2574
+ //
2575
+ }
2576
+ else if (!isAuthenticated || limit !== undefined) {
2163
2577
  if (level === 2) {
2164
2578
  request['level'] = level;
2165
2579
  if (limit !== undefined) {
@@ -3347,10 +3761,12 @@ export default class kucoin extends Exchange {
3347
3761
  * @name kucoin#fetchTrades
3348
3762
  * @description get the list of most recent trades for a particular symbol
3349
3763
  * @see https://www.kucoin.com/docs/rest/spot-trading/market-data/get-trade-histories
3764
+ * @see https://www.kucoin.com/docs-new/rest/ua/get-trades
3350
3765
  * @param {string} symbol unified symbol of the market to fetch trades for
3351
3766
  * @param {int} [since] timestamp in ms of the earliest trade to fetch
3352
3767
  * @param {int} [limit] the maximum amount of trades to fetch
3353
3768
  * @param {object} [params] extra parameters specific to the exchange API endpoint
3769
+ * @param {boolean} [params.uta] set to true for the unified trading account (uta), defaults to false
3354
3770
  * @returns {Trade[]} a list of [trade structures]{@link https://docs.ccxt.com/#/?id=public-trades}
3355
3771
  */
3356
3772
  async fetchTrades(symbol, since = undefined, limit = undefined, params = {}) {
@@ -3366,22 +3782,59 @@ export default class kucoin extends Exchange {
3366
3782
  // if (limit !== undefined) {
3367
3783
  // request['pageSize'] = limit;
3368
3784
  // }
3369
- const response = await this.publicGetMarketHistories(this.extend(request, params));
3370
- //
3371
- // {
3372
- // "code": "200000",
3373
- // "data": [
3374
- // {
3375
- // "sequence": "1548764654235",
3376
- // "side": "sell",
3377
- // "size":"0.6841354",
3378
- // "price":"0.03202",
3379
- // "time":1548848575203567174
3380
- // }
3381
- // ]
3382
- // }
3383
- //
3384
- const trades = this.safeList(response, 'data', []);
3785
+ let uta = undefined;
3786
+ [uta, params] = this.handleOptionAndParams(params, 'fetchTrades', 'uta', false);
3787
+ let response = undefined;
3788
+ let trades = undefined;
3789
+ if (uta) {
3790
+ let type = undefined;
3791
+ [type, params] = this.handleMarketTypeAndParams('fetchTrades', market, params);
3792
+ if (type === 'spot') {
3793
+ request['tradeType'] = 'SPOT';
3794
+ }
3795
+ else {
3796
+ request['tradeType'] = 'FUTURES';
3797
+ }
3798
+ response = await this.utaGetMarketTrade(this.extend(request, params));
3799
+ //
3800
+ // {
3801
+ // "code": "200000",
3802
+ // "data": {
3803
+ // "tradeType": "SPOT",
3804
+ // "list": [
3805
+ // {
3806
+ // "sequence": "18746044393340932",
3807
+ // "tradeId": "18746044393340932",
3808
+ // "price": "104355.6",
3809
+ // "size": "0.00011886",
3810
+ // "side": "sell",
3811
+ // "ts": 1762242540829000000
3812
+ // },
3813
+ // ]
3814
+ // }
3815
+ // }
3816
+ //
3817
+ const data = this.safeDict(response, 'data', {});
3818
+ trades = this.safeList(data, 'list', []);
3819
+ }
3820
+ else {
3821
+ response = await this.publicGetMarketHistories(this.extend(request, params));
3822
+ //
3823
+ // {
3824
+ // "code": "200000",
3825
+ // "data": [
3826
+ // {
3827
+ // "sequence": "1548764654235",
3828
+ // "side": "sell",
3829
+ // "size":"0.6841354",
3830
+ // "price":"0.03202",
3831
+ // "time":1548848575203567174
3832
+ // }
3833
+ // ]
3834
+ // }
3835
+ //
3836
+ trades = this.safeList(response, 'data', []);
3837
+ }
3385
3838
  return this.parseTrades(trades, market, since, limit);
3386
3839
  }
3387
3840
  parseTrade(trade, market = undefined) {
@@ -3461,12 +3914,23 @@ export default class kucoin extends Exchange {
3461
3914
  // "id":"5c4d389e4c8c60413f78e2e5",
3462
3915
  // }
3463
3916
  //
3917
+ // uta fetchTrades
3918
+ //
3919
+ // {
3920
+ // "sequence": "18746044393340932",
3921
+ // "tradeId": "18746044393340932",
3922
+ // "price": "104355.6",
3923
+ // "size": "0.00011886",
3924
+ // "side": "sell",
3925
+ // "ts": 1762242540829000000
3926
+ // }
3927
+ //
3464
3928
  const marketId = this.safeString(trade, 'symbol');
3465
3929
  market = this.safeMarket(marketId, market, '-');
3466
3930
  const id = this.safeString2(trade, 'tradeId', 'id');
3467
3931
  const orderId = this.safeString(trade, 'orderId');
3468
3932
  const takerOrMaker = this.safeString(trade, 'liquidity');
3469
- let timestamp = this.safeInteger(trade, 'time');
3933
+ let timestamp = this.safeInteger2(trade, 'time', 'ts');
3470
3934
  if (timestamp !== undefined) {
3471
3935
  timestamp = this.parseToInt(timestamp / 1000000);
3472
3936
  }
@@ -5087,6 +5551,140 @@ export default class kucoin extends Exchange {
5087
5551
  request['isIsolated'] = (marginMode === 'isolated');
5088
5552
  return await this.privatePostPositionUpdateUserLeverage(this.extend(request, params));
5089
5553
  }
5554
+ /**
5555
+ * @method
5556
+ * @name kucoin#fetchFundingRate
5557
+ * @description fetch the current funding rate
5558
+ * @see https://www.kucoin.com/docs-new/rest/ua/get-current-funding-rate
5559
+ * @param {string} symbol unified market symbol
5560
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
5561
+ * @returns {object} a [funding rate structure]{@link https://docs.ccxt.com/#/?id=funding-rate-structure}
5562
+ */
5563
+ async fetchFundingRate(symbol, params = {}) {
5564
+ await this.loadMarkets();
5565
+ const market = this.market(symbol);
5566
+ const request = {
5567
+ 'symbol': market['id'],
5568
+ };
5569
+ const response = await this.utaGetMarketFundingRate(this.extend(request, params));
5570
+ //
5571
+ // {
5572
+ // "code": "200000",
5573
+ // "data": {
5574
+ // "symbol": ".XBTUSDTMFPI8H",
5575
+ // "nextFundingRate": 7.4E-5,
5576
+ // "fundingTime": 1762444800000,
5577
+ // "fundingRateCap": 0.003,
5578
+ // "fundingRateFloor": -0.003
5579
+ // }
5580
+ // }
5581
+ //
5582
+ const data = this.safeDict(response, 'data', {});
5583
+ return this.parseFundingRate(data, market);
5584
+ }
5585
+ parseFundingRate(data, market = undefined) {
5586
+ //
5587
+ // {
5588
+ // "symbol": ".XBTUSDTMFPI8H",
5589
+ // "nextFundingRate": 7.4E-5,
5590
+ // "fundingTime": 1762444800000,
5591
+ // "fundingRateCap": 0.003,
5592
+ // "fundingRateFloor": -0.003
5593
+ // }
5594
+ //
5595
+ const fundingTimestamp = this.safeInteger(data, 'fundingTime');
5596
+ const marketId = this.safeString(data, 'symbol');
5597
+ return {
5598
+ 'info': data,
5599
+ 'symbol': this.safeSymbol(marketId, market, undefined, 'contract'),
5600
+ 'markPrice': undefined,
5601
+ 'indexPrice': undefined,
5602
+ 'interestRate': undefined,
5603
+ 'estimatedSettlePrice': undefined,
5604
+ 'timestamp': undefined,
5605
+ 'datetime': undefined,
5606
+ 'fundingRate': this.safeNumber(data, 'nextFundingRate'),
5607
+ 'fundingTimestamp': fundingTimestamp,
5608
+ 'fundingDatetime': this.iso8601(fundingTimestamp),
5609
+ 'nextFundingRate': undefined,
5610
+ 'nextFundingTimestamp': undefined,
5611
+ 'nextFundingDatetime': undefined,
5612
+ 'previousFundingRate': undefined,
5613
+ 'previousFundingTimestamp': undefined,
5614
+ 'previousFundingDatetime': undefined,
5615
+ 'interval': undefined,
5616
+ };
5617
+ }
5618
+ /**
5619
+ * @method
5620
+ * @name kucoin#fetchFundingRateHistory
5621
+ * @description fetches historical funding rate prices
5622
+ * @see https://www.kucoin.com/docs-new/rest/ua/get-history-funding-rate
5623
+ * @param {string} symbol unified symbol of the market to fetch the funding rate history for
5624
+ * @param {int} [since] not used by kucuoinfutures
5625
+ * @param {int} [limit] the maximum amount of [funding rate structures]{@link https://docs.ccxt.com/#/?id=funding-rate-history-structure} to fetch
5626
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
5627
+ * @param {int} [params.until] end time in ms
5628
+ * @returns {object[]} a list of [funding rate structures]{@link https://docs.ccxt.com/#/?id=funding-rate-history-structure}
5629
+ */
5630
+ async fetchFundingRateHistory(symbol = undefined, since = undefined, limit = undefined, params = {}) {
5631
+ if (symbol === undefined) {
5632
+ throw new ArgumentsRequired(this.id + ' fetchFundingRateHistory() requires a symbol argument');
5633
+ }
5634
+ if (since === undefined) {
5635
+ throw new ArgumentsRequired(this.id + ' fetchFundingRateHistory() requires a since argument');
5636
+ }
5637
+ await this.loadMarkets();
5638
+ const market = this.market(symbol);
5639
+ const request = {
5640
+ 'symbol': market['id'],
5641
+ };
5642
+ const until = this.safeInteger(params, 'until');
5643
+ params = this.omit(params, 'until');
5644
+ if (since !== undefined) {
5645
+ request['startAt'] = since;
5646
+ if (until === undefined) {
5647
+ request['endAt'] = this.milliseconds();
5648
+ }
5649
+ }
5650
+ if (until !== undefined) {
5651
+ request['endAt'] = until;
5652
+ }
5653
+ const response = await this.utaGetMarketFundingRateHistory(this.extend(request, params));
5654
+ //
5655
+ // {
5656
+ // "code": "200000",
5657
+ // "data": {
5658
+ // "symbol": "XBTUSDTM",
5659
+ // "list": [
5660
+ // {
5661
+ // "fundingRate": 7.6E-5,
5662
+ // "ts": 1706097600000
5663
+ // },
5664
+ // ]
5665
+ // }
5666
+ // }
5667
+ //
5668
+ const data = this.safeDict(response, 'data', {});
5669
+ const result = this.safeList(data, 'list', []);
5670
+ return this.parseFundingRateHistories(result, market, since, limit);
5671
+ }
5672
+ parseFundingRateHistory(info, market = undefined) {
5673
+ //
5674
+ // {
5675
+ // "fundingRate": 7.6E-5,
5676
+ // "ts": 1706097600000
5677
+ // }
5678
+ //
5679
+ const timestamp = this.safeInteger(info, 'ts');
5680
+ return {
5681
+ 'info': info,
5682
+ 'symbol': this.safeSymbol(undefined, market),
5683
+ 'fundingRate': this.safeNumber(info, 'fundingRate'),
5684
+ 'timestamp': timestamp,
5685
+ 'datetime': this.iso8601(timestamp),
5686
+ };
5687
+ }
5090
5688
  sign(path, api = 'public', method = 'GET', params = {}, headers = undefined, body = undefined) {
5091
5689
  //
5092
5690
  // the v2 URL is https://openapi-v2.kucoin.com/api/v1/endpoint
@@ -5106,8 +5704,12 @@ export default class kucoin extends Exchange {
5106
5704
  if (api === 'earn') {
5107
5705
  endpoint = '/api/v1/' + this.implodeParams(path, params);
5108
5706
  }
5707
+ let isUtaPrivate = false;
5109
5708
  if (api === 'uta') {
5110
5709
  endpoint = '/api/ua/v1/' + this.implodeParams(path, params);
5710
+ if (path === 'market/orderbook') {
5711
+ isUtaPrivate = true;
5712
+ }
5111
5713
  }
5112
5714
  const query = this.omit(params, this.extractParams(path));
5113
5715
  let endpart = '';
@@ -5128,7 +5730,7 @@ export default class kucoin extends Exchange {
5128
5730
  const isPrivate = (api === 'private');
5129
5731
  const isBroker = (api === 'broker');
5130
5732
  const isEarn = (api === 'earn');
5131
- if (isPrivate || isFuturePrivate || isBroker || isEarn) {
5733
+ if (isPrivate || isFuturePrivate || isBroker || isEarn || isUtaPrivate) {
5132
5734
  this.checkRequiredCredentials();
5133
5735
  const timestamp = this.nonce().toString();
5134
5736
  headers = this.extend({