ccxt 4.5.1 → 4.5.3

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 (73) hide show
  1. package/README.md +110 -112
  2. package/dist/ccxt.browser.min.js +3 -3
  3. package/dist/cjs/ccxt.js +1 -9
  4. package/dist/cjs/src/ascendex.js +1 -1
  5. package/dist/cjs/src/base/Exchange.js +11 -0
  6. package/dist/cjs/src/binance.js +25 -25
  7. package/dist/cjs/src/bitget.js +2 -2
  8. package/dist/cjs/src/coincatch.js +2 -2
  9. package/dist/cjs/src/gate.js +27 -12
  10. package/dist/cjs/src/gemini.js +3 -3
  11. package/dist/cjs/src/htx.js +4 -4
  12. package/dist/cjs/src/indodax.js +11 -12
  13. package/dist/cjs/src/kucoinfutures.js +8 -8
  14. package/dist/cjs/src/mexc.js +30 -1
  15. package/dist/cjs/src/okx.js +19 -5
  16. package/dist/cjs/src/poloniex.js +1 -1
  17. package/dist/cjs/src/pro/binance.js +3 -3
  18. package/dist/cjs/src/pro/bitfinex.js +140 -0
  19. package/dist/cjs/src/pro/bitget.js +222 -42
  20. package/dist/cjs/src/pro/bitmart.js +1 -1
  21. package/dist/cjs/src/pro/bybit.js +3 -3
  22. package/dist/cjs/src/pro/gemini.js +7 -2
  23. package/dist/cjs/src/pro/hyperliquid.js +5 -0
  24. package/dist/cjs/src/pro/kraken.js +4 -6
  25. package/dist/cjs/src/pro/kucoin.js +64 -0
  26. package/dist/cjs/src/pro/mexc.js +7 -3
  27. package/dist/cjs/src/zonda.js +12 -0
  28. package/js/ccxt.d.ts +2 -11
  29. package/js/ccxt.js +2 -8
  30. package/js/src/ascendex.js +1 -1
  31. package/js/src/base/Exchange.d.ts +2 -0
  32. package/js/src/base/Exchange.js +11 -0
  33. package/js/src/binance.d.ts +1 -1
  34. package/js/src/binance.js +25 -25
  35. package/js/src/bitget.js +2 -2
  36. package/js/src/coincatch.js +2 -2
  37. package/js/src/gate.js +27 -12
  38. package/js/src/gemini.js +3 -3
  39. package/js/src/htx.js +4 -4
  40. package/js/src/indodax.js +11 -12
  41. package/js/src/kucoinfutures.js +8 -8
  42. package/js/src/mexc.d.ts +3 -0
  43. package/js/src/mexc.js +30 -1
  44. package/js/src/okx.d.ts +4 -2
  45. package/js/src/okx.js +19 -5
  46. package/js/src/poloniex.js +1 -1
  47. package/js/src/pro/binance.js +3 -3
  48. package/js/src/pro/bitfinex.d.ts +30 -0
  49. package/js/src/pro/bitfinex.js +140 -0
  50. package/js/src/pro/bitget.d.ts +10 -0
  51. package/js/src/pro/bitget.js +228 -42
  52. package/js/src/pro/bitmart.js +1 -1
  53. package/js/src/pro/bybit.d.ts +2 -2
  54. package/js/src/pro/bybit.js +3 -3
  55. package/js/src/pro/gemini.d.ts +1 -1
  56. package/js/src/pro/gemini.js +7 -2
  57. package/js/src/pro/hyperliquid.js +5 -0
  58. package/js/src/pro/kraken.js +4 -6
  59. package/js/src/pro/kucoin.d.ts +22 -0
  60. package/js/src/pro/kucoin.js +64 -0
  61. package/js/src/pro/mexc.js +7 -3
  62. package/js/src/zonda.js +12 -0
  63. package/package.json +2 -1
  64. package/js/src/abstract/ellipx.d.ts +0 -28
  65. package/js/src/abstract/ellipx.js +0 -11
  66. package/js/src/abstract/vertex.d.ts +0 -22
  67. package/js/src/abstract/vertex.js +0 -11
  68. package/js/src/ellipx.d.ts +0 -237
  69. package/js/src/ellipx.js +0 -2071
  70. package/js/src/pro/vertex.d.ts +0 -104
  71. package/js/src/pro/vertex.js +0 -999
  72. package/js/src/vertex.d.ts +0 -346
  73. package/js/src/vertex.js +0 -3146
