ccxt 4.1.4 → 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 (72) hide show
  1. package/README.md +3 -3
  2. package/dist/ccxt.browser.js +1231 -81
  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/coinex.js +1 -1
  15. package/dist/cjs/src/coinsph.js +1 -2
  16. package/dist/cjs/src/cryptocom.js +30 -0
  17. package/dist/cjs/src/gate.js +56 -3
  18. package/dist/cjs/src/huobi.js +69 -4
  19. package/dist/cjs/src/kraken.js +18 -8
  20. package/dist/cjs/src/krakenfutures.js +24 -0
  21. package/dist/cjs/src/kucoin.js +59 -4
  22. package/dist/cjs/src/kucoinfutures.js +35 -1
  23. package/dist/cjs/src/kuna.js +97 -10
  24. package/dist/cjs/src/okx.js +66 -4
  25. package/dist/cjs/src/poloniex.js +18 -2
  26. package/dist/cjs/src/pro/bitget.js +22 -6
  27. package/js/ccxt.d.ts +1 -1
  28. package/js/ccxt.js +1 -1
  29. package/js/src/abstract/kuna.d.ts +34 -0
  30. package/js/src/base/Exchange.d.ts +7 -0
  31. package/js/src/base/Exchange.js +216 -0
  32. package/js/src/binance.d.ts +5 -5
  33. package/js/src/binance.js +96 -1
  34. package/js/src/bingx.d.ts +1 -1
  35. package/js/src/bingx.js +24 -0
  36. package/js/src/bitfinex2.d.ts +3 -3
  37. package/js/src/bitfinex2.js +56 -12
  38. package/js/src/bitget.d.ts +7 -6
  39. package/js/src/bitget.js +132 -12
  40. package/js/src/bitmex.d.ts +6 -6
  41. package/js/src/bitmex.js +49 -0
  42. package/js/src/bybit.d.ts +6 -6
  43. package/js/src/bybit.js +56 -3
  44. package/js/src/coinbase.d.ts +5 -5
  45. package/js/src/coinbase.js +86 -7
  46. package/js/src/coinbasepro.d.ts +5 -5
  47. package/js/src/coinbasepro.js +18 -0
  48. package/js/src/coinex.js +1 -1
  49. package/js/src/coinsph.js +1 -2
  50. package/js/src/cryptocom.d.ts +4 -4
  51. package/js/src/cryptocom.js +30 -0
  52. package/js/src/gate.d.ts +4 -4
  53. package/js/src/gate.js +56 -3
  54. package/js/src/huobi.d.ts +2 -2
  55. package/js/src/huobi.js +69 -4
  56. package/js/src/kraken.d.ts +2 -2
  57. package/js/src/kraken.js +18 -8
  58. package/js/src/krakenfutures.d.ts +2 -2
  59. package/js/src/krakenfutures.js +24 -0
  60. package/js/src/kucoin.d.ts +5 -5
  61. package/js/src/kucoin.js +59 -4
  62. package/js/src/kucoinfutures.d.ts +4 -4
  63. package/js/src/kucoinfutures.js +35 -1
  64. package/js/src/kuna.d.ts +1 -0
  65. package/js/src/kuna.js +97 -10
  66. package/js/src/okx.d.ts +6 -6
  67. package/js/src/okx.js +66 -4
  68. package/js/src/poloniex.d.ts +1 -1
  69. package/js/src/poloniex.js +18 -2
  70. package/js/src/pro/bitget.d.ts +5 -0
  71. package/js/src/pro/bitget.js +22 -6
  72. package/package.json +1 -1
@@ -397,11 +397,18 @@ class poloniex extends poloniex$1 {
397
397
  * @param {int} [since] timestamp in ms of the earliest candle to fetch
398
398
  * @param {int} [limit] the maximum amount of candles to fetch
399
399
  * @param {object} [params] extra parameters specific to the poloniex api endpoint
400
+ * @param {int} [params.until] timestamp in ms
401
+ * @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)
400
402
  * @returns {int[][]} A list of candles ordered as timestamp, open, high, low, close, volume
401
403
  */
402
404
  await this.loadMarkets();
