ccxt 4.2.43 → 4.2.45

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 (46) hide show
  1. package/README.md +3 -3
  2. package/dist/ccxt.browser.js +1489 -463
  3. package/dist/ccxt.browser.min.js +6 -6
  4. package/dist/cjs/ccxt.js +1 -1
  5. package/dist/cjs/src/base/Exchange.js +54 -0
  6. package/dist/cjs/src/binance.js +627 -51
  7. package/dist/cjs/src/bingx.js +46 -6
  8. package/dist/cjs/src/bitstamp.js +1 -1
  9. package/dist/cjs/src/blofin.js +2 -1
  10. package/dist/cjs/src/bybit.js +96 -43
  11. package/dist/cjs/src/coinbase.js +221 -41
  12. package/dist/cjs/src/deribit.js +1 -1
  13. package/dist/cjs/src/krakenfutures.js +3 -2
  14. package/dist/cjs/src/kucoin.js +9 -5
  15. package/dist/cjs/src/mexc.js +348 -266
  16. package/dist/cjs/src/pro/gate.js +76 -42
  17. package/dist/cjs/src/pro/hitbtc.js +1 -0
  18. package/dist/cjs/src/probit.js +3 -3
  19. package/js/ccxt.d.ts +1 -1
  20. package/js/ccxt.js +1 -1
  21. package/js/src/abstract/coinbase.d.ts +1 -0
  22. package/js/src/base/Exchange.d.ts +4 -0
  23. package/js/src/base/Exchange.js +54 -0
  24. package/js/src/binance.d.ts +1 -0
  25. package/js/src/binance.js +627 -51
  26. package/js/src/bingx.d.ts +2 -1
  27. package/js/src/bingx.js +46 -6
  28. package/js/src/bitstamp.js +1 -1
  29. package/js/src/blofin.js +2 -1
  30. package/js/src/bybit.d.ts +4 -1
  31. package/js/src/bybit.js +96 -43
  32. package/js/src/coinbase.d.ts +10 -4
  33. package/js/src/coinbase.js +221 -41
  34. package/js/src/coinbasepro.d.ts +1 -1
  35. package/js/src/deribit.js +1 -1
  36. package/js/src/krakenfutures.js +3 -2
  37. package/js/src/kucoin.js +9 -5
  38. package/js/src/mexc.d.ts +4 -5
  39. package/js/src/mexc.js +348 -266
  40. package/js/src/pro/gate.d.ts +4 -0
  41. package/js/src/pro/gate.js +76 -42
  42. package/js/src/pro/hitbtc.js +1 -0
  43. package/js/src/probit.js +3 -3
  44. package/js/src/static_dependencies/jsencrypt/lib/jsbn/jsbn.d.ts +1 -1
  45. package/package.json +1 -1
  46. package/skip-tests.json +2 -0
