ccxt 4.2.87 → 4.2.88

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.
package/dist/cjs/ccxt.js CHANGED
@@ -182,7 +182,7 @@ var woo$1 = require('./src/pro/woo.js');
182
182
 
183
183
  //-----------------------------------------------------------------------------
184
184
  // this is updated by vss.js when building
185
- const version = '4.2.87';
185
+ const version = '4.2.88';
186
186
  Exchange["default"].ccxtVersion = version;
187
187
  const exchanges = {
188
188
  'ace': ace,
@@ -374,8 +374,10 @@ exports.BadResponse = errors.BadResponse;
374
374
  exports.BadSymbol = errors.BadSymbol;
375
375
  exports.BaseError = errors.BaseError;
376
376
  exports.CancelPending = errors.CancelPending;
377
+ exports.ContractUnavailable = errors.ContractUnavailable;
377
378
  exports.DDoSProtection = errors.DDoSProtection;
378
379
  exports.DuplicateOrderId = errors.DuplicateOrderId;
380
+ exports.ExchangeClosedByUser = errors.ExchangeClosedByUser;
379
381
  exports.ExchangeError = errors.ExchangeError;
380
382
  exports.ExchangeNotAvailable = errors.ExchangeNotAvailable;
381
383
  exports.InsufficientFunds = errors.InsufficientFunds;
@@ -388,11 +390,14 @@ exports.NoChange = errors.NoChange;
388
390
  exports.NotSupported = errors.NotSupported;
389
391
  exports.NullResponse = errors.NullResponse;
390
392
  exports.OnMaintenance = errors.OnMaintenance;
393
+ exports.OperationFailed = errors.OperationFailed;
394
+ exports.OperationRejected = errors.OperationRejected;
391
395
  exports.OrderImmediatelyFillable = errors.OrderImmediatelyFillable;
392
396
  exports.OrderNotCached = errors.OrderNotCached;
393
397
  exports.OrderNotFillable = errors.OrderNotFillable;
394
398
  exports.OrderNotFound = errors.OrderNotFound;
395
399
  exports.PermissionDenied = errors.PermissionDenied;
400
+ exports.ProxyError = errors.ProxyError;
396
401
  exports.RateLimitExceeded = errors.RateLimitExceeded;
397
402
  exports.RequestTimeout = errors.RequestTimeout;
398
403
  exports.errors = errors;
@@ -4720,6 +4720,30 @@ class Exchange {
4720
4720
  }
4721
4721
  return parsedPrecision + '1';
4722
4722
  }
