ccxt 4.2.88 → 4.2.90

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 (164) hide show
  1. package/README.md +3 -3
  2. package/build.sh +2 -2
  3. package/dist/ccxt.browser.js +1062 -241
  4. package/dist/ccxt.browser.min.js +6 -4
  5. package/dist/cjs/ccxt.js +1 -1
  6. package/dist/cjs/src/ascendex.js +3 -0
  7. package/dist/cjs/src/base/Exchange.js +53 -7
  8. package/dist/cjs/src/base/functions/crypto.js +37 -0
  9. package/dist/cjs/src/base/functions/rsa.js +19 -4
  10. package/dist/cjs/src/binance.js +92 -9
  11. package/dist/cjs/src/bingx.js +101 -1
  12. package/dist/cjs/src/bitfinex2.js +1 -0
  13. package/dist/cjs/src/bitflyer.js +2 -0
  14. package/dist/cjs/src/bitget.js +9 -1
  15. package/dist/cjs/src/bitmart.js +2 -0
  16. package/dist/cjs/src/bitmex.js +1 -0
  17. package/dist/cjs/src/bitrue.js +1 -0
  18. package/dist/cjs/src/bitstamp.js +83 -99
  19. package/dist/cjs/src/blofin.js +2 -0
  20. package/dist/cjs/src/bybit.js +63 -0
  21. package/dist/cjs/src/coinbase.js +48 -24
  22. package/dist/cjs/src/coinbaseinternational.js +1 -0
  23. package/dist/cjs/src/coinex.js +102 -8
  24. package/dist/cjs/src/coinsph.js +2 -0
  25. package/dist/cjs/src/cryptocom.js +1 -0
  26. package/dist/cjs/src/delta.js +1 -0
  27. package/dist/cjs/src/digifinex.js +3 -0
  28. package/dist/cjs/src/exmo.js +1 -0
  29. package/dist/cjs/src/gate.js +4 -0
  30. package/dist/cjs/src/gemini.js +10 -9
  31. package/dist/cjs/src/hitbtc.js +3 -0
  32. package/dist/cjs/src/htx.js +3 -0
  33. package/dist/cjs/src/hyperliquid.js +1 -0
  34. package/dist/cjs/src/kucoin.js +40 -15
  35. package/dist/cjs/src/kucoinfutures.js +34 -3
  36. package/dist/cjs/src/latoken.js +4 -0
  37. package/dist/cjs/src/lbank.js +3 -1
  38. package/dist/cjs/src/luno.js +2 -0
  39. package/dist/cjs/src/mexc.js +55 -6
  40. package/dist/cjs/src/okx.js +159 -8
  41. package/dist/cjs/src/phemex.js +1 -0
  42. package/dist/cjs/src/pro/bitget.js +2 -0
  43. package/dist/cjs/src/static_dependencies/noble-curves/p256.js +48 -0
  44. package/dist/cjs/src/timex.js +2 -0
  45. package/dist/cjs/src/woo.js +1 -0
  46. package/js/ccxt.d.ts +1 -1
  47. package/js/ccxt.js +1 -1
  48. package/js/src/abstract/bingx.d.ts +2 -0
  49. package/js/src/abstract/bybit.d.ts +2 -0
  50. package/js/src/ascendex.d.ts +3 -3
  51. package/js/src/ascendex.js +3 -0
  52. package/js/src/base/Exchange.d.ts +13 -8
  53. package/js/src/base/Exchange.js +53 -7
  54. package/js/src/base/functions/crypto.js +37 -0
  55. package/js/src/base/functions/rsa.d.ts +1 -1
  56. package/js/src/base/functions/rsa.js +21 -5
  57. package/js/src/base/types.d.ts +35 -1
  58. package/js/src/bigone.d.ts +2 -2
  59. package/js/src/binance.d.ts +6 -15
  60. package/js/src/binance.js +92 -9
  61. package/js/src/bingx.d.ts +3 -2
  62. package/js/src/bingx.js +101 -1
  63. package/js/src/bit2c.d.ts +2 -2
  64. package/js/src/bitbank.d.ts +2 -2
  65. package/js/src/bitfinex.d.ts +2 -2
  66. package/js/src/bitfinex2.d.ts +3 -3
  67. package/js/src/bitfinex2.js +1 -0
  68. package/js/src/bitflyer.d.ts +2 -7
  69. package/js/src/bitflyer.js +2 -0
  70. package/js/src/bitget.d.ts +6 -9
  71. package/js/src/bitget.js +9 -1
  72. package/js/src/bitmart.d.ts +4 -14
  73. package/js/src/bitmart.js +2 -0
  74. package/js/src/bitmex.d.ts +2 -2
  75. package/js/src/bitmex.js +1 -0
  76. package/js/src/bitopro.d.ts +3 -3
  77. package/js/src/bitrue.d.ts +2 -2
  78. package/js/src/bitrue.js +1 -0
  79. package/js/src/bitso.d.ts +2 -2
  80. package/js/src/bitstamp.d.ts +7 -19
  81. package/js/src/bitstamp.js +83 -99
  82. package/js/src/bitteam.d.ts +2 -2
  83. package/js/src/bitvavo.d.ts +3 -3
  84. package/js/src/bl3p.d.ts +2 -2
  85. package/js/src/blockchaincom.d.ts +2 -2
  86. package/js/src/blofin.d.ts +2 -7
  87. package/js/src/blofin.js +2 -0
  88. package/js/src/bybit.d.ts +7 -15
  89. package/js/src/bybit.js +63 -0
  90. package/js/src/cex.d.ts +3 -3
  91. package/js/src/coinbase.d.ts +2 -2
  92. package/js/src/coinbase.js +48 -24
  93. package/js/src/coinbaseinternational.d.ts +2 -2
  94. package/js/src/coinbaseinternational.js +1 -0
  95. package/js/src/coinbasepro.d.ts +3 -3
  96. package/js/src/coincheck.d.ts +2 -2
  97. package/js/src/coinex.d.ts +7 -19
  98. package/js/src/coinex.js +102 -8
  99. package/js/src/coinlist.d.ts +3 -3
  100. package/js/src/coinmate.d.ts +2 -9
  101. package/js/src/coinmetro.d.ts +2 -2
  102. package/js/src/coinone.d.ts +2 -2
  103. package/js/src/coinsph.d.ts +4 -14
  104. package/js/src/coinsph.js +2 -0
  105. package/js/src/cryptocom.js +1 -0
  106. package/js/src/currencycom.d.ts +3 -3
  107. package/js/src/delta.d.ts +2 -2
  108. package/js/src/delta.js +1 -0
  109. package/js/src/deribit.d.ts +3 -3
  110. package/js/src/digifinex.d.ts +4 -14
  111. package/js/src/digifinex.js +3 -0
  112. package/js/src/exmo.d.ts +3 -3
  113. package/js/src/exmo.js +1 -0
  114. package/js/src/gate.d.ts +6 -9
  115. package/js/src/gate.js +4 -0
  116. package/js/src/gemini.d.ts +3 -3
  117. package/js/src/gemini.js +10 -9
  118. package/js/src/hitbtc.d.ts +5 -15
  119. package/js/src/hitbtc.js +3 -0
  120. package/js/src/hollaex.d.ts +3 -3
  121. package/js/src/htx.d.ts +4 -14
  122. package/js/src/htx.js +3 -0
  123. package/js/src/huobijp.d.ts +2 -2
  124. package/js/src/hyperliquid.d.ts +2 -2
  125. package/js/src/hyperliquid.js +1 -0
  126. package/js/src/idex.d.ts +3 -3
  127. package/js/src/independentreserve.d.ts +2 -2
  128. package/js/src/kraken.d.ts +3 -10
  129. package/js/src/kucoin.d.ts +3 -10
  130. package/js/src/kucoin.js +40 -15
  131. package/js/src/kucoinfutures.d.ts +2 -9
  132. package/js/src/kucoinfutures.js +34 -3
  133. package/js/src/kuna.d.ts +2 -2
  134. package/js/src/latoken.d.ts +7 -8
  135. package/js/src/latoken.js +4 -0
  136. package/js/src/lbank.d.ts +4 -9
  137. package/js/src/lbank.js +3 -1
  138. package/js/src/luno.d.ts +2 -7
  139. package/js/src/luno.js +2 -0
  140. package/js/src/lykke.d.ts +2 -2
  141. package/js/src/mexc.d.ts +3 -3
  142. package/js/src/mexc.js +55 -6
  143. package/js/src/ndax.d.ts +2 -2
  144. package/js/src/oceanex.d.ts +2 -2
  145. package/js/src/okcoin.d.ts +2 -2
  146. package/js/src/okx.d.ts +5 -14
  147. package/js/src/okx.js +159 -8
  148. package/js/src/onetrading.d.ts +3 -3
  149. package/js/src/phemex.d.ts +2 -2
  150. package/js/src/phemex.js +1 -0
  151. package/js/src/poloniex.d.ts +3 -3
  152. package/js/src/pro/bitget.js +2 -0
  153. package/js/src/pro/bitvavo.d.ts +2 -2
  154. package/js/src/probit.d.ts +2 -2
  155. package/js/src/timex.d.ts +4 -14
  156. package/js/src/timex.js +2 -0
  157. package/js/src/upbit.d.ts +2 -9
  158. package/js/src/wazirx.d.ts +2 -2
  159. package/js/src/whitebit.d.ts +3 -3
  160. package/js/src/woo.d.ts +3 -3
  161. package/js/src/woo.js +1 -0
  162. package/js/src/yobit.d.ts +2 -2
  163. package/package.json +1 -1
  164. package/skip-tests.json +6 -1
