ccxt 4.1.5 → 4.1.6

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 (61) hide show
  1. package/README.md +3 -3
  2. package/dist/ccxt.browser.js +1106 -55
  3. package/dist/ccxt.browser.min.js +12 -12
  4. package/dist/cjs/ccxt.js +1 -1
  5. package/dist/cjs/src/base/Exchange.js +216 -0
  6. package/dist/cjs/src/binance.js +96 -1
  7. package/dist/cjs/src/bingx.js +24 -0
  8. package/dist/cjs/src/bitfinex2.js +55 -11
  9. package/dist/cjs/src/bitget.js +132 -12
  10. package/dist/cjs/src/bitmex.js +49 -0
  11. package/dist/cjs/src/bybit.js +56 -3
  12. package/dist/cjs/src/coinbase.js +85 -6
  13. package/dist/cjs/src/coinbasepro.js +18 -0
  14. package/dist/cjs/src/cryptocom.js +30 -0
  15. package/dist/cjs/src/gate.js +56 -3
  16. package/dist/cjs/src/huobi.js +69 -4
  17. package/dist/cjs/src/kraken.js +17 -3
  18. package/dist/cjs/src/krakenfutures.js +24 -0
  19. package/dist/cjs/src/kucoin.js +59 -4
  20. package/dist/cjs/src/kucoinfutures.js +35 -1
  21. package/dist/cjs/src/okx.js +66 -4
  22. package/dist/cjs/src/poloniex.js +18 -2
  23. package/js/ccxt.d.ts +1 -1
  24. package/js/ccxt.js +1 -1
  25. package/js/src/base/Exchange.d.ts +7 -0
  26. package/js/src/base/Exchange.js +216 -0
  27. package/js/src/binance.d.ts +5 -5
  28. package/js/src/binance.js +96 -1
  29. package/js/src/bingx.d.ts +1 -1
  30. package/js/src/bingx.js +24 -0
  31. package/js/src/bitfinex2.d.ts +3 -3
  32. package/js/src/bitfinex2.js +56 -12
  33. package/js/src/bitget.d.ts +7 -6
  34. package/js/src/bitget.js +132 -12
  35. package/js/src/bitmex.d.ts +6 -6
  36. package/js/src/bitmex.js +49 -0
  37. package/js/src/bybit.d.ts +6 -6
  38. package/js/src/bybit.js +56 -3
  39. package/js/src/coinbase.d.ts +5 -5
  40. package/js/src/coinbase.js +86 -7
  41. package/js/src/coinbasepro.d.ts +5 -5
  42. package/js/src/coinbasepro.js +18 -0
  43. package/js/src/cryptocom.d.ts +4 -4
  44. package/js/src/cryptocom.js +30 -0
  45. package/js/src/gate.d.ts +4 -4
  46. package/js/src/gate.js +56 -3
  47. package/js/src/huobi.d.ts +2 -2
  48. package/js/src/huobi.js +69 -4
  49. package/js/src/kraken.d.ts +1 -1
  50. package/js/src/kraken.js +17 -3
  51. package/js/src/krakenfutures.d.ts +2 -2
  52. package/js/src/krakenfutures.js +24 -0
  53. package/js/src/kucoin.d.ts +5 -5
  54. package/js/src/kucoin.js +59 -4
  55. package/js/src/kucoinfutures.d.ts +4 -4
  56. package/js/src/kucoinfutures.js +35 -1
  57. package/js/src/okx.d.ts +6 -6
  58. package/js/src/okx.js +66 -4
  59. package/js/src/poloniex.d.ts +1 -1
  60. package/js/src/poloniex.js +18 -2
  61. package/package.json +1 -1
@@ -340,6 +340,7 @@ class bitfinex2 extends bitfinex2$1 {
340
340
  },
