ccxt 4.4.93 → 4.4.94

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
@@ -193,7 +193,7 @@ var xt$1 = require('./src/pro/xt.js');
193
193
 
194
194
  //-----------------------------------------------------------------------------
195
195
  // this is updated by vss.js when building
196
- const version = '4.4.93';
196
+ const version = '4.4.94';
197
197
  Exchange["default"].ccxtVersion = version;
198
198
  const exchanges = {
199
199
  'alpaca': alpaca,
@@ -3514,8 +3514,7 @@ class Exchange {
3514
3514
  }
3515
3515
  safeTicker(ticker, market = undefined) {
3516
3516
  let open = this.omitZero(this.safeString(ticker, 'open'));
3517
- let close = this.omitZero(this.safeString(ticker, 'close'));
3518
- let last = this.omitZero(this.safeString(ticker, 'last'));
3517
+ let close = this.omitZero(this.safeString2(ticker, 'close', 'last'));
3519
3518
  let change = this.omitZero(this.safeString(ticker, 'change'));
3520
3519
  let percentage = this.omitZero(this.safeString(ticker, 'percentage'));
3521
3520
  let average = this.omitZero(this.safeString(ticker, 'average'));
@@ -3525,17 +3524,55 @@ class Exchange {
3525
3524
  if (vwap === undefined) {
3526
3525
  vwap = Precise["default"].stringDiv(this.omitZero(quoteVolume), baseVolume);
3527
3526
  }
3528
- if ((last !== undefined) && (close === undefined)) {
3529
- close = last;
3527
+ // calculate open
3528
+ if (change !== undefined) {
3529
+ if (close === undefined && average !== undefined) {
3530
+ close = Precise["default"].stringAdd(average, Precise["default"].stringDiv(change, '2'));
3531
+ }
3532
+ if (open === undefined && close !== undefined) {
3533
+ open = Precise["default"].stringSub(close, change);
3534
+ }
3530
3535
  }
3531
- else if ((last === undefined) && (close !== undefined)) {
3532
- last = close;
3536
+ else if (percentage !== undefined) {
3537
+ if (close === undefined && average !== undefined) {
3538
+ const openAddClose = Precise["default"].stringMul(average, '2');
3539
+ // openAddClose = open * (1 + (100 + percentage)/100)
3540
+ const denominator = Precise["default"].stringAdd('2', Precise["default"].stringDiv(percentage, '100'));
3541
+ const calcOpen = (open !== undefined) ? open : Precise["default"].stringDiv(openAddClose, denominator);
3542
+ close = Precise["default"].stringMul(calcOpen, Precise["default"].stringAdd('1', Precise["default"].stringDiv(percentage, '100')));
3543
+ }
3544
+ if (open === undefined && close !== undefined) {
3545
+ open = Precise["default"].stringDiv(close, Precise["default"].stringAdd('1', Precise["default"].stringDiv(percentage, '100')));
3546
+ }
3533
3547
  }
3534
- if ((last !== undefined) && (open !== undefined)) {
3535
- if (change === undefined) {
3536
- change = Precise["default"].stringSub(last, open);
3548
+ // change
3549
+ if (change === undefined) {
3550
+ if (close !== undefined && open !== undefined) {
3551
+ change = Precise["default"].stringSub(close, open);
3537
3552
  }
3538
- if (average === undefined) {
3553
+ else if (close !== undefined && percentage !== undefined) {
3554
+ change = Precise["default"].stringMul(Precise["default"].stringDiv(percentage, '100'), Precise["default"].stringDiv(close, '100'));
3555
+ }
3556
+ else if (open !== undefined && percentage !== undefined) {
3557
+ change = Precise["default"].stringMul(open, Precise["default"].stringDiv(percentage, '100'));
3558
+ }
3559
+ }
3560
+ // calculate things according to "open" (similar can be done with "close")
3561
+ if (open !== undefined) {
3562
+ // percentage (using change)
3563
+ if (percentage === undefined && change !== undefined) {
3564
+ percentage = Precise["default"].stringMul(Precise["default"].stringDiv(change, open), '100');
3565
+ }
3566
+ // close (using change)
3567
+ if (close === undefined && change !== undefined) {
3568
+ close = Precise["default"].stringAdd(open, change);
3569
+ }
3570
+ // close (using average)
3571
+ if (close === undefined && average !== undefined) {
3572
+ close = Precise["default"].stringMul(average, '2');
3573
+ }
3574
+ // average
3575
+ if (average === undefined && close !== undefined) {
3539
3576
  let precision = 18;
3540
3577
  if (market !== undefined && this.isTickPrecision()) {
3541
3578
  const marketPrecision = this.safeDict(market, 'precision');
@@ -3544,20 +3581,12 @@ class Exchange {
3544
3581
  precision = this.precisionFromString(precisionPrice);
3545
3582
  }
3546
3583
  }
3547
- average = Precise["default"].stringDiv(Precise["default"].stringAdd(last, open), '2', precision);
3584
+ average = Precise["default"].stringDiv(Precise["default"].stringAdd(open, close), '2', precision);
3548
3585
  }
3549
3586
  }
3550
- if ((percentage === undefined) && (change !== undefined) && (open !== undefined) && Precise["default"].stringGt(open, '0')) {
3551
- percentage = Precise["default"].stringMul(Precise["default"].stringDiv(change, open), '100');
3552
- }
3553
- if ((change === undefined) && (percentage !== undefined) && (open !== undefined)) {
3554
- change = Precise["default"].stringDiv(Precise["default"].stringMul(percentage, open), '100');
3555
- }
3556
- if ((open === undefined) && (last !== undefined) && (change !== undefined)) {
3557
- open = Precise["default"].stringSub(last, change);
3558
- }
3559
3587
  // timestamp and symbol operations don't belong in safeTicker
3560
3588
  // they should be done in the derived classes
3589
+ const closeParsed = this.parseNumber(this.omitZero(close));
3561
3590
  return this.extend(ticker, {
3562
3591
  'bid': this.parseNumber(this.omitZero(this.safeString(ticker, 'bid'))),
3563
3592
  'bidVolume': this.safeNumber(ticker, 'bidVolume'),
@@ -3566,8 +3595,8 @@ class Exchange {
3566
3595
  'high': this.parseNumber(this.omitZero(this.safeString(ticker, 'high'))),
3567
3596
  'low': this.parseNumber(this.omitZero(this.safeString(ticker, 'low'))),
3568
3597
  'open': this.parseNumber(this.omitZero(open)),
3569
- 'close': this.parseNumber(this.omitZero(close)),
3570
- 'last': this.parseNumber(this.omitZero(last)),
3598
+ 'close': closeParsed,
3599
+ 'last': closeParsed,
3571
3600
  'change': this.parseNumber(change),
3572
3601
  'percentage': this.parseNumber(percentage),
3573
3602
  'average': this.parseNumber(average),
@@ -3911,7 +3911,7 @@ class bybit extends bybit$1 {
3911
3911
  const isTakeProfit = takeProfitPrice !== undefined;
3912
3912
  const orderRequest = this.createOrderRequest(symbol, type, side, amount, price, params, enableUnifiedAccount);
3913
3913
  let defaultMethod = undefined;
3914
- if (isTrailingAmountOrder || isStopLoss || isTakeProfit) {
3914
+ if ((isTrailingAmountOrder || isStopLoss || isTakeProfit) && !market['spot']) {
3915
3915
  defaultMethod = 'privatePostV5PositionTradingStop';
3916
3916
  }
3917
3917
  else {
@@ -3992,7 +3992,7 @@ class bybit extends bybit$1 {
3992
3992
  const isLimit = lowerCaseType === 'limit';
3993
3993
  const isBuy = side === 'buy';
3994
3994
  let defaultMethod = undefined;
3995
- if (isTrailingAmountOrder || isStopLossTriggerOrder || isTakeProfitTriggerOrder) {
3995
+ if ((isTrailingAmountOrder || isStopLossTriggerOrder || isTakeProfitTriggerOrder) && !market['spot']) {
3996
3996
  defaultMethod = 'privatePostV5PositionTradingStop';
3997
3997
  }
3998
3998
  else {
@@ -322,12 +322,14 @@ class coinbase extends coinbase$1 {
322
322
  'rate_limit_exceeded': errors.RateLimitExceeded,
323
323
  'internal_server_error': errors.ExchangeError,
324
324
  'UNSUPPORTED_ORDER_CONFIGURATION': errors.BadRequest,
325
- 'INSUFFICIENT_FUND': errors.BadRequest,
325
+ 'INSUFFICIENT_FUND': errors.InsufficientFunds,
326
326
  'PERMISSION_DENIED': errors.PermissionDenied,
327
327
  'INVALID_ARGUMENT': errors.BadRequest,
328
328
  'PREVIEW_STOP_PRICE_ABOVE_LAST_TRADE_PRICE': errors.InvalidOrder,
329
+ 'PREVIEW_INSUFFICIENT_FUND': errors.InsufficientFunds,
329
330
  },
330
331
  'broad': {
332
+ 'Insufficient balance in source account': errors.InsufficientFunds,
331
333
  'request timestamp expired': errors.InvalidNonce,
332
334
  'order with this orderID was not found': errors.OrderNotFound, // {"error":"unknown","error_details":"order with this orderID was not found","message":"order with this orderID was not found"}
333
335
  },
@@ -210,6 +210,7 @@ class coinmetro extends coinmetro$1 {
210
210
  'options': {
211
211
  'currenciesByIdForParseMarket': undefined,
212
212
  'currencyIdsListForParseMarket': ['QRDO'],
213
+ 'skippedMarkets': ['VXVUSDT'], // broken markets which do not have enough info in API
213
214
  },
214
215
  'features': {
215
216
  'spot': {
@@ -435,10 +436,13 @@ class coinmetro extends coinmetro$1 {
435
436
  * @returns {object[]} an array of objects representing market data
436
437
  */
437
438
  async fetchMarkets(params = {}) {
438
- const response = await this.publicGetMarkets(params);
439
+ const promises = [];
440
+ promises.push(this.publicGetMarkets(params));
439
441
  if (this.safeValue(this.options, 'currenciesByIdForParseMarket') === undefined) {
440
- await this.fetchCurrencies();
442
+ promises.push(this.fetchCurrencies());
441
443
  }
444
+ const responses = await Promise.all(promises);
445
+ const response = responses[0];
442
446
  //
443
447
  // [
444
448
  // {
@@ -454,7 +458,16 @@ class coinmetro extends coinmetro$1 {
454
458
  // ...
455
459
  // ]
456
460
  //
457
- return this.parseMarkets(response);
461
+ const skippedMarkets = this.safeList(this.options, 'skippedMarkets', []);
462
+ const result = [];
463
+ for (let i = 0; i < response.length; i++) {
464
+ const market = this.parseMarket(response[i]);
465
+ if (this.inArray(market['id'], skippedMarkets)) {
466
+ continue;
467
+ }
468
+ result.push(market);
469
+ }
470
+ return result;
458
471
  }
459
472
  parseMarket(market) {
460
473
  const id = this.safeString(market, 'pair');
@@ -7107,13 +7107,19 @@ class htx extends htx$1 {
7107
7107
  let paginate = false;
7108
7108
  [paginate, params] = this.handleOptionAndParams(params, 'fetchFundingRateHistory', 'paginate');
7109
7109
  if (paginate) {
7110
- return await this.fetchPaginatedCallCursor('fetchFundingRateHistory', symbol, since, limit, params, 'page_index', 'current_page', 1, 50);
7110
+ return await this.fetchPaginatedCallCursor('fetchFundingRateHistory', symbol, since, limit, params, 'current_page', 'page_index', 1, 50);
7111
7111
  }
7112
7112
  await this.loadMarkets();
7113
7113
  const market = this.market(symbol);
7114
7114
  const request = {
7115
7115
  'contract_code': market['id'],
7116
7116
  };
7117
+ if (limit !== undefined) {
7118
+ request['page_size'] = limit;
7119
+ }
7120
+ else {
7121
+ request['page_size'] = 50; // max
7122
+ }
7117
7123
  let response = undefined;
7118
7124
  if (market['inverse']) {
7119
7125
  response = await this.contractPublicGetSwapApiV1SwapHistoricalFundingRate(this.extend(request, params));