ccxt 4.4.6 → 4.4.8

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 (55) hide show
  1. package/README.md +3 -3
  2. package/dist/ccxt.browser.min.js +2 -2
  3. package/dist/cjs/ccxt.js +1 -1
  4. package/dist/cjs/src/base/Exchange.js +21 -2
  5. package/dist/cjs/src/binance.js +51 -12
  6. package/dist/cjs/src/bingx.js +3 -0
  7. package/dist/cjs/src/bitget.js +10 -6
  8. package/dist/cjs/src/bitmart.js +124 -1
  9. package/dist/cjs/src/bybit.js +377 -10
  10. package/dist/cjs/src/gate.js +3 -0
  11. package/dist/cjs/src/htx.js +22 -0
  12. package/dist/cjs/src/kucoin.js +2 -2
  13. package/dist/cjs/src/mexc.js +97 -13
  14. package/dist/cjs/src/okx.js +4 -0
  15. package/dist/cjs/src/pro/bitget.js +66 -0
  16. package/dist/cjs/src/pro/bitmart.js +81 -0
  17. package/dist/cjs/src/pro/bitvavo.js +92 -1
  18. package/dist/cjs/src/pro/blofin.js +64 -0
  19. package/dist/cjs/src/pro/okx.js +11 -5
  20. package/examples/js/cli.js +2 -0
  21. package/js/ccxt.d.ts +1 -1
  22. package/js/ccxt.js +1 -1
  23. package/js/src/abstract/binance.d.ts +1 -0
  24. package/js/src/abstract/binancecoinm.d.ts +1 -0
  25. package/js/src/abstract/binanceus.d.ts +1 -0
  26. package/js/src/abstract/binanceusdm.d.ts +1 -0
  27. package/js/src/abstract/bybit.d.ts +5 -0
  28. package/js/src/abstract/okx.d.ts +2 -0
  29. package/js/src/base/Exchange.d.ts +4 -0
  30. package/js/src/base/Exchange.js +21 -2
  31. package/js/src/binance.d.ts +15 -15
  32. package/js/src/binance.js +51 -12
  33. package/js/src/bingx.js +3 -0
  34. package/js/src/bitget.js +10 -6
  35. package/js/src/bitmart.d.ts +1 -0
  36. package/js/src/bitmart.js +124 -1
  37. package/js/src/bybit.d.ts +7 -1
  38. package/js/src/bybit.js +377 -10
  39. package/js/src/gate.js +3 -0
  40. package/js/src/htx.js +22 -0
  41. package/js/src/kucoin.js +2 -2
  42. package/js/src/mexc.d.ts +2 -0
  43. package/js/src/mexc.js +97 -13
  44. package/js/src/okx.js +4 -0
  45. package/js/src/pro/bitget.d.ts +3 -0
  46. package/js/src/pro/bitget.js +66 -0
  47. package/js/src/pro/bitmart.d.ts +3 -0
  48. package/js/src/pro/bitmart.js +81 -0
  49. package/js/src/pro/bitvavo.d.ts +7 -2
  50. package/js/src/pro/bitvavo.js +92 -1
  51. package/js/src/pro/blofin.d.ts +3 -0
  52. package/js/src/pro/blofin.js +64 -0
  53. package/js/src/pro/okx.d.ts +1 -0
  54. package/js/src/pro/okx.js +11 -5
  55. package/package.json +1 -1
package/dist/cjs/ccxt.js CHANGED
@@ -194,7 +194,7 @@ var xt$1 = require('./src/pro/xt.js');
194
194
 
195
195
  //-----------------------------------------------------------------------------
196
196
  // this is updated by vss.js when building
197
- const version = '4.4.6';
197
+ const version = '4.4.8';
198
198
  Exchange["default"].ccxtVersion = version;
199
199
  const exchanges = {
200
200
  'ace': ace,
@@ -1237,6 +1237,13 @@ class Exchange {
1237
1237
  rng$1.nextBytes(x);
1238
1238
  return Buffer.from(x).toString('hex');
1239
1239
  }
1240
+ randNumber(size) {
1241
+ let number = '';
1242
+ for (let i = 0; i < size; i++) {
1243
+ number += Math.floor(Math.random() * 10);
1244
+ }
1245
+ return parseInt(number, 10);
1246
+ }
1240
1247
  /* eslint-enable */
1241
1248
  // ------------------------------------------------------------------------
1242
1249
  // ########################################################################
@@ -2265,6 +2272,7 @@ class Exchange {
2265
2272
  'ETH': { 'ERC20': 'ETH' },
2266
2273
  'TRX': { 'TRC20': 'TRX' },
2267
2274
  'CRO': { 'CRC20': 'CRONOS' },
2275
+ 'BRC20': { 'BRC20': 'BTC' },
2268
2276
  },
2269
2277
  };
