ccxt 4.3.83 → 4.3.85

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 (41) hide show
  1. package/README.md +3 -3
  2. package/dist/ccxt.browser.min.js +2 -2
  3. package/dist/cjs/ccxt.js +2 -1
  4. package/dist/cjs/src/base/errors.js +8 -1
  5. package/dist/cjs/src/binance.js +1 -1
  6. package/dist/cjs/src/bitfinex2.js +2 -2
  7. package/dist/cjs/src/bitmex.js +4 -0
  8. package/dist/cjs/src/bybit.js +15 -14
  9. package/dist/cjs/src/cryptocom.js +117 -2
  10. package/dist/cjs/src/kraken.js +34 -8
  11. package/dist/cjs/src/kucoinfutures.js +5 -0
  12. package/dist/cjs/src/mexc.js +2 -2
  13. package/dist/cjs/src/pro/binance.js +7 -2
  14. package/dist/cjs/src/pro/bitget.js +113 -4
  15. package/dist/cjs/src/pro/bitrue.js +1 -9
  16. package/dist/cjs/src/pro/gate.js +4 -4
  17. package/dist/cjs/src/pro/okx.js +25 -4
  18. package/js/ccxt.d.ts +3 -3
  19. package/js/ccxt.js +3 -3
  20. package/js/src/abstract/cryptocom.d.ts +2 -0
  21. package/js/src/abstract/kucoinfutures.d.ts +2 -0
  22. package/js/src/base/errorHierarchy.d.ts +1 -0
  23. package/js/src/base/errorHierarchy.js +1 -0
  24. package/js/src/base/errors.d.ts +5 -1
  25. package/js/src/base/errors.js +8 -2
  26. package/js/src/binance.js +1 -1
  27. package/js/src/bitfinex2.js +2 -2
  28. package/js/src/bitmex.js +4 -0
  29. package/js/src/bybit.js +16 -15
  30. package/js/src/cryptocom.d.ts +5 -1
  31. package/js/src/cryptocom.js +117 -2
  32. package/js/src/kraken.js +34 -8
  33. package/js/src/kucoinfutures.js +5 -0
  34. package/js/src/mexc.js +2 -2
  35. package/js/src/pro/binance.js +7 -2
  36. package/js/src/pro/bitget.d.ts +4 -0
  37. package/js/src/pro/bitget.js +113 -4
  38. package/js/src/pro/bitrue.js +1 -9
  39. package/js/src/pro/gate.js +4 -4
  40. package/js/src/pro/okx.js +25 -4
  41. package/package.json +1 -1
