ccxt 4.4.5 → 4.4.7

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 (45) hide show
  1. package/README.md +3 -3
  2. package/dist/ccxt.browser.min.js +2 -2
  3. package/dist/cjs/ccxt.js +1 -1
  4. package/dist/cjs/src/base/Exchange.js +21 -2
  5. package/dist/cjs/src/bingx.js +3 -0
  6. package/dist/cjs/src/bitflyer.js +2 -2
  7. package/dist/cjs/src/bitget.js +19 -7
  8. package/dist/cjs/src/bitmart.js +310 -128
  9. package/dist/cjs/src/bybit.js +25 -11
  10. package/dist/cjs/src/coinbase.js +6 -8
  11. package/dist/cjs/src/gate.js +3 -0
  12. package/dist/cjs/src/kraken.js +6 -1
  13. package/dist/cjs/src/kucoin.js +2 -2
  14. package/dist/cjs/src/mexc.js +127 -19
  15. package/dist/cjs/src/pro/bitget.js +66 -0
  16. package/dist/cjs/src/pro/htx.js +14 -0
  17. package/dist/cjs/src/pro/kraken.js +60 -0
  18. package/dist/cjs/src/pro/okx.js +11 -5
  19. package/examples/js/cli.js +2 -0
  20. package/js/ccxt.d.ts +1 -1
  21. package/js/ccxt.js +1 -1
  22. package/js/src/abstract/bitmart.d.ts +4 -0
  23. package/js/src/base/Exchange.d.ts +4 -0
  24. package/js/src/base/Exchange.js +21 -2
  25. package/js/src/bingx.js +3 -0
  26. package/js/src/bitflyer.js +2 -2
  27. package/js/src/bitget.d.ts +1 -0
  28. package/js/src/bitget.js +19 -7
  29. package/js/src/bitmart.d.ts +1 -0
  30. package/js/src/bitmart.js +310 -128
  31. package/js/src/bybit.js +25 -11
  32. package/js/src/coinbase.js +6 -8
  33. package/js/src/gate.js +3 -0
  34. package/js/src/kraken.js +6 -1
  35. package/js/src/kucoin.js +2 -2
  36. package/js/src/mexc.d.ts +3 -0
  37. package/js/src/mexc.js +127 -19
  38. package/js/src/pro/bitget.d.ts +3 -0
  39. package/js/src/pro/bitget.js +66 -0
  40. package/js/src/pro/htx.js +14 -0
  41. package/js/src/pro/kraken.d.ts +3 -0
  42. package/js/src/pro/kraken.js +60 -0
  43. package/js/src/pro/okx.d.ts +1 -0
  44. package/js/src/pro/okx.js +11 -5
  45. package/package.json +1 -1
@@ -20,6 +20,7 @@ class kraken extends kraken$1 {
20
20
  'watchOrders': true,
21
21
  'watchTicker': true,
22
22
  'watchTickers': true,
23
+ 'watchBidsAsks': true,
23
24
  'watchTrades': true,
24
25
  'watchTradesForSymbols': true,
25
26
  'createOrderWs': true,
@@ -496,6 +497,64 @@ class kraken extends kraken$1 {
496
497
  }
497
498
  return this.filterByArray(this.tickers, 'symbol', symbols);
498
499
  }