@@ -272,6 +272,7 @@ class gate extends gate$1 {
272
272
  /**
273
273
  * @method
274
274
  * @name gate#watchTicker
275
+ * @see https://www.gate.io/docs/developers/apiv4/ws/en/#tickers-channel
275
276
  * @description watches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market
276
277
  * @param {string} symbol unified symbol of the market to fetch the ticker for
277
278
  * @param {object} [params] extra parameters specific to the exchange API endpoint
@@ -280,45 +281,21 @@ class gate extends gate$1 {
280
281
  await this.loadMarkets();
281
282
  const market = this.market(symbol);
282
283
  symbol = market['symbol'];
283
- const marketId = market['id'];
284
- const url = this.getUrlByMarket(market);
285
- const messageType = this.getTypeByMarket(market);
286
- const [topic, query] = this.handleOptionAndParams(params, 'watchTicker', 'name', 'tickers');
287
- const channel = messageType + '.' + topic;
288
- const messageHash = 'ticker:' + symbol;
289
- const payload = [marketId];
290
- return await this.subscribePublic(url, messageHash, payload, channel, query);
284
+ params['callerMethodName'] = 'watchTicker';
285
+ const result = await this.watchTickers([symbol], params);
286
+ return this.safeValue(result, symbol);
291
287
  }
292
288
  async watchTickers(symbols = undefined, params = {}) {
293
289
  /**
294
290
  * @method
295
291
  * @name gate#watchTickers
292
+ * @see https://www.gate.io/docs/developers/apiv4/ws/en/#tickers-channel
296
293
  * @description watches a price ticker, a statistical calculation with the information calculated over the past 24 hours for all markets of a specific list
297
294
  * @param {string[]} symbols unified symbol of the market to fetch the ticker for
298
295
  * @param {object} [params] extra parameters specific to the exchange API endpoint
299
296
  * @returns {object} a [ticker structure]{@link https://docs.ccxt.com/#/?id=ticker-structure}
300
297
  */
301
- await this.loadMarkets();
302
- symbols = this.marketSymbols(symbols);
303
- if (symbols === undefined) {
304
- throw new errors.ArgumentsRequired(this.id + ' watchTickers requires symbols');
305
- }
306
- const market = this.market(symbols[0]);
307
- const messageType = this.getTypeByMarket(market);
308
- const marketIds = this.marketIds(symbols);
309
- const [topic, query] = this.handleOptionAndParams(params, 'watchTicker', 'method', 'tickers');
310
- const channel = messageType + '.' + topic;
311
- const messageHash = 'tickers';
312
- const url = this.getUrlByMarket(market);
313
- const ticker = await this.subscribePublic(url, messageHash, marketIds, channel, query);
314
- let result = {};
315
- if (this.newUpdates) {
316
- result[ticker['symbol']] = ticker;
317
- }
318
- else {
319
- result = this.tickers;
320
- }
321
- return this.filterByArray(result, 'symbol', symbols, true);
298
+ return await this.subscribeWatchTickersAndBidsAsks(symbols, 'watchTickers', this.extend({ 'method': 'tickers' }, params));
322
299
  }