package/js/src/mexc.js CHANGED
@@ -1168,7 +1168,7 @@ export default class mexc extends Exchange {
1168
1168
  // "symbols": [
1169
1169
  // {
1170
1170
  // "symbol": "OGNUSDT",
1171
- // "status": "ENABLED",
1171
+ // "status": "1",
1172
1172
  // "baseAsset": "OGN",
1173
1173
  // "baseAssetPrecision": "2",
1174
1174
  // "quoteAsset": "USDT",
@@ -1213,7 +1213,7 @@ export default class mexc extends Exchange {
1213
1213
  const status = this.safeString(market, 'status');
1214
1214
  const isSpotTradingAllowed = this.safeValue(market, 'isSpotTradingAllowed');
1215
1215
  let active = false;
1216
- if ((status === 'ENABLED') && (isSpotTradingAllowed)) {
1216
+ if ((status === '1') && (isSpotTradingAllowed)) {
1217
1217
  active = true;
1218
1218
  }
1219
1219
  const isMarginTradingAllowed = this.safeValue(market, 'isMarginTradingAllowed');
@@ -233,7 +233,7 @@ export default class binance extends binanceRest {
233
233
  else {
234
234
  for (let i = 0; i < symbols.length; i++) {
235
235
  const market = this.market(symbols[i]);
236
- subscriptionHashes.push(market['id'] + '@forceOrder');
236
+ subscriptionHashes.push(market['lowercaseId'] + '@forceOrder');
237
237
  messageHashes.push('liquidations::' + symbols[i]);
238
238
  }
239
239
  streamHash += '::' + symbols.join(',');
@@ -1220,6 +1220,9 @@ export default class binance extends binanceRest {
1220
1220
  * @param {object} [params.timezone] if provided, kline intervals are interpreted in that timezone instead of UTC, example '+08:00'
1221
1221
  * @returns {int[][]} A list of candles ordered as timestamp, open, high, low, close, volume
1222
1222
  */
1223
+ await this.loadMarkets();
1224
+ const market = this.market(symbol);
1225
+ symbol = market['symbol'];
1223
1226
  params['callerMethodName'] = 'watchOHLCV';
1224
1227
  const result = await this.watchOHLCVForSymbols([[symbol, timeframe]], since, limit, params);
1225
1228
  return result[symbol][timeframe];
@@ -1270,7 +1273,7 @@ export default class binance extends binanceRest {
1270
1273
  const suffix = '@+08:00';
1271
1274
  const utcSuffix = shouldUseUTC8 ? suffix : '';
1272
1275
  rawHashes.push(marketId + '@' + klineType + '_' + interval + utcSuffix);
1273
- messageHashes.push('ohlcv::' + symbolString + '::' + timeframeString);
1276
+ messageHashes.push('ohlcv::' + market['symbol'] + '::' + timeframeString);
1274
1277
  }
1275
1278
  const url = this.urls['api']['ws'][type] + '/' + this.stream(type, 'multipleOHLCV');
1276
1279
  const requestId = this.requestId(url);
@@ -1546,6 +1549,8 @@ export default class binance extends binanceRest {
1546
1549
  * @param {object} [params] extra parameters specific to the exchange API endpoint
1547
1550
  * @returns {object} a [ticker structure]{@link https://docs.ccxt.com/#/?id=ticker-structure}
1548
1551
  */
1552
+ await this.loadMarkets();
1553
+ symbols = this.marketSymbols(symbols, undefined, true, false, true);
1549
1554
  const result = await this.watchMultiTickerHelper('watchBidsAsks', 'bookTicker', symbols, params);
1550
1555
  if (this.newUpdates) {
1551
1556
  return result;
@@ -17,8 +17,10 @@ export default class bitget extends bitgetRest {
17
17
  handleOHLCV(client: Client, message: any): void;
18
18
  parseWsOHLCV(ohlcv: any, market?: any): OHLCV;
19
19
  watchOrderBook(symbol: string, limit?: Int, params?: {}): Promise<OrderBook>;
20
+ unWatchOrderBook(symbol: string, params?: {}): Promise<any>;
20
21
  watchOrderBookForSymbols(symbols: string[], limit?: Int, params?: {}): Promise<OrderBook>;
21
22
  handleOrderBook(client: Client, message: any): void;
23
+ handleCheckSumError(client: Client, symbol: string, messageHash: string): Promise<void>;
22
24
  handleDelta(bookside: any, delta: any): void;
23
25
  handleDeltas(bookside: any, deltas: any): void;
24
26
  watchTrades(symbol: string, since?: Int, limit?: Int, params?: {}): Promise<Trade[]>;
@@ -37,6 +39,7 @@ export default class bitget extends bitgetRest {
37
39
  watchBalance(params?: {}): Promise<Balances>;
38
40
  handleBalance(client: Client, message: any): void;
39
41
  watchPublic(messageHash: any, args: any, params?: {}): Promise<any>;
42
+ unWatchPublic(messageHash: any, args: any, params?: {}): Promise<any>;
40
43
  watchPublicMultiple(messageHashes: any, argsArray: any, params?: {}): Promise<any>;
41
44
  authenticate(params?: {}): Promise<any>;
42
45
  watchPrivate(messageHash: any, subscriptionHash: any, args: any, params?: {}): Promise<any>;
@@ -46,4 +49,5 @@ export default class bitget extends bitgetRest {
46
49
  ping(client: Client): string;
47
50
  handlePong(client: Client, message: any): any;
48
51
  handleSubscriptionStatus(client: Client, message: any): any;
52
+ handleUnSubscriptionStatus(client: Client, message: any): any;
49
53
  }
@@ -442,6 +442,35 @@ export default class bitget extends bitgetRest {
442
442
  */
443
443
  return await this.watchOrderBookForSymbols([symbol], limit, params);
444
444
  }
445
+ async unWatchOrderBook(symbol, params = {}) {
446
+ /**
447
+ * @method
448
+ * @name bitget#unWatchOrderBook
449
+ * @description unsubscribe from the orderbook channel
450
+ * @see https://www.bitget.com/api-doc/spot/websocket/public/Depth-Channel
451
+ * @see https://www.bitget.com/api-doc/contract/websocket/public/Order-Book-Channel
452
+ * @param {string} symbol unified symbol of the market to fetch the order book for
453
+ * @param {int} [params.limit] orderbook limit, default is undefined
454
+ * @returns {object} A dictionary of [order book structures]{@link https://docs.ccxt.com/#/?id=order-book-structure} indexed by market symbols
455
+ */
456
+ await this.loadMarkets();
457
+ const market = this.market(symbol);
458
+ const messageHash = 'unsubscribe:orderbook:' + market['symbol'];
459
+ let channel = 'books';
460
+ const limit = this.safeInteger(params, 'limit');
461
+ if ((limit === 1) || (limit === 5) || (limit === 15)) {
462
+ params = this.omit(params, 'limit');
463
+ channel += limit.toString();
464
+ }
465
+ let instType = undefined;
466
+ [instType, params] = this.getInstType(market, params);
467
+ const args = {
468
+ 'instType': instType,
469
+ 'channel': channel,
470
+ 'instId': market['id'],
471
+ };
472
+ return await this.unWatchPublic(messageHash, args, params);
473
+ }
445
474
  async watchOrderBookForSymbols(symbols, limit = undefined, params = {}) {
446
475
  /**
447
476
  * @method
@@ -565,10 +594,11 @@ export default class bitget extends bitgetRest {
565
594
  const calculatedChecksum = this.crc32(payload, true);
566
595
  const responseChecksum = this.safeInteger(rawOrderBook, 'checksum');
567
596
  if (calculatedChecksum !== responseChecksum) {
568
- delete client.subscriptions[messageHash];
569
- delete this.orderbooks[symbol];
570
- const error = new ChecksumError(this.id + ' ' + this.orderbookChecksumMessage(symbol));
571
- client.reject(error, messageHash);
597
+ // if (messageHash in client.subscriptions) {
598
+ // // delete client.subscriptions[messageHash];
599
+ // // delete this.orderbooks[symbol];
600
+ // }
601
+ this.spawn(this.handleCheckSumError, client, symbol, messageHash);
572
602
  return;
573
603
  }
574
604
  }
@@ -581,6 +611,11 @@ export default class bitget extends bitgetRest {
581
611
  }
582
612
  client.resolve(this.orderbooks[symbol], messageHash);
583
613
  }
614
+ async handleCheckSumError(client, symbol, messageHash) {
615
+ await this.unWatchOrderBook(symbol);
616
+ const error = new ChecksumError(this.id + ' ' + this.orderbookChecksumMessage(symbol));
617
+ client.reject(error, messageHash);
618
+ }
584
619
  handleDelta(bookside, delta) {
585
620
  const bidAsk = this.parseBidAsk(delta, 0, 1);
586
621
  // we store the string representations in the orderbook for checksum calculation
@@ -1627,6 +1662,15 @@ export default class bitget extends bitgetRest {
1627
1662
  const message = this.extend(request, params);
1628
1663
  return await this.watch(url, messageHash, message, messageHash);
1629
1664
  }
1665
+ async unWatchPublic(messageHash, args, params = {}) {
1666
+ const url = this.urls['api']['ws']['public'];
1667
+ const request = {
1668
+ 'op': 'unsubscribe',
1669
+ 'args': [args],
1670
+ };
1671
+ const message = this.extend(request, params);
1672
+ return await this.watch(url, messageHash, message, messageHash);
1673
+ }
1630
1674
  async watchPublicMultiple(messageHashes, argsArray, params = {}) {
1631
1675
  const url = this.urls['api']['ws']['public'];
1632
1676
  const request = {
@@ -1747,6 +1791,17 @@ export default class bitget extends bitgetRest {
1747
1791
  // "event": "subscribe",
1748
1792
  // "arg": { instType: 'SPOT', channel: "account", instId: "default" }
1749
1793
  // }
1794
+ // unsubscribe
1795
+ // {
1796
+ // "op":"unsubscribe",
1797
+ // "args":[
1798
+ // {
1799
+ // "instType":"USDT-FUTURES",
1800
+ // "channel":"ticker",
1801
+ // "instId":"BTCUSDT"
1802
+ // }
1803
+ // ]
1804
+ // }
1750
1805
  //
1751
1806
  if (this.handleErrorMessage(client, message)) {
1752
1807
  return;
@@ -1769,6 +1824,10 @@ export default class bitget extends bitgetRest {
1769
1824
  this.handleSubscriptionStatus(client, message);
1770
1825
  return;
1771
1826
  }
1827
+ if (event === 'unsubscribe') {
1828
+ this.handleUnSubscriptionStatus(client, message);
1829
+ return;
1830
+ }
1772
1831
  const methods = {
1773
1832
  'ticker': this.handleTicker,
1774
1833
  'trade': this.handleTrades,
@@ -1812,4 +1871,54 @@ export default class bitget extends bitgetRest {
1812
1871
  //
1813
1872
  return message;
1814
1873
  }
1874
+ handleUnSubscriptionStatus(client, message) {
1875
+ //
1876
+ // {
1877
+ // "op":"unsubscribe",
1878
+ // "args":[
1879
+ // {
1880
+ // "instType":"USDT-FUTURES",
1881
+ // "channel":"ticker",
1882
+ // "instId":"BTCUSDT"
1883
+ // },
1884
+ // {
1885
+ // "instType":"USDT-FUTURES",
1886
+ // "channel":"candle1m",
1887
+ // "instId":"BTCUSDT"
1888
+ // }
1889
+ // ]
1890
+ // }
1891
+ // or
1892
+ // {"event":"unsubscribe","arg":{"instType":"SPOT","channel":"books","instId":"BTCUSDT"}}
1893
+ //
1894
+ let argsList = this.safeList(message, 'args');
1895
+ if (argsList === undefined) {
1896
+ argsList = [this.safeDict(message, 'arg', {})];
1897
+ }
1898
+ for (let i = 0; i < argsList.length; i++) {
1899
+ const arg = argsList[i];
1900
+ const channel = this.safeString(arg, 'channel');
1901
+ if (channel === 'books') {
1902
+ // for now only unWatchOrderBook is supporteod
1903
+ const instType = this.safeStringLower(arg, 'instType');
1904
+ const type = (instType === 'spot') ? 'spot' : 'contract';
1905
+ const instId = this.safeString(arg, 'instId');
1906
+ const market = this.safeMarket(instId, undefined, undefined, type);
1907
+ const symbol = market['symbol'];
1908
+ const messageHash = 'unsubscribe:orderbook:' + market['symbol'];
1909
+ const subMessageHash = 'orderbook:' + symbol;
1910
+ if (symbol in this.orderbooks) {
1911
+ delete this.orderbooks[symbol];
1912
+ }
1913
+ if (subMessageHash in client.subscriptions) {
1914
+ delete client.subscriptions[subMessageHash];
1915
+ }
1916
+ if (messageHash in client.subscriptions) {
1917
+ delete client.subscriptions[messageHash];
1918
+ }
1919
+ client.resolve(true, messageHash);
1920
+ }
1921
+ }
1922
+ return message;
1923
+ }
1815
1924
  }
@@ -414,15 +414,7 @@ export default class bitrue extends bitrueRest {
414
414
  async authenticate(params = {}) {
415
415
  const listenKey = this.safeValue(this.options, 'listenKey');
416
416
  if (listenKey === undefined) {
417
- let response = undefined;
418
- try {
419
- response = await this.openPrivatePostPoseidonApiV1ListenKey(params);
420
- }
421
- catch (error) {
422
- this.options['listenKey'] = undefined;
423
- this.options['listenKeyUrl'] = undefined;
424
- return undefined;
425
- }
417
+ const response = await this.openPrivatePostPoseidonApiV1ListenKey(params);
426
418
  //
427
419
  // {
428
420
  // "msg": "succ",
@@ -1517,7 +1517,7 @@ export default class gate extends gateRest {
1517
1517
  const errs = this.safeDict(data, 'errs');
1518
1518
  const error = this.safeDict(message, 'error', errs);
1519
1519
  const code = this.safeString2(error, 'code', 'label');
1520
- const id = this.safeString2(message, 'id', 'requestId');
1520
+ const id = this.safeStringN(message, ['id', 'requestId', 'request_id']);
1521
1521
  if (error !== undefined) {
1522
1522
  const messageHash = this.safeString(client.subscriptions, id);
1523
1523
  try {
@@ -1533,7 +1533,7 @@ export default class gate extends gateRest {
1533
1533
  delete client.subscriptions[messageHash];
1534
1534
  }
1535
1535
  }
1536
- if (id !== undefined) {
1536
+ if ((id !== undefined) && (id in client.subscriptions)) {
1537
1537
  delete client.subscriptions[id];
1538
1538
  }
1539
1539
  return true;
@@ -1821,7 +1821,7 @@ export default class gate extends gateRest {
1821
1821
  'event': event,
1822
1822
  'payload': payload,
1823
1823
  };
1824
- return await this.watch(url, messageHash, request, messageHash);
1824
+ return await this.watch(url, messageHash, request, messageHash, requestId);
1825
1825
  }
1826
1826
  async subscribePrivate(url, messageHash, payload, channel, params, requiresUid = false) {
1827
1827
  this.checkRequiredCredentials();
@@ -1865,6 +1865,6 @@ export default class gate extends gateRest {
1865
1865
  client.subscriptions[tempSubscriptionHash] = messageHash;
1866
1866
  }
1867
1867
  const message = this.extend(request, params);
1868
- return await this.watch(url, messageHash, message, messageHash);
1868
+ return await this.watch(url, messageHash, message, messageHash, messageHash);
1869
1869
  }
1870
1870
  }
package/js/src/pro/okx.js CHANGED
@@ -442,9 +442,16 @@ export default class okx extends okxRest {
442
442
  */
443
443
  await this.loadMarkets();
444
444
  symbols = this.marketSymbols(symbols, undefined, true, true);
445
- let messageHash = 'liquidations';
445
+ const messageHash = 'liquidations';
446
+ const messageHashes = [];
446
447
  if (symbols !== undefined) {
447
- messageHash += '::' + symbols.join(',');
448
+ for (let i = 0; i < symbols.length; i++) {
449
+ const symbol = symbols[i];
450
+ messageHashes.push(messageHash + '::' + symbol);
451
+ }
452
+ }
453
+ else {
454
+ messageHashes.push(messageHash);
448
455
  }
449
456
  const market = this.getMarketFromSymbols(symbols);
450
457
  let type = undefined;
@@ -458,9 +465,16 @@ export default class okx extends okxRest {
458
465
  }
459
466
  const uppercaseType = type.toUpperCase();
460
467
  const request = {
461
- 'instType': uppercaseType,
468
+ 'op': 'subscribe',
469
+ 'args': [
470
+ {
471
+ 'channel': channel,
472
+ 'instType': uppercaseType,
473
+ },
474
+ ],
462
475
  };
463
- const newLiquidations = await this.subscribe('public', messageHash, channel, undefined, this.extend(request, params));
476
+ const url = this.getUrl(channel, 'public');
477
+ const newLiquidations = await this.watchMultiple(url, messageHashes, request, messageHashes);
464
478
  if (this.newUpdates) {
465
479
  return newLiquidations;
466
480
  }
@@ -1396,6 +1410,13 @@ export default class okx extends okxRest {
1396
1410
  for (let i = 0; i < data.length; i++) {
1397
1411
  const rawPosition = data[i];
1398
1412
  const position = this.parsePosition(rawPosition);
1413
+ if (position['contracts'] === 0) {
1414
+ position['side'] = 'long';
1415
+ const shortPosition = this.clone(position);
1416
+ shortPosition['side'] = 'short';
1417
+ cache.append(shortPosition);
1418
+ newPositions.push(shortPosition);
1419
+ }
1399
1420
  newPositions.push(position);
1400
1421
  cache.append(position);
1401
1422
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ccxt",
3
- "version": "4.3.83",
3
+ "version": "4.3.85",
4
4
  "description": "A JavaScript / TypeScript / Python / C# / PHP cryptocurrency trading library with support for 100+ exchanges",
5
5
  "unpkg": "dist/ccxt.browser.min.js",
6
6
  "type": "module",