500
+ async watchBidsAsks(symbols = undefined, params = {}) {
501
+ /**
502
+ * @method
503
+ * @name kraken#watchBidsAsks
504
+ * @see https://docs.kraken.com/api/docs/websocket-v1/spread
505
+ * @description watches best bid & ask for symbols
506
+ * @param {string[]} symbols unified symbol of the market to fetch the ticker for
507
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
508
+ * @returns {object} a [ticker structure]{@link https://docs.ccxt.com/#/?id=ticker-structure}
509
+ */
510
+ await this.loadMarkets();
511
+ symbols = this.marketSymbols(symbols, undefined, false);
512
+ const ticker = await this.watchMultiHelper('bidask', 'spread', symbols, undefined, params);
513
+ if (this.newUpdates) {
514
+ const result = {};
515
+ result[ticker['symbol']] = ticker;
516
+ return result;
517
+ }
518
+ return this.filterByArray(this.bidsasks, 'symbol', symbols);
519
+ }
520
+ handleBidAsk(client, message, subscription) {
521
+ //
522
+ // [
523
+ // 7208974, // channelID
524
+ // [
525
+ // "63758.60000", // bid
526
+ // "63759.10000", // ask
527
+ // "1726814731.089778", // timestamp
528
+ // "0.00057917", // bid_volume
529
+ // "0.15681688" // ask_volume
530
+ // ],
531
+ // "spread",
532
+ // "XBT/USDT"
533
+ // ]
534
+ //
535
+ const parsedTicker = this.parseWsBidAsk(message);
536
+ const symbol = parsedTicker['symbol'];
537
+ this.bidsasks[symbol] = parsedTicker;
538
+ const messageHash = this.getMessageHash('bidask', undefined, symbol);
539
+ client.resolve(parsedTicker, messageHash);
540
+ }
541
+ parseWsBidAsk(ticker, market = undefined) {
542
+ const data = this.safeList(ticker, 1, []);
543
+ const marketId = this.safeString(ticker, 3);
544
+ market = this.safeValue(this.options['marketsByWsName'], marketId);
545
+ const symbol = this.safeString(market, 'symbol');
546
+ const timestamp = this.parseToInt(this.safeInteger(data, 2)) * 1000;
547
+ return this.safeTicker({
548
+ 'symbol': symbol,
549
+ 'timestamp': timestamp,
550
+ 'datetime': this.iso8601(timestamp),
551
+ 'ask': this.safeString(data, 1),
552
+ 'askVolume': this.safeString(data, 4),
553
+ 'bid': this.safeString(data, 0),
554
+ 'bidVolume': this.safeString(data, 3),
555
+ 'info': ticker,
556
+ }, market);
557
+ }
499
558
  async watchTrades(symbol, since = undefined, limit = undefined, params = {}) {
500
559
  /**
501
560
  * @method
@@ -1490,6 +1549,7 @@ class kraken extends kraken$1 {
1490
1549
  'book': this.handleOrderBook,
1491
1550
  'ohlc': this.handleOHLCV,
1492
1551
  'ticker': this.handleTicker,
1552
+ 'spread': this.handleBidAsk,
1493
1553
  'trade': this.handleTrades,
1494
1554
  // private
1495
1555
  'openOrders': this.handleOrders,
@@ -1952,6 +1952,12 @@ class okx extends okx$1 {
1952
1952
  client.resolve(this.orders, symbolMessageHash);
1953
1953
  }
1954
1954
  }
1955
+ requestId() {
1956
+ const ts = this.milliseconds().toString();
1957
+ const randomNumber = this.randNumber(4);
1958
+ const randomPart = randomNumber.toString();
1959
+ return ts + randomPart;
1960
+ }
1955
1961
  async createOrderWs(symbol, type, side, amount, price = undefined, params = {}) {
1956
1962
  /**
1957
1963
  * @method
@@ -1970,7 +1976,7 @@ class okx extends okx$1 {
1970
1976
  await this.loadMarkets();
1971
1977
  await this.authenticate();
1972
1978
  const url = this.getUrl('private', 'private');
1973
- const messageHash = this.milliseconds().toString();
1979
+ const messageHash = this.requestId();
1974
1980
  let op = undefined;
1975
1981
  [op, params] = this.handleOptionAndParams(params, 'createOrderWs', 'op', 'batch-orders');
1976
1982
  const args = this.createOrderRequest(symbol, type, side, amount, price, params);
@@ -2040,7 +2046,7 @@ class okx extends okx$1 {
2040
2046
  await this.loadMarkets();
2041
2047
  await this.authenticate();
2042
2048
  const url = this.getUrl('private', 'private');
2043
- const messageHash = this.milliseconds().toString();
2049
+ const messageHash = this.requestId();
2044
2050
  let op = undefined;
2045
2051
  [op, params] = this.handleOptionAndParams(params, 'editOrderWs', 'op', 'amend-order');
2046
2052
  const args = this.editOrderRequest(id, symbol, type, side, amount, price, params);
@@ -2069,7 +2075,7 @@ class okx extends okx$1 {
2069
2075
  await this.loadMarkets();
2070
2076
  await this.authenticate();
2071
2077
  const url = this.getUrl('private', 'private');
2072
- const messageHash = this.milliseconds().toString();
2078
+ const messageHash = this.requestId();
2073
2079
  const clientOrderId = this.safeString2(params, 'clOrdId', 'clientOrderId');
2074
2080
  params = this.omit(params, ['clientOrderId', 'clOrdId']);
2075
2081
  const arg = {
@@ -2109,7 +2115,7 @@ class okx extends okx$1 {
2109
2115
  await this.loadMarkets();
2110
2116
  await this.authenticate();
2111
2117
  const url = this.getUrl('private', 'private');
2112
- const messageHash = this.milliseconds().toString();
2118
+ const messageHash = this.requestId();
2113
2119
  const args = [];
2114
2120
  for (let i = 0; i < idsLength; i++) {
2115
2121
  const arg = {
@@ -2145,7 +2151,7 @@ class okx extends okx$1 {
2145
2151
  throw new errors.BadRequest(this.id + 'cancelAllOrdersWs is only applicable to Option in Portfolio Margin mode, and MMP privilege is required.');
2146
2152
  }
2147
2153
  const url = this.getUrl('private', 'private');
2148
- const messageHash = this.milliseconds().toString();
2154
+ const messageHash = this.requestId();
2149
2155
  const request = {
2150
2156
  'id': messageHash,
2151
2157
  'op': 'mass-cancel',
@@ -396,6 +396,8 @@ async function run () {
396
396
  }
397
397
  }
398
398
 
399
+ exchange.close()
400
+
399
401
  } else if (exchange[methodName] === undefined) {
400
402
  log.red (exchange.id + '.' + methodName + ': no such property')
401
403
  } else {
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 { Int, int, Str, Strings, Num, Bool, IndexType, OrderSide, OrderType, MarketType, SubType, Dict, NullableDict, List, NullableList, Fee, OHLCV, OHLCVC, implicitReturnType, Market, Currency, Dictionary, MinMax, FeeInterface, TradingFeeInterface, MarketInterface, Trade, Order, OrderBook, Ticker, Transaction, Tickers, CurrencyInterface, Balance, BalanceAccount, Account, PartialBalances, Balances, DepositAddress, WithdrawalResponse, DepositAddressResponse, FundingRate, FundingRates, Position, BorrowInterest, LeverageTier, LedgerEntry, DepositWithdrawFeeNetwork, DepositWithdrawFee, TransferEntry, CrossBorrowRate, IsolatedBorrowRate, FundingRateHistory, OpenInterest, Liquidation, OrderRequest, CancellationRequest, FundingHistory, MarketMarginModes, MarginMode, Greeks, Conversion, Option, LastPrice, Leverage, MarginModification, Leverages, LastPrices, Currencies, TradingFees, MarginModes, OptionChain, IsolatedBorrowRates, CrossBorrowRates, LeverageTiers } from './src/base/types.js';
6
6
  import { 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 } from './src/base/errors.js';
7
- declare const version = "4.4.4";
7
+ declare const version = "4.4.6";
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, 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 } from './src/base/errors.js';
39
39
  //-----------------------------------------------------------------------------
40
40
  // this is updated by vss.js when building
41
- const version = '4.4.5';
41
+ const version = '4.4.7';
42
42
  Exchange.ccxtVersion = version;
43
43
  //-----------------------------------------------------------------------------
44
44
  import ace from './src/ace.js';
@@ -100,6 +100,10 @@ interface Exchange {
100
100
  privatePostContractPrivateSubmitPlanOrder(params?: {}): Promise<implicitReturnType>;
101
101
  privatePostContractPrivateCancelPlanOrder(params?: {}): Promise<implicitReturnType>;
102
102
  privatePostContractPrivateSubmitLeverage(params?: {}): Promise<implicitReturnType>;
103
+ privatePostContractPrivateSubmitTpSlOrder(params?: {}): Promise<implicitReturnType>;
104
+ privatePostContractPrivateModifyPlanOrder(params?: {}): Promise<implicitReturnType>;
105
+ privatePostContractPrivateModifyPresetPlanOrder(params?: {}): Promise<implicitReturnType>;
106
+ privatePostContractPrivateModifyTpSlOrder(params?: {}): Promise<implicitReturnType>;
103
107
  }
104
108
  declare abstract class Exchange extends _Exchange {
105
109
  }
@@ -379,6 +379,7 @@ export default class Exchange {
379
379
  extendExchangeOptions(newOptions: Dict): void;
380
380
  createSafeDictionary(): {};
381
381
  randomBytes(length: number): string;
382
+ randNumber(size: number): number;
382
383
  describe(): {
383
384
  id: any;
384
385
  name: any;
@@ -809,6 +810,9 @@ export default class Exchange {
809
810
  CRO: {
810
811
  CRC20: string;
811
812
  };
813
+ BRC20: {
814
+ BRC20: string;
815
+ };
812
816
  };
813
817
  };
814
818
  safeLedgerEntry(entry: object, currency?: Currency): {
@@ -1220,6 +1220,13 @@ export default class Exchange {
1220
1220
  rng.nextBytes(x);
1221
1221
  return Buffer.from(x).toString('hex');
1222
1222
  }
1223
+ randNumber(size) {
1224
+ let number = '';
1225
+ for (let i = 0; i < size; i++) {
1226
+ number += Math.floor(Math.random() * 10);
1227
+ }
1228
+ return parseInt(number, 10);
1229
+ }
1223
1230
  /* eslint-enable */
1224
1231
  // ------------------------------------------------------------------------
1225
1232
  // ########################################################################
@@ -2248,6 +2255,7 @@ export default class Exchange {
2248
2255
  'ETH': { 'ERC20': 'ETH' },
2249
2256
  'TRX': { 'TRC20': 'TRX' },
2250
2257
  'CRO': { 'CRC20': 'CRONOS' },
2258
+ 'BRC20': { 'BRC20': 'BTC' },
2251
2259
  },
2252
2260
  };