2270
2278
  }
@@ -6122,8 +6130,19 @@ class Exchange {
6122
6130
  break;
6123
6131
  }
6124
6132
  result = this.arrayConcat(result, response);
6125
- const last = this.safeValue(response, responseLength - 1);
6126
- cursorValue = this.safeValue(last['info'], cursorReceived);
6133
+ const last = this.safeDict(response, responseLength - 1);
6134
+ // cursorValue = this.safeValue (last['info'], cursorReceived);
6135
+ cursorValue = undefined; // search for the cursor
6136
+ for (let j = 0; j < responseLength; j++) {
6137
+ const index = responseLength - j - 1;
6138
+ const entry = this.safeDict(response, index);
6139
+ const info = this.safeDict(entry, 'info');
6140
+ const cursor = this.safeValue(info, cursorReceived);
6141
+ if (cursor !== undefined) {
6142
+ cursorValue = cursor;
6143
+ break;
6144
+ }
6145
+ }
6127
6146
  if (cursorValue === undefined) {
6128
6147
  break;
6129
6148
  }
@@ -1091,6 +1091,7 @@ class binance extends binance$1 {
1091
1091
  'repay-futures-negative-balance': 150,
1092
1092
  'listenKey': 1,
1093
1093
  'asset-collection': 3,
1094
+ 'margin/repay-debt': 0.4, // Weight(Order): 0.4 => (1000 / (50 * 0.4)) * 60 = 3000
1094
1095
  },