@@ -1219,7 +1219,7 @@ class okx extends okx$1["default"] {
1219
1219
  'FUTURES': 'FUTURES',
1220
1220
  'OPTION': 'OPTION',
1221
1221
  },
1222
- 'brokerId': 'e847386590ce4dBC',
1222
+ 'brokerId': '6b9ad766b55dBCDE',
1223
1223
  },
1224
1224
  'features': {
1225
1225
  'default': {
@@ -2419,6 +2419,7 @@ class okx extends okx$1["default"] {
2419
2419
  * @see https://www.okx.com/docs-v5/en/#rest-api-market-data-get-mark-price-candlesticks-history
2420
2420
  * @see https://www.okx.com/docs-v5/en/#rest-api-market-data-get-index-candlesticks
2421
2421
  * @see https://www.okx.com/docs-v5/en/#rest-api-market-data-get-index-candlesticks-history
2422
+ * @see https://www.okx.com/docs-v5/en/#order-book-trading-market-data-get-candlesticks-history
2422
2423
  * @param {string} symbol unified symbol of the market to fetch OHLCV data for
2423
2424
  * @param {string} timeframe the length of time each candle represents
2424
2425
  * @param {int} [since] timestamp in ms of the earliest candle to fetch
@@ -2426,6 +2427,7 @@ class okx extends okx$1["default"] {
2426
2427
  * @param {object} [params] extra parameters specific to the exchange API endpoint
2427
2428
  * @param {string} [params.price] "mark" or "index" for mark price and index price candles
2428
2429
  * @param {int} [params.until] timestamp in ms of the latest candle to fetch
2430
+ * @param {string} [params.type] "Candles" or "HistoryCandles", default is "Candles" for recent candles, "HistoryCandles" for older candles
2429
2431
  * @param {boolean} [params.paginate] default false, when true will automatically paginate by calling this endpoint multiple times. See in the docs all the [availble parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
2430
2432
  * @returns {int[][]} A list of candles ordered as timestamp, open, high, low, close, volume
2431
2433
  */
@@ -2441,6 +2443,7 @@ class okx extends okx$1["default"] {
2441
2443
  params = this.omit(params, 'price');
2442
2444
  const options = this.safeDict(this.options, 'fetchOHLCV', {});
2443
2445
  const timezone = this.safeString(options, 'timezone', 'UTC');
2446
+ const limitIsUndefined = (limit === undefined);
2444
2447
  if (limit === undefined) {
2445
2448
  limit = 100; // default 100, max 100
2446
2449
  }
@@ -2465,7 +2468,8 @@ class okx extends okx$1["default"] {
2465
2468
  const historyBorder = now - ((1440 - 1) * durationInMilliseconds);
2466
2469
  if (since < historyBorder) {
2467
2470
  defaultType = 'HistoryCandles';
2468
- limit = Math.min(limit, 100); // max 100 for historical endpoint
2471
+ const maxLimit = (price !== undefined) ? 100 : 300;
2472
+ limit = Math.min(limit, maxLimit); // max 300 for historical endpoint
2469
2473
  }
2470
2474
  const startTime = Math.max(since - 1, 0);
2471
2475
  request['before'] = startTime;
@@ -2500,6 +2504,10 @@ class okx extends okx$1["default"] {
2500
2504
  }
2501
2505
  else {
2502
2506
  if (isHistoryCandles) {
2507
+ if (limitIsUndefined && (limit === 100)) {
2508
+ limit = 300;
2509
+ request['limit'] = 300; // reassign to 300, but this whole logic needs to be simplified...
2510
+ }
2503
2511
  response = await this.publicGetMarketHistoryCandles(this.extend(request, params));
2504
2512
  }
2505
2513
  else {
@@ -2847,8 +2855,8 @@ class okx extends okx$1["default"] {
2847
2855
  /**
2848
2856
  * @method
2849
2857
  * @name okx#createMarketBuyOrderWithCost
2850
- * @see https://www.okx.com/docs-v5/en/#order-book-trading-trade-post-place-order
2851
2858
  * @description create a market buy order by providing the symbol and cost
2859
+ * @see https://www.okx.com/docs-v5/en/#order-book-trading-trade-post-place-order
2852
2860
  * @param {string} symbol unified symbol of the market to create an order in
2853
2861
  * @param {float} cost how much you want to trade in units of the quote currency
2854
2862
  * @param {object} [params] extra parameters specific to the exchange API endpoint
@@ -2869,8 +2877,8 @@ class okx extends okx$1["default"] {
2869
2877
  /**
2870
2878
  * @method
2871
2879
  * @name okx#createMarketSellOrderWithCost
2872
- * @see https://www.okx.com/docs-v5/en/#order-book-trading-trade-post-place-order
2873
2880
  * @description create a market buy order by providing the symbol and cost
2881
+ * @see https://www.okx.com/docs-v5/en/#order-book-trading-trade-post-place-order
2874
2882
  * @param {string} symbol unified symbol of the market to create an order in
2875
2883
  * @param {float} cost how much you want to trade in units of the quote currency
2876
2884
  * @param {object} [params] extra parameters specific to the exchange API endpoint
@@ -2933,6 +2941,8 @@ class okx extends okx$1["default"] {
2933
2941
  const takeProfitDefined = (takeProfit !== undefined);
2934
2942
  const trailingPercent = this.safeString2(params, 'trailingPercent', 'callbackRatio');
2935
2943
  const isTrailingPercentOrder = trailingPercent !== undefined;
2944
+ const trailingPrice = this.safeString2(params, 'trailingPrice', 'callbackSpread');
2945
+ const isTrailingPriceOrder = trailingPrice !== undefined;
2936
2946
  const trigger = (triggerPrice !== undefined) || (type === 'trigger');
2937
2947
  const isReduceOnly = this.safeValue(params, 'reduceOnly', false);
2938
2948
  const defaultMarginMode = this.safeString2(this.options, 'defaultMarginMode', 'marginMode', 'cross');
@@ -3049,6 +3059,10 @@ class okx extends okx$1["default"] {
3049
3059
  request['callbackRatio'] = convertedTrailingPercent;
3050
3060
  request['ordType'] = 'move_order_stop';
3051
3061
  }
3062
+ else if (isTrailingPriceOrder) {
3063
+ request['callbackSpread'] = trailingPrice;
3064
+ request['ordType'] = 'move_order_stop';
3065
+ }
3052
3066
  else if (stopLossDefined || takeProfitDefined) {
3053
3067
  if (stopLossDefined) {
3054
3068
  const stopLossTriggerPrice = this.safeValueN(stopLoss, ['triggerPrice', 'stopPrice', 'slTriggerPx']);
@@ -6315,7 +6329,7 @@ class okx extends okx$1["default"] {
6315
6329
  this.checkRequiredCredentials();
6316
6330
  // inject id in implicit api call
6317
6331
  if (method === 'POST' && (path === 'trade/batch-orders' || path === 'trade/order-algo' || path === 'trade/order')) {
6318
- const brokerId = this.safeString(this.options, 'brokerId', 'e847386590ce4dBC');
6332
+ const brokerId = this.safeString(this.options, 'brokerId', '6b9ad766b55dBCDE');
6319
6333
  if (Array.isArray(params)) {
6320
6334
  for (let i = 0; i < params.length; i++) {
6321
6335
  const entry = params[i];
@@ -2647,7 +2647,7 @@ class poloniex extends poloniex$1["default"] {
2647
2647
  // "scale" : "-1",
2648
2648
  // "asks" : [ "23139.82", "0.317981", "23140", "0.191091", "23170.06", "0.01", "23200", "0.107758", "23230.55", "0.01", "23247.2", "0.154", "23254", "0.005121", "23263", "0.038", "23285.4", "0.308", "23300", "0.108896" ],
2649
2649
  // "bids" : [ "23139.74", "0.432092", "23139.73", "0.198592", "23123.21", "0.000886", "23123.2", "0.308", "23121.4", "0.154", "23105", "0.000789", "23100", "0.078175", "23069.1", "0.026276", "23068.83", "0.001329", "23051", "0.000048" ],
2650
- // "ts" : 1659695219513
2650
+ // "ts" : 1659695219512
2651
2651
  // }
2652
2652
  //
2653
2653
  const timestamp = this.safeInteger(response, 'time');
@@ -3240,8 +3240,8 @@ class binance extends binance$1["default"] {
3240
3240
  await this.loadMarkets();
3241
3241
  const market = this.market(symbol);
3242
3242
  const type = this.getMarketType('cancelAllOrdersWs', market, params);
3243
- if (type !== 'spot' && type !== 'future') {
3244
- throw new errors.BadRequest(this.id + ' cancelAllOrdersWs only supports spot or swap markets');
3243
+ if (type !== 'spot') {
3244
+ throw new errors.BadRequest(this.id + ' cancelAllOrdersWs only supports spot markets');
3245
3245
  }
3246
3246
  const url = this.urls['api']['ws']['ws-api'][type];
3247
3247
  const requestId = this.requestId(url);
@@ -3254,7 +3254,7 @@ class binance extends binance$1["default"] {
3254
3254
  };
3255
3255
  const message = {
3256
3256
  'id': messageHash,
3257
- 'method': 'order.cancel',
3257
+ 'method': 'openOrders.cancelAll',
3258
3258
  'params': this.signParams(this.extend(payload, params)),
3259
3259
  };
3260
3260
  const subscription = {
@@ -24,6 +24,10 @@ class bitfinex extends bitfinex$1["default"] {
24
24
  'watchBalance': true,
25
25
  'watchOHLCV': true,
26
26
  'watchOrders': true,
27
+ 'unWatchTicker': true,
28
+ 'unWatchTrades': true,
29
+ 'unWatchOHLCV': true,
30
+ 'unWatchOrderBook': true,
27
31
  },
28
32
  'urls': {
29
33
  'api': {
@@ -66,6 +70,31 @@ class bitfinex extends bitfinex$1["default"] {
66
70
  }
67
71
  return result;
68
72
  }
73
+ async unSubscribe(channel, topic, symbol, params = {}) {
74
+ await this.loadMarkets();
75
+ const market = this.market(symbol);
76
+ const marketId = market['id'];
77
+ const url = this.urls['api']['ws']['public'];
78
+ const client = this.client(url);
79
+ const subMessageHash = channel + ':' + marketId;
80
+ const messageHash = 'unsubscribe:' + channel + ':' + marketId;
81
+ const unSubTopic = 'unsubscribe' + ':' + topic + ':' + symbol;
82
+ const channelId = this.safeString(client.subscriptions, unSubTopic);
83
+ const request = {
84
+ 'event': 'unsubscribe',
85
+ 'chanId': channelId,
86
+ };
87
+ const unSubChanMsg = 'unsubscribe:' + channelId;
88
+ client.subscriptions[unSubChanMsg] = subMessageHash;
89
+ const subscription = {
90
+ 'messageHashes': [messageHash],
91
+ 'subMessageHashes': [subMessageHash],
92
+ 'topic': topic,
93
+ 'unsubscribe': true,
94
+ 'symbols': [symbol],
95
+ };
96
+ return await this.watch(url, messageHash, this.deepExtend(request, params), messageHash, subscription);
97
+ }
69
98
  async subscribePrivate(messageHash) {
70
99
  await this.loadMarkets();
71
100
  await this.authenticate();
@@ -104,6 +133,42 @@ class bitfinex extends bitfinex$1["default"] {
104
133
  }
105
134
  return this.filterBySinceLimit(ohlcv, since, limit, 0, true);
106
135
  }
136
+ /**
137
+ * @method
138
+ * @name bitfinex#unWatchOHLCV
139
+ * @description unWatches historical candlestick data containing the open, high, low, and close price, and the volume of a market
140
+ * @param {string} symbol unified symbol of the market to fetch OHLCV data for
141
+ * @param {string} timeframe the length of time each candle represents
142
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
143
+ * @returns {bool} true if successfully unsubscribed, false otherwise
144
+ */
145
+ async unWatchOHLCV(symbol, timeframe = '1m', params = {}) {
146
+ await this.loadMarkets();
147
+ const market = this.market(symbol);
148
+ symbol = market['symbol'];
149
+ const interval = this.safeString(this.timeframes, timeframe, timeframe);
150
+ const channel = 'candles';
151
+ const subMessageHash = channel + ':' + interval + ':' + market['id'];
152
+ const messageHash = 'unsubscribe:' + subMessageHash;
153
+ const url = this.urls['api']['ws']['public'];
154
+ const client = this.client(url);
155
+ const subId = 'unsubscribe:trade:' + interval + ':' + market['id']; // trade here because we use the key
156
+ const channelId = this.safeString(client.subscriptions, subId);
157
+ const request = {
158
+ 'event': 'unsubscribe',
159
+ 'chanId': channelId,
160
+ };
161
+ const unSubChanMsg = 'unsubscribe:' + channelId;
162
+ client.subscriptions[unSubChanMsg] = subMessageHash;
163
+ const subscription = {
164
+ 'messageHashes': [messageHash],
165
+ 'subMessageHashes': [subMessageHash],
166
+ 'topic': 'ohlcv',
167
+ 'unsubscribe': true,
168
+ 'symbols': [symbol],
169
+ };
170
+ return await this.watch(url, messageHash, this.deepExtend(request, params), messageHash, subscription);
171
+ }
107
172
  handleOHLCV(client, message, subscription) {
108
173
  //
109
174
  // initial snapshot
@@ -204,6 +269,17 @@ class bitfinex extends bitfinex$1["default"] {
204
269
  }
205
270
  return this.filterBySinceLimit(trades, since, limit, 'timestamp', true);
206
271
  }
272
+ /**
273
+ * @method
274
+ * @name bitfinex#unWatchTrades
275
+ * @description unWatches the list of most recent trades for a particular symbol
276
+ * @param {string} symbol unified symbol of the market to fetch trades for
277
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
278
+ * @returns {object[]} a list of [trade structures]{@link https://docs.ccxt.com/#/?id=public-trades}
279
+ */
280
+ async unWatchTrades(symbol, params = {}) {
281
+ return await this.unSubscribe('trades', 'trades', symbol, params);
282
+ }
207
283
  /**
208
284
  * @method
209
285
  * @name bitfinex#watchMyTrades
@@ -238,6 +314,17 @@ class bitfinex extends bitfinex$1["default"] {
238
314
  async watchTicker(symbol, params = {}) {
239
315
  return await this.subscribe('ticker', symbol, params);
240
316
  }
317
+ /**
318
+ * @method
319
+ * @name bitfinex#unWatchTicker
320
+ * @description unWatches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market
321
+ * @param {string} symbol unified symbol of the market to fetch the ticker for
322
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
323
+ * @returns {object} a [ticker structure]{@link https://docs.ccxt.com/#/?id=ticker-structure}
324
+ */
325
+ async unWatchTicker(symbol, params = {}) {
326
+ return await this.unSubscribe('ticker', 'ticker', symbol, params);
327
+ }
241
328
  handleMyTrade(client, message, subscription = {}) {
242
329
  //
243
330
  // trade execution
@@ -831,6 +918,29 @@ class bitfinex extends bitfinex$1["default"] {
831
918
  //
832
919
  return message;
833
920
  }
921
+ handleUnsubscriptionStatus(client, message) {
922
+ //
923
+ // {
924
+ // "event": "unsubscribed",
925
+ // "status": "OK",
926
+ // "chanId": CHANNEL_ID
927
+ // }
928
+ //
929
+ const channelId = this.safeString(message, 'chanId');
930
+ const unSubChannel = 'unsubscribe:' + channelId;
931
+ const subMessageHash = this.safeString(client.subscriptions, unSubChannel);
932
+ const subscription = this.safeDict(client.subscriptions, 'unsubscribe:' + subMessageHash);
933
+ delete client.subscriptions[unSubChannel];
934
+ const messageHashes = this.safeList(subscription, 'messageHashes', []);
935
+ const subMessageHashes = this.safeList(subscription, 'subMessageHashes', []);
936
+ for (let i = 0; i < messageHashes.length; i++) {
937
+ const messageHash = messageHashes[i];
938
+ const subHash = subMessageHashes[i];
939
+ this.cleanUnsubscription(client, subHash, messageHash);
940
+ }
941
+ this.cleanCache(subscription);
942
+ return true;
943
+ }
834
944
  handleSubscriptionStatus(client, message) {
835
945
  //
836
946
  // {
@@ -844,8 +954,37 @@ class bitfinex extends bitfinex$1["default"] {
844
954
  // "pair": "BTCUSD"
845
955
  // }
846
956
  //
957
+ // {
958
+ // event: 'subscribed',
959
+ // channel: 'candles',
960
+ // chanId: 128306,
961
+ // key: 'trade:1m:tBTCUST'
962
+ // }
963
+ //
847
964
  const channelId = this.safeString(message, 'chanId');
848
965
  client.subscriptions[channelId] = message;
966
+ // store the opposite direction too for unWatch
967
+ const mappings = {
968
+ 'book': 'orderbook',
969
+ 'candles': 'ohlcv',
970
+ 'ticker': 'ticker',
971
+ 'trades': 'trades',
972
+ };
973
+ const unifiedChannel = this.safeString(mappings, this.safeString(message, 'channel'));
974
+ if ('key' in message) {
975
+ // handle ohlcv differently because the message is different
976
+ const key = this.safeString(message, 'key');
977
+ const subKeyId = 'unsubscribe:' + key;
978
+ client.subscriptions[subKeyId] = channelId;
979
+ }
980
+ else {
981
+ const marketId = this.safeString(message, 'symbol');
982
+ const symbol = this.safeSymbol(marketId);
983
+ if (unifiedChannel !== undefined) {
984
+ const subId = 'unsubscribe:' + unifiedChannel + ':' + symbol;
985
+ client.subscriptions[subId] = channelId;
986
+ }
987
+ }
849
988
  return message;
850
989
  }
851
990
  async authenticate(params = {}) {
@@ -1152,6 +1291,7 @@ class bitfinex extends bitfinex$1["default"] {
1152
1291
  const methods = {
1153
1292
  'info': this.handleSystemStatus,
1154
1293
  'subscribed': this.handleSubscriptionStatus,
1294
+ 'unsubscribed': this.handleUnsubscriptionStatus,
1155
1295
  'auth': this.handleAuthenticationMessage,
1156
1296
  };
1157
1297
  const method = this.safeValue(methods, event);