2253
2261
  }
@@ -6105,8 +6113,19 @@ export default class Exchange {
6105
6113
  break;
6106
6114
  }
6107
6115
  result = this.arrayConcat(result, response);
6108
- const last = this.safeValue(response, responseLength - 1);
6109
- cursorValue = this.safeValue(last['info'], cursorReceived);
6116
+ const last = this.safeDict(response, responseLength - 1);
6117
+ // cursorValue = this.safeValue (last['info'], cursorReceived);
6118
+ cursorValue = undefined; // search for the cursor
6119
+ for (let j = 0; j < responseLength; j++) {
6120
+ const index = responseLength - j - 1;
6121
+ const entry = this.safeDict(response, index);
6122
+ const info = this.safeDict(entry, 'info');
6123
+ const cursor = this.safeValue(info, cursorReceived);
6124
+ if (cursor !== undefined) {
6125
+ cursorValue = cursor;
6126
+ break;
6127
+ }
6128
+ }
6110
6129
  if (cursorValue === undefined) {
6111
6130
  break;
6112
6131
  }
package/js/src/bingx.js CHANGED
@@ -491,6 +491,9 @@ export default class bingx extends Exchange {
491
491
  'BTC': 'BTC',
492
492
  'LTC': 'LTC',
493
493
  },