1095
1096
  'put': {
1096
1097
  'listenKey': 1, // 1
@@ -1208,6 +1209,7 @@ class binance extends binance$1 {
1208
1209
  ],
1209
1210
  'fetchCurrencies': true,
1210
1211
  // 'fetchTradesMethod': 'publicGetAggTrades', // publicGetTrades, publicGetHistoricalTrades, eapiPublicGetTrades
1212
+ // 'repayCrossMarginMethod': 'papiPostRepayLoan', // papiPostMarginRepayDebt
1211
1213
  'defaultTimeInForce': 'GTC',
1212
1214
  'defaultType': 'spot',
1213
1215
  'defaultSubType': undefined,
@@ -2904,7 +2906,7 @@ class binance extends binance$1 {
2904
2906
  const res = this.safeValue(results, i);
2905
2907
  if (fetchMargins && Array.isArray(res)) {
2906
2908
  const keysList = Object.keys(this.indexBy(res, 'symbol'));
2907
- const length = (Object.keys(this.options['crossMarginPairsData'])).length;
2909
+ const length = this.options['crossMarginPairsData'].length;
2908
2910
  // first one is the cross-margin promise
2909
2911
  if (length === 0) {
2910
2912
  this.options['crossMarginPairsData'] = keysList;
@@ -12217,10 +12219,13 @@ class binance extends binance$1 {
12217
12219
  * @description repay borrowed margin and interest
12218
12220
  * @see https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Margin-Account-Repay
12219
12221
  * @see https://developers.binance.com/docs/margin_trading/borrow-and-repay/Margin-Account-Borrow-Repay
12222
+ * @see https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Margin-Account-Repay-Debt
12220
12223
  * @param {string} code unified currency code of the currency to repay
12221
12224
  * @param {float} amount the amount to repay
12222
12225
  * @param {object} [params] extra parameters specific to the exchange API endpoint
12223
12226
  * @param {boolean} [params.portfolioMargin] set to true if you would like to repay margin in a portfolio margin account
12227
+ * @param {string} [params.repayCrossMarginMethod] *portfolio margin only* 'papiPostRepayLoan' (default), 'papiPostMarginRepayDebt' (alternative)
12228
+ * @param {string} [params.specifyRepayAssets] *portfolio margin papiPostMarginRepayDebt only* specific asset list to repay debt
12224
12229
  * @returns {object} a [margin loan structure]{@link https://docs.ccxt.com/#/?id=margin-loan-structure}
12225
12230
  */
12226
12231
  await this.loadMarkets();
@@ -12233,19 +12238,41 @@ class binance extends binance$1 {
12233
12238
  let isPortfolioMargin = undefined;
12234
12239
  [isPortfolioMargin, params] = this.handleOptionAndParams2(params, 'repayCrossMargin', 'papi', 'portfolioMargin', false);
12235
12240
  if (isPortfolioMargin) {
12236
- response = await this.papiPostRepayLoan(this.extend(request, params));
12241
+ let method = undefined;
12242
+ [method, params] = this.handleOptionAndParams2(params, 'repayCrossMargin', 'repayCrossMarginMethod', 'method');
12243
+ if (method === 'papiPostMarginRepayDebt') {
12244
+ response = await this.papiPostMarginRepayDebt(this.extend(request, params));
12245
+ //
12246
+ // {
12247
+ // "asset": "USDC",
12248
+ // "amount": 10,
12249
+ // "specifyRepayAssets": null,
12250
+ // "updateTime": 1727170761267,
12251
+ // "success": true
12252
+ // }
12253
+ //
12254
+ }
12255
+ else {
12256
+ response = await this.papiPostRepayLoan(this.extend(request, params));
12257
+ //
12258
+ // {
12259
+ // "tranId": 108988250265,
12260
+ // "clientTag":""
12261
+ // }
12262
+ //
12263
+ }
12237
12264
  }
12238
12265
  else {
12239
12266
  request['isIsolated'] = 'FALSE';
12240
12267
  request['type'] = 'REPAY';
12241
12268
  response = await this.sapiPostMarginBorrowRepay(this.extend(request, params));
12269
+ //
12270
+ // {
12271
+ // "tranId": 108988250265,
12272
+ // "clientTag":""
12273
+ // }
12274
+ //
12242
12275
  }
12243
- //
12244
- // {
12245
- // "tranId": 108988250265,
12246
- // "clientTag":""
12247
- // }
12248
- //
12249
12276
  return this.parseMarginLoan(response, currency);
12250
12277
  }
12251
12278
  async repayIsolatedMargin(symbol, code, amount, params = {}) {
@@ -12355,13 +12382,25 @@ class binance extends binance$1 {
12355
12382
  // "clientTag":""
12356
12383
  // }
12357
12384
  //
12385
+ // repayCrossMargin alternative endpoint
12386
+ //
12387
+ // {
12388
+ // "asset": "USDC",
12389
+ // "amount": 10,
12390
+ // "specifyRepayAssets": null,
12391
+ // "updateTime": 1727170761267,
12392
+ // "success": true
12393
+ // }
12394
+ //
12395
+ const currencyId = this.safeString(info, 'asset');
12396
+ const timestamp = this.safeInteger(info, 'updateTime');
12358
12397
  return {
12359
12398
  'id': this.safeInteger(info, 'tranId'),
12360
- 'currency': this.safeCurrencyCode(undefined, currency),
12361
- 'amount': undefined,
12399
+ 'currency': this.safeCurrencyCode(currencyId, currency),
12400
+ 'amount': this.safeNumber(info, 'amount'),
12362
12401
  'symbol': undefined,
12363
- 'timestamp': undefined,
12364
- 'datetime': undefined,
12402
+ 'timestamp': timestamp,
12403
+ 'datetime': this.iso8601(timestamp),
12365
12404
  'info': info,
12366
12405
  };
12367
12406
  }
@@ -488,6 +488,9 @@ class bingx extends bingx$1 {
488
488
  'BTC': 'BTC',
489
489
  'LTC': 'LTC',
490
490
  },
491
+ 'networks': {
492
+ 'ARB': 'ARBITRUM',
493
+ },
491
494
  },
492
495
  });
493
496
  }
@@ -1415,12 +1415,13 @@ class bitget extends bitget$1 {
1415
1415
  'networks': {
1416
1416
  'TRX': 'TRC20',
1417
1417
  'ETH': 'ERC20',
1418
- 'BSC': 'BEP20',
1419
- },
1420
- 'networksById': {
1421
- 'TRC20': 'TRX',
1422
- 'BSC': 'BEP20',
1418
+ 'BEP20': 'BSC',
1419
+ 'ZKSYNC': 'zkSyncEra',
1420
+ 'STARKNET': 'Starknet',
1421
+ 'OPTIMISM': 'Optimism',
1422
+ 'ARBITRUM': 'Arbitrum',
1423
1423
  },
1424
+ 'networksById': {},
1424
1425
  'fetchPositions': {
1425
1426
  'method': 'privateMixGetV2MixPositionAllPosition', // or privateMixGetV2MixPositionHistoryPosition
1426
1427
  },
@@ -1862,7 +1863,10 @@ class bitget extends bitget$1 {
1862
1863
  for (let j = 0; j < chains.length; j++) {
1863
1864
  const chain = chains[j];
1864
1865
  const networkId = this.safeString(chain, 'chain');
1865
- const network = this.safeCurrencyCode(networkId);
1866
+ let network = this.networkIdToCode(networkId, code);
1867
+ if (network !== undefined) {
1868
+ network = network.toUpperCase();
1869
+ }
1866
1870
  const withdrawEnabled = this.safeString(chain, 'withdrawable');
1867
1871
  const canWithdraw = withdrawEnabled === 'true';
1868
1872
  withdraw = (canWithdraw) ? canWithdraw : withdraw;
@@ -2294,7 +2294,7 @@ class bitmart extends bitmart$1 {
2294
2294
  }
2295
2295
  parseOrder(order, market = undefined) {
2296
2296
  //
2297
- // createOrder
2297
+ // createOrder, editOrder
2298
2298
  //
2299
2299
  // {
2300
2300
  // "order_id": 2707217580
@@ -4777,6 +4777,129 @@ class bitmart extends bitmart$1 {
4777
4777
  'datetime': this.iso8601(timestamp),
4778
4778
  });
4779
4779
  }
4780
+ async editOrder(id, symbol, type, side, amount = undefined, price = undefined, params = {}) {
4781
+ /**
4782
+ * @method
4783
+ * @name bitmart#editOrder
4784
+ * @description edits an open order
4785
+ * @see https://developer-pro.bitmart.com/en/futuresv2/#modify-plan-order-signed
4786
+ * @see https://developer-pro.bitmart.com/en/futuresv2/#modify-tp-sl-order-signed
4787
+ * @see https://developer-pro.bitmart.com/en/futuresv2/#modify-preset-plan-order-signed
4788
+ * @param {string} id order id
4789
+ * @param {string} symbol unified symbol of the market to edit an order in
4790
+ * @param {string} type 'market' or 'limit'
4791
+ * @param {string} side 'buy' or 'sell'
4792
+ * @param {float} [amount] how much you want to trade in units of the base currency
4793
+ * @param {float} [price] the price to fulfill the order, in units of the quote currency, ignored in market orders
4794
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
4795
+ * @param {string} [params.triggerPrice] *swap only* the price to trigger a stop order
4796
+ * @param {string} [params.stopLossPrice] *swap only* the price to trigger a stop-loss order
4797
+ * @param {string} [params.takeProfitPrice] *swap only* the price to trigger a take-profit order
4798
+ * @param {string} [params.stopLoss.triggerPrice] *swap only* the price to trigger a preset stop-loss order
4799
+ * @param {string} [params.takeProfit.triggerPrice] *swap only* the price to trigger a preset take-profit order
4800
+ * @param {string} [params.clientOrderId] client order id of the order
4801
+ * @param {int} [params.price_type] *swap only* 1: last price, 2: fair price, default is 1
4802
+ * @param {int} [params.plan_category] *swap tp/sl only* 1: tp/sl, 2: position tp/sl, default is 1
4803
+ * @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
4804
+ */
4805
+ await this.loadMarkets();
4806
+ const market = this.market(symbol);
4807
+ if (!market['swap']) {
4808
+ throw new errors.NotSupported(this.id + ' editOrder() does not support ' + market['type'] + ' markets, only swap markets are supported');
4809
+ }
4810
+ const stopLossPrice = this.safeString(params, 'stopLossPrice');
4811
+ const takeProfitPrice = this.safeString(params, 'takeProfitPrice');
4812
+ const triggerPrice = this.safeStringN(params, ['triggerPrice', 'stopPrice', 'trigger_price']);
4813
+ const stopLoss = this.safeDict(params, 'stopLoss', {});
4814
+ const takeProfit = this.safeDict(params, 'takeProfit', {});
4815
+ const presetStopLoss = this.safeString(stopLoss, 'triggerPrice');
4816
+ const presetTakeProfit = this.safeString(takeProfit, 'triggerPrice');
4817
+ const isTriggerOrder = triggerPrice !== undefined;
4818
+ const isStopLoss = stopLossPrice !== undefined;
4819
+ const isTakeProfit = takeProfitPrice !== undefined;
4820
+ const isPresetStopLoss = presetStopLoss !== undefined;
4821
+ const isPresetTakeProfit = presetTakeProfit !== undefined;
4822
+ const request = {
4823
+ 'symbol': market['id'],
4824
+ };
4825
+ const clientOrderId = this.safeString(params, 'clientOrderId');
4826
+ if (clientOrderId !== undefined) {
4827
+ params = this.omit(params, 'clientOrderId');
4828
+ request['client_order_id'] = clientOrderId;
4829
+ }
4830
+ if (id !== undefined) {
4831
+ request['order_id'] = id;
4832
+ }
4833
+ params = this.omit(params, ['triggerPrice', 'stopPrice', 'stopLossPrice', 'takeProfitPrice', 'stopLoss', 'takeProfit']);
4834
+ let response = undefined;
4835
+ if (isTriggerOrder || isStopLoss || isTakeProfit) {
4836
+ request['price_type'] = this.safeInteger(params, 'price_type', 1);
4837
+ if (price !== undefined) {
4838
+ request['executive_price'] = this.priceToPrecision(symbol, price);
4839
+ }
4840
+ }
4841
+ if (isTriggerOrder) {
4842
+ request['type'] = type;
4843
+ request['trigger_price'] = this.priceToPrecision(symbol, triggerPrice);
4844
+ response = await this.privatePostContractPrivateModifyPlanOrder(this.extend(request, params));
4845
+ //
4846
+ // {
4847
+ // "code": 1000,
4848
+ // "message": "Ok",
4849
+ // "data": {
4850
+ // "order_id": "3000023150003503"
4851
+ // },
4852
+ // "trace": "324523453245.108.1734567125596324575"
4853
+ // }
4854
+ //
4855
+ }
4856
+ else if (isStopLoss || isTakeProfit) {
4857
+ request['category'] = type;
4858
+ if (isStopLoss) {
4859
+ request['trigger_price'] = this.priceToPrecision(symbol, stopLossPrice);
4860
+ }
4861
+ else {
4862
+ request['trigger_price'] = this.priceToPrecision(symbol, takeProfitPrice);
4863
+ }
4864
+ response = await this.privatePostContractPrivateModifyTpSlOrder(this.extend(request, params));
4865
+ //
4866
+ // {
4867
+ // "code": 1000,
4868
+ // "message": "Ok",
4869
+ // "data": {
4870
+ // "order_id": "3000023150003480"
4871
+ // },
4872
+ // "trace": "23452345.104.1724536582682345459"
4873
+ // }
4874
+ //
4875
+ }
4876
+ else if (isPresetStopLoss || isPresetTakeProfit) {
4877
+ if (isPresetStopLoss) {
4878
+ request['preset_stop_loss_price_type'] = this.safeInteger(params, 'price_type', 1);
4879
+ request['preset_stop_loss_price'] = this.priceToPrecision(symbol, presetStopLoss);
4880
+ }
4881
+ else {
4882
+ request['preset_take_profit_price_type'] = this.safeInteger(params, 'price_type', 1);
4883
+ request['preset_take_profit_price'] = this.priceToPrecision(symbol, presetTakeProfit);
4884
+ }
4885
+ response = await this.privatePostContractPrivateModifyPresetPlanOrder(this.extend(request, params));
4886
+ //
4887
+ // {
4888
+ // "code": 1000,
4889
+ // "message": "Ok",
4890
+ // "data": {
4891
+ // "order_id": "3000023150003496"
4892
+ // },
4893
+ // "trace": "a5c3234534534a836bc476a203.123452.172716624359200197"
4894
+ // }
4895
+ //
4896
+ }
4897
+ else {
4898
+ throw new errors.NotSupported(this.id + ' editOrder() only supports trigger, stop loss and take profit orders');
4899
+ }
4900
+ const data = this.safeDict(response, 'data', {});
4901
+ return this.parseOrder(data, market);
4902
+ }
4780
4903
  nonce() {
4781
4904
  return this.milliseconds();
4782
4905
  }