323
300
  handleTicker(client, message) {
324
301
  //
@@ -338,6 +315,24 @@ class gate extends gate$1 {
338
315
  // "low_24h": "42721.03"
339
316
  // }
340
317
  // }
318
+ //
319
+ this.handleTickerAndBidAsk('ticker', client, message);
320
+ }
321
+ async watchBidsAsks(symbols = undefined, params = {}) {
322
+ /**
323
+ * @method
324
+ * @name gate#watchBidsAsks
325
+ * @see https://www.gate.io/docs/developers/apiv4/ws/en/#best-bid-or-ask-price
326
+ * @see https://www.gate.io/docs/developers/apiv4/ws/en/#order-book-channel
327
+ * @description watches best bid & ask for symbols
328
+ * @param {string[]} symbols unified symbol of the market to fetch the ticker for
329
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
330
+ * @returns {object} a [ticker structure]{@link https://docs.ccxt.com/#/?id=ticker-structure}
331
+ */
332
+ return await this.subscribeWatchTickersAndBidsAsks(symbols, 'watchBidsAsks', this.extend({ 'method': 'book_ticker' }, params));
333
+ }
334
+ handleBidAsk(client, message) {
335
+ //
341
336
  // {
342
337
  // "time": 1671363004,
343
338
  // "time_ms": 1671363004235,
@@ -354,24 +349,63 @@ class gate extends gate$1 {
354
349
  // }
355
350
  // }
356
351
  //
352
+ this.handleTickerAndBidAsk('bidask', client, message);
353
+ }
354
+ async subscribeWatchTickersAndBidsAsks(symbols = undefined, callerMethodName = undefined, params = {}) {
355
+ await this.loadMarkets();
356
+ [callerMethodName, params] = this.handleParamString(params, 'callerMethodName', callerMethodName);
357
+ symbols = this.marketSymbols(symbols, undefined, false);
358
+ const market = this.market(symbols[0]);
359
+ const messageType = this.getTypeByMarket(market);
360
+ const marketIds = this.marketIds(symbols);
361
+ let channelName = undefined;
362
+ [channelName, params] = this.handleOptionAndParams(params, callerMethodName, 'method');
363
+ const url = this.getUrlByMarket(market);
364
+ const channel = messageType + '.' + channelName;
365
+ const isWatchTickers = callerMethodName.indexOf('watchTicker') >= 0;
366
+ const prefix = isWatchTickers ? 'ticker' : 'bidask';
367
+ const messageHashes = [];
368
+ for (let i = 0; i < symbols.length; i++) {
369
+ const symbol = symbols[i];
370
+ messageHashes.push(prefix + ':' + symbol);
371
+ }
372
+ const tickerOrBidAsk = await this.subscribePublicMultiple(url, messageHashes, marketIds, channel, params);
373
+ if (this.newUpdates) {
374
+ const items = {};
375
+ items[tickerOrBidAsk['symbol']] = tickerOrBidAsk;
376
+ return items;
377
+ }
378
+ const result = isWatchTickers ? this.tickers : this.bidsasks;
379
+ return this.filterByArray(result, 'symbol', symbols, true);
380
+ }
381
+ handleTickerAndBidAsk(objectName, client, message) {
357
382
  const channel = this.safeString(message, 'channel');
358
383
  const parts = channel.split('.');
359
384
  const rawMarketType = this.safeString(parts, 0);
360
385
  const marketType = (rawMarketType === 'futures') ? 'contract' : 'spot';
361
- let result = this.safeValue(message, 'result');
362
- if (!Array.isArray(result)) {
363
- result = [result];
386
+ let results = [];
387
+ if (marketType === 'contract') {
388
+ results = this.safeList(message, 'result', []);
364
389
  }
365
- for (let i = 0; i < result.length; i++) {
366
- const ticker = result[i];
367
- const marketId = this.safeString(ticker, 's');
390
+ else {
391
+ const rawTicker = this.safeDict(message, 'result', {});
392
+ results = [rawTicker];
393
+ }
394
+ const isTicker = (objectName === 'ticker'); // whether ticker or bid-ask
395
+ for (let i = 0; i < results.length; i++) {
396
+ const rawTicker = results[i];
397
+ const marketId = this.safeString(rawTicker, 's');
368
398
  const market = this.safeMarket(marketId, undefined, '_', marketType);
369
- const parsed = this.parseTicker(ticker, market);
370
- const symbol = parsed['symbol'];
371
- this.tickers[symbol] = parsed;
372
- const messageHash = 'ticker:' + symbol;
373
- client.resolve(parsed, messageHash);
374
- client.resolve(parsed, 'tickers');
399
+ const parsedItem = this.parseTicker(rawTicker, market);
400
+ const symbol = parsedItem['symbol'];
401
+ if (isTicker) {
402
+ this.tickers[symbol] = parsedItem;
403
+ }
404
+ else {
405
+ this.bidsasks[symbol] = parsedItem;
406
+ }
407
+ const messageHash = objectName + ':' + symbol;
408
+ client.resolve(parsedItem, messageHash);
375
409
  }
376
410
  }
377
411
  async watchTrades(symbol, since = undefined, limit = undefined, params = {}) {
@@ -1172,7 +1206,7 @@ class gate extends gate$1 {
1172
1206
  'orders': this.handleOrder,
1173
1207
  'positions': this.handlePositions,
1174
1208
  'tickers': this.handleTicker,
1175
- 'book_ticker': this.handleTicker,
1209
+ 'book_ticker': this.handleBidAsk,
1176
1210
  'trades': this.handleTrades,
1177
1211
  'order_book_update': this.handleOrderBook,
1178
1212
  'balances': this.handleBalance,
@@ -408,6 +408,7 @@ class hitbtc extends hitbtc$1 {
408
408
  const messageHash = channel + '::' + symbol;
409
409
  client.resolve(newTickers, messageHash);
410
410
  }
411
+ client.resolve(newTickers, 'tickers');
411
412
  const messageHashes = this.findMessageHashes(client, 'tickers::');
412
413
  for (let i = 0; i < messageHashes.length; i++) {
413
414
  const messageHash = messageHashes[i];
@@ -1589,12 +1589,12 @@ class probit extends probit$1 {
1589
1589
  const currencyId = this.safeString(transaction, 'currency_id');
1590
1590
  const code = this.safeCurrencyCode(currencyId);
1591
1591
  const status = this.parseTransactionStatus(this.safeString(transaction, 'status'));
1592
- const feeCost = this.safeNumber(transaction, 'fee');
1592
+ const feeCostString = this.safeString(transaction, 'fee');
1593
1593
  let fee = undefined;
1594
- if (feeCost !== undefined && feeCost !== 0) {
1594
+ if (feeCostString !== undefined && feeCostString !== '0') {
1595
1595
  fee = {
1596
1596
  'currency': code,
1597
- 'cost': feeCost,
1597
+ 'cost': this.parseNumber(feeCostString),
1598
1598
  };
1599
1599
  }
1600
1600
  return {
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 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 } 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.2.42";
7
+ declare const version = "4.2.44";
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.2.43';
41
+ const version = '4.2.45';
42
42
  Exchange.ccxtVersion = version;
43
43
  //-----------------------------------------------------------------------------
44
44
  import ace from './src/ace.js';
@@ -2,6 +2,7 @@ import { implicitReturnType } from '../base/types.js';
2
2
  import { Exchange as _Exchange } from '../base/Exchange.js';
3
3
  interface Exchange {
4
4
  v2PublicGetCurrencies(params?: {}): Promise<implicitReturnType>;
5
+ v2PublicGetCurrenciesCrypto(params?: {}): Promise<implicitReturnType>;
5
6
  v2PublicGetTime(params?: {}): Promise<implicitReturnType>;
6
7
  v2PublicGetExchangeRates(params?: {}): Promise<implicitReturnType>;
7
8
  v2PublicGetUsersUserId(params?: {}): Promise<implicitReturnType>;
@@ -75,6 +75,7 @@ export default class Exchange {
75
75
  balance: {};
76
76
  orderbooks: {};
77
77
  tickers: {};
78
+ bidsasks: {};
78
79
  orders: any;
79
80
  triggerOrders: any;
80
81
  trades: any;
@@ -744,7 +745,10 @@ export default class Exchange {
744
745
  setHeaders(headers: any): any;
745
746
  marketId(symbol: string): string;
746
747
  symbol(symbol: string): string;
748
+ handleParamString(params: object, paramName: string, defaultValue?: any): [string, object];
747
749
  resolvePath(path: any, params: any): any[];
750
+ getListFromObjectValues(objects: any, key: IndexType): any[];
751
+ getSymbolsForMarketType(marketType?: string, subType?: string, symbolWithActiveStatus?: boolean, symbolWithUnknownStatus?: boolean): any[];
748
752
  filterByArray(objects: any, key: IndexType, values?: any, indexed?: boolean): any;
749
753
  fetch2(path: any, api?: any, method?: string, params?: {}, headers?: any, body?: any, config?: {}): Promise<any>;
750
754
  request(path: any, api?: any, method?: string, params?: {}, headers?: any, body?: any, config?: {}): Promise<any>;
@@ -59,6 +59,7 @@ export default class Exchange {
59
59
  this.balance = {};
60
60
  this.orderbooks = {};
61
61
  this.tickers = {};
62
+ this.bidsasks = {};
62
63
  this.orders = undefined;
63
64
  this.triggerOrders = undefined;
64
65
  this.transactions = {};
@@ -3136,6 +3137,9 @@ export default class Exchange {
3136
3137
  * @param {string} currencyCode unified currency code, but this argument is not required by default, unless there is an exchange (like huobi) that needs an override of the method to be able to pass currencyCode argument additionally
3137
3138
  * @returns {string|undefined} exchange-specific network id
3138
3139
  */
3140
+ if (networkCode === undefined) {
3141
+ return undefined;
3142
+ }
3139
3143
  const networkIdsByCodes = this.safeValue(this.options, 'networks', {});
3140
3144
  let networkId = this.safeString(networkIdsByCodes, networkCode);
3141
3145
  // for example, if 'ETH' is passed for networkCode, but 'ETH' key not defined in `options->networks` object
@@ -3179,6 +3183,9 @@ export default class Exchange {
3179
3183
  * @param {string|undefined} currencyCode unified currency code, but this argument is not required by default, unless there is an exchange (like huobi) that needs an override of the method to be able to pass currencyCode argument additionally
3180
3184
  * @returns {string|undefined} unified network code
3181
3185
  */
3186
+ if (networkId === undefined) {
3187
+ return undefined;
3188
+ }
3182
3189
  const networkCodesByIds = this.safeDict(this.options, 'networksById', {});
3183
3190
  let networkCode = this.safeString(networkCodesByIds, networkId, networkId);
3184
3191
  // replace mainnet network-codes (i.e. ERC20->ETH)
@@ -3420,12 +3427,46 @@ export default class Exchange {
3420
3427
  const market = this.market(symbol);
3421
3428
  return this.safeString(market, 'symbol', symbol);
3422
3429
  }
3430
+ handleParamString(params, paramName, defaultValue = undefined) {
3431
+ const value = this.safeString(params, paramName, defaultValue);
3432
+ if (value !== undefined) {
3433
+ params = this.omit(params, paramName);
3434
+ }
3435
+ return [value, params];
3436
+ }
3423
3437
  resolvePath(path, params) {
3424
3438
  return [
3425
3439
  this.implodeParams(path, params),
3426
3440
  this.omit(params, this.extractParams(path)),
3427
3441
  ];
3428
3442
  }
3443
+ getListFromObjectValues(objects, key) {
3444
+ const newArray = this.toArray(objects);
3445
+ const results = [];
3446
+ for (let i = 0; i < newArray.length; i++) {
3447
+ results.push(newArray[i][key]);
3448
+ }
3449
+ return results;
3450
+ }
3451
+ getSymbolsForMarketType(marketType = undefined, subType = undefined, symbolWithActiveStatus = true, symbolWithUnknownStatus = true) {
3452
+ let filteredMarkets = this.markets;
3453
+ if (marketType !== undefined) {
3454
+ filteredMarkets = this.filterBy(filteredMarkets, 'type', marketType);
3455
+ }
3456
+ if (subType !== undefined) {
3457
+ this.checkRequiredArgument('getSymbolsForMarketType', subType, 'subType', ['linear', 'inverse', 'quanto']);
3458
+ filteredMarkets = this.filterBy(filteredMarkets, 'subType', subType);
3459
+ }
3460
+ const activeStatuses = [];
3461
+ if (symbolWithActiveStatus) {
3462
+ activeStatuses.push(true);
3463
+ }
3464
+ if (symbolWithUnknownStatus) {
3465
+ activeStatuses.push(undefined);
3466
+ }
3467
+ filteredMarkets = this.filterByArray(filteredMarkets, 'active', activeStatuses, false);
3468
+ return this.getListFromObjectValues(filteredMarkets, 'symbol');
3469
+ }
3429
3470
  filterByArray(objects, key, values = undefined, indexed = true) {
3430
3471
  objects = this.toArray(objects);
3431
3472
  // return all of them if no values were passed
@@ -4351,6 +4392,19 @@ export default class Exchange {
4351
4392
  return depositAddress;
4352
4393
  }
4353
4394
  }
4395
+ else if (this.has['fetchDepositAddressesByNetwork']) {
4396
+ const network = this.safeString(params, 'network');
4397
+ params = this.omit(params, 'network');
4398
+ const addressStructures = await this.fetchDepositAddressesByNetwork(code, params);
4399
+ if (network !== undefined) {
4400
+ return this.safeDict(addressStructures, network);
4401
+ }
4402
+ else {
4403
+ const keys = Object.keys(addressStructures);
4404
+ const key = this.safeString(keys, 0);
4405
+ return this.safeDict(addressStructures, key);
4406
+ }
4407
+ }
4354
4408
  else {
4355
4409
  throw new NotSupported(this.id + ' fetchDepositAddress() is not supported yet');
4356
4410
  }
@@ -63,6 +63,7 @@ export default class binance extends Exchange {
63
63
  fetchOrder(id: string, symbol?: Str, params?: {}): Promise<Order>;
64
64
  fetchOrders(symbol?: Str, since?: Int, limit?: Int, params?: {}): Promise<Order[]>;
65
65
  fetchOpenOrders(symbol?: Str, since?: Int, limit?: Int, params?: {}): Promise<Order[]>;
66
+ fetchOpenOrder(id: string, symbol?: Str, params?: {}): Promise<Order>;
66
67
  fetchClosedOrders(symbol?: Str, since?: Int, limit?: Int, params?: {}): Promise<Order[]>;
67
68
  fetchCanceledOrders(symbol?: Str, since?: Int, limit?: Int, params?: {}): Promise<any>;
68
69
  cancelOrder(id: string, symbol?: Str, params?: {}): Promise<Order>;