405
+ let paginate = false;
406
+ [paginate, params] = this.handleOptionAndParams(params, 'fetchOHLCV', 'paginate', false);
407
+ if (paginate) {
408
+ return await this.fetchPaginatedCallDeterministic('fetchOHLCV', symbol, since, limit, timeframe, params, 500);
409
+ }
403
410
  const market = this.market(symbol);
404
- const request = {
411
+ let request = {
405
412
  'symbol': market['id'],
406
413
  'interval': this.safeString(this.timeframes, timeframe, timeframe),
407
414
  };
@@ -412,6 +419,7 @@ class poloniex extends poloniex$1 {
412
419
  // limit should in between 100 and 500
413
420
  request['limit'] = limit;
414
421
  }
422
+ [request, params] = this.handleUntilOption('endTime', request, params);
415
423
  const response = await this.publicGetMarketsSymbolCandles(this.extend(request, params));
416
424
  //
417
425
  // [
@@ -951,14 +959,21 @@ class poloniex extends poloniex$1 {
951
959
  * @param {int} [since] the earliest time in ms to fetch trades for
952
960
  * @param {int} [limit] the maximum number of trades structures to retrieve
953
961
  * @param {object} [params] extra parameters specific to the poloniex api endpoint
962
+ * @param {int} [params.until] the latest time in ms to fetch entries for
963
+ * @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)
954
964
  * @returns {Trade[]} a list of [trade structures]{@link https://github.com/ccxt/ccxt/wiki/Manual#trade-structure}
955
965
  */
956
966
  await this.loadMarkets();
967
+ let paginate = false;
968
+ [paginate, params] = this.handleOptionAndParams(params, 'fetchMyTrades', 'paginate');
969
+ if (paginate) {
970
+ return await this.fetchPaginatedCallDynamic('fetchMyTrades', symbol, since, limit, params);
971
+ }
957
972
  let market = undefined;
958
973
  if (symbol !== undefined) {
959
974
  market = this.market(symbol);
960
975
  }
961
- const request = {
976
+ let request = {
962
977
  // 'from': 12345678, // A 'trade Id'. The query begins at ‘from'.
963
978
  // 'direction': 'PRE', // PRE, NEXT The direction before or after ‘from'.
964
979
  };
@@ -968,6 +983,7 @@ class poloniex extends poloniex$1 {
968
983
  if (limit !== undefined) {
969
984
  request['limit'] = limit;
970
985
  }
986
+ [request, params] = this.handleUntilOption('endTime', request, params);
971
987
  const response = await this.privateGetTrades(this.extend(request, params));
972
988
  //
973
989
  // [
@@ -8,6 +8,11 @@ var sha256 = require('../static_dependencies/noble-hashes/sha256.js');
8
8
 
9
9
  // ---------------------------------------------------------------------------
10
10
  // ---------------------------------------------------------------------------
11
+ /**
12
+ * @class bitget
13
+ * @extends Exchange
14
+ * @description watching delivery future markets is not yet implemented (perpertual future / swap is implemented)
15
+ */
11
16
  class bitget extends bitget$1 {
12
17
  describe() {
13
18
  return this.deepExtend(super.describe(), {
@@ -80,10 +85,10 @@ class bitget extends bitget$1 {
80
85
  }
81
86
  else {
82
87
  if (!sandboxMode) {
83
- return market['id'].replace('_UMCBL', '');
88
+ return market['id'].replace('_UMCBL', '').replace('_DMCBL', '').replace('_CMCBL', '');
84
89
  }
85
90
  else {
86
- return market['id'].replace('_SUMCBL', '');
91
+ return market['id'].replace('_SUMCBL', '').replace('_SDMCBL', '').replace('_SCMCBL', '');
87
92
  }
88
93
  }
89
94
  }
@@ -95,15 +100,24 @@ class bitget extends bitget$1 {
95
100
  const sandboxMode = this.safeValue(this.options, 'sandboxMode', false);
96
101
  let marketId = this.safeString(arg, 'instId');
97
102
  if (instType === 'sp') {
98
- marketId += '_SPBL';
103
+ marketId = marketId + '_SPBL';
99
104
  }
100
105
  else {
101
- if (!sandboxMode) {
102
- marketId += '_UMCBL';
106
+ let extension = sandboxMode ? '_S' : '_';
107
+ const splitByUSDT = marketId.split('USDT');
108
+ const splitByPERP = marketId.split('PERP');
109
+ const splitByUSDTLength = splitByUSDT.length;
110
+ const splitByPERPLength = splitByPERP.length;
111
+ if (splitByUSDTLength > 1) {
112
+ extension += 'UMCBL';
113
+ }
114
+ else if (splitByPERPLength > 1) {
115
+ extension += 'CMCBL';
103
116
  }
104
117
  else {
105
- marketId += '_SUMCBL';
118
+ extension += 'DMCBL';
106
119
  }
120
+ marketId = marketId + extension;
107
121
  }
108
122
  return marketId;
109
123
  }
@@ -606,6 +620,8 @@ class bitget extends bitget$1 {
606
620
  * @method
607
621
  * @name bitget#watchTrades
608
622
  * @description get the list of most recent trades for a particular symbol
623
+ * @see https://bitgetlimited.github.io/apidoc/en/spot/#trades-channel
624
+ * @see https://bitgetlimited.github.io/apidoc/en/mix/#trades-channel
609
625
  * @param {string} symbol unified symbol of the market to fetch trades for
610
626
  * @param {int} [since] timestamp in ms of the earliest trade to fetch
611
627
  * @param {int} [limit] the maximum amount of trades to fetch
package/js/ccxt.d.ts CHANGED
@@ -4,7 +4,7 @@ import * as functions from './src/base/functions.js';
4
4
  import * as errors from './src/base/errors.js';
5
5
  import { Market, Trade, Fee, Ticker, OrderBook, Order, Transaction, Tickers, Currency, Balance, DepositAddress, WithdrawalResponse, DepositAddressResponse, OHLCV, Balances, PartialBalances, Dictionary, MinMax, Position } from './src/base/types.js';
6
6
  import { BaseError, ExchangeError, PermissionDenied, AccountNotEnabled, AccountSuspended, ArgumentsRequired, BadRequest, BadSymbol, MarginModeAlreadySet, BadResponse, NullResponse, InsufficientFunds, InvalidAddress, InvalidOrder, OrderNotFound, OrderNotCached, CancelPending, OrderImmediatelyFillable, OrderNotFillable, DuplicateOrderId, NotSupported, NetworkError, DDoSProtection, RateLimitExceeded, ExchangeNotAvailable, OnMaintenance, InvalidNonce, RequestTimeout, AuthenticationError, AddressPending, NoChange } from './src/base/errors.js';
7
- declare const version = "4.1.3";
7
+ declare const version = "4.1.5";
8
8
  import ace from './src/ace.js';
9
9
  import alpaca from './src/alpaca.js';
10
10
  import ascendex from './src/ascendex.js';
package/js/ccxt.js CHANGED
@@ -38,7 +38,7 @@ import * as errors from './src/base/errors.js';
38
38
  import { BaseError, ExchangeError, PermissionDenied, AccountNotEnabled, AccountSuspended, ArgumentsRequired, BadRequest, BadSymbol, MarginModeAlreadySet, BadResponse, NullResponse, InsufficientFunds, InvalidAddress, InvalidOrder, OrderNotFound, OrderNotCached, CancelPending, OrderImmediatelyFillable, OrderNotFillable, DuplicateOrderId, NotSupported, NetworkError, DDoSProtection, RateLimitExceeded, ExchangeNotAvailable, OnMaintenance, InvalidNonce, RequestTimeout, AuthenticationError, AddressPending, NoChange } from './src/base/errors.js';
39
39
  //-----------------------------------------------------------------------------
40
40
  // this is updated by vss.js when building
41
- const version = '4.1.4';
41
+ const version = '4.1.6';
42
42
  Exchange.ccxtVersion = version;
43
43
  //-----------------------------------------------------------------------------
44
44
  import ace from './src/ace.js';
@@ -5,6 +5,40 @@ interface Exchange {
5
5
  xreserveGetFee(params?: {}): Promise<implicitReturnType>;
6
6
  xreserveGetDelegatedTransactions(params?: {}): Promise<implicitReturnType>;
7
7
  xreservePostDelegateTransfer(params?: {}): Promise<implicitReturnType>;
8
+ v4PrivateGetMe(params?: {}): Promise<implicitReturnType>;
9
+ v4PrivateGetGetBalance(params?: {}): Promise<implicitReturnType>;
10
+ v4PrivateGetActive(params?: {}): Promise<implicitReturnType>;
11
+ v4PrivateGetOrderHistory(params?: {}): Promise<implicitReturnType>;
12
+ v4PrivateGetOrderPrivateIdTrades(params?: {}): Promise<implicitReturnType>;
13
+ v4PrivateGetOrderDetailsIdWithTradesWithTrades(params?: {}): Promise<implicitReturnType>;
14
+ v4PrivateGetTradeHistory(params?: {}): Promise<implicitReturnType>;
15
+ v4PrivateGetTransactionHash(params?: {}): Promise<implicitReturnType>;
16
+ v4PrivateGetDepositPreRequest(params?: {}): Promise<implicitReturnType>;
17
+ v4PrivateGetDepositCryptoAddress(params?: {}): Promise<implicitReturnType>;
18
+ v4PrivateGetDepositCryptoGetMerchantAddress(params?: {}): Promise<implicitReturnType>;
19
+ v4PrivateGetDepositHistory(params?: {}): Promise<implicitReturnType>;
20
+ v4PrivateGetDepositDetailsDepositId(params?: {}): Promise<implicitReturnType>;
21
+ v4PrivateGetWithdrawPreRequest(params?: {}): Promise<implicitReturnType>;
22
+ v4PrivateGetWithdrawHistory(params?: {}): Promise<implicitReturnType>;
23
+ v4PrivateGetWithdrawDetailsWithdrawId(params?: {}): Promise<implicitReturnType>;
24
+ v4PrivateGetKunaCodeId(params?: {}): Promise<implicitReturnType>;
25
+ v4PrivateGetKunaCodeCodeCheck(params?: {}): Promise<implicitReturnType>;
26
+ v4PrivateGetKunaCodeIssuedByMe(params?: {}): Promise<implicitReturnType>;
27
+ v4PrivateGetKunaCodeRedeemedByMe(params?: {}): Promise<implicitReturnType>;
28
+ v4PrivatePostOrderCreate(params?: {}): Promise<implicitReturnType>;
29
+ v4PrivatePostOrderCancel(params?: {}): Promise<implicitReturnType>;
30
+ v4PrivatePostOrderCancelMulti(params?: {}): Promise<implicitReturnType>;
31
+ v4PrivatePostDepositCryptoGenerateAddress(params?: {}): Promise<implicitReturnType>;
32
+ v4PrivatePostDepositCryptoGenerateMerchantAddress(params?: {}): Promise<implicitReturnType>;
33
+ v4PrivatePostWithdrawCreate(params?: {}): Promise<implicitReturnType>;
34
+ v4PrivatePostKunaCode(params?: {}): Promise<implicitReturnType>;
35
+ v4PrivatePutKunaCodeRedeem(params?: {}): Promise<implicitReturnType>;
36
+ v4PublicGetTimestamp(params?: {}): Promise<implicitReturnType>;
37
+ v4PublicGetFees(params?: {}): Promise<implicitReturnType>;
38
+ v4PublicGetCurrenciesTypeType(params?: {}): Promise<implicitReturnType>;
39
+ v4PublicGetMarketsGetAll(params?: {}): Promise<implicitReturnType>;
40
+ v4PublicGetMarketsTickersPairsPairs(params?: {}): Promise<implicitReturnType>;
41
+ v4PublicGetOrderBookPairs(params?: {}): Promise<implicitReturnType>;
8
42
  v3PublicGetTimestamp(params?: {}): Promise<implicitReturnType>;
9
43
  v3PublicGetCurrencies(params?: {}): Promise<implicitReturnType>;
10
44
  v3PublicGetMarkets(params?: {}): Promise<implicitReturnType>;
@@ -805,5 +805,12 @@ export default class Exchange {
805
805
  resolvePromiseIfMessagehashMatches(client: any, prefix: string, symbol: string, data: any): void;
806
806
  resolveMultipleOHLCV(client: any, prefix: string, symbol: string, timeframe: string, data: any): void;
807
807
  createOHLCVObject(symbol: string, timeframe: string, data: any): Dictionary<Dictionary<OHLCV[]>>;
808
+ handleMaxEntriesPerRequestAndParams(method: string, maxEntriesPerRequest?: Int, params?: {}): [Int, any];
809
+ fetchPaginatedCallDynamic(method: string, symbol?: string, since?: Int, limit?: Int, params?: {}, maxEntriesPerRequest?: Int): Promise<any>;
810
+ safeDeterministicCall(method: string, symbol?: string, since?: Int, limit?: Int, timeframe?: string, params?: {}): Promise<any>;
811
+ fetchPaginatedCallDeterministic(method: string, symbol?: string, since?: Int, limit?: Int, timeframe?: string, params?: {}, maxEntriesPerRequest?: any): Promise<any>;
812
+ fetchPaginatedCallCursor(method: string, symbol?: string, since?: any, limit?: any, params?: {}, cursorReceived?: any, cursorSent?: any, cursorIncrement?: any, maxEntriesPerRequest?: any): Promise<any>;
813
+ removeRepeatedElementsFromArray(input: any): any;
814
+ handleUntilOption(key: any, request: any, params: any, multiplier?: number): any[];
808
815
  }
809
816
  export { Exchange, };
@@ -4094,5 +4094,221 @@ export default class Exchange {
4094
4094
  res[symbol][timeframe] = data;
4095
4095
  return res;
4096
4096
  }
4097
+ handleMaxEntriesPerRequestAndParams(method, maxEntriesPerRequest = undefined, params = {}) {
4098
+ let newMaxEntriesPerRequest = undefined;
4099
+ [newMaxEntriesPerRequest, params] = this.handleOptionAndParams(params, method, 'maxEntriesPerRequest');
4100
+ if ((newMaxEntriesPerRequest !== undefined) && (newMaxEntriesPerRequest !== maxEntriesPerRequest)) {
4101
+ maxEntriesPerRequest = newMaxEntriesPerRequest;
4102
+ }
4103
+ if (maxEntriesPerRequest === undefined) {
4104
+ maxEntriesPerRequest = 1000; // default to 1000
4105
+ }
4106
+ return [maxEntriesPerRequest, params];
4107
+ }
4108
+ async fetchPaginatedCallDynamic(method, symbol = undefined, since = undefined, limit = undefined, params = {}, maxEntriesPerRequest = undefined) {
4109
+ let maxCalls = undefined;
4110
+ [maxCalls, params] = this.handleOptionAndParams(params, method, 'paginationCalls', 10);
4111
+ let maxRetries = undefined;
4112
+ [maxRetries, params] = this.handleOptionAndParams(params, method, 'maxRetries', 3);
4113
+ let paginationDirection = undefined;
4114
+ [paginationDirection, params] = this.handleOptionAndParams(params, method, 'paginationDirection', 'backward');
4115
+ let paginationTimestamp = undefined;
4116
+ let calls = 0;
4117
+ let result = [];
4118
+ let errors = 0;
4119
+ const until = this.safeInteger2(params, 'untill', 'till'); // do not omit it from params here
4120
+ [maxEntriesPerRequest, params] = this.handleMaxEntriesPerRequestAndParams(method, maxEntriesPerRequest, params);
4121
+ if ((paginationDirection === 'forward')) {
4122
+ if (since === undefined) {
4123
+ throw new ArgumentsRequired(this.id + ' pagination requires a since argument when paginationDirection set to forward');
4124
+ }
4125
+ paginationTimestamp = since;
4126
+ }
4127
+ while ((calls < maxCalls)) {
4128
+ calls += 1;
4129
+ try {
4130
+ if (paginationDirection === 'backward') {
4131
+ // do it backwards, starting from the last
4132
+ // UNTIL filtering is required in order to work
4133
+ if (paginationTimestamp !== undefined) {
4134
+ params['until'] = paginationTimestamp - 1;
4135
+ }
4136
+ const response = await this[method](symbol, undefined, maxEntriesPerRequest, params);
4137
+ const responseLength = response.length;
4138
+ if (this.verbose) {
4139
+ this.log('Dynamic pagination call', calls, 'method', method, 'response length', responseLength, 'timestamp', paginationTimestamp);
4140
+ }
4141
+ if (responseLength === 0) {
4142
+ break;
4143
+ }
4144
+ errors = 0;
4145
+ result = this.arrayConcat(result, response);
4146
+ const firstElement = this.safeValue(response, 0);
4147
+ paginationTimestamp = this.safeInteger2(firstElement, 'timestamp', 0);
4148
+ if ((since !== undefined) && (paginationTimestamp <= since)) {
4149
+ break;
4150
+ }
4151
+ }
4152
+ else {
4153
+ // do it forwards, starting from the since
4154
+ const response = await this[method](symbol, paginationTimestamp, maxEntriesPerRequest, params);
4155
+ const responseLength = response.length;
4156
+ if (this.verbose) {
4157
+ this.log('Dynamic pagination call', calls, 'method', method, 'response length', responseLength, 'timestamp', paginationTimestamp);
4158
+ }
4159
+ if (responseLength === 0) {
4160
+ break;
4161
+ }
4162
+ errors = 0;
4163
+ result = this.arrayConcat(result, response);
4164
+ const last = this.safeValue(response, responseLength - 1);
4165
+ paginationTimestamp = this.safeInteger(last, 'timestamp') - 1;
4166
+ if ((until !== undefined) && (paginationTimestamp >= until)) {
4167
+ break;
4168
+ }
4169
+ }
4170
+ }
4171
+ catch (e) {
4172
+ errors += 1;
4173
+ if (errors > maxRetries) {
4174
+ throw e;
4175
+ }
4176
+ }
4177
+ }
4178
+ return this.removeRepeatedElementsFromArray(result);
4179
+ }
4180
+ async safeDeterministicCall(method, symbol = undefined, since = undefined, limit = undefined, timeframe = undefined, params = {}) {
4181
+ let maxRetries = undefined;
4182
+ [maxRetries, params] = this.handleOptionAndParams(params, method, 'maxRetries', 3);
4183
+ let errors = 0;
4184
+ try {
4185
+ if (timeframe && method !== 'fetchFundingRateHistory') {
4186
+ return await this[method](symbol, timeframe, since, limit, params);
4187
+ }
4188
+ else {
4189
+ return await this[method](symbol, since, limit, params);
4190
+ }
4191
+ }
4192
+ catch (e) {
4193
+ if (e instanceof RateLimitExceeded) {
4194
+ throw e; // if we are rate limited, we should not retry and fail fast
4195
+ }
4196
+ errors += 1;
4197
+ if (errors > maxRetries) {
4198
+ throw e;
4199
+ }
4200
+ }
4201
+ }
4202
+ async fetchPaginatedCallDeterministic(method, symbol = undefined, since = undefined, limit = undefined, timeframe = undefined, params = {}, maxEntriesPerRequest = undefined) {
4203
+ let maxCalls = undefined;
4204
+ [maxCalls, params] = this.handleOptionAndParams(params, method, 'paginationCalls', 10);
4205
+ [maxEntriesPerRequest, params] = this.handleMaxEntriesPerRequestAndParams(method, maxEntriesPerRequest, params);
4206
+ const current = this.milliseconds();
4207
+ const tasks = [];
4208
+ const time = this.parseTimeframe(timeframe) * 1000;
4209
+ const step = time * maxEntriesPerRequest;
4210
+ let currentSince = current - (maxCalls * step) - 1;
4211
+ if (since !== undefined) {
4212
+ currentSince = Math.max(currentSince, since);
4213
+ }
4214
+ const until = this.safeInteger2(params, 'until', 'till'); // do not omit it here
4215
+ if (until !== undefined) {
4216
+ const requiredCalls = Math.ceil((until - since) / step);
4217
+ if (requiredCalls > maxCalls) {
4218
+ throw new BadRequest(this.id + ' the number of required calls is greater than the max number of calls allowed, either increase the paginationCalls or decrease the since-until gap. Current paginationCalls limit is ' + maxCalls.toString() + ' required calls is ' + requiredCalls.toString());
4219
+ }
4220
+ }
4221
+ for (let i = 0; i < maxCalls; i++) {
4222
+ if ((until !== undefined) && (currentSince >= until)) {
4223
+ break;
4224
+ }
4225
+ tasks.push(this.safeDeterministicCall(method, symbol, currentSince, maxEntriesPerRequest, timeframe, params));
4226
+ currentSince = this.sum(currentSince, step) - 1;
4227
+ }
4228
+ const results = await Promise.all(tasks);
4229
+ let result = [];
4230
+ for (let i = 0; i < results.length; i++) {
4231
+ result = this.arrayConcat(result, results[i]);
4232
+ }
4233
+ return this.removeRepeatedElementsFromArray(result);
4234
+ }
4235
+ async fetchPaginatedCallCursor(method, symbol = undefined, since = undefined, limit = undefined, params = {}, cursorReceived = undefined, cursorSent = undefined, cursorIncrement = undefined, maxEntriesPerRequest = undefined) {
4236
+ let maxCalls = undefined;
4237
+ [maxCalls, params] = this.handleOptionAndParams(params, method, 'paginationCalls', 10);
4238
+ let maxRetries = undefined;
4239
+ [maxRetries, params] = this.handleOptionAndParams(params, method, 'maxRetries', 3);
4240
+ [maxEntriesPerRequest, params] = this.handleMaxEntriesPerRequestAndParams(method, maxEntriesPerRequest, params);
4241
+ let cursorValue = undefined;
4242
+ let i = 0;
4243
+ let errors = 0;
4244
+ let result = [];
4245
+ while (i < maxCalls) {
4246
+ try {
4247
+ if (cursorValue !== undefined) {
4248
+ if (cursorIncrement !== undefined) {
4249
+ cursorValue = this.parseToInt(cursorValue) + cursorIncrement;
4250
+ }
4251
+ params[cursorSent] = cursorValue;
4252
+ }
4253
+ const response = await this[method](symbol, since, maxEntriesPerRequest, params);
4254
+ errors = 0;
4255
+ const responseLength = response.length;
4256
+ if (this.verbose) {
4257
+ this.log('Cursor pagination call', i + 1, 'method', method, 'response length', responseLength, 'cursor', cursorValue);
4258
+ }
4259
+ if (responseLength === 0) {
4260
+ break;
4261
+ }
4262
+ result = this.arrayConcat(result, response);
4263
+ const last = this.safeValue(response, responseLength - 1);
4264
+ cursorValue = this.safeValue(last['info'], cursorReceived);
4265
+ if (cursorValue === undefined) {
4266
+ break;
4267
+ }
4268
+ }
4269
+ catch (e) {
4270
+ errors += 1;
4271
+ if (errors > maxRetries) {
4272
+ throw e;
4273
+ }
4274
+ }
4275
+ i += 1;
4276
+ }
4277
+ return result;
4278
+ }
4279
+ removeRepeatedElementsFromArray(input) {
4280
+ const uniqueResult = {};
4281
+ for (let i = 0; i < input.length; i++) {
4282
+ const entry = input[i];
4283
+ const id = this.safeString(entry, 'id');
4284
+ if (id !== undefined) {
4285
+ if (this.safeString(uniqueResult, id) === undefined) {
4286
+ uniqueResult[id] = entry;
4287
+ }
4288
+ }
4289
+ else {
4290
+ const timestamp = this.safeInteger2(entry, 'timestamp', 0);
4291
+ if (timestamp !== undefined) {
4292
+ if (this.safeString(uniqueResult, timestamp) === undefined) {
4293
+ uniqueResult[timestamp] = entry;
4294
+ }
4295
+ }
4296
+ }
4297
+ }
4298
+ const values = Object.values(uniqueResult);
4299
+ const valuesLength = values.length;
4300
+ if (valuesLength > 0) {
4301
+ return values;
4302
+ }
4303
+ return input;
4304
+ }
4305
+ handleUntilOption(key, request, params, multiplier = 1) {
4306
+ const until = this.safeValue2(params, 'until', 'till');
4307
+ if (until !== undefined) {
4308
+ request[key] = this.parseToInt(until * multiplier);
4309
+ params = this.omit(params, ['until', 'till']);
4310
+ }
4311
+ return [request, params];
4312
+ }
4097
4313
  }
4098
4314
  export { Exchange, };
@@ -97,7 +97,7 @@ export default class binance extends Exchange {
97
97
  };
98
98
  fetchTickers(symbols?: string[], params?: {}): Promise<import("./base/types.js").Dictionary<import("./base/types.js").Ticker>>;
99
99
  parseOHLCV(ohlcv: any, market?: any): number[];
100
- fetchOHLCV(symbol: string, timeframe?: string, since?: Int, limit?: Int, params?: {}): Promise<import("./base/types.js").OHLCV[]>;
100
+ fetchOHLCV(symbol: string, timeframe?: string, since?: Int, limit?: Int, params?: {}): Promise<any>;
101
101
  parseTrade(trade: any, market?: any): import("./base/types.js").Trade | {
102
102
  id: any;
103
103
  timestamp: number;
@@ -116,7 +116,7 @@ export default class binance extends Exchange {
116
116
  };
117
117
  info: any;
118
118
  };
119
- fetchTrades(symbol: string, since?: Int, limit?: Int, params?: {}): Promise<import("./base/types.js").Trade[]>;
119
+ fetchTrades(symbol: string, since?: Int, limit?: Int, params?: {}): Promise<any>;
120
120
  editSpotOrder(id: string, symbol: any, type: any, side: any, amount: any, price?: any, params?: {}): Promise<import("./base/types.js").Order>;
121
121
  editSpotOrderRequest(id: string, symbol: any, type: any, side: any, amount: any, price?: any, params?: {}): any;
122
122
  editContractOrder(id: string, symbol: any, type: any, side: any, amount: any, price?: any, params?: {}): Promise<import("./base/types.js").Order>;
@@ -126,15 +126,15 @@ export default class binance extends Exchange {
126
126
  createOrder(symbol: string, type: OrderType, side: OrderSide, amount: any, price?: any, params?: {}): Promise<import("./base/types.js").Order>;
127
127
  createOrderRequest(symbol: string, type: OrderType, side: OrderSide, amount: any, price?: any, params?: {}): any;
128
128
  fetchOrder(id: string, symbol?: string, params?: {}): Promise<import("./base/types.js").Order>;
129
- fetchOrders(symbol?: string, since?: Int, limit?: Int, params?: {}): Promise<import("./base/types.js").Order[]>;
129
+ fetchOrders(symbol?: string, since?: Int, limit?: Int, params?: {}): Promise<any>;
130
130
  fetchOpenOrders(symbol?: string, since?: Int, limit?: Int, params?: {}): Promise<import("./base/types.js").Order[]>;
131
131
  fetchClosedOrders(symbol?: string, since?: Int, limit?: Int, params?: {}): Promise<any[]>;
132
132
  fetchCanceledOrders(symbol?: string, since?: Int, limit?: Int, params?: {}): Promise<any>;
133
133
  cancelOrder(id: string, symbol?: string, params?: {}): Promise<import("./base/types.js").Order>;
134
134
  cancelAllOrders(symbol?: string, params?: {}): Promise<any>;
135
135
  cancelOrders(ids: Int[], symbol?: string, params?: {}): Promise<import("./base/types.js").Order[]>;
136
- fetchOrderTrades(id: string, symbol?: string, since?: Int, limit?: Int, params?: {}): Promise<import("./base/types.js").Trade[]>;
137
- fetchMyTrades(symbol?: string, since?: Int, limit?: Int, params?: {}): Promise<import("./base/types.js").Trade[]>;
136
+ fetchOrderTrades(id: string, symbol?: string, since?: Int, limit?: Int, params?: {}): Promise<any>;
137
+ fetchMyTrades(symbol?: string, since?: Int, limit?: Int, params?: {}): Promise<any>;
138
138
  fetchMyDustTrades(symbol?: string, since?: Int, limit?: Int, params?: {}): Promise<any>;
139
139
  parseDustTrade(trade: any, market?: any): {
140
140
  id: any;