494
+ 'networks': {
495
+ 'ARB': 'ARBITRUM',
496
+ },
494
497
  },
495
498
  });
496
499
  }
@@ -1065,10 +1065,10 @@ export default class bitflyer extends Exchange {
1065
1065
  const feedback = this.id + ' ' + body;
1066
1066
  // i.e. {"status":-2,"error_message":"Under maintenance","data":null}
1067
1067
  const errorMessage = this.safeString(response, 'error_message');
1068
- const statusCode = this.safeNumber(response, 'status');
1068
+ const statusCode = this.safeInteger(response, 'status');
1069
1069
  if (errorMessage !== undefined) {
1070
1070
  this.throwExactlyMatchedException(this.exceptions['exact'], statusCode, feedback);
1071
- this.throwBroadlyMatchedException(this.exceptions['broad'], errorMessage, feedback);
1071
+ throw new ExchangeError(feedback);
1072
1072
  }
1073
1073
  return undefined;
1074
1074
  }
@@ -224,6 +224,7 @@ export default class bitget extends Exchange {
224
224
  parseConversion(conversion: Dict, fromCurrency?: Currency, toCurrency?: Currency): Conversion;
225
225
  fetchConvertCurrencies(params?: {}): Promise<Currencies>;
226
226
  handleErrors(code: int, reason: string, url: string, method: string, headers: Dict, body: string, response: any, requestHeaders: any, requestBody: any): any;
227
+ nonce(): number;
227
228
  sign(path: any, api?: any[], method?: string, params?: {}, headers?: any, body?: any): {
228
229
  url: string;
229
230
  method: string;
package/js/src/bitget.js CHANGED
@@ -1318,6 +1318,8 @@ export default class bitget extends Exchange {
1318
1318
  'TONCOIN': 'TON',
1319
1319
  },
1320
1320
  'options': {
1321
+ 'timeDifference': 0,
1322
+ 'adjustForTimeDifference': false,
1321
1323
  'timeframes': {
1322
1324
  'spot': {
1323
1325
  '1m': '1min',
@@ -1416,12 +1418,13 @@ export default class bitget extends Exchange {
1416
1418
  'networks': {
1417
1419
  'TRX': 'TRC20',
1418
1420
  'ETH': 'ERC20',
1419
- 'BSC': 'BEP20',
1420
- },
1421
- 'networksById': {
1422
- 'TRC20': 'TRX',
1423
- 'BSC': 'BEP20',
1421
+ 'BEP20': 'BSC',
1422
+ 'ZKSYNC': 'zkSyncEra',
1423
+ 'STARKNET': 'Starknet',
1424
+ 'OPTIMISM': 'Optimism',
1425
+ 'ARBITRUM': 'Arbitrum',
1424
1426
  },
1427
+ 'networksById': {},
1425
1428
  'fetchPositions': {
1426
1429
  'method': 'privateMixGetV2MixPositionAllPosition', // or privateMixGetV2MixPositionHistoryPosition
1427
1430
  },
@@ -1540,6 +1543,9 @@ export default class bitget extends Exchange {
1540
1543
  * @param {object} [params] extra parameters specific to the exchange API endpoint
1541
1544
  * @returns {object[]} an array of objects representing market data
1542
1545
  */
1546
+ if (this.options['adjustForTimeDifference']) {
1547
+ await this.loadTimeDifference();
1548
+ }
1543
1549
  const sandboxMode = this.safeBool(this.options, 'sandboxMode', false);
1544
1550
  let types = this.safeValue(this.options, 'fetchMarkets', ['spot', 'swap']);
1545
1551
  if (sandboxMode) {
@@ -1860,7 +1866,10 @@ export default class bitget extends Exchange {
1860
1866
  for (let j = 0; j < chains.length; j++) {
1861
1867
  const chain = chains[j];
1862
1868
  const networkId = this.safeString(chain, 'chain');
1863
- const network = this.safeCurrencyCode(networkId);
1869
+ let network = this.networkIdToCode(networkId, code);
1870
+ if (network !== undefined) {
1871
+ network = network.toUpperCase();
1872
+ }
1864
1873
  const withdrawEnabled = this.safeString(chain, 'withdrawable');
1865
1874
  const canWithdraw = withdrawEnabled === 'true';
1866
1875
  withdraw = (canWithdraw) ? canWithdraw : withdraw;
@@ -8825,6 +8834,9 @@ export default class bitget extends Exchange {
8825
8834
  }
8826
8835
  return undefined;
8827
8836
  }
8837
+ nonce() {
8838
+ return this.milliseconds() - this.options['timeDifference'];
8839
+ }
8828
8840
  sign(path, api = [], method = 'GET', params = {}, headers = undefined, body = undefined) {
8829
8841
  const signed = api[0] === 'private';
8830
8842
  const endpoint = api[1];
@@ -8842,7 +8854,7 @@ export default class bitget extends Exchange {
8842
8854
  }
8843
8855
  if (signed) {
8844
8856
  this.checkRequiredCredentials();
8845
- const timestamp = this.milliseconds().toString();
8857
+ const timestamp = this.nonce().toString();
8846
8858
  let auth = timestamp + method + payload;
8847
8859
  if (method === 'POST') {
8848
8860
  body = this.json(params);
@@ -167,6 +167,7 @@ export default class bitmart extends Exchange {
167
167
  parsePosition(position: Dict, market?: Market): import("./base/types.js").Position;
168
168
  fetchMyLiquidations(symbol?: Str, since?: Int, limit?: Int, params?: {}): Promise<import("./base/types.js").Liquidation[]>;
169
169
  parseLiquidation(liquidation: any, market?: Market): import("./base/types.js").Liquidation;
170
+ editOrder(id: string, symbol: string, type: OrderType, side: OrderSide, amount?: Num, price?: Num, params?: {}): Promise<Order>;
170
171
  nonce(): number;
171
172
  sign(path: any, api?: string, method?: string, params?: {}, headers?: any, body?: any): {
172
173
  url: string;