ccxt 4.4.96 → 4.4.98

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 (79) hide show
  1. package/README.md +15 -15
  2. package/dist/ccxt.browser.min.js +2 -2
  3. package/dist/cjs/ccxt.js +2 -1
  4. package/dist/cjs/src/base/Exchange.js +63 -15
  5. package/dist/cjs/src/base/errors.js +8 -1
  6. package/dist/cjs/src/base/functions/number.js +30 -9
  7. package/dist/cjs/src/binance.js +95 -34
  8. package/dist/cjs/src/binancecoinm.js +5 -1
  9. package/dist/cjs/src/binanceus.js +3 -1
  10. package/dist/cjs/src/binanceusdm.js +3 -1
  11. package/dist/cjs/src/bingx.js +1 -1
  12. package/dist/cjs/src/bitget.js +18 -2
  13. package/dist/cjs/src/coinmetro.js +2 -3
  14. package/dist/cjs/src/cryptocom.js +77 -1
  15. package/dist/cjs/src/exmo.js +1 -1
  16. package/dist/cjs/src/foxbit.js +1 -1
  17. package/dist/cjs/src/gate.js +1 -2
  18. package/dist/cjs/src/hashkey.js +39 -0
  19. package/dist/cjs/src/hyperliquid.js +42 -27
  20. package/dist/cjs/src/independentreserve.js +35 -0
  21. package/dist/cjs/src/indodax.js +34 -0
  22. package/dist/cjs/src/kucoin.js +2 -1
  23. package/dist/cjs/src/latoken.js +42 -0
  24. package/dist/cjs/src/luno.js +36 -0
  25. package/dist/cjs/src/mercado.js +34 -0
  26. package/dist/cjs/src/mexc.js +3 -25
  27. package/dist/cjs/src/ndax.js +8 -0
  28. package/dist/cjs/src/okx.js +1 -0
  29. package/dist/cjs/src/phemex.js +36 -31
  30. package/dist/cjs/src/pro/binancecoinm.js +3 -1
  31. package/dist/cjs/src/pro/binanceus.js +3 -1
  32. package/dist/cjs/src/pro/binanceusdm.js +3 -1
  33. package/dist/cjs/src/pro/bybit.js +33 -0
  34. package/js/ccxt.d.ts +3 -3
  35. package/js/ccxt.js +3 -3
  36. package/js/src/abstract/binance.d.ts +3 -0
  37. package/js/src/abstract/binancecoinm.d.ts +3 -0
  38. package/js/src/abstract/binanceus.d.ts +3 -0
  39. package/js/src/abstract/binanceusdm.d.ts +3 -0
  40. package/js/src/abstract/phemex.d.ts +1 -0
  41. package/js/src/base/Exchange.d.ts +11 -3
  42. package/js/src/base/Exchange.js +63 -15
  43. package/js/src/base/errorHierarchy.d.ts +1 -0
  44. package/js/src/base/errorHierarchy.js +1 -0
  45. package/js/src/base/errors.d.ts +5 -1
  46. package/js/src/base/errors.js +8 -2
  47. package/js/src/base/functions/number.js +30 -9
  48. package/js/src/binance.d.ts +1 -0
  49. package/js/src/binance.js +95 -34
  50. package/js/src/binancecoinm.js +5 -1
  51. package/js/src/binanceus.js +3 -1
  52. package/js/src/binanceusdm.js +3 -1
  53. package/js/src/bingx.js +1 -1
  54. package/js/src/bitget.js +18 -2
  55. package/js/src/coinmetro.js +2 -3
  56. package/js/src/cryptocom.d.ts +12 -1
  57. package/js/src/cryptocom.js +77 -1
  58. package/js/src/exmo.js +1 -1
  59. package/js/src/foxbit.js +1 -1
  60. package/js/src/gate.js +1 -2
  61. package/js/src/hashkey.js +39 -0
  62. package/js/src/hyperliquid.js +42 -27
  63. package/js/src/independentreserve.js +35 -0
  64. package/js/src/indodax.js +34 -0
  65. package/js/src/kucoin.js +2 -1
  66. package/js/src/latoken.js +42 -0
  67. package/js/src/luno.js +36 -0
  68. package/js/src/mercado.js +34 -0
  69. package/js/src/mexc.d.ts +0 -1
  70. package/js/src/mexc.js +3 -25
  71. package/js/src/ndax.js +8 -0
  72. package/js/src/okx.js +2 -1
  73. package/js/src/phemex.js +36 -31
  74. package/js/src/pro/binancecoinm.js +3 -1
  75. package/js/src/pro/binanceus.js +3 -1
  76. package/js/src/pro/binanceusdm.js +3 -1
  77. package/js/src/pro/bybit.d.ts +11 -1
  78. package/js/src/pro/bybit.js +33 -0
  79. package/package.json +1 -2
