ccxt 4.1.7 → 4.1.9

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 (63) hide show
  1. package/CHANGELOG.md +194 -0
  2. package/README.md +3 -3
  3. package/dist/ccxt.browser.js +1298 -202
  4. package/dist/ccxt.browser.min.js +7 -7
  5. package/dist/cjs/ccxt.js +3 -1
  6. package/dist/cjs/src/base/Exchange.js +58 -2
  7. package/dist/cjs/src/bingx.js +100 -39
  8. package/dist/cjs/src/bitbns.js +3 -3
  9. package/dist/cjs/src/bitget.js +26 -2
  10. package/dist/cjs/src/bitmart.js +2 -0
  11. package/dist/cjs/src/coinfalcon.js +3 -3
  12. package/dist/cjs/src/gate.js +9 -1
  13. package/dist/cjs/src/kucoin.js +2 -2
  14. package/dist/cjs/src/kucoinfutures.js +3 -3
  15. package/dist/cjs/src/mexc.js +46 -3
  16. package/dist/cjs/src/pro/bingx.js +891 -0
  17. package/dist/cjs/src/pro/exmo.js +1 -1
  18. package/js/ccxt.d.ts +6 -3
  19. package/js/ccxt.js +3 -1
  20. package/js/src/abstract/bingx.d.ts +1 -0
  21. package/js/src/abstract/bitmart.d.ts +1 -0
  22. package/js/src/abstract/mexc.d.ts +2 -0
  23. package/js/src/abstract/mexc3.d.ts +2 -0
  24. package/js/src/base/Exchange.d.ts +6 -3
  25. package/js/src/base/Exchange.js +58 -2
  26. package/js/src/base/types.d.ts +7 -0
  27. package/js/src/binance.d.ts +17 -17
  28. package/js/src/bingx.d.ts +4 -3
  29. package/js/src/bingx.js +100 -39
  30. package/js/src/bitbns.js +3 -3
  31. package/js/src/bitfinex2.d.ts +13 -13
  32. package/js/src/bitget.d.ts +15 -15
  33. package/js/src/bitget.js +26 -2
  34. package/js/src/bitmart.js +2 -0
  35. package/js/src/bitmex.d.ts +15 -15
  36. package/js/src/bybit.d.ts +23 -23
  37. package/js/src/coinbase.d.ts +16 -16
  38. package/js/src/coinbasepro.d.ts +12 -12
  39. package/js/src/coinex.d.ts +2 -2
  40. package/js/src/coinfalcon.js +3 -3
  41. package/js/src/cryptocom.d.ts +12 -12
  42. package/js/src/deribit.d.ts +2 -2
  43. package/js/src/digifinex.d.ts +2 -2
  44. package/js/src/gate.d.ts +10 -10
  45. package/js/src/gate.js +9 -1
  46. package/js/src/huobi.d.ts +16 -16
  47. package/js/src/kraken.d.ts +2 -2
  48. package/js/src/krakenfutures.d.ts +6 -6
  49. package/js/src/kucoin.d.ts +13 -13
  50. package/js/src/kucoin.js +2 -2
  51. package/js/src/kucoinfutures.d.ts +10 -10
  52. package/js/src/kucoinfutures.js +3 -3
  53. package/js/src/mexc.d.ts +3 -3
  54. package/js/src/mexc.js +46 -3
  55. package/js/src/okx.d.ts +13 -13
  56. package/js/src/phemex.d.ts +2 -2
  57. package/js/src/poloniex.d.ts +5 -5
  58. package/js/src/pro/bingx.d.ts +24 -0
  59. package/js/src/pro/bingx.js +892 -0
  60. package/js/src/pro/exmo.js +1 -1
  61. package/js/src/woo.d.ts +2 -2
  62. package/package.json +1 -1
  63. package/skip-tests.json +3 -0
package/dist/cjs/ccxt.js CHANGED
@@ -124,6 +124,7 @@ var binance$1 = require('./src/pro/binance.js');
124
124
  var binancecoinm$1 = require('./src/pro/binancecoinm.js');
125
125
  var binanceus$1 = require('./src/pro/binanceus.js');
126
126
  var binanceusdm$1 = require('./src/pro/binanceusdm.js');
127
+ var bingx$1 = require('./src/pro/bingx.js');
127
128
  var bitcoincom$1 = require('./src/pro/bitcoincom.js');
128
129
  var bitfinex$1 = require('./src/pro/bitfinex.js');
129
130
  var bitfinex2$1 = require('./src/pro/bitfinex2.js');
@@ -179,7 +180,7 @@ var woo$1 = require('./src/pro/woo.js');
179
180
 
180
181
  //-----------------------------------------------------------------------------
181
182
  // this is updated by vss.js when building
182
- const version = '4.1.7';
183
+ const version = '4.1.9';
183
184
  Exchange["default"].ccxtVersion = version;