341
341
  'exceptions': {
342
342
  'exact': {
343
+ '11010': errors.RateLimitExceeded,
343
344
  '10001': errors.PermissionDenied,
344
345
  '10020': errors.BadRequest,
345
346
  '10100': errors.AuthenticationError,
@@ -1265,17 +1266,24 @@ class bitfinex2 extends bitfinex2$1 {
1265
1266
  * @method
1266
1267
  * @name bitfinex2#fetchTrades
1267
1268
  * @description get the list of most recent trades for a particular symbol
1268
- * @see https://docs.bitfinex.com/reference/rest-public-tickers-history
1269
+ * @see https://docs.bitfinex.com/reference/rest-public-trades
1269
1270
  * @param {string} symbol unified symbol of the market to fetch trades for
1270
1271
  * @param {int} [since] timestamp in ms of the earliest trade to fetch
1271
1272
  * @param {int} [limit] the maximum amount of trades to fetch
1272
1273
  * @param {object} [params] extra parameters specific to the bitfinex2 api endpoint
1274
+ * @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] (ttps://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
1275
+ * @param {int} [params.until] the latest time in ms to fetch entries for
1273
1276
  * @returns {Trade[]} a list of [trade structures]{@link https://github.com/ccxt/ccxt/wiki/Manual#public-trades}
1274
1277
  */
1275
1278
  await this.loadMarkets();
1279
+ let paginate = false;
1280
+ [paginate, params] = this.handleOptionAndParams(params, 'fetchTrades', 'paginate');
1281
+ if (paginate) {
1282
+ return await this.fetchPaginatedCallDynamic('fetchTrades', symbol, since, limit, params, 10000);
1283
+ }
1276
1284
  const market = this.market(symbol);
1277
1285
  let sort = '-1';
1278
- const request = {
1286
+ let request = {
1279
1287
  'symbol': market['id'],
1280
1288
  };
1281
1289
  if (since !== undefined) {
@@ -1286,6 +1294,7 @@ class bitfinex2 extends bitfinex2$1 {
1286
1294
  request['limit'] = Math.min(limit, 10000); // default 120, max 10000
1287
1295
  }
1288
1296
  request['sort'] = sort;
1297
+ [request, params] = this.handleUntilOption('end', request, params);
1289
1298
  const response = await this.publicGetTradesSymbolHist(this.extend(request, params));
1290
1299
  //
1291
1300
  // [
@@ -1312,23 +1321,27 @@ class bitfinex2 extends bitfinex2$1 {
1312
1321
  * @param {int} [limit] the maximum amount of candles to fetch
1313
1322
  * @param {object} [params] extra parameters specific to the bitfinex2 api endpoint
1314
1323
  * @returns {int[][]} A list of candles ordered as timestamp, open, high, low, close, volume
1324
+ * @param {int} [params.until] timestamp in ms of the latest candle to fetch
1325
+ * @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] (ttps://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
1315
1326
  */
1316
1327
  await this.loadMarkets();
1328
+ let paginate = false;
1329
+ [paginate, params] = this.handleOptionAndParams(params, 'fetchOHLCV', 'paginate');
1330
+ if (paginate) {
1331
+ return await this.fetchPaginatedCallDeterministic('fetchOHLCV', symbol, since, limit, timeframe, params, 10000);
1332
+ }
1317
1333
  const market = this.market(symbol);
1318
1334
  if (limit === undefined) {
1319
- limit = 100; // default 100, max 5000
1320
- }
1321
- if (since === undefined) {
1322
- const duration = this.parseTimeframe(timeframe);
1323
- since = this.milliseconds() - duration * limit * 1000;
1335
+ limit = 10000; // default 100, max 5000
1324
1336
  }
1325
- const request = {
1337
+ let request = {
1326
1338
  'symbol': market['id'],
1327
1339
  'timeframe': this.safeString(this.timeframes, timeframe, timeframe),
1328
1340
  'sort': 1,
1329
1341
  'start': since,
1330
1342
  'limit': limit,
1331
1343
  };
1344
+ [request, params] = this.handleUntilOption('end', request, params);
1332
1345
  const response = await this.publicGetCandlesTradeTimeframeSymbolHist(this.extend(request, params));
1333
1346
  //
1334
1347
  // [
@@ -1802,17 +1815,25 @@ class bitfinex2 extends bitfinex2$1 {
1802
1815
  * @param {int} [since] the earliest time in ms to fetch orders for
1803
1816
  * @param {int} [limit] the maximum number of orde structures to retrieve
1804
1817
  * @param {object} [params] extra parameters specific to the bitfinex2 api endpoint
1818
+ * @param {int} [params.until] the latest time in ms to fetch entries for
1819
+ * @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] (ttps://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
1805
1820
  * @returns {Order[]} a list of [order structures]{@link https://github.com/ccxt/ccxt/wiki/Manual#order-structure}
1806
1821
  */
1807
1822
  // returns the most recent closed or canceled orders up to circa two weeks ago
1808
1823
  await this.loadMarkets();
1809
- const request = {};
1824
+ let paginate = false;
1825
+ [paginate, params] = this.handleOptionAndParams(params, 'fetchClosedOrders', 'paginate');
1826
+ if (paginate) {
1827
+ return await this.fetchPaginatedCallDynamic('fetchClosedOrders', symbol, since, limit, params);
1828
+ }
1829
+ let request = {};
1810
1830
  if (since !== undefined) {
1811
1831
  request['start'] = since;
1812
1832
  }
1813
1833
  if (limit !== undefined) {
1814
1834
  request['limit'] = limit; // default 25, max 2500
1815
1835
  }
1836
+ [request, params] = this.handleUntilOption('end', request, params);
1816
1837
  let market = undefined;
1817
1838
  let response = undefined;
1818
1839
  if (symbol === undefined) {
@@ -2573,6 +2594,7 @@ class bitfinex2 extends bitfinex2$1 {
2573
2594
  return { 'url': url, 'method': method, 'body': body, 'headers': headers };
2574
2595
  }
2575
2596
  handleErrors(statusCode, statusText, url, method, headers, body, response, requestHeaders, requestBody) {
2597
+ // ['error', 11010, 'ratelimit: error']
2576
2598
  if (response !== undefined) {
2577
2599
  if (!Array.isArray(response)) {
2578
2600
  const message = this.safeString2(response, 'message', 'error');
@@ -2585,6 +2607,9 @@ class bitfinex2 extends bitfinex2$1 {
2585
2607
  else if (response === '') {
2586
2608
  throw new errors.ExchangeError(this.id + ' returned empty response');
2587
2609
  }
2610
+ if (statusCode === 429) {
2611
+ throw new errors.RateLimitExceeded(this.id + ' ' + body);
2612
+ }
2588
2613
  if (statusCode === 500) {
2589
2614
  // See https://docs.bitfinex.com/docs/abbreviations-glossary#section-errorinfo-codes
2590
2615
  const errorCode = this.safeString(response, 1, '');
@@ -2680,18 +2705,26 @@ class bitfinex2 extends bitfinex2$1 {
2680
2705
  * @param {int} [since] timestamp in ms of the earliest ledger entry, default is undefined
2681
2706
  * @param {int} [limit] max number of ledger entrys to return, default is undefined
2682
2707
  * @param {object} [params] extra parameters specific to the bitfinex2 api endpoint
2708
+ * @param {int} [params.until] timestamp in ms of the latest ledger entry
2709
+ * @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] (ttps://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
2683
2710
  * @returns {object} a [ledger structure]{@link https://github.com/ccxt/ccxt/wiki/Manual#ledger-structure}
2684
2711
  */
2685
2712
  await this.loadMarkets();
2686
2713
  await this.loadMarkets();
2714
+ let paginate = false;
2715
+ [paginate, params] = this.handleOptionAndParams(params, 'fetchLedger', 'paginate');
2716
+ if (paginate) {
2717
+ return await this.fetchPaginatedCallDynamic('fetchLedger', code, since, limit, params, 2500);
2718
+ }
2687
2719
  let currency = undefined;
2688
- const request = {};
2720
+ let request = {};
2689
2721
  if (since !== undefined) {
2690
2722
  request['start'] = since;
2691
2723
  }
2692
2724
  if (limit !== undefined) {
2693
2725
  request['limit'] = limit; // max 2500
2694
2726
  }
2727
+ [request, params] = this.handleUntilOption('end', request, params);
2695
2728
  let response = undefined;
2696
2729
  if (code !== undefined) {
2697
2730
  currency = this.currency(code);
@@ -2789,14 +2822,25 @@ class bitfinex2 extends bitfinex2$1 {
2789
2822
  * @see https://docs.bitfinex.com/reference/rest-public-derivatives-status-history
2790
2823
  * @param {string} symbol unified market symbol
2791
2824
  * @param {object} [params] extra parameters specific to the bingx api endpoint
2825
+ * @param {int} [params.until] timestamp in ms of the latest funding rate
2826
+ * @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] (ttps://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
2792
2827
  * @returns {object} a [funding rate structure]{@link https://github.com/ccxt/ccxt/wiki/Manual#funding-rate-structure}
2793
2828
  */
2794
2829
  await this.loadMarkets();
2795
2830
  this.checkRequiredSymbol('fetchFundingRateHistory', symbol);
2831
+ let paginate = false;
2832
+ [paginate, params] = this.handleOptionAndParams(params, 'fetchFundingRateHistory', 'paginate');
2833
+ if (paginate) {
2834
+ return await this.fetchPaginatedCallDeterministic('fetchFundingRateHistory', symbol, since, limit, '8h', params, 5000);
2835
+ }
2796
2836
  const market = this.market(symbol);
2797
- const request = {
2837
+ let request = {
2798
2838
  'symbol': market['id'],
2799
2839
  };
2840
+ if (since !== undefined) {
2841
+ request['start'] = since;
2842
+ }
2843
+ [request, params] = this.handleUntilOption('end', request, params);
2800
2844
  const response = await this.publicGetStatusDerivSymbolHist(this.extend(request, params));
2801
2845
  //
2802
2846
  // [
@@ -1558,9 +1558,16 @@ class bitget extends bitget$1 {
1558
1558
  * @param {object} [params] extra parameters specific to the bitget api endpoint
1559
1559
  * @param {string} [params.pageNo] pageNo default 1
1560
1560
  * @param {string} [params.pageSize] pageSize default 20. Max 100
1561
+ * @param {int} [params.until] end tim in ms
1562
+ * @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] (ttps://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
1561
1563
  * @returns {object[]} a list of [transaction structures]{@link https://github.com/ccxt/ccxt/wiki/Manual#transaction-structure}
1562
1564
  */
1563
1565
  await this.loadMarkets();
1566
+ let paginate = false;
1567
+ [paginate, params] = this.handleOptionAndParams(params, 'fetchDeposits', 'paginate');
1568
+ if (paginate) {
1569
+ return await this.fetchPaginatedCallDynamic('fetchDeposits', code, since, limit, params);
1570
+ }
1564
1571
  if (code === undefined) {
1565
1572
  throw new errors.ArgumentsRequired(this.id + ' fetchDeposits() requires a `code` argument');
1566
1573
  }
@@ -1568,7 +1575,7 @@ class bitget extends bitget$1 {
1568
1575
  if (since === undefined) {
1569
1576
  since = this.milliseconds() - 31556952000; // 1yr
1570
1577
  }
1571
- const request = {
1578
+ let request = {
1572
1579
  'coin': currency['code'],
1573
1580
  'startTime': since,
1574
1581
  'endTime': this.milliseconds(),
@@ -1576,6 +1583,7 @@ class bitget extends bitget$1 {
1576
1583
  if (limit !== undefined) {
1577
1584
  request['pageSize'] = limit;
1578
1585
  }
1586
+ [request, params] = this.handleUntilOption('endTime', request, params);
1579
1587
  const response = await this.privateSpotGetWalletDepositList(this.extend(request, params));
1580
1588
  //
1581
1589
  // {
@@ -1688,9 +1696,16 @@ class bitget extends bitget$1 {
1688
1696
  * @param {object} [params] extra parameters specific to the bitget api endpoint
1689
1697
  * @param {string} [params.pageNo] pageNo default 1
1690
1698
  * @param {string} [params.pageSize] pageSize default 20. Max 100
1699
+ * @param {int} [params.until] end time in ms
1700
+ * @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] (ttps://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
1691
1701
  * @returns {object[]} a list of [transaction structures]{@link https://github.com/ccxt/ccxt/wiki/Manual#transaction-structure}
1692
1702
  */
1693
1703
  await this.loadMarkets();
1704
+ let paginate = false;
1705
+ [paginate, params] = this.handleOptionAndParams(params, 'fetchWithdrawals', 'paginate');
1706
+ if (paginate) {
1707
+ return await this.fetchPaginatedCallDynamic('fetchWithdrawals', code, since, limit, params);
1708
+ }
1694
1709
  if (code === undefined) {
1695
1710
  throw new errors.ArgumentsRequired(this.id + ' fetchWithdrawals() requires a `code` argument');
1696
1711
  }
@@ -1698,11 +1713,12 @@ class bitget extends bitget$1 {
1698
1713
  if (since === undefined) {
1699
1714
  since = this.milliseconds() - 31556952000; // 1yr
1700
1715
  }
1701
- const request = {
1716
+ let request = {
1702
1717
  'coin': currency['code'],
1703
1718
  'startTime': since,
1704
1719
  'endTime': this.milliseconds(),
1705
1720
  };
1721
+ [request, params] = this.handleUntilOption('endTime', params, request);
1706
1722
  if (limit !== undefined) {
1707
1723
  request['pageSize'] = limit;
1708
1724
  }
@@ -2247,9 +2263,15 @@ class bitget extends bitget$1 {
2247
2263
  * @param {int} [limit] the maximum amount of trades to fetch
2248
2264
  * @param {object} [params] extra parameters specific to the bitget api endpoint
2249
2265
  * @param {int} [params.until] the latest time in ms to fetch deposits for
2266
+ * @param {boolean} [params.paginate] *only applies to publicSpotGetMarketFillsHistory and publicMixGetMarketFillsHistory* default false, when true will automatically paginate by calling this endpoint multiple times
2250
2267
  * @returns {Trade[]} a list of [trade structures]{@link https://github.com/ccxt/ccxt/wiki/Manual#public-trades}
2251
2268
  */
2252
2269
  await this.loadMarkets();
2270
+ let paginate = false;
2271
+ [paginate, params] = this.handleOptionAndParams(params, 'fetchTrades', 'paginate');
2272
+ if (paginate) {
2273
+ return await this.fetchPaginatedCallCursor('fetchTrades', symbol, since, limit, params, 'tradeId', 'tradeId');
2274
+ }
2253
2275
  const market = this.market(symbol);
2254
2276
  const request = {
2255
2277
  'symbol': market['id'],
@@ -2266,10 +2288,9 @@ class bitget extends bitget$1 {
2266
2288
  }
2267
2289
  }
2268
2290
  if (until !== undefined) {
2269
- this.checkRequiredArgument('fetchTrades', since, 'since');
2291
+ params = this.omit(params, 'until');
2270
2292
  request['endTime'] = until;
2271
2293
  }
2272
- params = this.omit(params, 'until');
2273
2294
  const options = this.safeValue(this.options, 'fetchTrades', {});
2274
2295
  let response = undefined;
2275
2296
  if (market['spot']) {
@@ -2491,9 +2512,15 @@ class bitget extends bitget$1 {
2491
2512
  * @param {int} [limit] the maximum amount of candles to fetch
2492
2513
  * @param {object} [params] extra parameters specific to the bitget api endpoint
2493
2514
  * @param {int} [params.until] timestamp in ms of the latest candle to fetch
2515
+ * @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] (ttps://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
2494
2516
  * @returns {int[][]} A list of candles ordered as timestamp, open, high, low, close, volume
2495
2517
  */
2496
2518
  await this.loadMarkets();
2519
+ let paginate = false;
2520
+ [paginate, params] = this.handleOptionAndParams(params, 'fetchOHLCV', 'paginate');
2521
+ if (paginate) {
2522
+ return await this.fetchPaginatedCallDeterministic('fetchOHLCV', symbol, since, limit, timeframe, params, 1000);
2523
+ }
2497
2524
  const market = this.market(symbol);
2498
2525
  const request = {
2499
2526
  'symbol': market['id'],
@@ -3589,9 +3616,10 @@ class bitget extends bitget$1 {
3589
3616
  if (typeof response === 'string') {
3590
3617
  response = JSON.parse(response);
3591
3618
  }
3592
- let data = this.safeValue(response, 'data', []);
3619
+ const data = this.safeValue(response, 'data', []);
3593
3620
  if (!Array.isArray(data)) {
3594
- data = this.safeValue(data, 'orderList', []);
3621
+ const result = this.safeValue(data, 'orderList', []);
3622
+ return this.addPaginationCursorToResult(data, result);
3595
3623
  }
3596
3624
  return this.parseOrders(data, market, since, limit);
3597
3625
  }
@@ -3602,15 +3630,26 @@ class bitget extends bitget$1 {
3602
3630
  * @description fetches information on multiple closed orders made by the user
3603
3631
  * @see https://bitgetlimited.github.io/apidoc/en/spot/#get-order-history
3604
3632
  * @see https://bitgetlimited.github.io/apidoc/en/mix/#get-history-orders
3633
+ * @see https://bitgetlimited.github.io/apidoc/en/mix/#get-history-plan-orders-tpsl
3634
+ * @see https://bitgetlimited.github.io/apidoc/en/spot/#get-history-plan-orders
3605
3635
  * @param {string} symbol unified market symbol of the closed orders
3606
3636
  * @param {int} [since] timestamp in ms of the earliest order
3607
3637
  * @param {int} [limit] the max number of closed orders to return
3608
3638
  * @param {object} [params] extra parameters specific to the bitget api endpoint
3639
+ * @param {int} [params.until] the latest time in ms to fetch entries for
3609
3640
  * @returns {Order[]} a list of [order structures]{@link https://github.com/ccxt/ccxt/wiki/Manual#order-structure}
3610
3641
  */
3611
3642
  await this.loadMarkets();
3612
3643
  this.checkRequiredSymbol('fetchClosedOrders', symbol);
3613
3644
  const market = this.market(symbol);
3645
+ let paginate = false;
3646
+ [paginate, params] = this.handleOptionAndParams(params, 'fetchClosedOrders', 'paginate');
3647
+ if (paginate) {
3648
+ const isStop = this.safeValue2(params, 'stop', 'trigger', false);
3649
+ const cursorReceived = (market['spot'] && !isStop) ? 'orderId' : 'endId';
3650
+ const cursorSent = (market['spot'] && !isStop) ? 'after' : 'lastEndId';
3651
+ return await this.fetchPaginatedCallCursor('fetchClosedOrders', symbol, since, limit, params, cursorReceived, cursorSent, undefined, 50);
3652
+ }
3614
3653
  const response = await this.fetchCanceledAndClosedOrders(symbol, since, limit, params);
3615
3654
  const result = [];
3616
3655
  for (let i = 0; i < response.length; i++) {
@@ -3629,15 +3668,26 @@ class bitget extends bitget$1 {
3629
3668
  * @description fetches information on multiple canceled orders made by the user
3630
3669
  * @see https://bitgetlimited.github.io/apidoc/en/spot/#get-order-history
3631
3670
  * @see https://bitgetlimited.github.io/apidoc/en/mix/#get-history-orders
3671
+ * @see https://bitgetlimited.github.io/apidoc/en/mix/#get-history-plan-orders-tpsl
3672
+ * @see https://bitgetlimited.github.io/apidoc/en/spot/#get-history-plan-orders
3632
3673
  * @param {string} symbol unified market symbol of the canceled orders
3633
3674
  * @param {int} [since] timestamp in ms of the earliest order
3634
3675
  * @param {int} [limit] the max number of canceled orders to return
3635
3676
  * @param {object} [params] extra parameters specific to the bitget api endpoint
3677
+ * @param {int} [params.until] the latest time in ms to fetch entries for
3636
3678
  * @returns {object} a list of [order structures]{@link https://github.com/ccxt/ccxt/wiki/Manual#order-structure}
3637
3679
  */
3638
3680
  await this.loadMarkets();
3639
3681
  this.checkRequiredSymbol('fetchCanceledOrders', symbol);
3640
3682
  const market = this.market(symbol);
3683
+ let paginate = false;
3684
+ [paginate, params] = this.handleOptionAndParams(params, 'fetchCanceledOrders', 'paginate');
3685
+ if (paginate) {
3686
+ const isStop = this.safeValue2(params, 'stop', 'trigger', false);
3687
+ const cursorReceived = (market['spot'] && !isStop) ? 'orderId' : 'endId';
3688
+ const cursorSent = (market['spot'] && !isStop) ? 'after' : 'lastEndId';
3689
+ return await this.fetchPaginatedCallCursor('fetchCanceledOrders', symbol, since, limit, params, cursorReceived, cursorSent, undefined, 50);
3690
+ }
3641
3691
  const response = await this.fetchCanceledAndClosedOrders(symbol, since, limit, params);
3642
3692
  const result = [];
3643
3693
  for (let i = 0; i < response.length; i++) {
@@ -3654,9 +3704,14 @@ class bitget extends bitget$1 {
3654
3704
  const market = this.market(symbol);
3655
3705
  let marketType = undefined;
3656
3706
  [marketType, params] = this.handleMarketTypeAndParams('fetchCanceledAndClosedOrders', market, params);
3707
+ const endTime = this.safeIntegerN(params, ['endTime', 'until', 'till']);
3708
+ params = this.omit(params, ['until', 'till']);
3657
3709
  const request = {
3658
3710
  'symbol': market['id'],
3659
3711
  };
3712
+ if (since !== undefined) {
3713
+ request['startTime'] = since;
3714
+ }
3660
3715
  let method = this.getSupportedMapping(marketType, {
3661
3716
  'spot': 'privateSpotPostTradeHistory',
3662
3717
  'swap': 'privateMixGetOrderHistory',
@@ -3681,7 +3736,20 @@ class bitget extends bitget$1 {
3681
3736
  since = 0;
3682
3737
  }
3683
3738
  request['startTime'] = since;
3684
- request['endTime'] = this.milliseconds();
3739
+ if (endTime === undefined) {
3740
+ request['endTime'] = this.milliseconds();
3741
+ }
3742
+ else {
3743
+ request['endTime'] = endTime;
3744
+ }
3745
+ }
3746
+ else {
3747
+ if (limit !== undefined) {
3748
+ request['pageSize'] = limit;
3749
+ }
3750
+ if (endTime !== undefined) {
3751
+ request['endTime'] = endTime;
3752
+ }
3685
3753
  }
3686
3754
  const response = await this[method](this.extend(request, params));
3687
3755
  //
@@ -3802,30 +3870,57 @@ class bitget extends bitget$1 {
3802
3870
  //
3803
3871
  const data = this.safeValue(response, 'data');
3804
3872
  if (data !== undefined) {
3805
- return this.safeValue(data, 'orderList', data);
3873
+ const result = this.safeValue(data, 'orderList', data);
3874
+ return this.addPaginationCursorToResult(data, result);
3806
3875
  }
3807
3876
  const parsedData = JSON.parse(response);
3808
3877
  return this.safeValue(parsedData, 'data', []);
3809
3878
  }
3879
+ addPaginationCursorToResult(response, data) {
3880
+ const endId = this.safeValue(response, 'endId');
3881
+ if (endId !== undefined) {
3882
+ const dataLength = data.length;
3883
+ if (dataLength > 0) {
3884
+ const first = data[0];
3885
+ const last = data[dataLength - 1];
3886
+ first['endId'] = endId;
3887
+ last['endId'] = endId;
3888
+ data[0] = first;
3889
+ data[dataLength - 1] = last;
3890
+ }
3891
+ }
3892
+ return data;
3893
+ }
3810
3894
  async fetchLedger(code = undefined, since = undefined, limit = undefined, params = {}) {
3811
3895
  /**
3812
3896
  * @method
3813
3897
  * @name bitget#fetchLedger
3814
- * @description fetch the history of changes, actions done by the user or operations that altered balance of the user
3815
3898
  * @see https://bitgetlimited.github.io/apidoc/en/spot/#get-bills
3899
+ * @description fetch the history of changes, actions done by the user or operations that altered balance of the user
3816
3900
  * @param {string} code unified currency code, default is undefined
3817
3901
  * @param {int} [since] timestamp in ms of the earliest ledger entry, default is undefined
3818
3902
  * @param {int} [limit] max number of ledger entrys to return, default is undefined
3819
3903
  * @param {object} [params] extra parameters specific to the bitget api endpoint
3904
+ * @param {int} [params.until] end tim in ms
3905
+ * @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] (ttps://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
3820
3906
  * @returns {object} a [ledger structure]{@link https://github.com/ccxt/ccxt/wiki/Manual#ledger-structure}
3821
3907
  */
3822
3908
  await this.loadMarkets();
3909
+ let paginate = false;
3910
+ [paginate, params] = this.handleOptionAndParams(params, 'fetchLedger', 'paginate');
3911
+ if (paginate) {
3912
+ return await this.fetchPaginatedCallDynamic('fetchLedger', code, since, limit, params, 500);
3913
+ }
3823
3914
  let currency = undefined;
3824
- const request = {};
3915
+ let request = {};
3825
3916
  if (code !== undefined) {
3826
3917
  currency = this.currency(code);
3827
3918
  request['coinId'] = currency['id'];
3828
3919
  }
3920
+ if (since !== undefined) {
3921
+ request['before'] = since;
3922
+ }
3923
+ [request, params] = this.handleUntilOption('after', params, request);
3829
3924
  const response = await this.privateSpotPostAccountBills(this.extend(request, params));
3830
3925
  //
3831
3926
  // {
@@ -3907,12 +4002,24 @@ class bitget extends bitget$1 {
3907
4002
  * @param {int} [since] the earliest time in ms to fetch trades for
3908
4003
  * @param {int} [limit] the maximum number of trades structures to retrieve
3909
4004
  * @param {object} [params] extra parameters specific to the bitget api endpoint
4005
+ * @param {int} [params.until] *swap only* the latest time in ms to fetch entries for
4006
+ * @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] (ttps://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
3910
4007
  * @returns {Trade[]} a list of [trade structures]{@link https://github.com/ccxt/ccxt/wiki/Manual#trade-structure}
3911
4008
  */
3912
4009
  this.checkRequiredSymbol('fetchMyTrades', symbol);
3913
4010
  await this.loadMarkets();
3914
4011
  const market = this.market(symbol);
3915
- const request = {
4012
+ let paginate = false;
4013
+ [paginate, params] = this.handleOptionAndParams(params, 'fetchMyTrades', 'paginate');
4014
+ if (paginate) {
4015
+ if (market['spot']) {
4016
+ return await this.fetchPaginatedCallCursor('fetchMyTrades', symbol, since, limit, params, 'orderId', 'after', undefined, 50);
4017
+ }
4018
+ else {
4019
+ return await this.fetchPaginatedCallDynamic('fetchMyTrades', symbol, since, limit, params, 500);
4020
+ }
4021
+ }
4022
+ let request = {
3916
4023
  'symbol': market['id'],
3917
4024
  };
3918
4025
  if (limit !== undefined) {
@@ -3923,6 +4030,10 @@ class bitget extends bitget$1 {
3923
4030
  response = await this.privateSpotPostTradeFills(this.extend(request, params));
3924
4031
  }
3925
4032
  else {
4033
+ if (since !== undefined) {
4034
+ request['startTime'] = since;
4035
+ }
4036
+ [request, params] = this.handleUntilOption('endTime', params, request);
3926
4037
  response = await this.privateMixGetOrderFills(this.extend(request, params));
3927
4038
  }
3928
4039
  //
@@ -4320,6 +4431,7 @@ class bitget extends bitget$1 {
4320
4431
  /**
4321
4432
  * @method
4322
4433
  * @name bitget#fetchFundingRateHistory
4434
+ * @see https://bitgetlimited.github.io/apidoc/en/mix/#get-history-funding-rate
4323
4435
  * @description fetches historical funding rate prices
4324
4436
  * @see https://bitgetlimited.github.io/apidoc/en/mix/#get-history-funding-rate
4325
4437
  * @param {string} symbol unified symbol of the market to fetch the funding rate history for
@@ -4796,16 +4908,23 @@ class bitget extends bitget$1 {
4796
4908
  * @param {int} [since] the earliest time in ms to fetch transfers for
4797
4909
  * @param {int} [limit] the maximum number of transfers structures to retrieve
4798
4910
  * @param {object} [params] extra parameters specific to the bitget api endpoint
4911
+ * @param {int} [params.until] the latest time in ms to fetch entries for
4912
+ * @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] (ttps://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
4799
4913
  * @returns {object[]} a list of [transfer structures]{@link https://github.com/ccxt/ccxt/wiki/Manual#transfer-structure}
4800
4914
  */
4801
4915
  await this.loadMarkets();
4916
+ let paginate = false;
4917
+ [paginate, params] = this.handleOptionAndParams(params, 'fetchTransfers', 'paginate');
4918
+ if (paginate) {
4919
+ return await this.fetchPaginatedCallDynamic('fetchTransfers', code, since, limit, params);
4920
+ }
4802
4921
  let type = undefined;
4803
4922
  [type, params] = this.handleMarketTypeAndParams('fetchTransfers', undefined, params);
4804
4923
  const fromAccount = this.safeString(params, 'fromAccount', type);
4805
4924
  params = this.omit(params, 'fromAccount');
4806
4925
  const accountsByType = this.safeValue(this.options, 'accountsByType', {});
4807
4926
  type = this.safeString(accountsByType, fromAccount);
4808
- const request = {
4927
+ let request = {
4809
4928
  'fromType': type,
4810
4929
  };
4811
4930
  let currency = undefined;
@@ -4819,6 +4938,7 @@ class bitget extends bitget$1 {
4819
4938
  if (limit !== undefined) {
4820
4939
  request['limit'] = limit;
4821
4940
  }
4941
+ [request, params] = this.handleUntilOption('after', params, request);
4822
4942
  const response = await this.privateSpotGetAccountTransferRecords(this.extend(request, params));
4823
4943
  //
4824
4944
  // {
@@ -855,14 +855,22 @@ class bitmex extends bitmex$1 {
855
855
  /**
856
856
  * @method
857
857
  * @name bitmex#fetchOrders
858
+ * @see https://www.bitmex.com/api/explorer/#!/Order/Order_getOrders
858
859
  * @description fetches information on multiple orders made by the user
859
860
  * @param {string} symbol unified market symbol of the market orders were made in
860
861
  * @param {int} [since] the earliest time in ms to fetch orders for
861
862
  * @param {int} [limit] the maximum number of orde structures to retrieve
862
863
  * @param {object} [params] extra parameters specific to the bitmex api endpoint
864
+ * @param {int} [params.until] the earliest time in ms to fetch orders for
865
+ * @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] (ttps://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
863
866
  * @returns {Order[]} a list of [order structures]{@link https://github.com/ccxt/ccxt/wiki/Manual#order-structure}
864
867
  */
865
868
  await this.loadMarkets();
869
+ let paginate = false;
870
+ [paginate, params] = this.handleOptionAndParams(params, 'fetchOrders', 'paginate');
871
+ if (paginate) {
872
+ return await this.fetchPaginatedCallDynamic('fetchOrders', symbol, since, limit, params, 100);
873
+ }
866
874
  let market = undefined;
867
875
  let request = {};
868
876
  if (symbol !== undefined) {
@@ -875,6 +883,11 @@ class bitmex extends bitmex$1 {
875
883
  if (limit !== undefined) {
876
884
  request['count'] = limit;
877
885
  }
886
+ const until = this.safeInteger2(params, 'until', 'endTime');
887
+ if (until !== undefined) {
888
+ params = this.omit(params, ['until']);
889
+ request['endTime'] = this.iso8601(until);
890
+ }
878
891
  request = this.deepExtend(request, params);
879
892
  // why the hassle? urlencode in python is kinda broken for nested dicts.
880
893
  // E.g. self.urlencode({"filter": {"open": True}}) will return "filter={'open':+True}"
@@ -922,14 +935,21 @@ class bitmex extends bitmex$1 {
922
935
  /**
923
936
  * @method
924
937
  * @name bitmex#fetchMyTrades
938
+ * @see https://www.bitmex.com/api/explorer/#!/Execution/Execution_getTradeHistory
925
939
  * @description fetch all trades made by the user
926
940
  * @param {string} symbol unified market symbol
927
941
  * @param {int} [since] the earliest time in ms to fetch trades for
928
942
  * @param {int} [limit] the maximum number of trades structures to retrieve
929
943
  * @param {object} [params] extra parameters specific to the bitmex api endpoint
944
+ * @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] (ttps://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
930
945
  * @returns {Trade[]} a list of [trade structures]{@link https://github.com/ccxt/ccxt/wiki/Manual#trade-structure}
931
946
  */
932
947
  await this.loadMarkets();
948
+ let paginate = false;
949
+ [paginate, params] = this.handleOptionAndParams(params, 'fetchMyTrades', 'paginate');
950
+ if (paginate) {
951
+ return await this.fetchPaginatedCallDynamic('fetchMyTrades', symbol, since, limit, params, 100);
952
+ }
933
953
  let market = undefined;
934
954
  let request = {};
935
955
  if (symbol !== undefined) {
@@ -942,6 +962,11 @@ class bitmex extends bitmex$1 {
942
962
  if (limit !== undefined) {
943
963
  request['count'] = limit;
944
964
  }
965
+ const until = this.safeInteger2(params, 'until', 'endTime');
966
+ if (until !== undefined) {
967
+ params = this.omit(params, ['until']);
968
+ request['endTime'] = this.iso8601(until);
969
+ }
945
970
  request = this.deepExtend(request, params);
946
971
  // why the hassle? urlencode in python is kinda broken for nested dicts.
947
972
  // E.g. self.urlencode({"filter": {"open": True}}) will return "filter={'open':+True}"
@@ -1390,15 +1415,22 @@ class bitmex extends bitmex$1 {
1390
1415
  /**
1391
1416
  * @method
1392
1417
  * @name bitmex#fetchOHLCV
1418
+ * @see https://www.bitmex.com/api/explorer/#!/Trade/Trade_getBucketed
1393
1419
  * @description fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market
1394
1420
  * @param {string} symbol unified symbol of the market to fetch OHLCV data for
1395
1421
  * @param {string} timeframe the length of time each candle represents
1396
1422
  * @param {int} [since] timestamp in ms of the earliest candle to fetch
1397
1423
  * @param {int} [limit] the maximum amount of candles to fetch
1398
1424
  * @param {object} [params] extra parameters specific to the bitmex api endpoint
1425
+ * @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] (ttps://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
1399
1426
  * @returns {int[][]} A list of candles ordered as timestamp, open, high, low, close, volume
1400
1427
  */
1401
1428
  await this.loadMarkets();
1429
+ let paginate = false;
1430
+ [paginate, params] = this.handleOptionAndParams(params, 'fetchOHLCV', 'paginate');
1431
+ if (paginate) {
1432
+ return await this.fetchPaginatedCallDeterministic('fetchOHLCV', symbol, since, limit, timeframe, params);
1433
+ }
1402
1434
  // send JSON key/value pairs, such as {"key": "value"}
1403
1435
  // filter by individual fields and do advanced queries on timestamps
1404
1436
  // let filter = { 'key': 'value' };
@@ -1419,6 +1451,11 @@ class bitmex extends bitmex$1 {
1419
1451
  if (limit !== undefined) {
1420
1452
  request['count'] = limit; // default 100, max 500
1421
1453
  }
1454
+ const until = this.safeInteger2(params, 'until', 'endTime');
1455
+ if (until !== undefined) {
1456
+ params = this.omit(params, ['until']);
1457
+ request['endTime'] = this.iso8601(until);
1458
+ }
1422
1459
  const duration = this.parseTimeframe(timeframe) * 1000;
1423
1460
  const fetchOHLCVOpenTimestamp = this.safeValue(this.options, 'fetchOHLCVOpenTimestamp', true);
1424
1461
  // if since is not set, they will return candles starting from 2017-01-01
@@ -1702,14 +1739,21 @@ class bitmex extends bitmex$1 {
1702
1739
  /**
1703
1740
  * @method
1704
1741
  * @name bitmex#fetchTrades
1742
+ * @see https://www.bitmex.com/api/explorer/#!/Trade/Trade_get
1705
1743
  * @description get the list of most recent trades for a particular symbol
1706
1744
  * @param {string} symbol unified symbol of the market to fetch trades for
1707
1745
  * @param {int} [since] timestamp in ms of the earliest trade to fetch
1708
1746
  * @param {int} [limit] the maximum amount of trades to fetch
1709
1747
  * @param {object} [params] extra parameters specific to the bitmex api endpoint
1748
+ * @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] (ttps://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
1710
1749
  * @returns {Trade[]} a list of [trade structures]{@link https://github.com/ccxt/ccxt/wiki/Manual#public-trades}
1711
1750
  */
1712
1751
  await this.loadMarkets();
1752
+ let paginate = false;
1753
+ [paginate, params] = this.handleOptionAndParams(params, 'fetchTrades', 'paginate');
1754
+ if (paginate) {
1755
+ return await this.fetchPaginatedCallDynamic('fetchTrades', symbol, since, limit, params);
1756
+ }
1713
1757
  const market = this.market(symbol);
1714
1758
  const request = {
1715
1759
  'symbol': market['id'],
@@ -1724,6 +1768,11 @@ class bitmex extends bitmex$1 {
1724
1768
  if (limit !== undefined) {
1725
1769
  request['count'] = Math.min(limit, 1000); // api maximum 1000
1726
1770
  }
1771
+ const until = this.safeInteger2(params, 'until', 'endTime');
1772
+ if (until !== undefined) {
1773
+ params = this.omit(params, ['until']);
1774
+ request['endTime'] = this.iso8601(until);
1775
+ }
1727
1776
  const response = await this.publicGetTrade(this.extend(request, params));
1728
1777
  //
1729
1778
  // [