4723
+ integerPrecisionToAmount(precision) {
4724
+ /**
4725
+ * @ignore
4726
+ * @method
4727
+ * @description handles positive & negative numbers too. parsePrecision() does not handle negative numbers, but this method handles
4728
+ * @param {string} precision The number of digits to the right of the decimal
4729
+ * @returns {string} a string number equal to 1e-precision
4730
+ */
4731
+ if (precision === undefined) {
4732
+ return undefined;
4733
+ }
4734
+ if (Precise["default"].stringGe(precision, '0')) {
4735
+ return this.parsePrecision(precision);
4736
+ }
4737
+ else {
4738
+ const positivePrecisionString = Precise["default"].stringAbs(precision);
4739
+ const positivePrecision = parseInt(positivePrecisionString);
4740
+ let parsedPrecision = '1';
4741
+ for (let i = 0; i < positivePrecision - 1; i++) {
4742
+ parsedPrecision = parsedPrecision + '0';
4743
+ }
4744
+ return parsedPrecision + '0';
4745
+ }
4746
+ }
4723
4747
  async loadTimeDifference(params = {}) {
4724
4748
  const serverTime = await this.fetchTime(params);
4725
4749
  const after = this.milliseconds();
@@ -5200,8 +5224,8 @@ class Exchange {
5200
5224
  const entry = responseKeys[i];
5201
5225
  const dictionary = isArray ? entry : response[entry];
5202
5226
  const currencyId = isArray ? this.safeString(dictionary, currencyIdKey) : entry;
5203
- const currency = this.safeValue(this.currencies_by_id, currencyId);
5204
- const code = this.safeString(currency, 'code', currencyId);
5227
+ const currency = this.safeCurrency(currencyId);
5228
+ const code = this.safeString(currency, 'code');
5205
5229
  if ((codes === undefined) || (this.inArray(code, codes))) {
5206
5230
  depositWithdrawFees[code] = this.parseDepositWithdrawFee(dictionary, currency);
5207
5231
  }
@@ -1860,7 +1860,7 @@ class binance extends binance$1 {
1860
1860
  '-4140': errors.BadRequest,
1861
1861
  '-4141': errors.OperationRejected,
1862
1862
  '-4144': errors.BadSymbol,
1863
- '-4164': errors.OperationRejected,
1863
+ '-4164': errors.InvalidOrder,
1864
1864
  '-4165': errors.BadRequest,
1865
1865
  '-4167': errors.BadRequest,
1866
1866
  '-4168': errors.BadRequest,
@@ -9140,7 +9140,7 @@ class binance extends binance$1 {
9140
9140
  'previousFundingDatetime': undefined,
9141
9141
  };
9142
9142
  }
9143
- parseAccountPositions(account) {
9143
+ parseAccountPositions(account, filterClosed = false) {
9144
9144
  const positions = this.safeList(account, 'positions');
9145
9145
  const assets = this.safeList(account, 'assets', []);
9146
9146
  const balances = {};
@@ -9163,7 +9163,8 @@ class binance extends binance$1 {
9163
9163
  const code = market['linear'] ? market['quote'] : market['base'];
9164
9164
  const maintenanceMargin = this.safeString(position, 'maintMargin');
9165
9165
  // check for maintenance margin so empty positions are not returned
9166
- if ((maintenanceMargin !== '0') && (maintenanceMargin !== '0.00000000')) {
9166
+ const isPositionOpen = (maintenanceMargin !== '0') && (maintenanceMargin !== '0.00000000');
9167
+ if (!filterClosed || isPositionOpen) {
9167
9168
  // sometimes not all the codes are correctly returned...
9168
9169
  if (code in balances) {
9169
9170
  const parsed = this.parseAccountPosition(this.extend(position, {
@@ -10005,10 +10006,11 @@ class binance extends binance$1 {
10005
10006
  * @see https://binance-docs.github.io/apidocs/delivery/en/#account-information-user_data
10006
10007
  * @see https://binance-docs.github.io/apidocs/pm/en/#get-um-account-detail-user_data
10007
10008
  * @see https://binance-docs.github.io/apidocs/pm/en/#get-cm-account-detail-user_data
10008
- * @param {string[]|undefined} symbols list of unified market symbols
10009
+ * @param {string[]} [symbols] list of unified market symbols
10009
10010
  * @param {object} [params] extra parameters specific to the exchange API endpoint
10010
10011
  * @param {boolean} [params.portfolioMargin] set to true if you would like to fetch positions in a portfolio margin account
10011
10012
  * @param {string} [params.subType] "linear" or "inverse"
10013
+ * @param {boolean} [params.filterClosed] set to true if you would like to filter out closed positions, default is false
10012
10014
  * @returns {object} data on account positions
10013
10015
  */
10014
10016
  if (symbols !== undefined) {
@@ -10045,7 +10047,9 @@ class binance extends binance$1 {
10045
10047
  else {
10046
10048
  throw new errors.NotSupported(this.id + ' fetchPositions() supports linear and inverse contracts only');
10047
10049
  }
10048
- const result = this.parseAccountPositions(response);
10050
+ let filterClosed = undefined;
10051
+ [filterClosed, params] = this.handleOptionAndParams(params, 'fetchAccountPositions', 'filterClosed', false);
10052
+ const result = this.parseAccountPositions(response, filterClosed);
10049
10053
  symbols = this.marketSymbols(symbols);
10050
10054
  return this.filterByArrayPositions(result, 'symbol', symbols, false);
10051
10055
  }
@@ -11183,7 +11187,7 @@ class binance extends binance$1 {
11183
11187
  }
11184
11188
  await this.loadMarkets();
11185
11189
  const market = this.market(symbol);
11186
- amount = this.costToPrecision(symbol, amount);
11190
+ amount = this.amountToPrecision(symbol, amount);
11187
11191
  const request = {
11188
11192
  'type': addOrReduce,
11189
11193
  'symbol': market['id'],
@@ -1295,6 +1295,7 @@ class bitget extends bitget$1 {
1295
1295
  'commonCurrencies': {
1296
1296
  'JADE': 'Jade Protocol',
1297
1297
  'DEGEN': 'DegenReborn',
1298
+ 'TONCOIN': 'TON',
1298
1299
  },
1299
1300
  'options': {
1300
1301
  'timeframes': {
@@ -1874,8 +1875,8 @@ class bitget extends bitget$1 {
1874
1875
  const data = this.safeValue(response, 'data', []);
1875
1876
  for (let i = 0; i < data.length; i++) {
1876
1877
  const entry = data[i];
1877
- const id = this.safeString(entry, 'coinId');
1878
- const code = this.safeCurrencyCode(this.safeString(entry, 'coin'));
1878
+ const id = this.safeString(entry, 'coin'); // we don't use 'coinId' as it has no use. it is 'coin' field that needs to be used in currency related endpoints (deposit, withdraw, etc..)
1879
+ const code = this.safeCurrencyCode(id);
1879
1880
  const chains = this.safeValue(entry, 'chains', []);
1880
1881
  const networks = {};
1881
1882
  let deposit = false;
@@ -2004,7 +2005,7 @@ class bitget extends bitget$1 {
2004
2005
  }
2005
2006
  params = this.omit(params, 'code');
2006
2007
  const currency = this.currency(code);
2007
- request['coin'] = currency['code'];
2008
+ request['coin'] = currency['id'];
2008
2009
  response = await this.privateMarginGetV2MarginCrossedTierData(this.extend(request, params));
2009
2010
  }
2010
2011
  else {
@@ -2160,7 +2161,7 @@ class bitget extends bitget$1 {
2160
2161
  since = this.milliseconds() - 7776000000; // 90 days
2161
2162
  }
2162
2163
  let request = {
2163
- 'coin': currency['code'],
2164
+ 'coin': currency['id'],
2164
2165
  'startTime': since,
2165
2166
  'endTime': this.milliseconds(),
2166
2167
  };
@@ -2219,7 +2220,7 @@ class bitget extends bitget$1 {
2219
2220
  const currency = this.currency(code);
2220
2221
  const networkId = this.networkCodeToId(chain);
2221
2222
  const request = {
2222
- 'coin': currency['code'],
2223
+ 'coin': currency['id'],
2223
2224
  'address': address,
2224
2225
  'chain': networkId,
2225
2226
  'size': amount,
@@ -2305,7 +2306,7 @@ class bitget extends bitget$1 {
2305
2306
  since = this.milliseconds() - 7776000000; // 90 days
2306
2307
  }
2307
2308
  let request = {
2308
- 'coin': currency['code'],
2309
+ 'coin': currency['id'],
2309
2310
  'startTime': since,
2310
2311
  'endTime': this.milliseconds(),
2311
2312
  };
@@ -2448,7 +2449,7 @@ class bitget extends bitget$1 {
2448
2449
  }
2449
2450
  const currency = this.currency(code);
2450
2451
  const request = {
2451
- 'coin': currency['code'],
2452
+ 'coin': currency['id'],
2452
2453
  };
2453
2454
  if (networkId !== undefined) {
2454
2455
  request['chain'] = networkId;
@@ -5901,7 +5902,7 @@ class bitget extends bitget$1 {
5901
5902
  let request = {};
5902
5903
  if (code !== undefined) {
5903
5904
  currency = this.currency(code);
5904
- request['coin'] = currency['code'];
5905
+ request['coin'] = currency['id'];
5905
5906
  }
5906
5907
  [request, params] = this.handleUntilOption('endTime', request, params);
5907
5908
  if (since !== undefined) {
@@ -7340,7 +7341,7 @@ class bitget extends bitget$1 {
7340
7341
  type = this.safeString(accountsByType, fromAccount);
7341
7342
  const currency = this.currency(code);
7342
7343
  let request = {
7343
- 'coin': currency['code'],
7344
+ 'coin': currency['id'],
7344
7345
  'fromType': type,
7345
7346
  };
7346
7347
  if (since !== undefined) {
@@ -7399,7 +7400,7 @@ class bitget extends bitget$1 {
7399
7400
  'fromType': fromType,
7400
7401
  'toType': toType,
7401
7402
  'amount': amount,
7402
- 'coin': currency['code'],
7403
+ 'coin': currency['id'],
7403
7404
  };
7404
7405
  const symbol = this.safeString(params, 'symbol');
7405
7406
  params = this.omit(params, 'symbol');
@@ -7586,7 +7587,7 @@ class bitget extends bitget$1 {
7586
7587
  await this.loadMarkets();
7587
7588
  const currency = this.currency(code);
7588
7589
  const request = {
7589
- 'coin': currency['code'],
7590
+ 'coin': currency['id'],
7590
7591
  'borrowAmount': this.currencyToPrecision(code, amount),
7591
7592
  };
7592
7593
  const response = await this.privateMarginPostV2MarginCrossedAccountBorrow(this.extend(request, params));
@@ -7621,7 +7622,7 @@ class bitget extends bitget$1 {
7621
7622
  const currency = this.currency(code);
7622
7623
  const market = this.market(symbol);
7623
7624
  const request = {
7624
- 'coin': currency['code'],
7625
+ 'coin': currency['id'],
7625
7626
  'borrowAmount': this.currencyToPrecision(code, amount),
7626
7627
  'symbol': market['id'],
7627
7628
  };
@@ -7658,7 +7659,7 @@ class bitget extends bitget$1 {
7658
7659
  const currency = this.currency(code);
7659
7660
  const market = this.market(symbol);
7660
7661
  const request = {
7661
- 'coin': currency['code'],
7662
+ 'coin': currency['id'],
7662
7663
  'repayAmount': this.currencyToPrecision(code, amount),
7663
7664
  'symbol': market['id'],
7664
7665
  };
@@ -7694,7 +7695,7 @@ class bitget extends bitget$1 {
7694
7695
  await this.loadMarkets();
7695
7696
  const currency = this.currency(code);
7696
7697
  const request = {
7697
- 'coin': currency['code'],
7698
+ 'coin': currency['id'],
7698
7699
  'repayAmount': this.currencyToPrecision(code, amount),
7699
7700
  };
7700
7701
  const response = await this.privateMarginPostV2MarginCrossedAccountRepay(this.extend(request, params));
@@ -8056,7 +8057,7 @@ class bitget extends bitget$1 {
8056
8057
  await this.loadMarkets();
8057
8058
  const currency = this.currency(code);
8058
8059
  const request = {
8059
- 'coin': currency['code'],
8060
+ 'coin': currency['id'],
8060
8061
  };
8061
8062
  const response = await this.privateMarginGetV2MarginCrossedInterestRateAndLimit(this.extend(request, params));
8062
8063
  //
@@ -8151,7 +8152,7 @@ class bitget extends bitget$1 {
8151
8152
  let currency = undefined;
8152
8153
  if (code !== undefined) {
8153
8154
  currency = this.currency(code);
8154
- request['coin'] = currency['code'];
8155
+ request['coin'] = currency['id'];
8155
8156
  }
8156
8157
  if (since !== undefined) {
8157
8158
  request['startTime'] = since;
@@ -2755,7 +2755,7 @@ class cryptocom extends cryptocom$1 {
2755
2755
  //
2756
2756
  const result = this.safeDict(response, 'result', {});
2757
2757
  const data = this.safeList(result, 'data', []);
2758
- return this.parsePosition(data[0], market);
2758
+ return this.parsePosition(this.safeDict(data, 0), market);
2759
2759
  }
2760
2760
  async fetchPositions(symbols = undefined, params = {}) {
2761
2761
  /**
@@ -1859,7 +1859,7 @@ class gate extends gate$1 {
1859
1859
  await this.loadMarkets();
1860
1860
  const currency = this.currency(code);
1861
1861
  const request = {
1862
- 'currency': currency['id'],
1862
+ 'currency': currency['id'], // todo: currencies have network-junctions
1863
1863
  };
1864
1864
  const response = await this.privateWalletGetDepositAddress(this.extend(request, params));
1865
1865
  const addresses = this.safeValue(response, 'multichain_addresses');
@@ -1910,7 +1910,7 @@ class gate extends gate$1 {
1910
1910
  const rawNetwork = this.safeStringUpper(params, 'network');
1911
1911
  params = this.omit(params, 'network');
1912
1912
  const request = {
1913
- 'currency': currency['id'],
1913
+ 'currency': currency['id'], // todo: currencies have network-junctions
1914
1914
  };
1915
1915
  const response = await this.privateWalletGetDepositAddress(this.extend(request, params));
1916
1916
  //
@@ -3526,7 +3526,7 @@ class gate extends gate$1 {
3526
3526
  let currency = undefined;
3527
3527
  if (code !== undefined) {
3528
3528
  currency = this.currency(code);
3529
- request['currency'] = currency['id'];
3529
+ request['currency'] = currency['id']; // todo: currencies have network-junctions
3530
3530
  }
3531
3531
  if (limit !== undefined) {
3532
3532
  request['limit'] = limit;
@@ -3564,7 +3564,7 @@ class gate extends gate$1 {
3564
3564
  let currency = undefined;
3565
3565
  if (code !== undefined) {
3566
3566
  currency = this.currency(code);
3567
- request['currency'] = currency['id'];
3567
+ request['currency'] = currency['id']; // todo: currencies have network-junctions
3568
3568
  }
3569
3569
  if (limit !== undefined) {
3570
3570
  request['limit'] = limit;
@@ -3611,7 +3611,7 @@ class gate extends gate$1 {
3611
3611
  params = this.omit(params, 'network');
3612
3612
  }
3613
3613
  else {
3614
- request['chain'] = currency['id'];
3614
+ request['chain'] = currency['id']; // todo: currencies have network-junctions
3615
3615
  }
3616
3616
  const response = await this.privateWithdrawalsPostWithdrawals(this.extend(request, params));
3617
3617
  //
@@ -5145,7 +5145,7 @@ class gate extends gate$1 {
5145
5145
  params = this.omit(params, 'symbol');
5146
5146
  }
5147
5147
  if ((toId === 'futures') || (toId === 'delivery') || (fromId === 'futures') || (fromId === 'delivery')) {
5148
- request['settle'] = currency['id'];
5148
+ request['settle'] = currency['id']; // todo: currencies have network-junctions
5149
5149
  }
5150
5150
  const response = await this.privateWalletPostTransfers(this.extend(request, params));
5151
5151
  //
@@ -6453,7 +6453,7 @@ class gate extends gate$1 {
6453
6453
  if ((type === 'spot') || (type === 'margin')) {
6454
6454
  if (code !== undefined) {
6455
6455
  currency = this.currency(code);
6456
- request['currency'] = currency['id'];
6456
+ request['currency'] = currency['id']; // todo: currencies have network-junctions
6457
6457
  }
6458
6458
  }
6459
6459
  if ((type === 'swap') || (type === 'future')) {
@@ -7272,7 +7272,7 @@ class gate extends gate$1 {
7272
7272
  await this.loadMarkets();
7273
7273
  const currency = this.currency(code);
7274
7274
  const request = {
7275
- 'underlying': currency['code'] + '_USDT',
7275
+ 'underlying': currency['code'] + '_USDT', // todo: currency['id'].toUpperCase () & network junctions
7276
7276
  };
7277
7277
  const response = await this.publicOptionsGetContracts(this.extend(request, params));
7278
7278
  //
@@ -352,7 +352,8 @@ class krakenfutures extends krakenfutures$1 {
352
352
  // swap == perpetual
353
353
  let settle = undefined;
354
354
  let settleId = undefined;
355
- const amountPrecision = this.parseNumber(this.parsePrecision(this.safeString(market, 'contractValueTradePrecision', '0')));
355
+ const cvtp = this.safeString(market, 'contractValueTradePrecision');
356
+ const amountPrecision = this.parseNumber(this.integerPrecisionToAmount(cvtp));
356
357
  const pricePrecision = this.safeNumber(market, 'tickSize');
357
358
  const contract = (swap || future || index);
358
359
  const swapOrFutures = (swap || future);
@@ -3537,9 +3537,9 @@ class kucoin extends kucoin$1 {
3537
3537
  * @method
3538
3538
  * @name kucoin#fetchBalance
3539
3539
  * @description query for balance and get the amount of funds available for trading or funds locked in orders
3540
- * @see https://docs.kucoin.com/#list-accounts
3541
3540
  * @see https://www.kucoin.com/docs/rest/account/basic-info/get-account-list-spot-margin-trade_hf
3542
- * @see https://docs.kucoin.com/#query-isolated-margin-account-info
3541
+ * @see https://www.kucoin.com/docs/rest/funding/funding-overview/get-account-detail-margin
3542
+ * @see https://www.kucoin.com/docs/rest/funding/funding-overview/get-account-detail-isolated-margin
3543
3543
  * @param {object} [params] extra parameters specific to the exchange API endpoint
3544
3544
  * @param {object} [params.marginMode] 'cross' or 'isolated', margin type for fetching margin balance
3545
3545
  * @param {object} [params.type] extra parameters specific to the exchange API endpoint
@@ -3566,7 +3566,7 @@ class kucoin extends kucoin$1 {
3566
3566
  let response = undefined;
3567
3567
  const request = {};
3568
3568
  const isolated = (marginMode === 'isolated') || (type === 'isolated');
3569
- const cross = (marginMode === 'cross') || (type === 'cross');
3569
+ const cross = (marginMode === 'cross') || (type === 'margin');
3570
3570
  if (isolated) {
3571
3571
  if (currency !== undefined) {
3572
3572
  request['balanceCurrency'] = currency['id'];
@@ -3636,13 +3636,14 @@ class kucoin extends kucoin$1 {
3636
3636
  // }
3637
3637
  // }
3638
3638
  //
3639
- const data = this.safeList(response, 'data', []);
3639
+ let data = undefined;
3640
3640
  const result = {
3641
3641
  'info': response,
3642
3642
  'timestamp': undefined,
3643
3643
  'datetime': undefined,
3644
3644
  };
3645
3645
  if (isolated) {
3646
+ data = this.safeDict(response, 'data', {});
3646
3647
  const assets = this.safeValue(data, 'assets', data);
3647
3648
  for (let i = 0; i < assets.length; i++) {
3648
3649
  const entry = assets[i];
@@ -3659,6 +3660,7 @@ class kucoin extends kucoin$1 {
3659
3660
  }
3660
3661
  }
3661
3662
  else if (cross) {
3663
+ data = this.safeDict(response, 'data', {});
3662
3664
  const accounts = this.safeList(data, 'accounts', []);
3663
3665
  for (let i = 0; i < accounts.length; i++) {
3664
3666
  const balance = accounts[i];
@@ -3668,6 +3670,7 @@ class kucoin extends kucoin$1 {
3668
3670
  }
3669
3671
  }
3670
3672
  else {
3673
+ data = this.safeList(response, 'data', []);
3671
3674
  for (let i = 0; i < data.length; i++) {
3672
3675
  const balance = data[i];
3673
3676
  const balanceType = this.safeString(balance, 'type');
@@ -4511,7 +4511,7 @@ class mexc extends mexc$1 {
4511
4511
  }
4512
4512
  }
4513
4513
  if (result === undefined) {
4514
- throw new errors.InvalidAddress(this.id + ' fetchDepositAddress() cannot find a deposit address for ' + code + ', and network' + network + 'consider creating one using the MEXC platform');
4514
+ throw new errors.InvalidAddress(this.id + ' fetchDepositAddress() cannot find a deposit address for ' + code + ', and network' + network + 'consider creating one using .createDepositAddress() method or in MEXC website');
4515
4515
  }
4516
4516
  return result;
4517
4517
  }
@@ -4,8 +4,6 @@ import path from 'path'
4
4
  import ansi from 'ansicolor'
5
5
  import asTable from 'as-table'
6
6
  import ololog from 'ololog'
7
- import util from 'util'
8
- import { execSync } from 'child_process'
9
7
  import ccxt from '../../js/ccxt.js'
10
8
  import { Agent } from 'https'
11
9
 
@@ -3,8 +3,6 @@ import path from 'path'
3
3
  import ansi from 'ansicolor'
4
4
  import asTable from 'as-table'
5
5
  import ololog from 'ololog'
6
- import util from 'util'
7
- import { execSync } from 'child_process'
8
6
  import ccxt from '../../ts/ccxt.js'
9
7
  import { Agent } from 'https'
10
8
 
package/js/ccxt.d.ts CHANGED
@@ -3,8 +3,8 @@ import { Precise } from './src/base/Precise.js';
3
3
  import * as functions from './src/base/functions.js';
4
4
  import * as errors from './src/base/errors.js';
5
5
  import type { Market, Trade, Fee, Ticker, OrderBook, Order, Transaction, Tickers, Currency, Balance, DepositAddress, WithdrawalResponse, DepositAddressResponse, OHLCV, Balances, PartialBalances, Dictionary, MinMax, Position, FundingRateHistory, Liquidation, FundingHistory, MarginMode, Greeks, Leverage, Leverages, Option, OptionChain } from './src/base/types.js';
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.2.86";
6
+ import { BaseError, ExchangeError, AuthenticationError, PermissionDenied, AccountNotEnabled, AccountSuspended, ArgumentsRequired, BadRequest, BadSymbol, OperationRejected, NoChange, MarginModeAlreadySet, BadResponse, NullResponse, InsufficientFunds, InvalidAddress, AddressPending, InvalidOrder, OrderNotFound, OrderNotCached, CancelPending, OrderImmediatelyFillable, OrderNotFillable, DuplicateOrderId, ContractUnavailable, NotSupported, ProxyError, OperationFailed, NetworkError, DDoSProtection, RateLimitExceeded, ExchangeNotAvailable, OnMaintenance, InvalidNonce, RequestTimeout, ExchangeClosedByUser } from './src/base/errors.js';
7
+ declare const version = "4.2.87";
8
8
  import ace from './src/ace.js';
9
9
  import alpaca from './src/alpaca.js';
10
10
  import ascendex from './src/ascendex.js';
@@ -519,5 +519,5 @@ declare const ccxt: {
519
519
  zaif: typeof zaif;
520
520
  zonda: typeof zonda;
521
521
  } & typeof functions & typeof errors;
522
- export { version, Exchange, exchanges, pro, Precise, functions, errors, 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, Market, Trade, Fee, Ticker, OrderBook, Order, Transaction, Tickers, Currency, Balance, DepositAddress, WithdrawalResponse, DepositAddressResponse, OHLCV, Balances, PartialBalances, Dictionary, MinMax, Position, FundingRateHistory, Liquidation, FundingHistory, MarginMode, Greeks, Leverage, Leverages, Option, OptionChain, ace, alpaca, ascendex, bequant, bigone, binance, binancecoinm, binanceus, binanceusdm, bingx, bit2c, bitbank, bitbay, bitbns, bitcoincom, bitfinex, bitfinex2, bitflyer, bitget, bithumb, bitmart, bitmex, bitopro, bitpanda, bitrue, bitso, bitstamp, bitteam, bitvavo, bl3p, blockchaincom, blofin, btcalpha, btcbox, btcmarkets, btcturk, bybit, cex, coinbase, coinbaseinternational, coinbasepro, coincheck, coinex, coinlist, coinmate, coinmetro, coinone, coinsph, coinspot, cryptocom, currencycom, delta, deribit, digifinex, exmo, fmfwio, gate, gateio, gemini, hitbtc, hitbtc3, hollaex, htx, huobi, huobijp, hyperliquid, idex, independentreserve, indodax, kraken, krakenfutures, kucoin, kucoinfutures, kuna, latoken, lbank, luno, lykke, mercado, mexc, ndax, novadax, oceanex, okcoin, okx, onetrading, p2b, paymium, phemex, poloniex, poloniexfutures, probit, timex, tokocrypto, tradeogre, upbit, wavesexchange, wazirx, whitebit, woo, yobit, zaif, zonda, };
522
+ export { version, Exchange, exchanges, pro, Precise, functions, errors, BaseError, ExchangeError, AuthenticationError, PermissionDenied, AccountNotEnabled, AccountSuspended, ArgumentsRequired, BadRequest, BadSymbol, OperationRejected, NoChange, MarginModeAlreadySet, BadResponse, NullResponse, InsufficientFunds, InvalidAddress, AddressPending, InvalidOrder, OrderNotFound, OrderNotCached, CancelPending, OrderImmediatelyFillable, OrderNotFillable, DuplicateOrderId, ContractUnavailable, NotSupported, ProxyError, OperationFailed, NetworkError, DDoSProtection, RateLimitExceeded, ExchangeNotAvailable, OnMaintenance, InvalidNonce, RequestTimeout, ExchangeClosedByUser, Market, Trade, Fee, Ticker, OrderBook, Order, Transaction, Tickers, Currency, Balance, DepositAddress, WithdrawalResponse, DepositAddressResponse, OHLCV, Balances, PartialBalances, Dictionary, MinMax, Position, FundingRateHistory, Liquidation, FundingHistory, MarginMode, Greeks, Leverage, Leverages, Option, OptionChain, ace, alpaca, ascendex, bequant, bigone, binance, binancecoinm, binanceus, binanceusdm, bingx, bit2c, bitbank, bitbay, bitbns, bitcoincom, bitfinex, bitfinex2, bitflyer, bitget, bithumb, bitmart, bitmex, bitopro, bitpanda, bitrue, bitso, bitstamp, bitteam, bitvavo, bl3p, blockchaincom, blofin, btcalpha, btcbox, btcmarkets, btcturk, bybit, cex, coinbase, coinbaseinternational, coinbasepro, coincheck, coinex, coinlist, coinmate, coinmetro, coinone, coinsph, coinspot, cryptocom, currencycom, delta, deribit, digifinex, exmo, fmfwio, gate, gateio, gemini, hitbtc, hitbtc3, hollaex, htx, huobi, huobijp, hyperliquid, idex, independentreserve, indodax, kraken, krakenfutures, kucoin, kucoinfutures, kuna, latoken, lbank, luno, lykke, mercado, mexc, ndax, novadax, oceanex, okcoin, okx, onetrading, p2b, paymium, phemex, poloniex, poloniexfutures, probit, timex, tokocrypto, tradeogre, upbit, wavesexchange, wazirx, whitebit, woo, yobit, zaif, zonda, };
523
523
  export default ccxt;
package/js/ccxt.js CHANGED
@@ -35,10 +35,10 @@ import { Exchange } from './src/base/Exchange.js';
35
35
  import { Precise } from './src/base/Precise.js';
36
36
  import * as functions from './src/base/functions.js';
37
37
  import * as errors from './src/base/errors.js';
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';
38
+ import { BaseError, ExchangeError, AuthenticationError, PermissionDenied, AccountNotEnabled, AccountSuspended, ArgumentsRequired, BadRequest, BadSymbol, OperationRejected, NoChange, MarginModeAlreadySet, BadResponse, NullResponse, InsufficientFunds, InvalidAddress, AddressPending, InvalidOrder, OrderNotFound, OrderNotCached, CancelPending, OrderImmediatelyFillable, OrderNotFillable, DuplicateOrderId, ContractUnavailable, NotSupported, ProxyError, OperationFailed, NetworkError, DDoSProtection, RateLimitExceeded, ExchangeNotAvailable, OnMaintenance, InvalidNonce, RequestTimeout, ExchangeClosedByUser } from './src/base/errors.js';
39
39
  //-----------------------------------------------------------------------------
40
40
  // this is updated by vss.js when building
41
- const version = '4.2.87';
41
+ const version = '4.2.88';
42
42
  Exchange.ccxtVersion = version;
43
43
  //-----------------------------------------------------------------------------
44
44
  import ace from './src/ace.js';
@@ -392,6 +392,6 @@ pro.exchanges = Object.keys(pro);
392
392
  pro['Exchange'] = Exchange; // now the same for rest and ts
393
393
  //-----------------------------------------------------------------------------
394
394
  const ccxt = Object.assign({ version, Exchange, Precise, 'exchanges': Object.keys(exchanges), 'pro': pro }, exchanges, functions, errors);
395
- export { version, Exchange, exchanges, pro, Precise, functions, errors, 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, ace, alpaca, ascendex, bequant, bigone, binance, binancecoinm, binanceus, binanceusdm, bingx, bit2c, bitbank, bitbay, bitbns, bitcoincom, bitfinex, bitfinex2, bitflyer, bitget, bithumb, bitmart, bitmex, bitopro, bitpanda, bitrue, bitso, bitstamp, bitteam, bitvavo, bl3p, blockchaincom, blofin, btcalpha, btcbox, btcmarkets, btcturk, bybit, cex, coinbase, coinbaseinternational, coinbasepro, coincheck, coinex, coinlist, coinmate, coinmetro, coinone, coinsph, coinspot, cryptocom, currencycom, delta, deribit, digifinex, exmo, fmfwio, gate, gateio, gemini, hitbtc, hitbtc3, hollaex, htx, huobi, huobijp, hyperliquid, idex, independentreserve, indodax, kraken, krakenfutures, kucoin, kucoinfutures, kuna, latoken, lbank, luno, lykke, mercado, mexc, ndax, novadax, oceanex, okcoin, okx, onetrading, p2b, paymium, phemex, poloniex, poloniexfutures, probit, timex, tokocrypto, tradeogre, upbit, wavesexchange, wazirx, whitebit, woo, yobit, zaif, zonda, };
395
+ export { version, Exchange, exchanges, pro, Precise, functions, errors, BaseError, ExchangeError, AuthenticationError, PermissionDenied, AccountNotEnabled, AccountSuspended, ArgumentsRequired, BadRequest, BadSymbol, OperationRejected, NoChange, MarginModeAlreadySet, BadResponse, NullResponse, InsufficientFunds, InvalidAddress, AddressPending, InvalidOrder, OrderNotFound, OrderNotCached, CancelPending, OrderImmediatelyFillable, OrderNotFillable, DuplicateOrderId, ContractUnavailable, NotSupported, ProxyError, OperationFailed, NetworkError, DDoSProtection, RateLimitExceeded, ExchangeNotAvailable, OnMaintenance, InvalidNonce, RequestTimeout, ExchangeClosedByUser, ace, alpaca, ascendex, bequant, bigone, binance, binancecoinm, binanceus, binanceusdm, bingx, bit2c, bitbank, bitbay, bitbns, bitcoincom, bitfinex, bitfinex2, bitflyer, bitget, bithumb, bitmart, bitmex, bitopro, bitpanda, bitrue, bitso, bitstamp, bitteam, bitvavo, bl3p, blockchaincom, blofin, btcalpha, btcbox, btcmarkets, btcturk, bybit, cex, coinbase, coinbaseinternational, coinbasepro, coincheck, coinex, coinlist, coinmate, coinmetro, coinone, coinsph, coinspot, cryptocom, currencycom, delta, deribit, digifinex, exmo, fmfwio, gate, gateio, gemini, hitbtc, hitbtc3, hollaex, htx, huobi, huobijp, hyperliquid, idex, independentreserve, indodax, kraken, krakenfutures, kucoin, kucoinfutures, kuna, latoken, lbank, luno, lykke, mercado, mexc, ndax, novadax, oceanex, okcoin, okx, onetrading, p2b, paymium, phemex, poloniex, poloniexfutures, probit, timex, tokocrypto, tradeogre, upbit, wavesexchange, wazirx, whitebit, woo, yobit, zaif, zonda, };
396
396
  export default ccxt;
397
397
  //-----------------------------------------------------------------------------
@@ -943,6 +943,7 @@ export default class Exchange {
943
943
  safeNumber(obj: object, key: IndexType, defaultNumber?: Num): Num;
944
944
  safeNumberN(obj: object, arr: IndexType[], defaultNumber?: Num): Num;
945
945
  parsePrecision(precision?: string): string;
946
+ integerPrecisionToAmount(precision: Str): string;
946
947
  loadTimeDifference(params?: {}): Promise<any>;
947
948
  implodeHostname(url: string): any;
948
949
  fetchMarketLeverageTiers(symbol: string, params?: {}): Promise<any>;
@@ -4707,6 +4707,30 @@ export default class Exchange {
4707
4707
  }
4708
4708
  return parsedPrecision + '1';
4709
4709
  }
4710
+ integerPrecisionToAmount(precision) {
4711
+ /**
4712
+ * @ignore
4713
+ * @method
4714
+ * @description handles positive & negative numbers too. parsePrecision() does not handle negative numbers, but this method handles
4715
+ * @param {string} precision The number of digits to the right of the decimal
4716
+ * @returns {string} a string number equal to 1e-precision
4717
+ */
4718
+ if (precision === undefined) {
4719
+ return undefined;
4720
+ }
4721
+ if (Precise.stringGe(precision, '0')) {
4722
+ return this.parsePrecision(precision);
4723
+ }
4724
+ else {
4725
+ const positivePrecisionString = Precise.stringAbs(precision);
4726
+ const positivePrecision = parseInt(positivePrecisionString);
4727
+ let parsedPrecision = '1';
4728
+ for (let i = 0; i < positivePrecision - 1; i++) {
4729
+ parsedPrecision = parsedPrecision + '0';
4730
+ }
4731
+ return parsedPrecision + '0';
4732
+ }
4733
+ }
4710
4734
  async loadTimeDifference(params = {}) {
4711
4735
  const serverTime = await this.fetchTime(params);
4712
4736
  const after = this.milliseconds();
@@ -5187,8 +5211,8 @@ export default class Exchange {
5187
5211
  const entry = responseKeys[i];
5188
5212
  const dictionary = isArray ? entry : response[entry];
5189
5213
  const currencyId = isArray ? this.safeString(dictionary, currencyIdKey) : entry;
5190
- const currency = this.safeValue(this.currencies_by_id, currencyId);
5191
- const code = this.safeString(currency, 'code', currencyId);
5214
+ const currency = this.safeCurrency(currencyId);
5215
+ const code = this.safeString(currency, 'code');
5192
5216
  if ((codes === undefined) || (this.inArray(code, codes))) {
5193
5217
  depositWithdrawFees[code] = this.parseDepositWithdrawFee(dictionary, currency);
5194
5218
  }
@@ -252,7 +252,7 @@ export interface Position {
252
252
  liquidationPrice?: number;
253
253
  marginMode?: Str;
254
254
  hedged?: boolean;
255
- maintenenceMargin?: number;
255
+ maintenanceMargin?: number;
256
256
  maintenanceMarginPercentage?: number;
257
257
  initialMargin?: number;
258
258
  initialMarginPercentage?: number;
@@ -196,7 +196,7 @@ export default class binance extends Exchange {
196
196
  previousFundingTimestamp: any;
197
197
  previousFundingDatetime: any;
198
198
  };
199
- parseAccountPositions(account: any): any[];
199
+ parseAccountPositions(account: any, filterClosed?: boolean): any[];
200
200
  parseAccountPosition(position: any, market?: Market): {
201
201
  info: any;
202
202
  id: any;
package/js/src/binance.js CHANGED
@@ -1863,7 +1863,7 @@ export default class binance extends Exchange {
1863
1863
  '-4140': BadRequest,
1864
1864
  '-4141': OperationRejected,
1865
1865
  '-4144': BadSymbol,
1866
- '-4164': OperationRejected,
1866
+ '-4164': InvalidOrder,
1867
1867
  '-4165': BadRequest,
1868
1868
  '-4167': BadRequest,
1869
1869
  '-4168': BadRequest,
@@ -9143,7 +9143,7 @@ export default class binance extends Exchange {
9143
9143
  'previousFundingDatetime': undefined,
9144
9144
  };
9145
9145
  }
9146
- parseAccountPositions(account) {
9146
+ parseAccountPositions(account, filterClosed = false) {
9147
9147
  const positions = this.safeList(account, 'positions');
9148
9148
  const assets = this.safeList(account, 'assets', []);
9149
9149
  const balances = {};
@@ -9166,7 +9166,8 @@ export default class binance extends Exchange {
9166
9166
  const code = market['linear'] ? market['quote'] : market['base'];
9167
9167
  const maintenanceMargin = this.safeString(position, 'maintMargin');
9168
9168
  // check for maintenance margin so empty positions are not returned
9169
- if ((maintenanceMargin !== '0') && (maintenanceMargin !== '0.00000000')) {
9169
+ const isPositionOpen = (maintenanceMargin !== '0') && (maintenanceMargin !== '0.00000000');
9170
+ if (!filterClosed || isPositionOpen) {
9170
9171
  // sometimes not all the codes are correctly returned...
9171
9172
  if (code in balances) {
9172
9173
  const parsed = this.parseAccountPosition(this.extend(position, {
@@ -10008,10 +10009,11 @@ export default class binance extends Exchange {
10008
10009
  * @see https://binance-docs.github.io/apidocs/delivery/en/#account-information-user_data
10009
10010
  * @see https://binance-docs.github.io/apidocs/pm/en/#get-um-account-detail-user_data
10010
10011
  * @see https://binance-docs.github.io/apidocs/pm/en/#get-cm-account-detail-user_data
10011
- * @param {string[]|undefined} symbols list of unified market symbols
10012
+ * @param {string[]} [symbols] list of unified market symbols
10012
10013
  * @param {object} [params] extra parameters specific to the exchange API endpoint
10013
10014
  * @param {boolean} [params.portfolioMargin] set to true if you would like to fetch positions in a portfolio margin account
10014
10015
  * @param {string} [params.subType] "linear" or "inverse"
10016
+ * @param {boolean} [params.filterClosed] set to true if you would like to filter out closed positions, default is false
10015
10017
  * @returns {object} data on account positions
10016
10018
  */
10017
10019
  if (symbols !== undefined) {
@@ -10048,7 +10050,9 @@ export default class binance extends Exchange {
10048
10050
  else {
10049
10051
  throw new NotSupported(this.id + ' fetchPositions() supports linear and inverse contracts only');
10050
10052
  }
10051
- const result = this.parseAccountPositions(response);
10053
+ let filterClosed = undefined;
10054
+ [filterClosed, params] = this.handleOptionAndParams(params, 'fetchAccountPositions', 'filterClosed', false);
10055
+ const result = this.parseAccountPositions(response, filterClosed);
10052
10056
  symbols = this.marketSymbols(symbols);
10053
10057
  return this.filterByArrayPositions(result, 'symbol', symbols, false);
10054
10058
  }
@@ -11186,7 +11190,7 @@ export default class binance extends Exchange {
11186
11190
  }
11187
11191
  await this.loadMarkets();
11188
11192
  const market = this.market(symbol);
11189
- amount = this.costToPrecision(symbol, amount);
11193
+ amount = this.amountToPrecision(symbol, amount);
11190
11194
  const request = {
11191
11195
  'type': addOrReduce,
11192
11196
  'symbol': market['id'],