184
185
  const exchanges = {
185
186
  'ace': ace,
@@ -296,6 +297,7 @@ const pro = {
296
297
  'binancecoinm': binancecoinm$1,
297
298
  'binanceus': binanceus$1,
298
299
  'binanceusdm': binanceusdm$1,
300
+ 'bingx': bingx$1,
299
301
  'bitcoincom': bitcoincom$1,
300
302
  'bitfinex': bitfinex$1,
301
303
  'bitfinex2': bitfinex2$1,
@@ -3291,6 +3291,9 @@ class Exchange {
3291
3291
  async fetchOpenInterest(symbol, params = {}) {
3292
3292
  throw new errors.NotSupported(this.id + ' fetchOpenInterest() is not supported yet');
3293
3293
  }
3294
+ async fetchFundingRateHistory(symbol = undefined, since = undefined, limit = undefined, params = {}) {
3295
+ throw new errors.NotSupported(this.id + ' fetchFundingRateHistory() is not supported yet');
3296
+ }
3294
3297
  parseLastPrice(price, market = undefined) {
3295
3298
  throw new errors.NotSupported(this.id + ' parseLastPrice() is not supported yet');
3296
3299
  }
@@ -4181,7 +4184,9 @@ class Exchange {
4181
4184
  }
4182
4185
  }
4183
4186
  }
4184
- return this.removeRepeatedElementsFromArray(result);
4187
+ const uniqueResults = this.removeRepeatedElementsFromArray(result);
4188
+ const key = (method === 'fetchOHLCV') ? 0 : 'timestamp';
4189
+ return this.filterBySinceLimit(uniqueResults, since, limit, key);
4185
4190
  }
4186
4191
  async safeDeterministicCall(method, symbol = undefined, since = undefined, limit = undefined, timeframe = undefined, params = {}) {
4187
4192
  let maxRetries = undefined;
@@ -4236,7 +4241,9 @@ class Exchange {
4236
4241
  for (let i = 0; i < results.length; i++) {
4237
4242
  result = this.arrayConcat(result, results[i]);
4238
4243
  }
4239
- return this.removeRepeatedElementsFromArray(result);
4244
+ const uniqueResults = this.removeRepeatedElementsFromArray(result);
4245
+ const key = (method === 'fetchOHLCV') ? 0 : 'timestamp';
4246
+ return this.filterBySinceLimit(uniqueResults, since, limit, key);
4240
4247
  }
4241
4248
  async fetchPaginatedCallCursor(method, symbol = undefined, since = undefined, limit = undefined, params = {}, cursorReceived = undefined, cursorSent = undefined, cursorIncrement = undefined, maxEntriesPerRequest = undefined) {
4242
4249
  let maxCalls = undefined;
@@ -4280,6 +4287,55 @@ class Exchange {
4280
4287
  }
4281
4288
  i += 1;
4282
4289
  }
4290
+ const sorted = this.sortCursorPaginatedResult(result);
4291
+ const key = (method === 'fetchOHLCV') ? 0 : 'timestamp';
4292
+ return this.filterBySinceLimit(sorted, since, limit, key);
4293
+ }
4294
+ async fetchPaginatedCallIncremental(method, symbol = undefined, since = undefined, limit = undefined, params = {}, pageKey = undefined, maxEntriesPerRequest = undefined) {
4295
+ let maxCalls = undefined;
4296
+ [maxCalls, params] = this.handleOptionAndParams(params, method, 'paginationCalls', 10);
4297
+ let maxRetries = undefined;
4298
+ [maxRetries, params] = this.handleOptionAndParams(params, method, 'maxRetries', 3);
4299
+ [maxEntriesPerRequest, params] = this.handleMaxEntriesPerRequestAndParams(method, maxEntriesPerRequest, params);
4300
+ let i = 0;
4301
+ let errors = 0;
4302
+ let result = [];
4303
+ while (i < maxCalls) {
4304
+ try {
4305
+ params[pageKey] = i + 1;
4306
+ const response = await this[method](symbol, since, maxEntriesPerRequest, params);
4307
+ errors = 0;
4308
+ const responseLength = response.length;
4309
+ if (this.verbose) {
4310
+ this.log('Incremental pagination call', i + 1, 'method', method, 'response length', responseLength);
4311
+ }
4312
+ if (responseLength === 0) {
4313
+ break;
4314
+ }
4315
+ result = this.arrayConcat(result, response);
4316
+ }
4317
+ catch (e) {
4318
+ errors += 1;
4319
+ if (errors > maxRetries) {
4320
+ throw e;
4321
+ }
4322
+ }
4323
+ i += 1;
4324
+ }
4325
+ const sorted = this.sortCursorPaginatedResult(result);
4326
+ const key = (method === 'fetchOHLCV') ? 0 : 'timestamp';
4327
+ return this.filterBySinceLimit(sorted, since, limit, key);
4328
+ }
4329
+ sortCursorPaginatedResult(result) {
4330
+ const first = this.safeValue(result, 0);
4331
+ if (first !== undefined) {
4332
+ if ('timestamp' in first) {
4333
+ return this.sortBy(result, 'timestamp');
4334
+ }
4335
+ if ('id' in first) {
4336
+ return this.sortBy(result, 'id');
4337
+ }
4338
+ }
4283
4339
  return result;
4284
4340
  }
