ccxt 4.5.2 → 4.5.4

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 (66) hide show
  1. package/README.md +4 -4
  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 +78 -5
  5. package/dist/cjs/src/base/functions/encode.js +8 -0
  6. package/dist/cjs/src/base/functions/rsa.js +14 -1
  7. package/dist/cjs/src/base/functions.js +1 -0
  8. package/dist/cjs/src/binance.js +12 -15
  9. package/dist/cjs/src/bitget.js +1 -1
  10. package/dist/cjs/src/bitvavo.js +8 -0
  11. package/dist/cjs/src/bybit.js +20 -6
  12. package/dist/cjs/src/coinbase.js +28 -10
  13. package/dist/cjs/src/coincatch.js +34 -21
  14. package/dist/cjs/src/delta.js +1 -0
  15. package/dist/cjs/src/gate.js +27 -12
  16. package/dist/cjs/src/gemini.js +3 -3
  17. package/dist/cjs/src/htx.js +4 -4
  18. package/dist/cjs/src/kucoinfutures.js +11 -10
  19. package/dist/cjs/src/mexc.js +30 -1
  20. package/dist/cjs/src/okx.js +19 -4
  21. package/dist/cjs/src/pro/binance.js +3 -3
  22. package/dist/cjs/src/pro/bitfinex.js +140 -0
  23. package/dist/cjs/src/pro/bitget.js +168 -26
  24. package/dist/cjs/src/pro/bybit.js +67 -11
  25. package/dist/cjs/src/pro/coinex.js +10 -11
  26. package/dist/cjs/src/pro/kucoin.js +64 -0
  27. package/dist/cjs/src/pro/mexc.js +7 -3
  28. package/js/ccxt.d.ts +1 -1
  29. package/js/ccxt.js +1 -1
  30. package/js/src/abstract/myokx.d.ts +1 -0
  31. package/js/src/abstract/okx.d.ts +1 -0
  32. package/js/src/abstract/okxus.d.ts +1 -0
  33. package/js/src/base/Exchange.d.ts +6 -0
  34. package/js/src/base/Exchange.js +78 -5
  35. package/js/src/base/functions/encode.d.ts +2 -1
  36. package/js/src/base/functions/encode.js +8 -1
  37. package/js/src/base/functions/rsa.js +16 -3
  38. package/js/src/binance.js +12 -15
  39. package/js/src/bitget.js +1 -1
  40. package/js/src/bitvavo.js +8 -0
  41. package/js/src/bybit.js +20 -6
  42. package/js/src/coinbase.d.ts +1 -1
  43. package/js/src/coinbase.js +28 -10
  44. package/js/src/coincatch.d.ts +2 -0
  45. package/js/src/coincatch.js +34 -21
  46. package/js/src/delta.js +1 -0
  47. package/js/src/gate.js +27 -12
  48. package/js/src/gemini.js +3 -3
  49. package/js/src/htx.js +4 -4
  50. package/js/src/kucoinfutures.js +11 -10
  51. package/js/src/mexc.d.ts +3 -0
  52. package/js/src/mexc.js +30 -1
  53. package/js/src/okx.d.ts +4 -2
  54. package/js/src/okx.js +19 -4
  55. package/js/src/pro/binance.js +3 -3
  56. package/js/src/pro/bitfinex.d.ts +30 -0
  57. package/js/src/pro/bitfinex.js +140 -0
  58. package/js/src/pro/bitget.d.ts +9 -1
  59. package/js/src/pro/bitget.js +168 -26
  60. package/js/src/pro/bybit.d.ts +6 -2
  61. package/js/src/pro/bybit.js +67 -11
  62. package/js/src/pro/coinex.js +11 -12
  63. package/js/src/pro/kucoin.d.ts +22 -0
  64. package/js/src/pro/kucoin.js +64 -0
  65. package/js/src/pro/mexc.js +7 -3
  66. package/package.json +3 -3
@@ -25,6 +25,10 @@ export default class bitfinex extends bitfinexRest {
25
25
  'watchBalance': true,
26
26
  'watchOHLCV': true,
27
27
  'watchOrders': true,
28
+ 'unWatchTicker': true,
29
+ 'unWatchTrades': true,
30
+ 'unWatchOHLCV': true,
31
+ 'unWatchOrderBook': true,
28
32
  },