@@ -428,6 +428,30 @@ class bitstamp extends bitstamp$1 {
428
428
  'commonCurrencies': {
429
429
  'UST': 'USTC',
430
430
  },
431
+ // exchange-specific options
432
+ 'options': {
433
+ 'networksById': {
434
+ 'bitcoin-cash': 'BCH',
435
+ 'bitcoin': 'BTC',
436
+ 'ethereum': 'ERC20',
437
+ 'litecoin': 'LTC',
438
+ 'stellar': 'XLM',
439
+ 'xrpl': 'XRP',
440
+ 'tron': 'TRC20',
441
+ 'algorand': 'ALGO',
442
+ 'flare': 'FLR',
443
+ 'hedera': 'HBAR',
444
+ 'cardana': 'ADA',
445
+ 'songbird': 'FLR',
446
+ 'avalanche-c-chain': 'AVAX',
447
+ 'solana': 'SOL',
448
+ 'polkadot': 'DOT',
449
+ 'near': 'NEAR',
450
+ 'doge': 'DOGE',
451
+ 'sui': 'SUI',
452
+ 'casper': 'CSRP',
453
+ },
454
+ },
431
455
  'exceptions': {
432
456
  'exact': {
433
457
  'No permission found': errors.PermissionDenied,
@@ -1200,6 +1224,8 @@ class bitstamp extends bitstamp$1 {
1200
1224
  'symbol': this.safeSymbol(marketId, market),
1201
1225
  'maker': this.safeNumber(fees, 'maker'),
1202
1226
  'taker': this.safeNumber(fees, 'taker'),
1227
+ 'percentage': undefined,
1228
+ 'tierBased': undefined,
1203
1229
  };
1204
1230
  }
1205
1231
  parseTradingFees(fees) {
@@ -1245,60 +1271,41 @@ class bitstamp extends bitstamp$1 {
1245
1271
  * @name bitstamp#fetchTransactionFees
1246
1272
  * @deprecated
1247
1273
  * @description please use fetchDepositWithdrawFees instead
1248
- * @see https://www.bitstamp.net/api/#balance
1274
+ * @see https://www.bitstamp.net/api/#tag/Fees
1249
1275
  * @param {string[]|undefined} codes list of unified currency codes
1250
1276
  * @param {object} [params] extra parameters specific to the exchange API endpoint
1251
1277
  * @returns {object[]} a list of [fee structures]{@link https://docs.ccxt.com/#/?id=fee-structure}
1252
1278
  */
1253
1279
  await this.loadMarkets();
1254
- const balance = await this.privatePostBalance(params);
1255
- return this.parseTransactionFees(balance);
1280
+ const response = await this.privatePostFeesWithdrawal(params);
1281
+ //
1282
+ // [
1283
+ // {
1284
+ // "currency": "btc",
1285
+ // "fee": "0.00015000",
1286
+ // "network": "bitcoin"
1287
+ // }
1288
+ // ...
1289
+ // ]
1290
+ //
1291
+ return this.parseTransactionFees(response);
1256
1292
  }
1257
1293
  parseTransactionFees(response, codes = undefined) {
1258
- //
1259
- // {
1260
- // "yfi_available": "0.00000000",
1261
- // "yfi_balance": "0.00000000",
1262
- // "yfi_reserved": "0.00000000",
1263
- // "yfi_withdrawal_fee": "0.00070000",
1264
- // "yfieur_fee": "0.000",
1265
- // "yfiusd_fee": "0.000",
1266
- // "zrx_available": "0.00000000",
1267
- // "zrx_balance": "0.00000000",
1268
- // "zrx_reserved": "0.00000000",
1269
- // "zrx_withdrawal_fee": "12.00000000",
1270
- // "zrxeur_fee": "0.000",
1271
- // "zrxusd_fee": "0.000",
1272
- // ...
1273
- // }
1274
- //
1275
- if (codes === undefined) {
1276
- codes = Object.keys(this.currencies);
1277
- }
1278
1294
  const result = {};
1279
- let mainCurrencyId = undefined;
1280
- const ids = Object.keys(response);
1295
+ const currencies = this.indexBy(response, 'currency');
1296
+ const ids = Object.keys(currencies);
1281
1297
  for (let i = 0; i < ids.length; i++) {
1282
1298
  const id = ids[i];
1283
- const currencyId = id.split('_')[0];
1284
- const code = this.safeCurrencyCode(currencyId);
1285
- if (codes !== undefined && !this.inArray(code, codes)) {
1299
+ const fees = this.safeValue(response, i, {});
1300
+ const code = this.safeCurrencyCode(id);
1301
+ if ((codes !== undefined) && !this.inArray(code, codes)) {
1286
1302
  continue;
1287
1303
  }
1288
- if (id.indexOf('_available') >= 0) {
1289
- mainCurrencyId = currencyId;
1290
- result[code] = {
1291
- 'deposit': undefined,
1292
- 'withdraw': undefined,
1293
- 'info': {},
1294
- };
1295
- }
1296
- if (currencyId === mainCurrencyId) {
1297
- result[code]['info'][id] = this.safeNumber(response, id);
1298
- }
1299
- if (id.indexOf('_withdrawal_fee') >= 0) {
1300
- result[code]['withdraw'] = this.safeNumber(response, id);
1301
- }
1304
+ result[code] = {
1305
+ 'withdraw_fee': this.safeNumber(fees, 'fee'),
1306
+ 'deposit': {},
1307
+ 'info': this.safeDict(currencies, id),
1308
+ };
1302
1309
  }
1303
1310
  return result;
1304
1311
  }
@@ -1313,64 +1320,41 @@ class bitstamp extends bitstamp$1 {
1313
1320
  * @returns {object[]} a list of [fee structures]{@link https://docs.ccxt.com/#/?id=fee-structure}
1314
1321
  */
1315
1322
  await this.loadMarkets();
1316
- const response = await this.privatePostBalance(params);
1317
- //
1318
- // {
1319
- // "yfi_available": "0.00000000",
1320
- // "yfi_balance": "0.00000000",
1321
- // "yfi_reserved": "0.00000000",
1322
- // "yfi_withdrawal_fee": "0.00070000",
1323
- // "yfieur_fee": "0.000",
1324
- // "yfiusd_fee": "0.000",
1325
- // "zrx_available": "0.00000000",
1326
- // "zrx_balance": "0.00000000",
1327
- // "zrx_reserved": "0.00000000",
1328
- // "zrx_withdrawal_fee": "12.00000000",
1329
- // "zrxeur_fee": "0.000",
1330
- // "zrxusd_fee": "0.000",
1331
- // ...
1332
- // }
1333
- //
1334
- return this.parseDepositWithdrawFees(response, codes);
1335
- }
1336
- parseDepositWithdrawFees(response, codes = undefined, currencyIdKey = undefined) {
1337
- //
1338
- // {
1339
- // "yfi_available": "0.00000000",
1340
- // "yfi_balance": "0.00000000",
1341
- // "yfi_reserved": "0.00000000",
1342
- // "yfi_withdrawal_fee": "0.00070000",
1343
- // "yfieur_fee": "0.000",
1344
- // "yfiusd_fee": "0.000",
1345
- // "zrx_available": "0.00000000",
1346
- // "zrx_balance": "0.00000000",
1347
- // "zrx_reserved": "0.00000000",
1348
- // "zrx_withdrawal_fee": "12.00000000",
1349
- // "zrxeur_fee": "0.000",
1350
- // "zrxusd_fee": "0.000",
1351
- // ...
1352
- // }
1323
+ const response = await this.privatePostFeesWithdrawal(params);
1353
1324
  //
1354
- const result = {};
1355
- const ids = Object.keys(response);
1356
- for (let i = 0; i < ids.length; i++) {
1357
- const id = ids[i];
1358
- const currencyId = id.split('_')[0];
1359
- const code = this.safeCurrencyCode(currencyId);
1360
- const dictValue = this.safeNumber(response, id);
1361
- if (codes !== undefined && !this.inArray(code, codes)) {
1362
- continue;
1363
- }
1364
- if (id.indexOf('_available') >= 0) {
1365
- result[code] = this.depositWithdrawFee({});
1366
- }
1367
- if (id.indexOf('_withdrawal_fee') >= 0) {
1368
- result[code]['withdraw']['fee'] = dictValue;
1369
- }
1370
- const resultValue = this.safeValue(result, code);
1371
- if (resultValue !== undefined) {
1372
- result[code]['info'][id] = dictValue;
1373
- }
1325
+ // [
1326
+ // {
1327
+ // "currency": "btc",
1328
+ // "fee": "0.00015000",
1329
+ // "network": "bitcoin"
1330
+ // }
1331
+ // ...
1332
+ // ]
1333
+ //
1334
+ const responseByCurrencyId = this.groupBy(response, 'currency');
1335
+ return this.parseDepositWithdrawFees(responseByCurrencyId, codes);
1336
+ }
1337
+ parseDepositWithdrawFee(fee, currency = undefined) {
1338
+ const result = this.depositWithdrawFee(fee);
1339
+ for (let j = 0; j < fee.length; j++) {
1340
+ const networkEntry = fee[j];
1341
+ const networkId = this.safeString(networkEntry, 'network');
1342
+ const networkCode = this.networkIdToCode(networkId);
1343
+ const withdrawFee = this.safeNumber(networkEntry, 'fee');
1344
+ result['withdraw'] = {
1345
+ 'fee': withdrawFee,
1346
+ 'percentage': undefined,
1347
+ };
1348
+ result['networks'][networkCode] = {
1349
+ 'withdraw': {
1350
+ 'fee': withdrawFee,
1351
+ 'percentage': undefined,
1352
+ },
1353
+ 'deposit': {
1354
+ 'fee': undefined,
1355
+ 'percentage': undefined,
1356
+ },
1357
+ };
1374
1358
  }
1375
1359
  return result;
1376
1360
  }
@@ -941,6 +941,8 @@ class blofin extends blofin$1 {
941
941
  // blofin returns the fees as negative values opposed to other exchanges, so the sign needs to be flipped
942
942
  'maker': this.parseNumber(Precise["default"].stringNeg(this.safeString2(fee, 'maker', 'makerU'))),
943
943
  'taker': this.parseNumber(Precise["default"].stringNeg(this.safeString2(fee, 'taker', 'takerU'))),
944
+ 'percentage': undefined,
945
+ 'tierBased': undefined,
944
946
  };
945
947
  }
946
948
  async fetchBalance(params = {}) {
@@ -81,6 +81,7 @@ class bybit extends bybit$1 {
81
81
  'fetchLedger': true,
82
82
  'fetchLeverage': true,
83
83
  'fetchLeverageTiers': true,
84
+ 'fetchMarginAdjustmentHistory': false,
84
85
  'fetchMarketLeverageTiers': true,
85
86
  'fetchMarkets': true,
86
87
  'fetchMarkOHLCV': true,
@@ -151,6 +152,13 @@ class bybit extends bybit$1 {
151
152
  'public': 'https://api.{hostname}',
152
153
  'private': 'https://api.{hostname}',
153
154
  },
155
+ 'demotrading': {
156
+ 'spot': 'https://api-demo.{hostname}',
157
+ 'futures': 'https://api-demo.{hostname}',
158
+ 'v2': 'https://api-demo.{hostname}',
159
+ 'public': 'https://api-demo.{hostname}',
160
+ 'private': 'https://api-demo.{hostname}',
161
+ },
154
162
  'www': 'https://www.bybit.com',
155
163
  'doc': [
156
164
  'https://bybit-exchange.github.io/docs/inverse/',
@@ -339,6 +347,7 @@ class bybit extends bybit$1 {
339
347
  'v5/user/get-member-type': 5,
340
348
  'v5/user/aff-customer-info': 5,
341
349
  'v5/user/del-submember': 5,
350
+ 'v5/user/submembers': 5,
342
351
  // spot leverage token
343
352
  'v5/spot-lever-token/order-record': 1,
344
353
  // spot margin trade
@@ -499,6 +508,8 @@ class bybit extends bybit$1 {
499
508
  'v5/lending/redeem-cancel': 5,
500
509
  'v5/account/set-collateral-switch': 5,
501
510
  'v5/account/set-collateral-switch-batch': 5,
511
+ // demo trading
512
+ 'v5/account/demo-apply-money': 5,
502
513
  },
503
514
  },
504
515
  },
@@ -965,6 +976,8 @@ class bybit extends bybit$1 {
965
976
  },
966
977
  'precisionMode': number.TICK_SIZE,
967
978
  'options': {
979
+ 'sandboxMode': false,
980
+ 'enableDemoTrading': false,
968
981
  'fetchMarkets': ['spot', 'linear', 'inverse', 'option'],
969
982
  'createOrder': {
970
983
  'method': 'privatePostV5OrderCreate', // 'privatePostV5PositionTradingStop'
@@ -1048,6 +1061,39 @@ class bybit extends bybit$1 {
1048
1061
  },
1049
1062
  });
1050
1063
  }
1064
+ setSandboxMode(enable) {
1065
+ /**
1066
+ * @method
1067
+ * @name bybit#setSandboxMode
1068
+ * @description enables or disables sandbox mode
1069
+ * @param {boolean} [enable] true if demo trading should be enabled, false otherwise
1070
+ */
1071
+ super.setSandboxMode(enable);
1072
+ this.options['sandboxMode'] = enable;
1073
+ }
1074
+ enableDemoTrading(enable) {
1075
+ /**
1076
+ * @method
1077
+ * @name bybit#enableDemoTrading
1078
+ * @description enables or disables demo trading mode
1079
+ * @see https://bybit-exchange.github.io/docs/v5/demo
1080
+ * @param {boolean} [enable] true if demo trading should be enabled, false otherwise
1081
+ */
1082
+ if (this.options['sandboxMode']) {
1083
+ throw new errors.NotSupported(this.id + ' demo trading does not support in sandbox environment');
1084
+ }
1085
+ // enable demo trading in bybit, see: https://bybit-exchange.github.io/docs/v5/demo
1086
+ if (enable) {
1087
+ this.urls['apiBackupDemoTrading'] = this.urls['api'];
1088
+ this.urls['api'] = this.urls['demotrading'];
1089
+ }
1090
+ else if ('apiBackupDemoTrading' in this.urls) {
1091
+ this.urls['api'] = this.urls['apiBackupDemoTrading'];
1092
+ const newUrls = this.omit(this.urls, 'apiBackupDemoTrading');
1093
+ this.urls = newUrls;
1094
+ }
1095
+ this.options['enableDemoTrading'] = enable;
1096
+ }
1051
1097
  nonce() {
1052
1098
  return this.milliseconds() - this.options['timeDifference'];
1053
1099
  }
@@ -1064,12 +1110,24 @@ class bybit extends bybit$1 {
1064
1110
  return data;
1065
1111
  }
1066
1112
  async isUnifiedEnabled(params = {}) {
1113
+ /**
1114
+ * @method
1115
+ * @name bybit#isUnifiedEnabled
1116
+ * @description returns [enableUnifiedMargin, enableUnifiedAccount] so the user can check if unified account is enabled
1117
+ */
1067
1118
  // The API key of user id must own one of permissions will be allowed to call following API endpoints.
1068
1119
  // SUB UID: "Account Transfer"
1069
1120
  // MASTER UID: "Account Transfer", "Subaccount Transfer", "Withdrawal"
1070
1121
  const enableUnifiedMargin = this.safeValue(this.options, 'enableUnifiedMargin');
1071
1122
  const enableUnifiedAccount = this.safeValue(this.options, 'enableUnifiedAccount');
1072
1123
  if (enableUnifiedMargin === undefined || enableUnifiedAccount === undefined) {
1124
+ if (this.options['enableDemoTrading']) {
1125
+ // info endpoint is not available in demo trading
1126
+ // so we're assuming UTA is enabled
1127
+ this.options['enableUnifiedMargin'] = false;
1128
+ this.options['enableUnifiedAccount'] = true;
1129
+ return [this.options['enableUnifiedMargin'], this.options['enableUnifiedAccount']];
1130
+ }
1073
1131
  const response = await this.privateGetV5UserQueryApi(params);
1074
1132
  //
1075
1133
  // {
@@ -1239,6 +1297,9 @@ class bybit extends bybit$1 {
1239
1297
  if (!this.checkRequiredCredentials(false)) {
1240
1298
  return undefined;
1241
1299
  }
1300
+ if (this.options['enableDemoTrading']) {
1301
+ return undefined;
1302
+ }
1242
1303
  const response = await this.privateGetV5AssetCoinQueryInfo(params);
1243
1304
  //
1244
1305
  // {
@@ -7264,6 +7325,8 @@ class bybit extends bybit$1 {
7264
7325
  'symbol': symbol,
7265
7326
  'maker': this.safeNumber(fee, 'makerFeeRate'),
7266
7327
  'taker': this.safeNumber(fee, 'takerFeeRate'),
7328
+ 'percentage': undefined,
7329
+ 'tierBased': undefined,
7267
7330
  };
7268
7331
  }
7269
7332
  async fetchTradingFee(symbol, params = {}) {
@@ -5,6 +5,7 @@ var errors = require('./base/errors.js');
5
5
  var Precise = require('./base/Precise.js');
6
6
  var number = require('./base/functions/number.js');
7
7
  var sha256 = require('./static_dependencies/noble-hashes/sha256.js');
8
+ var rsa = require('./base/functions/rsa.js');
8
9
 
9
10
  // ----------------------------------------------------------------------------
10
11
  // ----------------------------------------------------------------------------
@@ -3783,31 +3784,16 @@ class coinbase extends coinbase$1 {
3783
3784
  const url = this.urls['api']['rest'] + fullPath;
3784
3785
  if (signed) {
3785
3786
  const authorization = this.safeString(this.headers, 'Authorization');
3787
+ let authorizationString = undefined;
3786
3788
  if (authorization !== undefined) {
3787
- headers = {
3788
- 'Authorization': authorization,
3789
- 'Content-Type': 'application/json',
3790
- };
3791
- if (method !== 'GET') {
3792
- if (Object.keys(query).length) {
3793
- body = this.json(query);
3794
- }
3795
- }
3789
+ authorizationString = authorization;
3796
3790
  }
3797
3791
  else if (this.token && !this.checkRequiredCredentials(false)) {
3798
- headers = {
3799
- 'Authorization': 'Bearer ' + this.token,
3800
- 'Content-Type': 'application/json',
3801
- };
3802
- if (method !== 'GET') {
3803
- if (Object.keys(query).length) {
3804
- body = this.json(query);
3805
- }
3806
- }
3792
+ authorizationString = 'Bearer ' + this.token;
3807
3793
  }
3808
3794
  else {
3809
3795
  this.checkRequiredCredentials();
3810
- const timestampString = this.seconds().toString();
3796
+ const seconds = this.seconds();
3811
3797
  let payload = '';
3812
3798
  if (method !== 'GET') {
3813
3799
  if (Object.keys(query).length) {
@@ -3826,14 +3812,52 @@ class coinbase extends coinbase$1 {
3826
3812
  // https://docs.cloud.coinbase.com/advanced-trade-api/docs/auth#example-request
3827
3813
  // v2: 'GET' require payload in the signature
3828
3814
  // https://docs.cloud.coinbase.com/sign-in-with-coinbase/docs/api-key-authentication
3829
- const auth = timestampString + method + savedPath + payload;
3830
- const signature = this.hmac(this.encode(auth), this.encode(this.secret), sha256.sha256);
3815
+ const isCloudAPiKey = (this.apiKey.indexOf('organizations/') >= 0) || (this.secret.startsWith('-----BEGIN'));
3816
+ if (isCloudAPiKey) {
3817
+ if (this.apiKey.startsWith('-----BEGIN')) {
3818
+ throw new errors.ArgumentsRequired(this.id + ' apiKey should contain the name (eg: organizations/3b910e93....) and not the public key');
3819
+ }
3820
+ // it may not work for v2
3821
+ let uri = method + ' ' + url.replace('https://', '');
3822
+ const quesPos = uri.indexOf('?');
3823
+ if (quesPos >= 0) {
3824
+ uri = uri.slice(0, quesPos);
3825
+ }
3826
+ const nonce = this.randomBytes(16);
3827
+ const request = {
3828
+ 'aud': ['retail_rest_api_proxy'],
3829
+ 'iss': 'coinbase-cloud',
3830
+ 'nbf': seconds,
3831
+ 'exp': seconds + 120,
3832
+ 'sub': this.apiKey,
3833
+ 'uri': uri,
3834
+ 'iat': seconds,
3835
+ };
3836
+ const token = rsa.jwt(request, this.encode(this.secret), sha256.sha256, false, { 'kid': this.apiKey, 'nonce': nonce, 'alg': 'ES256' });
3837
+ authorizationString = 'Bearer ' + token;
3838
+ }
3839
+ else {
3840
+ const timestampString = this.seconds().toString();
3841
+ const auth = timestampString + method + savedPath + payload;
3842
+ const signature = this.hmac(this.encode(auth), this.encode(this.secret), sha256.sha256);
3843
+ headers = {
3844
+ 'CB-ACCESS-KEY': this.apiKey,
3845
+ 'CB-ACCESS-SIGN': signature,
3846
+ 'CB-ACCESS-TIMESTAMP': timestampString,
3847
+ 'Content-Type': 'application/json',
3848
+ };
3849
+ }
3850
+ }
3851
+ if (authorizationString !== undefined) {
3831
3852
  headers = {
3832
- 'CB-ACCESS-KEY': this.apiKey,
3833
- 'CB-ACCESS-SIGN': signature,
3834
- 'CB-ACCESS-TIMESTAMP': timestampString,
3853
+ 'Authorization': authorizationString,
3835
3854
  'Content-Type': 'application/json',
3836
3855
  };
3856
+ if (method !== 'GET') {
3857
+ if (Object.keys(query).length) {
3858
+ body = this.json(query);
3859
+ }
3860
+ }
3837
3861
  }
3838
3862
  }
3839
3863
  return { 'url': url, 'method': method, 'body': body, 'headers': headers };
@@ -76,6 +76,7 @@ class coinbaseinternational extends coinbaseinternational$1 {
76
76
  'fetchLedger': false,
77
77
  'fetchLeverage': false,
78
78
  'fetchLeverageTiers': false,
79
+ 'fetchMarginAdjustmentHistory': false,
79
80
  'fetchMarginMode': false,
80
81
  'fetchMarkets': true,
81
82
  'fetchMarkOHLCV': false,
@@ -80,6 +80,7 @@ class coinex extends coinex$1 {
80
80
  'fetchLeverage': 'emulated',
81
81
  'fetchLeverages': true,
82
82
  'fetchLeverageTiers': true,
83
+ 'fetchMarginAdjustmentHistory': true,
83
84
  'fetchMarketLeverageTiers': 'emulated',
84
85
  'fetchMarkets': true,
85
86
  'fetchMarkOHLCV': false,
@@ -4239,11 +4240,10 @@ class coinex extends coinex$1 {
4239
4240
  // "message":"OK"
4240
4241
  // }
4241
4242
  //
4243
+ const data = this.safeDict(response, 'data');
4242
4244
  const status = this.safeString(response, 'message');
4243
- const type = (addOrReduce === 1) ? 'add' : 'reduce';
4244
- return this.extend(this.parseMarginModification(response, market), {
4245
+ return this.extend(this.parseMarginModification(data, market), {
4245
4246
  'amount': this.parseNumber(amount),
4246
- 'type': type,
4247
4247
  'status': status,
4248
4248
  });
4249
4249
  }
@@ -4303,13 +4303,34 @@ class coinex extends coinex$1 {
4303
4303
  // "user_id": 3620173
4304
4304
  // }
4305
4305
  //
4306
- const timestamp = this.safeIntegerProduct(data, 'update_time', 1000);
4306
+ // fetchMarginAdjustmentHistory
4307
+ //
4308
+ // {
4309
+ // bkr_price: '0',
4310
+ // leverage: '3',
4311
+ // liq_price: '0',
4312
+ // margin_amount: '5.33236666666666666666',
4313
+ // margin_change: '3',
4314
+ // market: 'XRPUSDT',
4315
+ // position_amount: '11',
4316
+ // position_id: '297155652',
4317
+ // position_type: '2',
4318
+ // settle_price: '0.6361',
4319
+ // time: '1711050906.382891',
4320
+ // type: '1',
4321
+ // user_id: '3685860'
4322
+ // }
4323
+ //
4324
+ const marketId = this.safeString(data, 'market');
4325
+ const type = this.safeString(data, 'type');
4326
+ const timestamp = this.safeIntegerProduct2(data, 'time', 'update_time', 1000);
4307
4327
  return {
4308
4328
  'info': data,
4309
- 'symbol': this.safeSymbol(undefined, market),
4310
- 'type': undefined,
4311
- 'amount': this.safeNumber(data, 'margin_amount'),
4312
- 'total': undefined,
4329
+ 'symbol': this.safeSymbol(marketId, market, undefined, 'swap'),
4330
+ 'type': (type === '1') ? 'add' : 'reduce',
4331
+ 'marginMode': 'isolated',
4332
+ 'amount': this.safeNumber(data, 'margin_change'),
4333
+ 'total': this.safeNumber(data, 'position_amount'),
4313
4334
  'code': market['quote'],
4314
4335
  'status': undefined,
4315
4336
  'timestamp': timestamp,
@@ -4960,6 +4981,7 @@ class coinex extends coinex$1 {
4960
4981
  const currencyId = this.safeString(transfer, 'asset');
4961
4982
  const currencyCode = this.safeCurrencyCode(currencyId, currency);
4962
4983
  return {
4984
+ 'info': transfer,
4963
4985
  'id': this.safeInteger(transfer, 'id'),
4964
4986
  'timestamp': timestamp,
4965
4987
  'datetime': this.iso8601(timestamp),
@@ -5792,6 +5814,78 @@ class coinex extends coinex$1 {
5792
5814
  }
5793
5815
  return undefined;
5794
5816
  }
5817
+ async fetchMarginAdjustmentHistory(symbol = undefined, type = undefined, since = undefined, limit = undefined, params = {}) {
5818
+ /**
5819
+ * @method
5820
+ * @name coinex#fetchMarginAdjustmentHistory
5821
+ * @description fetches the history of margin added or reduced from contract isolated positions
5822
+ * @see https://viabtc.github.io/coinex_api_en_doc/futures/#docsfutures001_http046_position_margin_history
5823
+ * @param {string} [symbol] unified market symbol
5824
+ * @param {string} [type] not used by coinex fetchMarginAdjustmentHistory
5825
+ * @param {int} [since] timestamp in ms of the earliest change to fetch
5826
+ * @param {int} [limit] the maximum amount of changes to fetch, default=100, max=100
5827
+ * @param {object} params extra parameters specific to the exchange api endpoint
5828
+ * @param {int} [params.until] timestamp in ms of the latest change to fetch
5829
+ *
5830
+ * EXCHANGE SPECIFIC PARAMETERS
5831
+ * @param {int} [params.offset] offset
5832
+ * @returns {object[]} a list of [margin structures]{@link https://docs.ccxt.com/#/?id=margin-loan-structure}
5833
+ */
5834
+ await this.loadMarkets();
5835
+ const until = this.safeInteger(params, 'until');
5836
+ params = this.omit(params, 'until');
5837
+ if (limit === undefined) {
5838
+ limit = 100;
5839
+ }
5840
+ const request = {
5841
+ 'market': '',
5842
+ 'position_id': 0,
5843
+ 'offset': 0,
5844
+ 'limit': limit,
5845
+ };
5846
+ if (symbol !== undefined) {
5847
+ const market = this.market(symbol);
5848
+ request['market'] = market['id'];
5849
+ }
5850
+ if (since !== undefined) {
5851
+ request['start_time'] = since;
5852
+ }
5853
+ if (until !== undefined) {
5854
+ request['end_time'] = until;
5855
+ }
5856
+ const response = await this.v1PerpetualPrivateGetPositionMarginHistory(this.extend(request, params));
5857
+ //
5858
+ // {
5859
+ // code: '0',
5860
+ // data: {
5861
+ // limit: '100',
5862
+ // offset: '0',
5863
+ // records: [
5864
+ // {
5865
+ // bkr_price: '0',
5866
+ // leverage: '3',
5867
+ // liq_price: '0',
5868
+ // margin_amount: '5.33236666666666666666',
5869
+ // margin_change: '3',
5870
+ // market: 'XRPUSDT',
5871
+ // position_amount: '11',
5872
+ // position_id: '297155652',
5873
+ // position_type: '2',
5874
+ // settle_price: '0.6361',
5875
+ // time: '1711050906.382891',
5876
+ // type: '1',
5877
+ // user_id: '3685860'
5878
+ // }
5879
+ // ]
5880
+ // },
5881
+ // message: 'OK'
5882
+ // }
5883
+ //
5884
+ const data = this.safeDict(response, 'data', {});
5885
+ const records = this.safeList(data, 'records', []);
5886
+ const modifications = this.parseMarginModifications(records, undefined, 'market', 'swap');
5887
+ return this.filterBySymbolSinceLimit(modifications, symbol, since, limit);
5888
+ }
5795
5889
  }
5796
5890
 
5797
5891
  module.exports = coinex;
@@ -1574,6 +1574,8 @@ class coinsph extends coinsph$1 {
1574
1574
  'symbol': symbol,
1575
1575
  'maker': this.safeNumber(fee, 'makerCommission'),
1576
1576
  'taker': this.safeNumber(fee, 'takerCommission'),
1577
+ 'percentage': undefined,
1578
+ 'tierBased': undefined,
1577
1579
  };
1578
1580
  }
1579
1581
  async withdraw(code, amount, address, tag = undefined, params = {}) {
@@ -66,6 +66,7 @@ class cryptocom extends cryptocom$1 {
66
66
  'fetchLedger': true,
67
67
  'fetchLeverage': false,
68
68
  'fetchLeverageTiers': false,
69
+ 'fetchMarginAdjustmentHistory': false,
69
70
  'fetchMarginMode': false,
70
71
  'fetchMarketLeverageTiers': false,
71
72
  'fetchMarkets': true,
@@ -2665,6 +2665,7 @@ class delta extends delta$1 {
2665
2665
  'info': data,
2666
2666
  'symbol': market['symbol'],
2667
2667
  'type': undefined,
2668
+ 'marginMode': 'isolated',
2668
2669
  'amount': undefined,
2669
2670
  'total': this.safeNumber(data, 'margin'),
2670
2671
  'code': undefined,