@@ -221,6 +221,7 @@ interface binance {
221
221
  sapiGetPortfolioBalance(params?: {}): Promise<implicitReturnType>;
222
222
  sapiGetPortfolioNegativeBalanceExchangeRecord(params?: {}): Promise<implicitReturnType>;
223
223
  sapiGetPortfolioPmloanHistory(params?: {}): Promise<implicitReturnType>;
224
+ sapiGetPortfolioEarnAssetBalance(params?: {}): Promise<implicitReturnType>;
224
225
  sapiGetStakingProductList(params?: {}): Promise<implicitReturnType>;
225
226
  sapiGetStakingPosition(params?: {}): Promise<implicitReturnType>;
226
227
  sapiGetStakingStakingRecord(params?: {}): Promise<implicitReturnType>;
@@ -394,6 +395,7 @@ interface binance {
394
395
  sapiPostPortfolioRepayFuturesNegativeBalance(params?: {}): Promise<implicitReturnType>;
395
396
  sapiPostPortfolioMint(params?: {}): Promise<implicitReturnType>;
396
397
  sapiPostPortfolioRedeem(params?: {}): Promise<implicitReturnType>;
398
+ sapiPostPortfolioEarnAssetTransfer(params?: {}): Promise<implicitReturnType>;
397
399
  sapiPostLendingAutoInvestPlanAdd(params?: {}): Promise<implicitReturnType>;
398
400
  sapiPostLendingAutoInvestPlanEdit(params?: {}): Promise<implicitReturnType>;
399
401
  sapiPostLendingAutoInvestPlanEditStatus(params?: {}): Promise<implicitReturnType>;
@@ -553,6 +555,7 @@ interface binance {
553
555
  fapiPublicGetApiTradingStatus(params?: {}): Promise<implicitReturnType>;
554
556
  fapiPublicGetLvtKlines(params?: {}): Promise<implicitReturnType>;
555
557
  fapiPublicGetConvertExchangeInfo(params?: {}): Promise<implicitReturnType>;
558
+ fapiPublicGetInsuranceBalance(params?: {}): Promise<implicitReturnType>;
556
559
  fapiDataGetDeliveryPrice(params?: {}): Promise<implicitReturnType>;
557
560
  fapiDataGetOpenInterestHist(params?: {}): Promise<implicitReturnType>;
558
561
  fapiDataGetTopLongShortAccountRatio(params?: {}): Promise<implicitReturnType>;
@@ -221,6 +221,7 @@ interface binance {
221
221
  sapiGetPortfolioBalance(params?: {}): Promise<implicitReturnType>;
222
222
  sapiGetPortfolioNegativeBalanceExchangeRecord(params?: {}): Promise<implicitReturnType>;
223
223
  sapiGetPortfolioPmloanHistory(params?: {}): Promise<implicitReturnType>;
224
+ sapiGetPortfolioEarnAssetBalance(params?: {}): Promise<implicitReturnType>;
224
225
  sapiGetStakingProductList(params?: {}): Promise<implicitReturnType>;
225
226
  sapiGetStakingPosition(params?: {}): Promise<implicitReturnType>;
226
227
  sapiGetStakingStakingRecord(params?: {}): Promise<implicitReturnType>;
@@ -363,6 +364,7 @@ interface binance {
363
364
  sapiPostPortfolioRepayFuturesNegativeBalance(params?: {}): Promise<implicitReturnType>;
364
365
  sapiPostPortfolioMint(params?: {}): Promise<implicitReturnType>;
365
366
  sapiPostPortfolioRedeem(params?: {}): Promise<implicitReturnType>;
367
+ sapiPostPortfolioEarnAssetTransfer(params?: {}): Promise<implicitReturnType>;
366
368
  sapiPostLendingAutoInvestPlanAdd(params?: {}): Promise<implicitReturnType>;
367
369
  sapiPostLendingAutoInvestPlanEdit(params?: {}): Promise<implicitReturnType>;
368
370
  sapiPostLendingAutoInvestPlanEditStatus(params?: {}): Promise<implicitReturnType>;
@@ -501,6 +503,7 @@ interface binance {
501
503
  fapiPublicGetApiTradingStatus(params?: {}): Promise<implicitReturnType>;
502
504
  fapiPublicGetLvtKlines(params?: {}): Promise<implicitReturnType>;
503
505
  fapiPublicGetConvertExchangeInfo(params?: {}): Promise<implicitReturnType>;
506
+ fapiPublicGetInsuranceBalance(params?: {}): Promise<implicitReturnType>;
504
507
  fapiDataGetDeliveryPrice(params?: {}): Promise<implicitReturnType>;
505
508
  fapiDataGetOpenInterestHist(params?: {}): Promise<implicitReturnType>;
506
509
  fapiDataGetTopLongShortAccountRatio(params?: {}): Promise<implicitReturnType>;
@@ -101,6 +101,7 @@ interface Exchange {
101
101
  privatePutSpotOrders(params?: {}): Promise<implicitReturnType>;
102
102
  privatePutOrdersReplace(params?: {}): Promise<implicitReturnType>;
103
103
  privatePutGOrdersReplace(params?: {}): Promise<implicitReturnType>;
104
+ privatePutGOrdersCreate(params?: {}): Promise<implicitReturnType>;
104
105
  privatePutPositionsLeverage(params?: {}): Promise<implicitReturnType>;
105
106
  privatePutGPositionsLeverage(params?: {}): Promise<implicitReturnType>;
106
107
  privatePutGPositionsSwitchPosModeSync(params?: {}): Promise<implicitReturnType>;
@@ -1,7 +1,7 @@
1
1
  import * as functions from './functions.js';
2
2
  import WsClient from './ws/WsClient.js';
3
3
  import { OrderBook as WsOrderBook, IndexedOrderBook, CountedOrderBook } from './ws/OrderBook.js';
4
- import type { Market, Trade, Ticker, OHLCV, OHLCVC, Order, OrderBook, Balance, Balances, Dictionary, Transaction, Currency, MinMax, IndexType, Int, OrderType, OrderSide, Position, FundingRate, DepositWithdrawFeeNetwork, LedgerEntry, BorrowInterest, OpenInterest, LeverageTier, TransferEntry, FundingRateHistory, Liquidation, FundingHistory, OrderRequest, MarginMode, Tickers, Greeks, Option, OptionChain, Str, Num, MarketInterface, CurrencyInterface, BalanceAccount, MarginModes, MarketType, Leverage, Leverages, LastPrice, LastPrices, Account, Strings, MarginModification, TradingFeeInterface, Currencies, TradingFees, Conversion, CancellationRequest, IsolatedBorrowRate, IsolatedBorrowRates, CrossBorrowRates, CrossBorrowRate, Dict, FundingRates, LeverageTiers, Bool, int, DepositAddress, LongShortRatio, OrderBooks, OpenInterests, ConstructorArgs } from './types.js';
4
+ import type { Market, Trade, Ticker, OHLCV, OHLCVC, Order, OrderBook, Balance, Balances, Dictionary, Transaction, Currency, MinMax, IndexType, Int, OrderType, OrderSide, Position, FundingRate, DepositWithdrawFee, LedgerEntry, BorrowInterest, OpenInterest, LeverageTier, TransferEntry, FundingRateHistory, Liquidation, FundingHistory, OrderRequest, MarginMode, Tickers, Greeks, Option, OptionChain, Str, Num, MarketInterface, CurrencyInterface, BalanceAccount, MarginModes, MarketType, Leverage, Leverages, LastPrice, LastPrices, Account, Strings, MarginModification, TradingFeeInterface, Currencies, TradingFees, Conversion, CancellationRequest, IsolatedBorrowRate, IsolatedBorrowRates, CrossBorrowRates, CrossBorrowRate, Dict, FundingRates, LeverageTiers, Bool, int, DepositAddress, LongShortRatio, OrderBooks, OpenInterests, ConstructorArgs } from './types.js';
5
5
  export type { Market, Trade, Fee, Ticker, OHLCV, OHLCVC, Order, OrderBook, Balance, Balances, Dictionary, Transaction, Currency, MinMax, IndexType, Int, Bool, OrderType, OrderSide, Position, LedgerEntry, BorrowInterest, OpenInterest, LeverageTier, TransferEntry, CrossBorrowRate, FundingRateHistory, Liquidation, FundingHistory, OrderRequest, MarginMode, Tickers, Greeks, Option, OptionChain, Str, Num, MarketInterface, CurrencyInterface, BalanceAccount, MarginModes, MarketType, Leverage, Leverages, LastPrice, LastPrices, Account, Strings, Conversion, DepositAddress, LongShortRatio } from './types.js';
6
6
  import { ArrayCache, ArrayCacheByTimestamp } from './ws/Cache.js';
7
7
  import { OrderBook as Ob } from './ws/OrderBook.js';
@@ -457,6 +457,7 @@ export default class Exchange {
457
457
  unWatchOHLCVForSymbols(symbolsAndTimeframes: string[][], params?: {}): Promise<any>;
458
458
  watchOrderBookForSymbols(symbols: string[], limit?: Int, params?: {}): Promise<OrderBook>;
459
459
  unWatchOrderBookForSymbols(symbols: string[], params?: {}): Promise<any>;
460
+ unWatchPositions(symbols?: Strings, params?: {}): Promise<any>;
460
461
  fetchDepositAddresses(codes?: Strings, params?: {}): Promise<DepositAddress[]>;
461
462
  fetchOrderBook(symbol: string, limit?: Int, params?: {}): Promise<OrderBook>;
462
463
  fetchOrderBookWs(symbol: string, limit?: Int, params?: {}): Promise<OrderBook>;
@@ -567,6 +568,12 @@ export default class Exchange {
567
568
  safeBalance(balance: Dict): Balances;
568
569
  safeOrder(order: Dict, market?: Market): Order;
569
570
  parseOrders(orders: object, market?: Market, since?: Int, limit?: Int, params?: {}): Order[];
571
+ calculateFeeWithRate(symbol: string, type: string, side: string, amount: number, price: number, takerOrMaker?: string, feeRate?: Num, params?: {}): {
572
+ type: string;
573
+ currency: any;
574
+ rate: number;
575
+ cost: number;
576
+ };
570
577
  calculateFee(symbol: string, type: string, side: string, amount: number, price: number, takerOrMaker?: string, params?: {}): {
571
578
  type: string;
572
579
  currency: any;
@@ -575,6 +582,7 @@ export default class Exchange {
575
582
  };
576
583
  safeLiquidation(liquidation: Dict, market?: Market): Liquidation;
577
584
  safeTrade(trade: Dict, market?: Market): Trade;
585
+ createCcxtTradeId(timestamp?: any, side?: any, amount?: any, price?: any, takerOrMaker?: any): any;
578
586
  parsedFeeAndFees(container: any): Dictionary<any>[];
579
587
  parseFeeNumeric(fee: any): any;
580
588
  findNearestCeiling(arr: number[], providedValue: number): number;
@@ -686,8 +694,8 @@ export default class Exchange {
686
694
  fetchStatus(params?: {}): Promise<any>;
687
695
  fetchTransactionFee(code: string, params?: {}): Promise<{}>;
688
696
  fetchTransactionFees(codes?: Strings, params?: {}): Promise<{}>;
689
- fetchDepositWithdrawFees(codes?: Strings, params?: {}): Promise<Dictionary<DepositWithdrawFeeNetwork>>;
690
- fetchDepositWithdrawFee(code: string, params?: {}): Promise<DepositWithdrawFeeNetwork>;
697
+ fetchDepositWithdrawFees(codes?: Strings, params?: {}): Promise<Dictionary<DepositWithdrawFee>>;
698
+ fetchDepositWithdrawFee(code: string, params?: {}): Promise<DepositWithdrawFee>;
691
699
  getSupportedMapping(key: any, mapping?: {}): any;
692
700
  fetchCrossBorrowRate(code: string, params?: {}): Promise<CrossBorrowRate>;
693
701
  fetchIsolatedBorrowRate(symbol: string, params?: {}): Promise<IsolatedBorrowRate>;
@@ -1566,6 +1566,17 @@ export default class Exchange {
1566
1566
  'watchLiquidations': undefined,
1567
1567
  'watchLiquidationsForSymbols': undefined,
1568
1568
  'watchMyLiquidations': undefined,
1569
+ 'unWatchOrders': undefined,
1570
+ 'unWatchTrades': undefined,
1571
+ 'unWatchTradesForSymbols': undefined,
1572
+ 'unWatchOHLCVForSymbols': undefined,
1573
+ 'unWatchOrderBookForSymbols': undefined,
1574
+ 'unWatchPositions': undefined,
1575
+ 'unWatchOrderBook': undefined,
1576
+ 'unWatchTickers': undefined,
1577
+ 'unWatchMyTrades': undefined,
1578
+ 'unWatchTicker': undefined,
1579
+ 'unWatchOHLCV': undefined,
1569
1580
  'watchMyLiquidationsForSymbols': undefined,
1570
1581
  'withdraw': undefined,
1571
1582
  'ws': undefined,
@@ -2127,6 +2138,9 @@ export default class Exchange {
2127
2138
  async unWatchOrderBookForSymbols(symbols, params = {}) {
2128
2139
  throw new NotSupported(this.id + ' unWatchOrderBookForSymbols() is not supported yet');
2129
2140
  }
2141
+ async unWatchPositions(symbols = undefined, params = {}) {
2142
+ throw new NotSupported(this.id + ' unWatchPositions() is not supported yet');
2143
+ }
2130
2144
  async fetchDepositAddresses(codes = undefined, params = {}) {
2131
2145
  throw new NotSupported(this.id + ' fetchDepositAddresses() is not supported yet');
2132
2146
  }
@@ -3243,19 +3257,7 @@ export default class Exchange {
3243
3257
  const symbol = (market !== undefined) ? market['symbol'] : undefined;
3244
3258
  return this.filterBySymbolSinceLimit(results, symbol, since, limit);
3245
3259
  }
3246
- calculateFee(symbol, type, side, amount, price, takerOrMaker = 'taker', params = {}) {
3247
- /**
3248
- * @method
3249
- * @description calculates the presumptive fee that would be charged for an order
3250
- * @param {string} symbol unified market symbol
3251
- * @param {string} type 'market' or 'limit'
3252
- * @param {string} side 'buy' or 'sell'
3253
- * @param {float} amount how much you want to trade, in units of the base currency on most exchanges, or number of contracts
3254
- * @param {float} price the price for the order to be filled at, in units of the quote currency
3255
- * @param {string} takerOrMaker 'taker' or 'maker'
3256
- * @param {object} params
3257
- * @returns {object} contains the rate, the percentage multiplied to the order amount to obtain the fee amount, and cost, the total value of the fee in units of the quote currency, for the order
3258
- */
3260
+ calculateFeeWithRate(symbol, type, side, amount, price, takerOrMaker = 'taker', feeRate = undefined, params = {}) {
3259
3261
  if (type === 'market' && takerOrMaker === 'maker') {
3260
3262
  throw new ArgumentsRequired(this.id + ' calculateFee() - you have provided incompatible arguments - "market" type order can not be "maker". Change either the "type" or the "takerOrMaker" argument to calculate the fee.');
3261
3263
  }
@@ -3292,7 +3294,7 @@ export default class Exchange {
3292
3294
  if (type === 'market') {
3293
3295
  takerOrMaker = 'taker';
3294
3296
  }
3295
- const rate = this.safeString(market, takerOrMaker);
3297
+ const rate = (feeRate !== undefined) ? this.numberToString(feeRate) : this.safeString(market, takerOrMaker);
3296
3298
  cost = Precise.stringMul(cost, rate);
3297
3299
  return {
3298
3300
  'type': takerOrMaker,
@@ -3301,6 +3303,21 @@ export default class Exchange {
3301
3303
  'cost': this.parseNumber(cost),
3302
3304
  };
3303
3305
  }
3306
+ calculateFee(symbol, type, side, amount, price, takerOrMaker = 'taker', params = {}) {
3307
+ /**
3308
+ * @method
3309
+ * @description calculates the presumptive fee that would be charged for an order
3310
+ * @param {string} symbol unified market symbol
3311
+ * @param {string} type 'market' or 'limit'
3312
+ * @param {string} side 'buy' or 'sell'
3313
+ * @param {float} amount how much you want to trade, in units of the base currency on most exchanges, or number of contracts
3314
+ * @param {float} price the price for the order to be filled at, in units of the quote currency
3315
+ * @param {string} takerOrMaker 'taker' or 'maker'
3316
+ * @param {object} params
3317
+ * @returns {object} contains the rate, the percentage multiplied to the order amount to obtain the fee amount, and cost, the total value of the fee in units of the quote currency, for the order
3318
+ */
3319
+ return this.calculateFeeWithRate(symbol, type, side, amount, price, takerOrMaker, undefined, params);
3320
+ }
3304
3321
  safeLiquidation(liquidation, market = undefined) {
3305
3322
  const contracts = this.safeString(liquidation, 'contracts');
3306
3323
  const contractSize = this.safeString(market, 'contractSize');
@@ -3345,6 +3362,26 @@ export default class Exchange {
3345
3362
  trade['cost'] = this.parseNumber(cost);
3346
3363
  return trade;
3347
3364
  }
3365
+ createCcxtTradeId(timestamp = undefined, side = undefined, amount = undefined, price = undefined, takerOrMaker = undefined) {
3366
+ // this approach is being used by multiple exchanges (mexc, woo, coinsbit, dydx, ...)
3367
+ let id = undefined;
3368
+ if (timestamp !== undefined) {
3369
+ id = this.numberToString(timestamp);
3370
+ if (side !== undefined) {
3371
+ id += '-' + side;
3372
+ }
3373
+ if (amount !== undefined) {
3374
+ id += '-' + this.numberToString(amount);
3375
+ }
3376
+ if (price !== undefined) {
3377
+ id += '-' + this.numberToString(price);
3378
+ }
3379
+ if (takerOrMaker !== undefined) {
3380
+ id += '-' + takerOrMaker;
3381
+ }
3382
+ }
3383
+ return id;
3384
+ }
3348
3385
  parsedFeeAndFees(container) {
3349
3386
  let fee = this.safeDict(container, 'fee');
3350
3387
  let fees = this.safeList(container, 'fees');
@@ -6589,7 +6626,7 @@ export default class Exchange {
6589
6626
  let calls = 0;
6590
6627
  let result = [];
6591
6628
  let errors = 0;
6592
- const until = this.safeInteger2(params, 'untill', 'till'); // do not omit it from params here
6629
+ const until = this.safeIntegerN(params, ['until', 'untill', 'till']); // do not omit it from params here
6593
6630
  [maxEntriesPerRequest, params] = this.handleMaxEntriesPerRequestAndParams(method, maxEntriesPerRequest, params);
6594
6631
  if ((paginationDirection === 'forward')) {
6595
6632
  if (since === undefined) {
@@ -7283,6 +7320,17 @@ export default class Exchange {
7283
7320
  else if (topic === 'orders' && (this.orders !== undefined)) {
7284
7321
  this.orders = undefined;
7285
7322
  }
7323
+ else if (topic === 'positions' && (this.positions !== undefined)) {
7324
+ this.positions = undefined;
7325
+ const clients = Object.values(this.clients);
7326
+ for (let i = 0; i < clients.length; i++) {
7327
+ const client = clients[i];
7328
+ const futures = this.safeDict(client, 'futures');
7329
+ if ((futures !== undefined) && ('fetchPositionsSnapshot' in futures)) {
7330
+ delete futures['fetchPositionsSnapshot'];
7331
+ }
7332
+ }
7333
+ }
7286
7334
  else if (topic === 'ticker' && (this.tickers !== undefined)) {
7287
7335
  const tickerSymbols = Object.keys(this.tickers);
7288
7336
  for (let i = 0; i < tickerSymbols.length; i++) {
@@ -17,6 +17,7 @@ declare const errorHierarchy: {
17
17
  };
18
18
  MarketClosed: {};
19
19
  ManualInteractionNeeded: {};
20
+ RestrictedLocation: {};
20
21
  };
21
22
  InsufficientFunds: {};
22
23
  InvalidAddress: {
@@ -23,6 +23,7 @@ const errorHierarchy = {
23
23
  },
24
24
  'MarketClosed': {},
25
25
  'ManualInteractionNeeded': {},
26
+ 'RestrictedLocation': {},
26
27
  },
27
28
  'InsufficientFunds': {},
28
29
  'InvalidAddress': {
@@ -40,6 +40,9 @@ declare class MarketClosed extends OperationRejected {
40
40
  declare class ManualInteractionNeeded extends OperationRejected {
41
41
  constructor(message: string);
42
42
  }
43
+ declare class RestrictedLocation extends OperationRejected {
44
+ constructor(message: string);
45
+ }
43
46
  declare class InsufficientFunds extends ExchangeError {
44
47
  constructor(message: string);
45
48
  }
@@ -118,7 +121,7 @@ declare class CancelPending extends OperationFailed {
118
121
  declare class UnsubscribeError extends BaseError {
119
122
  constructor(message: string);
120
123
  }
121
- export { BaseError, ExchangeError, AuthenticationError, PermissionDenied, AccountNotEnabled, AccountSuspended, ArgumentsRequired, BadRequest, BadSymbol, OperationRejected, NoChange, MarginModeAlreadySet, MarketClosed, ManualInteractionNeeded, InsufficientFunds, InvalidAddress, AddressPending, InvalidOrder, OrderNotFound, OrderNotCached, OrderImmediatelyFillable, OrderNotFillable, DuplicateOrderId, ContractUnavailable, NotSupported, InvalidProxySettings, ExchangeClosedByUser, OperationFailed, NetworkError, DDoSProtection, RateLimitExceeded, ExchangeNotAvailable, OnMaintenance, InvalidNonce, ChecksumError, RequestTimeout, BadResponse, NullResponse, CancelPending, UnsubscribeError };
124
+ export { BaseError, ExchangeError, AuthenticationError, PermissionDenied, AccountNotEnabled, AccountSuspended, ArgumentsRequired, BadRequest, BadSymbol, OperationRejected, NoChange, MarginModeAlreadySet, MarketClosed, ManualInteractionNeeded, RestrictedLocation, InsufficientFunds, InvalidAddress, AddressPending, InvalidOrder, OrderNotFound, OrderNotCached, OrderImmediatelyFillable, OrderNotFillable, DuplicateOrderId, ContractUnavailable, NotSupported, InvalidProxySettings, ExchangeClosedByUser, OperationFailed, NetworkError, DDoSProtection, RateLimitExceeded, ExchangeNotAvailable, OnMaintenance, InvalidNonce, ChecksumError, RequestTimeout, BadResponse, NullResponse, CancelPending, UnsubscribeError };
122
125
  declare const _default: {
123
126
  BaseError: typeof BaseError;
124
127
  ExchangeError: typeof ExchangeError;
@@ -134,6 +137,7 @@ declare const _default: {
134
137
  MarginModeAlreadySet: typeof MarginModeAlreadySet;
135
138
  MarketClosed: typeof MarketClosed;
136
139
  ManualInteractionNeeded: typeof ManualInteractionNeeded;
140
+ RestrictedLocation: typeof RestrictedLocation;
137
141
  InsufficientFunds: typeof InsufficientFunds;
138
142
  InvalidAddress: typeof InvalidAddress;
139
143
  AddressPending: typeof AddressPending;
@@ -89,6 +89,12 @@ class ManualInteractionNeeded extends OperationRejected {
89
89
  this.name = 'ManualInteractionNeeded';
90
90
  }
91
91
  }
92
+ class RestrictedLocation extends OperationRejected {
93
+ constructor(message) {
94
+ super(message);
95
+ this.name = 'RestrictedLocation';
96
+ }
97
+ }
92
98
  class InsufficientFunds extends ExchangeError {
93
99
  constructor(message) {
94
100
  super(message);
@@ -245,5 +251,5 @@ class UnsubscribeError extends BaseError {
245
251
  this.name = 'UnsubscribeError';
246
252
  }
247
253
  }
248
- export { BaseError, ExchangeError, AuthenticationError, PermissionDenied, AccountNotEnabled, AccountSuspended, ArgumentsRequired, BadRequest, BadSymbol, OperationRejected, NoChange, MarginModeAlreadySet, MarketClosed, ManualInteractionNeeded, InsufficientFunds, InvalidAddress, AddressPending, InvalidOrder, OrderNotFound, OrderNotCached, OrderImmediatelyFillable, OrderNotFillable, DuplicateOrderId, ContractUnavailable, NotSupported, InvalidProxySettings, ExchangeClosedByUser, OperationFailed, NetworkError, DDoSProtection, RateLimitExceeded, ExchangeNotAvailable, OnMaintenance, InvalidNonce, ChecksumError, RequestTimeout, BadResponse, NullResponse, CancelPending, UnsubscribeError };
249
- export default { BaseError, ExchangeError, AuthenticationError, PermissionDenied, AccountNotEnabled, AccountSuspended, ArgumentsRequired, BadRequest, BadSymbol, OperationRejected, NoChange, MarginModeAlreadySet, MarketClosed, ManualInteractionNeeded, InsufficientFunds, InvalidAddress, AddressPending, InvalidOrder, OrderNotFound, OrderNotCached, OrderImmediatelyFillable, OrderNotFillable, DuplicateOrderId, ContractUnavailable, NotSupported, InvalidProxySettings, ExchangeClosedByUser, OperationFailed, NetworkError, DDoSProtection, RateLimitExceeded, ExchangeNotAvailable, OnMaintenance, InvalidNonce, ChecksumError, RequestTimeout, BadResponse, NullResponse, CancelPending, UnsubscribeError };
254
+ export { BaseError, ExchangeError, AuthenticationError, PermissionDenied, AccountNotEnabled, AccountSuspended, ArgumentsRequired, BadRequest, BadSymbol, OperationRejected, NoChange, MarginModeAlreadySet, MarketClosed, ManualInteractionNeeded, RestrictedLocation, InsufficientFunds, InvalidAddress, AddressPending, InvalidOrder, OrderNotFound, OrderNotCached, OrderImmediatelyFillable, OrderNotFillable, DuplicateOrderId, ContractUnavailable, NotSupported, InvalidProxySettings, ExchangeClosedByUser, OperationFailed, NetworkError, DDoSProtection, RateLimitExceeded, ExchangeNotAvailable, OnMaintenance, InvalidNonce, ChecksumError, RequestTimeout, BadResponse, NullResponse, CancelPending, UnsubscribeError };
255
+ export default { BaseError, ExchangeError, AuthenticationError, PermissionDenied, AccountNotEnabled, AccountSuspended, ArgumentsRequired, BadRequest, BadSymbol, OperationRejected, NoChange, MarginModeAlreadySet, MarketClosed, ManualInteractionNeeded, RestrictedLocation, InsufficientFunds, InvalidAddress, AddressPending, InvalidOrder, OrderNotFound, OrderNotCached, OrderImmediatelyFillable, OrderNotFillable, DuplicateOrderId, ContractUnavailable, NotSupported, InvalidProxySettings, ExchangeClosedByUser, OperationFailed, NetworkError, DDoSProtection, RateLimitExceeded, ExchangeNotAvailable, OnMaintenance, InvalidNonce, ChecksumError, RequestTimeout, BadResponse, NullResponse, CancelPending, UnsubscribeError };
@@ -36,6 +36,8 @@ const precisionConstants = {
36
36
  NO_PADDING,
37
37
  PAD_WITH_ZERO,
38
38
  };
39
+ const assert = (x, y) => { if (!x)
40
+ throw new Error(y || 'assertion failed'); };
39
41
  /* ------------------------------------------------------------------------ */
40
42
  // See https://stackoverflow.com/questions/1685680/how-to-avoid-scientific-notation-for-large-numbers-in-javascript for discussion
41
43
  function numberToString(x) {
@@ -101,14 +103,21 @@ const decimalToPrecision = (x, roundingMode, numPrecisionDigits, countingMode =
101
103
  return _decimalToPrecision(x, roundingMode, numPrecisionDigits, countingMode, paddingMode);
102
104
  };
103
105
  const _decimalToPrecision = (x, roundingMode, numPrecisionDigits, countingMode = DECIMAL_PLACES, paddingMode = NO_PADDING) => {
106
+ assert(numPrecisionDigits !== undefined, 'numPrecisionDigits should not be undefined');
107
+ if (typeof numPrecisionDigits === 'string') {
108
+ numPrecisionDigits = parseFloat(numPrecisionDigits);
109
+ }
110
+ assert(Number.isFinite(numPrecisionDigits), 'numPrecisionDigits has an invalid number');
104
111
  if (countingMode === TICK_SIZE) {
105
- if (typeof numPrecisionDigits === 'string') {
106
- numPrecisionDigits = parseFloat(numPrecisionDigits);
107
- }
108
- if (numPrecisionDigits <= 0) {
109
- throw new Error('TICK_SIZE cant be used with negative or zero numPrecisionDigits');
110
- }
112
+ assert(numPrecisionDigits > 0, 'negative or zero numPrecisionDigits can not be used with TICK_SIZE precisionMode');
113
+ }
114
+ else {
115
+ assert(Number.isInteger(numPrecisionDigits), 'numPrecisionDigits must be an integer with DECIMAL_PLACES or SIGNIFICANT_DIGITS precisionMode');
111
116
  }
117
+ assert((roundingMode === ROUND) || (roundingMode === TRUNCATE), 'invalid roundingMode provided');
118
+ assert(countingMode === DECIMAL_PLACES || countingMode === SIGNIFICANT_DIGITS || countingMode === TICK_SIZE, 'invalid countingMode provided');
119
+ assert(paddingMode === NO_PADDING || paddingMode === PAD_WITH_ZERO, 'invalid paddingMode provided');
120
+ // end of checks
112
121
  if (numPrecisionDigits < 0) {
113
122
  const toNearest = Math.pow(10, -numPrecisionDigits);
114
123
  if (roundingMode === ROUND) {
@@ -122,6 +131,21 @@ const _decimalToPrecision = (x, roundingMode, numPrecisionDigits, countingMode =
122
131
  if (countingMode === TICK_SIZE) {
123
132
  const precisionDigitsString = _decimalToPrecision(numPrecisionDigits, ROUND, 22, DECIMAL_PLACES, NO_PADDING);
124
133
  const newNumPrecisionDigits = precisionFromString(precisionDigitsString);
134
+ if (roundingMode === TRUNCATE) {
135
+ // First, truncate the string to avoid floating-point precision issues
136
+ const xStr = numberToString(x);
137
+ const truncatedX = truncate_to_string(xStr, Math.max(0, newNumPrecisionDigits));
138
+ const xNum = Number(truncatedX);
139
+ const scale = Math.pow(10, newNumPrecisionDigits);
140
+ const xScaled = Math.round(xNum * scale);
141
+ const tickScaled = Math.round(numPrecisionDigits * scale);
142
+ const ticks = Math.trunc(xScaled / tickScaled);
143
+ x = (ticks * tickScaled) / scale;
144
+ if (paddingMode === NO_PADDING) {
145
+ return String(Number(x.toFixed(newNumPrecisionDigits)));
146
+ }
147
+ return _decimalToPrecision(x, ROUND, newNumPrecisionDigits, DECIMAL_PLACES, paddingMode);
148
+ }
125
149
  let missing = x % numPrecisionDigits;
126
150
  // See: https://github.com/ccxt/ccxt/pull/6486
127
151
  missing = Number(_decimalToPrecision(missing, ROUND, 8, DECIMAL_PLACES, NO_PADDING));
@@ -145,9 +169,6 @@ const _decimalToPrecision = (x, roundingMode, numPrecisionDigits, countingMode =
145
169
  }
146
170
  }
147
171
  }
148
- else if (roundingMode === TRUNCATE) {
149
- x = x - missing;
150
- }
151
172
  }
152
173
  return _decimalToPrecision(x, ROUND, newNumPrecisionDigits, DECIMAL_PLACES, paddingMode);
153
174
  }
@@ -169,6 +169,7 @@ export default class binance extends Exchange {
169
169
  * @returns {object} a dictionary of [ticker structures]{@link https://docs.ccxt.com/#/?id=ticker-structure}
170
170
  */
171
171
  fetchTickers(symbols?: Strings, params?: {}): Promise<Tickers>;
172
+ parseTickersForRolling(response: any, symbols: any): any;
172
173
  /**
173
174
  * @method
174
175
  * @name binance#fetchMarkPrice
package/js/src/binance.js CHANGED
@@ -485,6 +485,7 @@ export default class binance extends Exchange {
485
485
  'portfolio/balance': 2,
486
486
  'portfolio/negative-balance-exchange-record': 2,
487
487
  'portfolio/pmloan-history': 5,
488
+ 'portfolio/earn-asset-balance': 150,
488
489
  // staking
489
490
  'staking/productList': 0.1,
490
491
  'staking/position': 0.1,
@@ -643,6 +644,7 @@ export default class binance extends Exchange {
643
644
  'portfolio/repay-futures-negative-balance': 150,
644
645
  'portfolio/mint': 20,
645
646
  'portfolio/redeem': 20,
647
+ 'portfolio/earn-asset-transfer': 150,
646
648
  'lending/auto-invest/plan/add': 0.1,
647
649
  'lending/auto-invest/plan/edit': 0.1,
648
650
  'lending/auto-invest/plan/edit-status': 0.1,
@@ -831,6 +833,7 @@ export default class binance extends Exchange {
831
833
  'apiTradingStatus': { 'cost': 1, 'noSymbol': 10 },
832
834
  'lvtKlines': 1,
833
835
  'convert/exchangeInfo': 4,
836
+ 'insuranceBalance': 1,
834
837
  },
835
838
  },
836
839
  'fapiData': {
@@ -1268,12 +1271,14 @@ export default class binance extends Exchange {
1268
1271
  'options': {
1269
1272
  'sandboxMode': false,
1270
1273
  'fetchMargins': true,
1271
- 'fetchMarkets': [
1272
- 'spot',
1273
- 'linear',
1274
- 'inverse', // allows CORS in browsers
1275
- // 'option', // does not allow CORS, enable outside of the browser only
1276
- ],
1274
+ 'fetchMarkets': {
1275
+ 'types': [
1276
+ 'spot',
1277
+ 'linear',
1278
+ 'inverse', // allows CORS in browsers
1279
+ // 'option', // does not allow CORS, enable outside of the browser only
1280
+ ],
1281
+ },
1277
1282
  'loadAllOptions': false,
1278
1283
  'fetchCurrencies': true,
1279
1284
  // 'fetchTradesMethod': 'publicGetAggTrades', // publicGetTrades, publicGetHistoricalTrades, eapiPublicGetTrades
@@ -3040,7 +3045,16 @@ export default class binance extends Exchange {
3040
3045
  */
3041
3046
  async fetchMarkets(params = {}) {
3042
3047
  const promisesRaw = [];
3043
- const rawFetchMarkets = this.safeList(this.options, 'fetchMarkets', ['spot', 'linear', 'inverse']);
3048
+ let rawFetchMarkets = undefined;
3049
+ const defaultTypes = ['spot', 'linear', 'inverse'];
3050
+ const fetchMarketsOptions = this.safeDict(this.options, 'fetchMarkets');
3051
+ if (fetchMarketsOptions !== undefined) {
3052
+ rawFetchMarkets = this.safeList(fetchMarketsOptions, 'types', defaultTypes);
3053
+ }
3054
+ else {
3055
+ // for backward-compatibility
3056
+ rawFetchMarkets = this.safeList(this.options, 'fetchMarkets', defaultTypes);
3057
+ }
3044
3058
  // handle loadAllOptions option
3045
3059
  const loadAllOptions = this.safeBool(this.options, 'loadAllOptions', false);
3046
3060
  if (loadAllOptions) {
@@ -4010,29 +4024,52 @@ export default class binance extends Exchange {
4010
4024
  // "time": 1597370495002
4011
4025
  // }
4012
4026
  //
4013
- // {
4014
- // "symbol": "ETHBTC",
4015
- // "priceChange": "0.00068700",
4016
- // "priceChangePercent": "2.075",
4017
- // "weightedAvgPrice": "0.03342681",
4018
- // "prevClosePrice": "0.03310300",
4019
- // "lastPrice": "0.03378900",
4020
- // "lastQty": "0.07700000",
4021
- // "bidPrice": "0.03378900",
4022
- // "bidQty": "7.16800000",
4023
- // "askPrice": "0.03379000",
4024
- // "askQty": "24.00000000",
4025
- // "openPrice": "0.03310200",
4026
- // "highPrice": "0.03388900",
4027
- // "lowPrice": "0.03306900",
4028
- // "volume": "205478.41000000",
4029
- // "quoteVolume": "6868.48826294",
4030
- // "openTime": 1601469986932,
4031
- // "closeTime": 1601556386932,
4032
- // "firstId": 196098772,
4033
- // "lastId": 196186315,
4034
- // "count": 87544
4035
- // }
4027
+ // spot - ticker
4028
+ //
4029
+ // {
4030
+ // "symbol": "BTCUSDT",
4031
+ // "priceChange": "-188.18000000",
4032
+ // "priceChangePercent": "-0.159",
4033
+ // "weightedAvgPrice": "118356.64734074",
4034
+ // "lastPrice": "118449.03000000",
4035
+ // "prevClosePrice": "118637.22000000", // field absent in rolling ticker
4036
+ // "lastQty": "0.00731000", // field absent in rolling ticker
4037
+ // "bidPrice": "118449.02000000", // field absent in rolling ticker
4038
+ // "bidQty": "7.15931000", // field absent in rolling ticker
4039
+ // "askPrice": "118449.03000000", // field absent in rolling ticker
4040
+ // "askQty": "0.09592000", // field absent in rolling ticker
4041
+ // "openPrice": "118637.21000000",
4042
+ // "highPrice": "119273.36000000",
4043
+ // "lowPrice": "117427.50000000",
4044
+ // "volume": "14741.41491000",
4045
+ // "quoteVolume": "1744744445.80640740",
4046
+ // "openTime": "1753701474013",
4047
+ // "closeTime": "1753787874013",
4048
+ // "firstId": "5116031635",
4049
+ // "lastId": "5117964946",
4050
+ // "count": "1933312"
4051
+ // }
4052
+ //
4053
+ // usdm tickers
4054
+ //
4055
+ // {
4056
+ // "symbol": "SUSDT",
4057
+ // "priceChange": "-0.0229000",
4058
+ // "priceChangePercent": "-6.777",
4059
+ // "weightedAvgPrice": "0.3210035",
4060
+ // "lastPrice": "0.3150000",
4061
+ // "lastQty": "16",
4062
+ // "openPrice": "0.3379000",
4063
+ // "highPrice": "0.3411000",
4064
+ // "lowPrice": "0.3071000",
4065
+ // "volume": "120588225",
4066
+ // "quoteVolume": "38709237.2289000",
4067
+ // "openTime": "1753701720000",
4068
+ // "closeTime": "1753788172414",
4069
+ // "firstId": "72234973",
4070
+ // "lastId": "72423677",
4071
+ // "count": "188700"
4072
+ // }
4036
4073
  //
4037
4074
  // coinm
4038
4075
  //
@@ -4405,11 +4442,24 @@ export default class binance extends Exchange {
4405
4442
  response = await this.dapiPublicGetTicker24hr(params);
4406
4443
  }
4407
4444
  else if (type === 'spot') {
4408
- const request = {};
4409
- if (symbols !== undefined) {
4410
- request['symbols'] = this.json(this.marketIds(symbols));
4445
+ const rolling = this.safeBool(params, 'rolling', false);
4446
+ params = this.omit(params, 'rolling');
4447
+ if (rolling) {
4448
+ symbols = this.marketSymbols(symbols);
4449
+ const request = {
4450
+ 'symbols': this.json(this.marketIds(symbols)),
4451
+ };
4452
+ response = await this.publicGetTicker(this.extend(request, params));
4453
+ // parseTicker is not able to handle marketType for spot-rolling ticker fields, so we need custom parsing
4454
+ return this.parseTickersForRolling(response, symbols);
4455
+ }
4456
+ else {
4457
+ const request = {};
4458
+ if (symbols !== undefined) {
4459
+ request['symbols'] = this.json(this.marketIds(symbols));
4460
+ }
4461
+ response = await this.publicGetTicker24hr(this.extend(request, params));
4411
4462
  }
4412
- response = await this.publicGetTicker24hr(this.extend(request, params));
4413
4463
  }
4414
4464
  else if (type === 'option') {
4415
4465
  response = await this.eapiPublicGetTicker(params);
@@ -4419,6 +4469,17 @@ export default class binance extends Exchange {
4419
4469
  }
4420
4470
  return this.parseTickers(response, symbols);
4421
4471
  }
4472
+ parseTickersForRolling(response, symbols) {
4473
+ const results = [];
4474
+ for (let i = 0; i < response.length; i++) {
4475
+ const marketId = this.safeString(response[i], 'symbol');
4476
+ const tickerMarket = this.safeMarket(marketId, undefined, undefined, 'spot');
4477
+ const parsedTicker = this.parseTicker(response[i]);
4478
+ parsedTicker['symbol'] = tickerMarket['symbol'];
4479
+ results.push(parsedTicker);
4480
+ }
4481
+ return this.filterByArray(results, 'symbol', symbols);
4482
+ }
4422
4483
  /**
4423
4484
  * @method
4424
4485
  * @name binance#fetchMarkPrice
@@ -30,7 +30,11 @@ export default class binancecoinm extends binance {
30
30
  'createStopMarketOrder': true,
31
31
  },
32
32
  'options': {
33
- 'fetchMarkets': ['inverse'],
33
+ 'fetchMarkets': {
34
+ 'types': [
35
+ 'inverse',
36
+ ],
37
+ },
34
38
  'defaultSubType': 'inverse',
35
39
  'leverageBrackets': undefined,
36
40
  },
@@ -41,7 +41,9 @@ export default class binanceus extends binance {
41
41
  },
42
42
  },
43
43
  'options': {
44
- 'fetchMarkets': ['spot'],
44
+ 'fetchMarkets': {
45
+ 'types': ['spot'],
46
+ },
45
47
  'defaultType': 'spot',
46
48
  'fetchMargins': false,
47
49
  'quoteOrderQty': false,
@@ -31,7 +31,9 @@ export default class binanceusdm extends binance {
31
31
  'createStopMarketOrder': true,
32
32
  },
33
33
  'options': {
34
- 'fetchMarkets': ['linear'],
34
+ 'fetchMarkets': {
35
+ 'types': ['linear'],
36
+ },
35
37
  'defaultSubType': 'linear',
36
38
  // https://www.binance.com/en/support/faq/360033162192
37
39
  // tier amount, maintenance margin, initial margin,
package/js/src/bingx.js CHANGED
@@ -5304,7 +5304,7 @@ export default class bingx extends Exchange {
5304
5304
  const id = this.safeString(transaction, 'id', dataId);
5305
5305
  const address = this.safeString(transaction, 'address');
5306
5306
  const tag = this.safeString(transaction, 'addressTag');
5307
- let timestamp = this.safeInteger(transaction, 'insertTime');
5307
+ let timestamp = this.safeInteger2(transaction, 'insertTime', 'timestamp');
5308
5308
  let datetime = this.iso8601(timestamp);
5309
5309
  if (timestamp === undefined) {
5310
5310
  datetime = this.safeString(transaction, 'applyTime');