29
33
  'urls': {
30
34
  'api': {
@@ -67,6 +71,31 @@ export default class bitfinex extends bitfinexRest {
67
71
  }
68
72
  return result;
69
73
  }
74
+ async unSubscribe(channel, topic, symbol, params = {}) {
75
+ await this.loadMarkets();
76
+ const market = this.market(symbol);
77
+ const marketId = market['id'];
78
+ const url = this.urls['api']['ws']['public'];
79
+ const client = this.client(url);
80
+ const subMessageHash = channel + ':' + marketId;
81
+ const messageHash = 'unsubscribe:' + channel + ':' + marketId;
82
+ const unSubTopic = 'unsubscribe' + ':' + topic + ':' + symbol;
83
+ const channelId = this.safeString(client.subscriptions, unSubTopic);
84
+ const request = {
85
+ 'event': 'unsubscribe',
86
+ 'chanId': channelId,
87
+ };
88
+ const unSubChanMsg = 'unsubscribe:' + channelId;
89
+ client.subscriptions[unSubChanMsg] = subMessageHash;
90
+ const subscription = {
91
+ 'messageHashes': [messageHash],
92
+ 'subMessageHashes': [subMessageHash],
93
+ 'topic': topic,
94
+ 'unsubscribe': true,
95
+ 'symbols': [symbol],
96
+ };
97
+ return await this.watch(url, messageHash, this.deepExtend(request, params), messageHash, subscription);
98
+ }
70
99
  async subscribePrivate(messageHash) {
71
100
  await this.loadMarkets();
72
101
  await this.authenticate();
@@ -105,6 +134,42 @@ export default class bitfinex extends bitfinexRest {
105
134
  }
106
135
  return this.filterBySinceLimit(ohlcv, since, limit, 0, true);
107
136
  }
137
+ /**
138
+ * @method
139
+ * @name bitfinex#unWatchOHLCV
140
+ * @description unWatches historical candlestick data containing the open, high, low, and close price, and the volume of a market
141
+ * @param {string} symbol unified symbol of the market to fetch OHLCV data for
142
+ * @param {string} timeframe the length of time each candle represents
143
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
144
+ * @returns {bool} true if successfully unsubscribed, false otherwise
145
+ */
146
+ async unWatchOHLCV(symbol, timeframe = '1m', params = {}) {
147
+ await this.loadMarkets();
148
+ const market = this.market(symbol);
149
+ symbol = market['symbol'];
150
+ const interval = this.safeString(this.timeframes, timeframe, timeframe);
151
+ const channel = 'candles';
152
+ const subMessageHash = channel + ':' + interval + ':' + market['id'];
153
+ const messageHash = 'unsubscribe:' + subMessageHash;
154
+ const url = this.urls['api']['ws']['public'];
155
+ const client = this.client(url);
156
+ const subId = 'unsubscribe:trade:' + interval + ':' + market['id']; // trade here because we use the key
157
+ const channelId = this.safeString(client.subscriptions, subId);
158
+ const request = {
159
+ 'event': 'unsubscribe',
160
+ 'chanId': channelId,
161
+ };
162
+ const unSubChanMsg = 'unsubscribe:' + channelId;
163
+ client.subscriptions[unSubChanMsg] = subMessageHash;
164
+ const subscription = {
165
+ 'messageHashes': [messageHash],
166
+ 'subMessageHashes': [subMessageHash],
167
+ 'topic': 'ohlcv',
168
+ 'unsubscribe': true,
169
+ 'symbols': [symbol],
170
+ };
171
+ return await this.watch(url, messageHash, this.deepExtend(request, params), messageHash, subscription);
172
+ }
108
173
  handleOHLCV(client, message, subscription) {
109
174
  //
110
175
  // initial snapshot
@@ -205,6 +270,17 @@ export default class bitfinex extends bitfinexRest {
205
270
  }
206
271
  return this.filterBySinceLimit(trades, since, limit, 'timestamp', true);
207
272
  }
273
+ /**
274
+ * @method
275
+ * @name bitfinex#unWatchTrades
276
+ * @description unWatches the list of most recent trades for a particular symbol
277
+ * @param {string} symbol unified symbol of the market to fetch trades for
278
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
279
+ * @returns {object[]} a list of [trade structures]{@link https://docs.ccxt.com/#/?id=public-trades}
280
+ */
281
+ async unWatchTrades(symbol, params = {}) {
282
+ return await this.unSubscribe('trades', 'trades', symbol, params);
283
+ }
208
284
  /**
209
285
  * @method
210
286
  * @name bitfinex#watchMyTrades
@@ -239,6 +315,17 @@ export default class bitfinex extends bitfinexRest {
239
315
  async watchTicker(symbol, params = {}) {
240
316
  return await this.subscribe('ticker', symbol, params);
241
317
  }
318
+ /**
319
+ * @method
320
+ * @name bitfinex#unWatchTicker
321
+ * @description unWatches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market
322
+ * @param {string} symbol unified symbol of the market to fetch the ticker for
323
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
324
+ * @returns {object} a [ticker structure]{@link https://docs.ccxt.com/#/?id=ticker-structure}
325
+ */
326
+ async unWatchTicker(symbol, params = {}) {
327
+ return await this.unSubscribe('ticker', 'ticker', symbol, params);
328
+ }
242
329
  handleMyTrade(client, message, subscription = {}) {
243
330
  //
244
331
  // trade execution
@@ -832,6 +919,29 @@ export default class bitfinex extends bitfinexRest {
832
919
  //
833
920
  return message;
834
921
  }
922
+ handleUnsubscriptionStatus(client, message) {
923
+ //
924
+ // {
925
+ // "event": "unsubscribed",
926
+ // "status": "OK",
927
+ // "chanId": CHANNEL_ID
928
+ // }
929
+ //
930
+ const channelId = this.safeString(message, 'chanId');
931
+ const unSubChannel = 'unsubscribe:' + channelId;
932
+ const subMessageHash = this.safeString(client.subscriptions, unSubChannel);
933
+ const subscription = this.safeDict(client.subscriptions, 'unsubscribe:' + subMessageHash);
934
+ delete client.subscriptions[unSubChannel];
935
+ const messageHashes = this.safeList(subscription, 'messageHashes', []);
936
+ const subMessageHashes = this.safeList(subscription, 'subMessageHashes', []);
937
+ for (let i = 0; i < messageHashes.length; i++) {
938
+ const messageHash = messageHashes[i];
939
+ const subHash = subMessageHashes[i];
940
+ this.cleanUnsubscription(client, subHash, messageHash);
941
+ }
942
+ this.cleanCache(subscription);
943
+ return true;
944
+ }
835
945
  handleSubscriptionStatus(client, message) {
836
946
  //
837
947
  // {
@@ -845,8 +955,37 @@ export default class bitfinex extends bitfinexRest {
845
955
  // "pair": "BTCUSD"
846
956
  // }
847
957
  //
958
+ // {
959
+ // event: 'subscribed',
960
+ // channel: 'candles',
961
+ // chanId: 128306,
962
+ // key: 'trade:1m:tBTCUST'
963
+ // }
964
+ //
848
965
  const channelId = this.safeString(message, 'chanId');
849
966
  client.subscriptions[channelId] = message;
967
+ // store the opposite direction too for unWatch
968
+ const mappings = {
969
+ 'book': 'orderbook',
970
+ 'candles': 'ohlcv',
971
+ 'ticker': 'ticker',
972
+ 'trades': 'trades',
973
+ };
974
+ const unifiedChannel = this.safeString(mappings, this.safeString(message, 'channel'));
975
+ if ('key' in message) {
976
+ // handle ohlcv differently because the message is different
977
+ const key = this.safeString(message, 'key');
978
+ const subKeyId = 'unsubscribe:' + key;
979
+ client.subscriptions[subKeyId] = channelId;
980
+ }
981
+ else {
982
+ const marketId = this.safeString(message, 'symbol');
983
+ const symbol = this.safeSymbol(marketId);
984
+ if (unifiedChannel !== undefined) {
985
+ const subId = 'unsubscribe:' + unifiedChannel + ':' + symbol;
986
+ client.subscriptions[subId] = channelId;
987
+ }
988
+ }
850
989
  return message;
851
990
  }
852
991
  async authenticate(params = {}) {
@@ -1153,6 +1292,7 @@ export default class bitfinex extends bitfinexRest {
1153
1292
  const methods = {
1154
1293
  'info': this.handleSystemStatus,
1155
1294
  'subscribed': this.handleSubscriptionStatus,
1295
+ 'unsubscribed': this.handleUnsubscriptionStatus,
1156
1296
  'auth': this.handleAuthenticationMessage,
1157
1297
  };
1158
1298
  const method = this.safeValue(methods, event);
@@ -142,10 +142,12 @@ export default class bitget extends bitgetRest {
142
142
  * @description get the list of most recent trades for a particular symbol
143
143
  * @see https://www.bitget.com/api-doc/spot/websocket/public/Trades-Channel
144
144
  * @see https://www.bitget.com/api-doc/contract/websocket/public/New-Trades-Channel
145
+ * @see https://www.bitget.com/api-doc/uta/websocket/public/New-Trades-Channel
145
146
  * @param {string} symbol unified symbol of the market to fetch trades for
146
147
  * @param {int} [since] timestamp in ms of the earliest trade to fetch
147
148
  * @param {int} [limit] the maximum amount of trades to fetch
148
149
  * @param {object} [params] extra parameters specific to the exchange API endpoint
150
+ * @param {boolean} [params.uta] set to true for the unified trading account (uta), defaults to false
149
151
  * @returns {object[]} a list of [trade structures]{@link https://docs.ccxt.com/#/?id=public-trades}
150
152
  */
151
153
  watchTrades(symbol: string, since?: Int, limit?: Int, params?: {}): Promise<Trade[]>;
@@ -155,10 +157,12 @@ export default class bitget extends bitgetRest {
155
157
  * @description get the list of most recent trades for a particular symbol
156
158
  * @see https://www.bitget.com/api-doc/spot/websocket/public/Trades-Channel
157
159
  * @see https://www.bitget.com/api-doc/contract/websocket/public/New-Trades-Channel
160
+ * @see https://www.bitget.com/api-doc/uta/websocket/public/New-Trades-Channel
158
161
  * @param {string[]} symbols unified symbol of the market to fetch trades for
159
162
  * @param {int} [since] timestamp in ms of the earliest trade to fetch
160
163
  * @param {int} [limit] the maximum amount of trades to fetch
161
164
  * @param {object} [params] extra parameters specific to the exchange API endpoint
165
+ * @param {boolean} [params.uta] set to true for the unified trading account (uta), defaults to false
162
166
  * @returns {object[]} a list of [trade structures]{@link https://docs.ccxt.com/#/?id=public-trades}
163
167
  */
164
168
  watchTradesForSymbols(symbols: string[], since?: Int, limit?: Int, params?: {}): Promise<Trade[]>;
@@ -168,8 +172,10 @@ export default class bitget extends bitgetRest {
168
172
  * @description unsubscribe from the trades channel
169
173
  * @see https://www.bitget.com/api-doc/spot/websocket/public/Trades-Channel
170
174
  * @see https://www.bitget.com/api-doc/contract/websocket/public/New-Trades-Channel
175
+ * @see https://www.bitget.com/api-doc/uta/websocket/public/New-Trades-Channel
171
176
  * @param {string} symbol unified symbol of the market to unwatch the trades for
172
177
  * @param {object} [params] extra parameters specific to the exchange API endpoint
178
+ * @param {boolean} [params.uta] set to true for the unified trading account (uta), defaults to false
173
179
  * @returns {any} status of the unwatch request
174
180
  */
175
181
  unWatchTrades(symbol: string, params?: {}): Promise<any>;
@@ -217,11 +223,13 @@ export default class bitget extends bitgetRest {
217
223
  * @method
218
224
  * @name bitget#watchMyTrades
219
225
  * @description watches trades made by the user
220
- * @see https://www.bitget.com/api-doc/contract/websocket/private/Order-Channel
226
+ * @see https://www.bitget.com/api-doc/contract/websocket/private/Fill-Channel
227
+ * @see https://www.bitget.com/api-doc/uta/websocket/private/Fill-Channel
221
228
  * @param {str} symbol unified market symbol
222
229
  * @param {int} [since] the earliest time in ms to fetch trades for
223
230
  * @param {int} [limit] the maximum number of trades structures to retrieve
224
231
  * @param {object} [params] extra parameters specific to the exchange API endpoint
232
+ * @param {boolean} [params.uta] set to true for the unified trading account (uta), defaults to false
225
233
  * @returns {object[]} a list of [trade structures]{@link https://docs.ccxt.com/#/?id=trade-structure}
226
234
  */
227
235
  watchMyTrades(symbol?: Str, since?: Int, limit?: Int, params?: {}): Promise<Trade[]>;
@@ -929,10 +929,12 @@ export default class bitget extends bitgetRest {
929
929
  * @description get the list of most recent trades for a particular symbol
930
930
  * @see https://www.bitget.com/api-doc/spot/websocket/public/Trades-Channel
931
931
  * @see https://www.bitget.com/api-doc/contract/websocket/public/New-Trades-Channel
932
+ * @see https://www.bitget.com/api-doc/uta/websocket/public/New-Trades-Channel
932
933
  * @param {string} symbol unified symbol of the market to fetch trades for
933
934
  * @param {int} [since] timestamp in ms of the earliest trade to fetch
934
935
  * @param {int} [limit] the maximum amount of trades to fetch
935
936
  * @param {object} [params] extra parameters specific to the exchange API endpoint
937
+ * @param {boolean} [params.uta] set to true for the unified trading account (uta), defaults to false
936
938
  * @returns {object[]} a list of [trade structures]{@link https://docs.ccxt.com/#/?id=public-trades}
937
939
  */
938
940
  async watchTrades(symbol, since = undefined, limit = undefined, params = {}) {
@@ -944,10 +946,12 @@ export default class bitget extends bitgetRest {
944
946
  * @description get the list of most recent trades for a particular symbol
945
947
  * @see https://www.bitget.com/api-doc/spot/websocket/public/Trades-Channel
946
948
  * @see https://www.bitget.com/api-doc/contract/websocket/public/New-Trades-Channel
949
+ * @see https://www.bitget.com/api-doc/uta/websocket/public/New-Trades-Channel
947
950
  * @param {string[]} symbols unified symbol of the market to fetch trades for
948
951
  * @param {int} [since] timestamp in ms of the earliest trade to fetch
949
952
  * @param {int} [limit] the maximum amount of trades to fetch
950
953
  * @param {object} [params] extra parameters specific to the exchange API endpoint
954
+ * @param {boolean} [params.uta] set to true for the unified trading account (uta), defaults to false
951
955
  * @returns {object[]} a list of [trade structures]{@link https://docs.ccxt.com/#/?id=public-trades}
952
956
  */
953
957
  async watchTradesForSymbols(symbols, since = undefined, limit = undefined, params = {}) {
@@ -957,21 +961,28 @@ export default class bitget extends bitgetRest {
957
961
  }
958
962
  await this.loadMarkets();
959
963
  symbols = this.marketSymbols(symbols);
964
+ let uta = undefined;
965
+ [uta, params] = this.handleOptionAndParams(params, 'watchTradesForSymbols', 'uta', false);
960
966
  const topics = [];
961
967
  const messageHashes = [];
962
968
  for (let i = 0; i < symbols.length; i++) {
963
969
  const symbol = symbols[i];
964
970
  const market = this.market(symbol);
965
971
  let instType = undefined;
966
- [instType, params] = this.getInstType(market, false, params);
972
+ [instType, params] = this.getInstType(market, uta, params);
967
973
  const args = {
968
974
  'instType': instType,
969
- 'channel': 'trade',
970
- 'instId': market['id'],
971
975
  };
976
+ const topicOrChannel = uta ? 'topic' : 'channel';
977
+ const symbolOrInstId = uta ? 'symbol' : 'instId';
978
+ args[topicOrChannel] = uta ? 'publicTrade' : 'trade';
979
+ args[symbolOrInstId] = market['id'];
972
980
  topics.push(args);
973
981
  messageHashes.push('trade:' + symbol);
974
982
  }
983
+ if (uta) {
984
+ params['uta'] = true;
985
+ }
975
986
  const trades = await this.watchPublicMultiple(messageHashes, topics, params);
976
987
  if (this.newUpdates) {
977
988
  const first = this.safeValue(trades, 0);
@@ -992,13 +1003,17 @@ export default class bitget extends bitgetRest {
992
1003
  * @description unsubscribe from the trades channel
993
1004
  * @see https://www.bitget.com/api-doc/spot/websocket/public/Trades-Channel
994
1005
  * @see https://www.bitget.com/api-doc/contract/websocket/public/New-Trades-Channel
1006
+ * @see https://www.bitget.com/api-doc/uta/websocket/public/New-Trades-Channel
995
1007
  * @param {string} symbol unified symbol of the market to unwatch the trades for
996
1008
  * @param {object} [params] extra parameters specific to the exchange API endpoint
1009
+ * @param {boolean} [params.uta] set to true for the unified trading account (uta), defaults to false
997
1010
  * @returns {any} status of the unwatch request
998
1011
  */
999
1012
  async unWatchTrades(symbol, params = {}) {
1000
- await this.loadMarkets();
1001
- return await this.unWatchChannel(symbol, 'trade', 'trade', params);
1013
+ let uta = undefined;
1014
+ [uta, params] = this.handleOptionAndParams(params, 'unWatchTrades', 'uta', false);
1015
+ const channelTopic = uta ? 'publicTrade' : 'trade';
1016
+ return await this.unWatchChannel(symbol, channelTopic, 'trade', params);
1002
1017
  }
1003
1018
  handleTrades(client, message) {
1004
1019
  //
@@ -1017,10 +1032,28 @@ export default class bitget extends bitgetRest {
1017
1032
  // "ts": 1701910980730
1018
1033
  // }
1019
1034
  //
1035
+ // uta
1036
+ //
1037
+ // {
1038
+ // "action": "snapshot",
1039
+ // "arg": { "instType": "spot", "topic": "publicTrade", "symbol": "BTCUSDT" },
1040
+ // "data": [
1041
+ // {
1042
+ // "T": "1756287827920",
1043
+ // "P": "110878.5",
1044
+ // "v": "0.07",
1045
+ // "S": "buy",
1046
+ // "L": "1344534089797185550"
1047
+ // "i": "1344534089797185549"
1048
+ // },
1049
+ // ],
1050
+ // "ts": 1701910980730
1051
+ // }
1052
+ //
1020
1053
  const arg = this.safeValue(message, 'arg', {});
1021
- const instType = this.safeString(arg, 'instType');
1022
- const marketType = (instType === 'SPOT') ? 'spot' : 'contract';
1023
- const marketId = this.safeString(arg, 'instId');
1054
+ const instType = this.safeStringLower(arg, 'instType');
1055
+ const marketType = (instType === 'spot') ? 'spot' : 'contract';
1056
+ const marketId = this.safeString2(arg, 'instId', 'symbol');
1024
1057
  const market = this.safeMarket(marketId, undefined, undefined, marketType);
1025
1058
  const symbol = market['symbol'];
1026
1059
  let stored = this.safeValue(this.trades, symbol);
@@ -1099,13 +1132,57 @@ export default class bitget extends bitgetRest {
1099
1132
  // "uTime": "1714471204194"
1100
1133
  // }
1101
1134
  //
1135
+ // uta private
1136
+ //
1137
+ // {
1138
+ // "symbol": "BTCUSDT",
1139
+ // "orderType": "market",
1140
+ // "updatedTime": "1736378720623",
1141
+ // "side": "buy",
1142
+ // "orderId": "1288888888888888888",
1143
+ // "execPnl": "0",
1144
+ // "feeDetail": [
1145
+ // {
1146
+ // "feeCoin": "USDT",
1147
+ // "fee": "0.569958"
1148
+ // }
1149
+ // ],
1150
+ // "execTime": "1736378720623",
1151
+ // "tradeScope": "taker",
1152
+ // "tradeSide": "open",
1153
+ // "execId": "1288888888888888888",
1154
+ // "execLinkId": "1288888888888888888",
1155
+ // "execPrice": "94993",
1156
+ // "holdSide": "long",
1157
+ // "execValue": "949.93",
1158
+ // "category": "USDT-FUTURES",
1159
+ // "execQty": "0.01",
1160
+ // "clientOid": "1288888888888888889"
1161
+ // uta
1162
+ //
1163
+ // {
1164
+ // "i": "1344534089797185549", // Fill execution ID
1165
+ // "L": "1344534089797185550", // Execution correlation ID
1166
+ // "p": "110878.5", // Fill price
1167
+ // "v": "0.07", // Fill size
1168
+ // "S": "buy", // Fill side
1169
+ // "T": "1756287827920" // Fill timestamp
1170
+ // }
1171
+ //
1102
1172
  const instId = this.safeString2(trade, 'symbol', 'instId');
1103
1173
  const posMode = this.safeString(trade, 'posMode');
1104
- const defaultType = (posMode !== undefined) ? 'contract' : 'spot';
1174
+ const category = this.safeString(trade, 'category');
1175
+ let defaultType = undefined;
1176
+ if (category !== undefined) {
1177
+ defaultType = (category !== 'SPOT') ? 'contract' : 'spot';
1178
+ }
1179
+ else {
1180
+ defaultType = (posMode !== undefined) ? 'contract' : 'spot';
1181
+ }
1105
1182
  if (market === undefined) {
1106
1183
  market = this.safeMarket(instId, undefined, undefined, defaultType);
1107
1184
  }
1108
- const timestamp = this.safeIntegerN(trade, ['uTime', 'cTime', 'ts']);
1185
+ const timestamp = this.safeIntegerN(trade, ['uTime', 'cTime', 'ts', 'T', 'execTime']);
1109
1186
  const feeDetail = this.safeList(trade, 'feeDetail', []);
1110
1187
  const first = this.safeDict(feeDetail, 0);
1111
1188
  let fee = undefined;
@@ -1113,23 +1190,23 @@ export default class bitget extends bitgetRest {
1113
1190
  const feeCurrencyId = this.safeString(first, 'feeCoin');
1114
1191
  const feeCurrencyCode = this.safeCurrencyCode(feeCurrencyId);
1115
1192
  fee = {
1116
- 'cost': Precise.stringAbs(this.safeString(first, 'totalFee')),
1193
+ 'cost': Precise.stringAbs(this.safeString2(first, 'totalFee', 'fee')),
1117
1194
  'currency': feeCurrencyCode,
1118
1195
  };
1119
1196
  }
1120
1197
  return this.safeTrade({
1121
1198
  'info': trade,
1122
- 'id': this.safeString(trade, 'tradeId'),
1123
- 'order': this.safeString(trade, 'orderId'),
1199
+ 'id': this.safeStringN(trade, ['tradeId', 'i', 'execId']),
1200
+ 'order': this.safeString2(trade, 'orderId', 'L'),
1124
1201
  'timestamp': timestamp,
1125
1202
  'datetime': this.iso8601(timestamp),
1126
1203
  'symbol': market['symbol'],
1127
1204
  'type': this.safeString(trade, 'orderType'),
1128
- 'side': this.safeString(trade, 'side'),
1205
+ 'side': this.safeString2(trade, 'side', 'S'),
1129
1206
  'takerOrMaker': this.safeString(trade, 'tradeScope'),
1130
- 'price': this.safeString2(trade, 'priceAvg', 'price'),
1131
- 'amount': this.safeString2(trade, 'size', 'baseVolume'),
1132
- 'cost': this.safeString2(trade, 'amount', 'quoteVolume'),
1207
+ 'price': this.safeStringN(trade, ['priceAvg', 'price', 'execPrice', 'P']),
1208
+ 'amount': this.safeStringN(trade, ['size', 'baseVolume', 'execQty', 'v']),
1209
+ 'cost': this.safeStringN(trade, ['amount', 'quoteVolume', 'execValue']),
1133
1210
  'fee': fee,
1134
1211
  }, market);
1135
1212
  }
@@ -1725,11 +1802,13 @@ export default class bitget extends bitgetRest {
1725
1802
  * @method
1726
1803
  * @name bitget#watchMyTrades
1727
1804
  * @description watches trades made by the user
1728
- * @see https://www.bitget.com/api-doc/contract/websocket/private/Order-Channel
1805
+ * @see https://www.bitget.com/api-doc/contract/websocket/private/Fill-Channel
1806
+ * @see https://www.bitget.com/api-doc/uta/websocket/private/Fill-Channel
1729
1807
  * @param {str} symbol unified market symbol
1730
1808
  * @param {int} [since] the earliest time in ms to fetch trades for
1731
1809
  * @param {int} [limit] the maximum number of trades structures to retrieve
1732
1810
  * @param {object} [params] extra parameters specific to the exchange API endpoint
1811
+ * @param {boolean} [params.uta] set to true for the unified trading account (uta), defaults to false
1733
1812
  * @returns {object[]} a list of [trade structures]{@link https://docs.ccxt.com/#/?id=trade-structure}
1734
1813
  */
1735
1814
  async watchMyTrades(symbol = undefined, since = undefined, limit = undefined, params = {}) {
@@ -1744,18 +1823,29 @@ export default class bitget extends bitgetRest {
1744
1823
  let type = undefined;
1745
1824
  [type, params] = this.handleMarketTypeAndParams('watchMyTrades', market, params);
1746
1825
  let instType = undefined;
1826
+ let uta = undefined;
1827
+ [uta, params] = this.handleOptionAndParams(params, 'watchMyTrades', 'uta', false);
1747
1828
  if (market === undefined && type === 'spot') {
1748
- instType = 'spot';
1829
+ instType = 'SPOT';
1749
1830
  }
1750
1831
  else {
1751
- [instType, params] = this.getInstType(market, false, params);
1832
+ [instType, params] = this.getInstType(market, uta, params);
1833
+ }
1834
+ if (uta) {
1835
+ instType = 'UTA';
1752
1836
  }
1753
1837
  const subscriptionHash = 'fill:' + instType;
1754
1838
  const args = {
1755
1839
  'instType': instType,
1756
- 'channel': 'fill',
1757
- 'instId': 'default',
1758
1840
  };
1841
+ const topicOrChannel = uta ? 'topic' : 'channel';
1842
+ args[topicOrChannel] = 'fill';
1843
+ if (!uta) {
1844
+ args['instId'] = 'default';
1845
+ }
1846
+ else {
1847
+ params['uta'] = true;
1848
+ }
1759
1849
  const trades = await this.watchPrivate(messageHash, subscriptionHash, args, params);
1760
1850
  if (this.newUpdates) {
1761
1851
  limit = trades.getLimit(symbol, limit);
@@ -1834,6 +1924,44 @@ export default class bitget extends bitgetRest {
1834
1924
  // "ts": 1714471276629
1835
1925
  // }
1836
1926
  //
1927
+ // uta
1928
+ //
1929
+ // {
1930
+ // "data": [
1931
+ // {
1932
+ // "symbol": "BTCUSDT",
1933
+ // "orderType": "market",
1934
+ // "updatedTime": "1736378720623",
1935
+ // "side": "buy",
1936
+ // "orderId": "1288888888888888888",
1937
+ // "execPnl": "0",
1938
+ // "feeDetail": [
1939
+ // {
1940
+ // "feeCoin": "USDT",
1941
+ // "fee": "0.569958"
1942
+ // }
1943
+ // ],
1944
+ // "execTime": "1736378720623",
1945
+ // "tradeScope": "taker",
1946
+ // "tradeSide": "open",
1947
+ // "execId": "1288888888888888888",
1948
+ // "execLinkId": "1288888888888888888",
1949
+ // "execPrice": "94993",
1950
+ // "holdSide": "long",
1951
+ // "execValue": "949.93",
1952
+ // "category": "USDT-FUTURES",
1953
+ // "execQty": "0.01",
1954
+ // "clientOid": "1288888888888888889"
1955
+ // }
1956
+ // ],
1957
+ // "arg": {
1958
+ // "instType": "UTA",
1959
+ // "topic": "fill"
1960
+ // },
1961
+ // "action": "snapshot",
1962
+ // "ts": 1733904123981
1963
+ // }
1964
+ //
1837
1965
  if (this.myTrades === undefined) {
1838
1966
  const limit = this.safeInteger(this.options, 'tradesLimit', 1000);
1839
1967
  this.myTrades = new ArrayCache(limit);
@@ -2096,12 +2224,25 @@ export default class bitget extends bitgetRest {
2096
2224
  return await future;
2097
2225
  }
2098
2226
  async watchPrivate(messageHash, subscriptionHash, args, params = {}) {
2099
- let url = this.urls['api']['ws']['private'];
2227
+ let uta = undefined;
2228
+ let url = undefined;
2229
+ [uta, params] = this.handleOptionAndParams(params, 'watchPrivate', 'uta', false);
2230
+ if (uta) {
2231
+ url = this.urls['api']['ws']['utaPrivate'];
2232
+ }
2233
+ else {
2234
+ url = this.urls['api']['ws']['private'];
2235
+ }
2100
2236
  const sandboxMode = this.safeBool2(this.options, 'sandboxMode', 'sandbox', false);
2101
2237
  if (sandboxMode) {
2102
2238
  const instType = this.safeString(args, 'instType');
2103
2239
  if ((instType !== 'SCOIN-FUTURES') && (instType !== 'SUSDT-FUTURES') && (instType !== 'SUSDC-FUTURES')) {
2104
- url = this.urls['api']['demo']['private'];
2240
+ if (uta) {
2241
+ url = this.urls['api']['demo']['utaPrivate'];
2242
+ }
2243
+ else {
2244
+ url = this.urls['api']['demo']['private'];
2245
+ }
2105
2246
  }
2106
2247
  }
2107
2248
  await this.authenticate({ 'url': url });
@@ -2260,6 +2401,7 @@ export default class bitget extends bitgetRest {
2260
2401
  const methods = {
2261
2402
  'ticker': this.handleTicker,
2262
2403
  'trade': this.handleTrades,
2404
+ 'publicTrade': this.handleTrades,
2263
2405
  'fill': this.handleMyTrades,
2264
2406
  'orders': this.handleOrder,
2265
2407
  'ordersAlgo': this.handleOrder,
@@ -2333,7 +2475,7 @@ export default class bitget extends bitgetRest {
2333
2475
  const arg = this.safeDict(message, 'arg', {});
2334
2476
  const instType = this.safeStringLower(arg, 'instType');
2335
2477
  const type = (instType === 'spot') ? 'spot' : 'contract';
2336
- const instId = this.safeString(arg, 'instId');
2478
+ const instId = this.safeString2(arg, 'instId', 'symbol');
2337
2479
  const market = this.safeMarket(instId, undefined, undefined, type);
2338
2480
  const symbol = market['symbol'];
2339
2481
  const messageHash = 'unsubscribe:trade:' + market['symbol'];
@@ -2450,7 +2592,7 @@ export default class bitget extends bitgetRest {
2450
2592
  // for now only unWatchOrderBook is supporteod
2451
2593
  this.handleOrderBookUnSubscription(client, message);
2452
2594
  }
2453
- else if (channel === 'trade') {
2595
+ else if ((channel === 'trade') || (channel === 'publicTrade')) {
2454
2596
  this.handleTradesUnSubscription(client, message);
2455
2597
  }
2456
2598
  else if (channel === 'ticker') {
@@ -117,11 +117,11 @@ export default class bybit extends bybitRest {
117
117
  * @description unWatches a price ticker
118
118
  * @see https://bybit-exchange.github.io/docs/v5/websocket/public/ticker
119
119
  * @see https://bybit-exchange.github.io/docs/v5/websocket/public/etp-ticker
120
- * @param {string[]} symbols unified symbol of the market to fetch the ticker for
120
+ * @param {string[]} symbol unified symbol of the market to fetch the ticker for
121
121
  * @param {object} [params] extra parameters specific to the exchange API endpoint
122
122
  * @returns {object} a [ticker structure]{@link https://docs.ccxt.com/#/?id=ticker-structure}
123
123
  */
124
- unWatchTicker(symbols: string, params?: {}): Promise<any>;
124
+ unWatchTicker(symbol: string, params?: {}): Promise<any>;
125
125
  handleTicker(client: Client, message: any): void;
126
126
  /**
127
127
  * @method
@@ -285,11 +285,13 @@ export default class bybit extends bybitRest {
285
285
  * @name bybit#watchMyTrades
286
286
  * @description watches information on multiple trades made by the user
287
287
  * @see https://bybit-exchange.github.io/docs/v5/websocket/private/execution
288
+ * @see https://bybit-exchange.github.io/docs/v5/websocket/private/fast-execution
288
289
  * @param {string} symbol unified market symbol of the market orders were made in
289
290
  * @param {int} [since] the earliest time in ms to fetch orders for
290
291
  * @param {int} [limit] the maximum number of order structures to retrieve
291
292
  * @param {object} [params] extra parameters specific to the exchange API endpoint
292
293
  * @param {boolean} [params.unifiedMargin] use unified margin account
294
+ * @param {boolean} [params.executionFast] use fast execution
293
295
  * @returns {object[]} a list of [order structures]{@link https://docs.ccxt.com/#/?id=order-structure}
294
296
  */
295
297
  watchMyTrades(symbol?: Str, since?: Int, limit?: Int, params?: {}): Promise<Trade[]>;
@@ -298,9 +300,11 @@ export default class bybit extends bybitRest {
298
300
  * @name bybit#unWatchMyTrades
299
301
  * @description unWatches information on multiple trades made by the user
300
302
  * @see https://bybit-exchange.github.io/docs/v5/websocket/private/execution
303
+ * @see https://bybit-exchange.github.io/docs/v5/websocket/private/fast-execution
301
304
  * @param {string} symbol unified market symbol of the market orders were made in
302
305
  * @param {object} [params] extra parameters specific to the exchange API endpoint
303
306
  * @param {boolean} [params.unifiedMargin] use unified margin account
307
+ * @param {boolean} [params.executionFast] use fast execution
304
308
  * @returns {object[]} a list of [order structures]{@link https://docs.ccxt.com/#/?id=order-structure}
305
309
  */
306
310
  unWatchMyTrades(symbol?: Str, params?: {}): Promise<any>;