4285
4341
  removeRepeatedElementsFromArray(input) {
@@ -66,6 +66,7 @@ class bingx extends bingx$1 {
66
66
  'swap': 'https://open-api.{hostname}/openApi',
67
67
  'contract': 'https://open-api.{hostname}/openApi',
68
68
  'wallets': 'https://open-api.{hostname}/openApi',
69
+ 'user': 'https://open-api.{hostname}/openApi',
69
70
  'subAccount': 'https://open-api.{hostname}/openApi',
70
71
  'account': 'https://open-api.{hostname}/openApi',
71
72
  },
@@ -234,6 +235,15 @@ class bingx extends bingx$1 {
234
235
  },
235
236
  },
236
237
  },
238
+ 'user': {
239
+ 'auth': {
240
+ 'private': {
241
+ 'post': {
242
+ 'userDataStream': 1,
243
+ },
244
+ },
245
+ },
246
+ },
237
247
  'copyTrading': {
238
248
  'v1': {
239
249
  'private': {
@@ -311,6 +321,7 @@ class bingx extends bingx$1 {
311
321
  },
312
322
  'commonCurrencies': {},
313
323
  'options': {
324
+ 'defaultType': 'spot',
314
325
  'accountsByType': {
315
326
  'spot': 'FUND',
316
327
  'swap': 'PFUTURES',
@@ -830,37 +841,63 @@ class bingx extends bingx$1 {
830
841
  // filledTime: '2023-07-04T20:56:01.000+0800'
831
842
  // }
832
843
  //
833
- let time = this.safeInteger2(trade, 'time', 'filledTm');
844
+ //
845
+ // ws
846
+ //
847
+ // spot
848
+ //
849
+ // {
850
+ // E: 1690214529432,
851
+ // T: 1690214529386,
852
+ // e: 'trade',
853
+ // m: true,
854
+ // p: '29110.19',
855
+ // q: '0.1868',
856
+ // s: 'BTC-USDT',
857
+ // t: '57903921'
858
+ // }
859
+ //
860
+ // swap
861
+ //
862
+ // {
863
+ // q: '0.0421',
864
+ // p: '29023.5',
865
+ // T: 1690221401344,
866
+ // m: false,
867
+ // s: 'BTC-USDT'
868
+ // }
869
+ //
870
+ let time = this.safeIntegerN(trade, ['time', 'filledTm', 'T']);
834
871
  const datetimeId = this.safeString(trade, 'filledTm');
835
872
  if (datetimeId !== undefined) {
836
873
  time = this.parse8601(datetimeId);
837
874
  }
838
- const isBuyerMaker = this.safeValue2(trade, 'buyerMaker', 'isBuyerMaker');
839
- let takeOrMaker = undefined;
840
- let side = undefined;
841
- if (isBuyerMaker !== undefined) {
842
- side = isBuyerMaker ? 'sell' : 'buy';
843
- takeOrMaker = 'taker';
875
+ if (time === 0) {
876
+ time = undefined;
844
877
  }
878
+ const isBuyerMaker = this.safeValue2(trade, 'buyerMaker', 'isBuyerMaker');
879
+ const side = this.safeStringLower2(trade, 'side', 'S');
845
880
  const cost = this.safeString(trade, 'quoteQty');
846
881
  const type = (cost === undefined) ? 'spot' : 'swap';
847
- const currencyId = this.safeString(trade, 'currency');
882
+ const currencyId = this.safeString2(trade, 'currency', 'N');
848
883
  const currencyCode = this.safeCurrencyCode(currencyId);
884
+ const m = this.safeValue(trade, 'm', false);
885
+ const marketId = this.safeString(trade, 's');
849
886
  return this.safeTrade({
850
- 'id': this.safeString2(trade, 'id', 'orderId'),
887
+ 'id': this.safeStringN(trade, ['id', 't']),
851
888
  'info': trade,
852
889
  'timestamp': time,
853
890
  'datetime': this.iso8601(time),
854
- 'symbol': this.safeSymbol(undefined, market, '-', type),
855
- 'order': undefined,
856
- 'type': undefined,
857
- 'side': side,
858
- 'takerOrMaker': takeOrMaker,
859
- 'price': this.safeString(trade, 'price'),
860
- 'amount': this.safeString2(trade, 'qty', 'amount'),
891
+ 'symbol': this.safeSymbol(marketId, market, '-', type),
892
+ 'order': this.safeString2(trade, 'orderId', 'i'),
893
+ 'type': this.safeStringLower(trade, 'o'),
894
+ 'side': this.parseOrderSide(side),
895
+ 'takerOrMaker': (isBuyerMaker || m) ? 'maker' : 'taker',
896
+ 'price': this.safeString2(trade, 'price', 'p'),
897
+ 'amount': this.safeStringN(trade, ['qty', 'amount', 'q']),
861
898
  'cost': cost,
862
899
  'fee': {
863
- 'cost': this.parseNumber(Precise["default"].stringAbs(this.safeString(trade, 'commission'))),
900
+ 'cost': this.parseNumber(Precise["default"].stringAbs(this.safeString2(trade, 'commission', 'n'))),
864
901
  'currency': currencyCode,
865
902
  'rate': undefined,
866
903
  },
@@ -1580,15 +1617,20 @@ class bingx extends bingx$1 {
1580
1617
  request['timeInForce'] = 'POC';
1581
1618
  }
1582
1619
  const createMarketBuyOrderRequiresPrice = this.safeValue(this.options, 'createMarketBuyOrderRequiresPrice', true);
1583
- if (createMarketBuyOrderRequiresPrice && isMarketOrder && (side === 'buy')) {
1584
- if (price === undefined) {
1585
- throw new errors.InvalidOrder(this.id + ' createOrder() requires price argument for market buy orders on spot markets to calculate the total amount to spend (amount * price), alternatively set the createMarketBuyOrderRequiresPrice option to false and pass in the cost to spend into the amount parameter');
1620
+ if (isMarketOrder && (side === 'buy')) {
1621
+ if (createMarketBuyOrderRequiresPrice) {
1622
+ if (price === undefined) {
1623
+ throw new errors.InvalidOrder(this.id + ' createOrder() requires price argument for market buy orders on spot markets to calculate the total amount to spend (amount * price), alternatively set the createMarketBuyOrderRequiresPrice option to false and pass in the cost to spend into the amount parameter');
1624
+ }
1625
+ else {
1626
+ const amountString = this.numberToString(amount);
1627
+ const priceString = this.numberToString(price);
1628
+ const cost = this.parseNumber(Precise["default"].stringMul(amountString, priceString));
1629
+ request['quoteOrderQty'] = this.priceToPrecision(symbol, cost);
1630
+ }
1586
1631
  }
1587
1632
  else {
1588
- const amountString = this.numberToString(amount);
1589
- const priceString = this.numberToString(price);
1590
- const cost = this.parseNumber(Precise["default"].stringMul(amountString, priceString));
1591
- request['quoteOrderQty'] = this.priceToPrecision(symbol, cost);
1633
+ request['quoteOrderQty'] = this.priceToPrecision(symbol, amount);
1592
1634
  }
1593
1635
  }
1594
1636
  else {
@@ -1704,6 +1746,15 @@ class bingx extends bingx$1 {
1704
1746
  const order = this.safeValue(data, 'order', data);
1705
1747
  return this.parseOrder(order, market);
1706
1748
  }
1749
+ parseOrderSide(side) {
1750
+ const sides = {
1751
+ 'BUY': 'buy',
1752
+ 'SELL': 'sell',
1753
+ 'SHORT': 'sell',
1754
+ 'LONG': 'buy',
1755
+ };
1756
+ return this.safeString(sides, side, side);
1757
+ }
1707
1758
  parseOrder(order, market = undefined) {
1708
1759
  //
1709
1760
  // spot
@@ -1801,39 +1852,49 @@ class bingx extends bingx$1 {
1801
1852
  // "workingType": "MARK_PRICE"
1802
1853
  // }
1803
1854
  //
1804
- const positionSide = this.safeString(order, 'positionSide');
1855
+ const positionSide = this.safeString2(order, 'positionSide', 'ps');
1805
1856
  const marketType = (positionSide === undefined) ? 'spot' : 'swap';
1806
- const marketId = this.safeString(order, 'symbol');
1857
+ const marketId = this.safeString2(order, 'symbol', 's');
1807
1858
  const symbol = this.safeSymbol(marketId, market, '-', marketType);
1808
- const timestamp = this.safeInteger2(order, 'time', 'transactTime');
1859
+ const orderId = this.safeString2(order, 'orderId', 'i');
1860
+ const side = this.safeStringLower2(order, 'side', 'S');
1861
+ const type = this.safeStringLower2(order, 'type', 'o');
1862
+ const timestamp = this.safeIntegerN(order, ['time', 'transactTime', 'E']);
1863
+ const lastTradeTimestamp = this.safeInteger2(order, 'updateTime', 'T');
1864
+ const price = this.safeString2(order, 'price', 'p');
1865
+ const average = this.safeString2(order, 'avgPrice', 'ap');
1866
+ const amount = this.safeString2(order, 'origQty', 'q');
1867
+ const filled = this.safeString2(order, 'executedQty', 'z');
1868
+ const statusId = this.safeString2(order, 'status', 'X');
1809
1869
  const fee = {
1810
- 'currency': this.safeString(order, 'feeAsset'),
1811
- 'rate': this.safeString2(order, 'fee', 'commission'),
1870
+ 'currency': this.safeString2(order, 'feeAsset', 'N'),
1871
+ 'rate': this.safeStringN(order, ['fee', 'commission', 'n']),
1812
1872
  };
1873
+ const clientOrderId = this.safeString2(order, 'clientOrderId', 'c');
1813
1874
  return this.safeOrder({
1814
1875
  'info': order,
1815
- 'id': this.safeString(order, 'orderId'),
1816
- 'clientOrderId': this.safeString(order, 'clientOrderId'),
1876
+ 'id': orderId,
1877
+ 'clientOrderId': clientOrderId,
1817
1878
  'timestamp': timestamp,
1818
1879
  'datetime': this.iso8601(timestamp),
1819
- 'lastTradeTimestamp': this.safeInteger(order, 'updateTime'),
1880
+ 'lastTradeTimestamp': lastTradeTimestamp,
1820
1881
  'lastUpdateTimestamp': this.safeInteger(order, 'updateTime'),
1821
1882
  'symbol': symbol,
1822
- 'type': this.safeStringLower(order, 'type'),
1883
+ 'type': type,
1823
1884
  'timeInForce': undefined,
1824
1885
  'postOnly': undefined,
1825
- 'side': this.safeStringLower(order, 'side'),
1826
- 'price': this.safeString(order, 'price'),
1886
+ 'side': this.parseOrderSide(side),
1887
+ 'price': price,
1827
1888
  'stopPrice': this.safeNumber(order, 'stopPrice'),
1828
1889
  'triggerPrice': this.safeNumber(order, 'stopPrice'),
1829
1890
  'stopLossPrice': this.safeNumber(order, 'stopLoss'),
1830
1891
  'takeProfitPrice': this.safeNumber(order, 'takeProfit'),
1831
- 'average': this.safeString(order, 'avgPrice'),
1892
+ 'average': average,
1832
1893
  'cost': undefined,
1833
- 'amount': this.safeString(order, 'origQty'),
1834
- 'filled': this.safeString(order, 'executedQty'),
1894
+ 'amount': amount,
1895
+ 'filled': filled,
1835
1896
  'remaining': undefined,
1836
- 'status': this.parseOrderStatus(this.safeString(order, 'status')),
1897
+ 'status': this.parseOrderStatus(statusId),
1837
1898
  'fee': fee,
1838
1899
  'trades': undefined,
1839
1900
  }, market);
@@ -438,13 +438,13 @@ class bitbns extends bitbns$1 {
438
438
  if (numParts > 1) {
439
439
  let currencyId = this.safeString(parts, 1);
440
440
  // note that "Money" stands for INR - the only fiat in bitbns
441
+ const account = this.account();
442
+ account['free'] = this.safeString(data, key);
443
+ account['used'] = this.safeString(data, 'inorder' + currencyId);
441
444
  if (currencyId === 'Money') {
442
445
  currencyId = 'INR';
443
446
  }
444
447
  const code = this.safeCurrencyCode(currencyId);
445
- const account = this.account();
446
- account['free'] = this.safeString(data, key);
447
- account['used'] = this.safeString(data, 'inorder' + currencyId);
448
448
  result[code] = account;
449
449
  }
450
450
  }
@@ -1649,8 +1649,26 @@ class bitget extends bitget$1 {
1649
1649
  // "data": "888291686266343424"
1650
1650
  // }
1651
1651
  //
1652
+ // {
1653
+ // "code":"00000",
1654
+ // "msg":"success",
1655
+ // "requestTime":1696784219602,
1656
+ // "data":{
1657
+ // "orderId":"1094957867615789056",
1658
+ // "clientOrderId":"64f1e4ce842041d296b4517df1b5c2d7"
1659
+ // }
1660
+ // }
1661
+ //
1662
+ const data = this.safeValue(response, 'data');
1663
+ let id = undefined;
1664
+ if (typeof data === 'string') {
1665
+ id = data;
1666
+ }
1667
+ else if (data !== undefined) {
1668
+ id = this.safeString(data, 'orderId');
1669
+ }
1652
1670
  const result = {
1653
- 'id': this.safeString(response, 'data'),
1671
+ 'id': id,
1654
1672
  'info': response,
1655
1673
  'txid': undefined,
1656
1674
  'timestamp': undefined,
@@ -4433,15 +4451,20 @@ class bitget extends bitget$1 {
4433
4451
  * @name bitget#fetchFundingRateHistory
4434
4452
  * @see https://bitgetlimited.github.io/apidoc/en/mix/#get-history-funding-rate
4435
4453
  * @description fetches historical funding rate prices
4436
- * @see https://bitgetlimited.github.io/apidoc/en/mix/#get-history-funding-rate
4437
4454
  * @param {string} symbol unified symbol of the market to fetch the funding rate history for
4438
4455
  * @param {int} [since] timestamp in ms of the earliest funding rate to fetch
4439
4456
  * @param {int} [limit] the maximum amount of [funding rate structures]{@link https://github.com/ccxt/ccxt/wiki/Manual#funding-rate-history-structure} to fetch
4440
4457
  * @param {object} [params] extra parameters specific to the bitget api endpoint
4458
+ * @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)
4441
4459
  * @returns {object[]} a list of [funding rate structures]{@link https://github.com/ccxt/ccxt/wiki/Manual#funding-rate-history-structure}
4442
4460
  */
4443
4461
  this.checkRequiredSymbol('fetchFundingRateHistory', symbol);
4444
4462
  await this.loadMarkets();
4463
+ let paginate = false;
4464
+ [paginate, params] = this.handleOptionAndParams(params, 'fetchFundingRateHistory', 'paginate');
4465
+ if (paginate) {
4466
+ return await this.fetchPaginatedCallIncremental('fetchFundingRateHistory', symbol, since, limit, params, 'pageNo', 50);
4467
+ }
4445
4468
  const market = this.market(symbol);
4446
4469
  const request = {
4447
4470
  'symbol': market['id'],
@@ -4452,6 +4475,7 @@ class bitget extends bitget$1 {
4452
4475
  if (limit !== undefined) {
4453
4476
  request['pageSize'] = limit;
4454
4477
  }
4478
+ request['nextPage'] = true;
4455
4479
  const response = await this.publicMixGetMarketHistoryFundRate(this.extend(request, params));
4456
4480
  //
4457
4481
  // {
@@ -179,6 +179,8 @@ class bitmart extends bitmart$1 {
179
179
  'spot/v1/margin/isolated/account': 6,
180
180
  'spot/v1/trade_fee': 6,
181
181
  'spot/v1/user_fee': 6,
182
+ // broker
183
+ 'spot/v1/broker/rebate': 1,
182
184
  // contract
183
185
  'contract/private/assets-detail': 5,
184
186
  'contract/private/order': 1.2,
@@ -933,9 +933,9 @@ class coinfalcon extends coinfalcon$1 {
933
933
  const amountString = this.safeString(transaction, 'amount');
934
934
  const amount = this.parseNumber(amountString);
935
935
  const feeCostString = this.safeString(transaction, 'fee');
936
- let feeCost = 0;
936
+ let feeCost = '0';
937
937
  if (feeCostString !== undefined) {
938
- feeCost = this.parseNumber(feeCostString);
938
+ feeCost = feeCostString;
939
939
  }
940
940
  return {
941
941
  'info': transaction,
@@ -957,7 +957,7 @@ class coinfalcon extends coinfalcon$1 {
957
957
  'updated': undefined,
958
958
  'fee': {
959
959
  'currency': code,
960
- 'cost': feeCost,
960
+ 'cost': this.parseNumber(feeCost),
961
961
  },
962
962
  };
963
963
  }
@@ -3573,6 +3573,13 @@ class gate extends gate$1 {
3573
3573
  // "memo": null
3574
3574
  // }
3575
3575
  //
3576
+ // {
3577
+ // "currency":"usdt",
3578
+ // "address":"0x01b0A9b7b4CdE774AF0f3E47CB4f1c2CCdBa0806",
3579
+ // "amount":"1880",
3580
+ // "chain":"eth"
3581
+ // }
3582
+ //
3576
3583
  const id = this.safeString(transaction, 'id');
3577
3584
  let type = undefined;
3578
3585
  let amountString = this.safeString(transaction, 'amount');
@@ -3590,6 +3597,7 @@ class gate extends gate$1 {
3590
3597
  if (type === 'withdrawal') {
3591
3598
  amountString = Precise["default"].stringSub(amountString, feeCostString);
3592
3599
  }
3600
+ const networkId = this.safeStringUpper(transaction, 'chain');
3593
3601
  const currencyId = this.safeString(transaction, 'currency');
3594
3602
  const code = this.safeCurrencyCode(currencyId);
3595
3603
  const txid = this.safeString(transaction, 'txid');
@@ -3604,7 +3612,7 @@ class gate extends gate$1 {
3604
3612
  'txid': txid,
3605
3613
  'currency': code,
3606
3614
  'amount': this.parseNumber(amountString),
3607
- 'network': undefined,
3615
+ 'network': this.networkIdToCode(networkId),
3608
3616
  'address': address,
3609
3617
  'addressTo': undefined,
3610
3618
  'addressFrom': undefined,
@@ -2225,7 +2225,7 @@ class kucoin extends kucoin$1 {
2225
2225
  * @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)
2226
2226
  * @returns {Order[]} a list of [order structures]{@link https://github.com/ccxt/ccxt/wiki/Manual#order-structure}
2227
2227
  */
2228
- await this.loadMarkets;
2228
+ await this.loadMarkets();
2229
2229
  let paginate = false;
2230
2230
  [paginate, params] = this.handleOptionAndParams(params, 'fetchClosedOrders', 'paginate');
2231
2231
  if (paginate) {
@@ -2258,7 +2258,7 @@ class kucoin extends kucoin$1 {
2258
2258
  * @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)
2259
2259
  * @returns {Order[]} a list of [order structures]{@link https://github.com/ccxt/ccxt/wiki/Manual#order-structure}
2260
2260
  */
2261
- await this.loadMarkets;
2261
+ await this.loadMarkets();
2262
2262
  let paginate = false;
2263
2263
  [paginate, params] = this.handleOptionAndParams(params, 'fetchOpenOrders', 'paginate');
2264
2264
  if (paginate) {
@@ -1534,7 +1534,7 @@ class kucoinfutures extends kucoinfutures$1 {
1534
1534
  * @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)
1535
1535
  * @returns {Order[]} a list of [order structures]{@link https://github.com/ccxt/ccxt/wiki/Manual#order-structure}
1536
1536
  */
1537
- await this.loadMarkets;
1537
+ await this.loadMarkets();
1538
1538
  let paginate = false;
1539
1539
  [paginate, params] = this.handleOptionAndParams(params, 'fetchClosedOrders', 'paginate');
1540
1540
  if (paginate) {
@@ -2325,12 +2325,12 @@ class kucoinfutures extends kucoinfutures$1 {
2325
2325
  async fetchFundingRateHistory(symbol = undefined, since = undefined, limit = undefined, params = {}) {
2326
2326
  /**
2327
2327
  * @method
2328
- * @name okx#fetchFundingRateHistory
2328
+ * @name kucoinfutures#fetchFundingRateHistory
2329
2329
  * @description fetches historical funding rate prices
2330
2330
  * @param {string} symbol unified symbol of the market to fetch the funding rate history for
2331
2331
  * @param {int} [since] not used by kucuoinfutures
2332
2332
  * @param {int} [limit] the maximum amount of [funding rate structures]{@link https://github.com/ccxt/ccxt/wiki/Manual#funding-rate-history-structure} to fetch
2333
- * @param {object} [params] extra parameters specific to the okx api endpoint
2333
+ * @param {object} [params] extra parameters specific to the kucoinfutures api endpoint
2334
2334
  * @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)
2335
2335
  * @returns {object[]} a list of [funding rate structures]{@link https://github.com/ccxt/ccxt/wiki/Manual#funding-rate-history-structure}
2336
2336
  */
@@ -193,6 +193,8 @@ class mexc extends mexc$1 {
193
193
  'rebate/detail/kickback': 1,
194
194
  'rebate/referCode': 1,
195
195
  'rebate/affiliate/commission': 1,
196
+ 'rebate/affiliate/withdraw': 1,
197
+ 'rebate/affiliate/commission/detail': 1,
196
198
  'mxDeduct/enable': 1,
197
199
  'userDataStream': 1,
198
200
  },
@@ -1357,11 +1359,15 @@ class mexc extends mexc$1 {
1357
1359
  /**
1358
1360
  * @method
1359
1361
  * @name mexc3#fetchTrades
1362
+ * @see https://mexcdevelop.github.io/apidocs/spot_v3_en/#recent-trades-list
1363
+ * @see https://mexcdevelop.github.io/apidocs/spot_v3_en/#compressed-aggregate-trades-list
1364
+ * @see https://mexcdevelop.github.io/apidocs/contract_v1_en/#get-contract-transaction-data
1360
1365
  * @description get the list of most recent trades for a particular symbol
1361
1366
  * @param {string} symbol unified symbol of the market to fetch trades for
1362
1367
  * @param {int} [since] timestamp in ms of the earliest trade to fetch
1363
1368
  * @param {int} [limit] the maximum amount of trades to fetch
1364
1369
  * @param {object} [params] extra parameters specific to the mexc3 api endpoint
1370
+ * @param {int} [params.until] *spot only* *since must be defined* the latest time in ms to fetch entries for
1365
1371
  * @returns {Trade[]} a list of [trade structures]{@link https://github.com/ccxt/ccxt/wiki/Manual#public-trades}
1366
1372
  */
1367
1373
  await this.loadMarkets();
@@ -1372,11 +1378,21 @@ class mexc extends mexc$1 {
1372
1378
  if (limit !== undefined) {
1373
1379
  request['limit'] = limit;
1374
1380
  }
1375
- // if (since !== undefined) {
1376
- // request['startTime'] = since; bug in api, waiting for fix
1377
- // }
1378
1381
  let trades = undefined;
1379
1382
  if (market['spot']) {
1383
+ const until = this.safeIntegerN(params, ['endTime', 'until', 'till']);
1384
+ if (since !== undefined) {
1385
+ request['startTime'] = since;
1386
+ if (until === undefined) {
1387
+ throw new errors.ArgumentsRequired(this.id + ' fetchTrades() requires an until parameter when since is provided');
1388
+ }
1389
+ }
1390
+ if (until !== undefined) {
1391
+ if (since === undefined) {
1392
+ throw new errors.ArgumentsRequired(this.id + ' fetchTrades() requires a since parameter when until is provided');
1393
+ }
1394
+ request['endTime'] = until;
1395
+ }
1380
1396
  let method = this.safeString(this.options, 'fetchTradesMethod', 'spotPublicGetAggTrades');
1381
1397
  method = this.safeString(params, 'method', method); // AggTrades, HistoricalTrades, Trades
1382
1398
  trades = await this[method](this.extend(request, params));
@@ -1607,31 +1623,53 @@ class mexc extends mexc$1 {
1607
1623
  /**
1608
1624
  * @method
1609
1625
  * @name mexc3#fetchOHLCV
1626
+ * @see https://mexcdevelop.github.io/apidocs/spot_v3_en/#kline-candlestick-data
1627
+ * @see https://mexcdevelop.github.io/apidocs/contract_v1_en/#k-line-data
1610
1628
  * @description fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market
1611
1629
  * @param {string} symbol unified symbol of the market to fetch OHLCV data for
1612
1630
  * @param {string} timeframe the length of time each candle represents
1613
1631
  * @param {int} [since] timestamp in ms of the earliest candle to fetch
1614
1632
  * @param {int} [limit] the maximum amount of candles to fetch
1615
1633
  * @param {object} [params] extra parameters specific to the mexc3 api endpoint
1634
+ * @param {int} [params.until] timestamp in ms of the latest candle to fetch
1635
+ * @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)
1616
1636
  * @returns {int[][]} A list of candles ordered as timestamp, open, high, low, close, volume
1617
1637
  */
1618
1638
  await this.loadMarkets();
1619
1639
  const market = this.market(symbol);
1640
+ const maxLimit = (market['spot']) ? 1000 : 2000;
1641
+ let paginate = false;
1642
+ [paginate, params] = this.handleOptionAndParams(params, 'fetchOHLCV', 'paginate', false);
1643
+ if (paginate) {
1644
+ return await this.fetchPaginatedCallDeterministic('fetchOHLCV', symbol, since, limit, timeframe, params, maxLimit);
1645
+ }
1620
1646
  const options = this.safeValue(this.options, 'timeframes', {});
1621
1647
  const timeframes = this.safeValue(options, market['type'], {});
1622
1648
  const timeframeValue = this.safeString(timeframes, timeframe);
1649
+ const duration = this.parseTimeframe(timeframe) * 1000;
1623
1650
  const request = {
1624
1651
  'symbol': market['id'],
1625
1652
  'interval': timeframeValue,
1626
1653
  };
1627
1654
  let candles = undefined;
1628
1655
  if (market['spot']) {
1656
+ const until = this.safeIntegerN(params, ['until', 'endTime', 'till']);
1629
1657
  if (since !== undefined) {
1630
1658
  request['startTime'] = since;
1659
+ if (until === undefined) {
1660
+ // we have to calculate it assuming we can get at most 2000 entries per request
1661
+ const end = this.sum(since, maxLimit * duration);
1662
+ const now = this.milliseconds();
1663
+ request['endTime'] = Math.min(end, now);
1664
+ }
1631
1665
  }
1632
1666
  if (limit !== undefined) {
1633
1667
  request['limit'] = limit;
1634
1668
  }
1669
+ if (until !== undefined) {
1670
+ params = this.omit(params, ['until', 'till']);
1671
+ request['endTime'] = until;
1672
+ }
1635
1673
  const response = await this.spotPublicGetKlines(this.extend(request, params));
1636
1674
  //
1637
1675
  // [
@@ -1650,9 +1688,14 @@ class mexc extends mexc$1 {
1650
1688
  candles = response;
1651
1689
  }
1652
1690
  else if (market['swap']) {
1691
+ const until = this.safeIntegerProductN(params, ['until', 'endTime', 'till'], 0.001);
1653
1692
  if (since !== undefined) {
1654
1693
  request['start'] = this.parseToInt(since / 1000);
1655
1694
  }
1695
+ if (until !== undefined) {
1696
+ params = this.omit(params, ['until', 'till']);
1697
+ request['end'] = until;
1698
+ }
1656
1699
  const priceType = this.safeString(params, 'price', 'default');
1657
1700
  params = this.omit(params, 'price');
1658
1701
  const method = this.getSupportedMapping(priceType, {