ccxt 4.2.22 → 4.2.24

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.
@@ -7,7 +7,7 @@
7
7
  // ----------------------------------------------------------------------------
8
8
  import bitoproRest from '../bitopro.js';
9
9
  import { ExchangeError } from '../base/errors.js';
10
- import { ArrayCache } from '../base/ws/Cache.js';
10
+ import { ArrayCache, ArrayCacheBySymbolById } from '../base/ws/Cache.js';
11
11
  import { sha384 } from '../static_dependencies/noble-hashes/sha512.js';
12
12
  // ----------------------------------------------------------------------------
13
13
  export default class bitopro extends bitoproRest {
@@ -16,7 +16,7 @@ export default class bitopro extends bitoproRest {
16
16
  'has': {
17
17
  'ws': true,
18
18
  'watchBalance': true,
19
- 'watchMyTrades': false,
19
+ 'watchMyTrades': true,
20
20
  'watchOHLCV': false,
21
21
  'watchOrderBook': true,
22
22
  'watchOrders': false,
@@ -177,6 +177,150 @@ export default class bitopro extends bitoproRest {
177
177
  this.trades[symbol] = tradesCache;
178
178
  client.resolve(tradesCache, messageHash);
179
179
  }
180
+ async watchMyTrades(symbol = undefined, since = undefined, limit = undefined, params = {}) {
181
+ /**
182
+ * @method
183
+ * @name bitopro#watchMyTrades
184
+ * @description watches information on multiple trades made by the user
185
+ * @see https://github.com/bitoex/bitopro-offical-api-docs/blob/master/ws/private/matches_stream.md
186
+ * @param {string} symbol unified market symbol of the market trades were made in
187
+ * @param {int} [since] the earliest time in ms to fetch trades for
188
+ * @param {int} [limit] the maximum number of trade structures to retrieve
189
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
190
+ * @returns {object[]} a list of [trade structures]{@link https://docs.ccxt.com/#/?id=trade-structure
191
+ */
192
+ this.checkRequiredCredentials();
193
+ await this.loadMarkets();
194
+ let messageHash = 'USER_TRADE';
195
+ if (symbol !== undefined) {
196
+ const market = this.market(symbol);
197
+ messageHash = messageHash + ':' + market['symbol'];
198
+ }
199
+ const url = this.urls['ws']['private'] + '/' + 'user-trades';
200
+ this.authenticate(url);
201
+ const trades = await this.watch(url, messageHash, undefined, messageHash);
202
+ if (this.newUpdates) {
203
+ limit = trades.getLimit(symbol, limit);
204
+ }
205
+ return this.filterBySinceLimit(trades, since, limit, 'timestamp', true);
206
+ }
207
+ handleMyTrade(client, message) {
208
+ //
209
+ // {
210
+ // "event": "USER_TRADE",
211
+ // "timestamp": 1694667358782,
212
+ // "datetime": "2023-09-14T12:55:58.782Z",
213
+ // "data": {
214
+ // "base": "usdt",
215
+ // "quote": "twd",
216
+ // "side": "ask",
217
+ // "price": "32.039",
218
+ // "volume": "1",
219
+ // "fee": "6407800",
220
+ // "feeCurrency": "twd",
221
+ // "transactionTimestamp": 1694667358,
222
+ // "eventTimestamp": 1694667358,
223
+ // "orderID": 390733918,
224
+ // "orderType": "LIMIT",
225
+ // "matchID": "bd07673a-94b1-419e-b5ee-d7b723261a5d",
226
+ // "isMarket": false,
227
+ // "isMaker": false
228
+ // }
229
+ // }
230
+ //
231
+ const data = this.safeValue(message, 'data', {});
232
+ const baseId = this.safeString(data, 'base');
233
+ const quoteId = this.safeString(data, 'quote');
234
+ const base = this.safeCurrencyCode(baseId);
235
+ const quote = this.safeCurrencyCode(quoteId);
236
+ const symbol = this.symbol(base + '/' + quote);
237
+ const messageHash = this.safeString(message, 'event');
238
+ if (this.myTrades === undefined) {
239
+ const limit = this.safeInteger(this.options, 'tradesLimit', 1000);
240
+ this.myTrades = new ArrayCacheBySymbolById(limit);
241
+ }
242
+ const trades = this.myTrades;
243
+ const parsed = this.parseWsTrade(data);
244
+ trades.append(parsed);
245
+ client.resolve(trades, messageHash);
246
+ client.resolve(trades, messageHash + ':' + symbol);
247
+ }
248
+ parseWsTrade(trade, market = undefined) {
249
+ //
250
+ // {
251
+ // "base": "usdt",
252
+ // "quote": "twd",
253
+ // "side": "ask",
254
+ // "price": "32.039",
255
+ // "volume": "1",
256
+ // "fee": "6407800",
257
+ // "feeCurrency": "twd",
258
+ // "transactionTimestamp": 1694667358,
259
+ // "eventTimestamp": 1694667358,
260
+ // "orderID": 390733918,
261
+ // "orderType": "LIMIT",
262
+ // "matchID": "bd07673a-94b1-419e-b5ee-d7b723261a5d",
263
+ // "isMarket": false,
264
+ // "isMaker": false
265
+ // }
266
+ //
267
+ const id = this.safeString(trade, 'matchID');
268
+ const orderId = this.safeString(trade, 'orderID');
269
+ const timestamp = this.safeTimestamp(trade, 'transactionTimestamp');
270
+ const baseId = this.safeString(trade, 'base');
271
+ const quoteId = this.safeString(trade, 'quote');
272
+ const base = this.safeCurrencyCode(baseId);
273
+ const quote = this.safeCurrencyCode(quoteId);
274
+ const symbol = this.symbol(base + '/' + quote);
275
+ market = this.safeMarket(symbol, market);
276
+ const price = this.safeString(trade, 'price');
277
+ const type = this.safeStringLower(trade, 'orderType');
278
+ let side = this.safeString(trade, 'side');
279
+ if (side !== undefined) {
280
+ if (side === 'ask') {
281
+ side = 'sell';
282
+ }
283
+ else if (side === 'bid') {
284
+ side = 'buy';
285
+ }
286
+ }
287
+ const amount = this.safeString(trade, 'volume');
288
+ let fee = undefined;
289
+ const feeAmount = this.safeString(trade, 'fee');
290
+ const feeSymbol = this.safeCurrencyCode(this.safeString(trade, 'feeCurrency'));
291
+ if (feeAmount !== undefined) {
292
+ fee = {
293
+ 'cost': feeAmount,
294
+ 'currency': feeSymbol,
295
+ 'rate': undefined,
296
+ };
297
+ }
298
+ const isMaker = this.safeValue(trade, 'isMaker');
299
+ let takerOrMaker = undefined;
300
+ if (isMaker !== undefined) {
301
+ if (isMaker) {
302
+ takerOrMaker = 'maker';
303
+ }
304
+ else {
305
+ takerOrMaker = 'taker';
306
+ }
307
+ }
308
+ return this.safeTrade({
309
+ 'id': id,
310
+ 'info': trade,
311
+ 'order': orderId,
312
+ 'timestamp': timestamp,
313
+ 'datetime': this.iso8601(timestamp),
314
+ 'symbol': symbol,
315
+ 'takerOrMaker': takerOrMaker,
316
+ 'type': type,
317
+ 'side': side,
318
+ 'price': price,
319
+ 'amount': amount,
320
+ 'cost': undefined,
321
+ 'fee': fee,
322
+ }, market);
323
+ }
180
324
  async watchTicker(symbol, params = {}) {
181
325
  /**
182
326
  * @method
@@ -319,6 +463,7 @@ export default class bitopro extends bitoproRest {
319
463
  'TICKER': this.handleTicker,
320
464
  'ORDER_BOOK': this.handleOrderBook,
321
465
  'ACCOUNT_BALANCE': this.handleBalance,
466
+ 'USER_TRADE': this.handleMyTrade,
322
467
  };
323
468
  const event = this.safeString(message, 'event');
324
469
  const method = this.safeValue(methods, event);
@@ -35,6 +35,12 @@ export default class hitbtc extends hitbtcRest {
35
35
  'private': 'wss://api.hitbtc.com/api/3/ws/trading',
36
36
  },
37
37
  },
38
+ 'test': {
39
+ 'ws': {
40
+ 'public': 'wss://api.demo.hitbtc.com/api/3/ws/public',
41
+ 'private': 'wss://api.demo.hitbtc.com/api/3/ws/trading',
42
+ },
43
+ },
38
44
  },
39
45
  'options': {
40
46
  'tradesLimit': 1000,
package/js/src/pro/okx.js CHANGED
@@ -853,13 +853,15 @@ export default class okx extends okxRest {
853
853
  /**
854
854
  * @method
855
855
  * @name okx#watchMyTrades
856
- * @see https://www.okx.com/docs-v5/en/#order-book-trading-trade-ws-order-channel
857
856
  * @description watches information on multiple trades made by the user
857
+ * @see https://www.okx.com/docs-v5/en/#order-book-trading-trade-ws-order-channel
858
858
  * @param {string} [symbol] unified market symbol of the market trades were made in
859
859
  * @param {int} [since] the earliest time in ms to fetch trades for
860
860
  * @param {int} [limit] the maximum number of trade structures to retrieve
861
861
  * @param {object} [params] extra parameters specific to the exchange API endpoint
862
862
  * @param {bool} [params.stop] true if fetching trigger or conditional trades
863
+ * @param {string} [params.type] 'spot', 'swap', 'future', 'option', 'ANY', 'SPOT', 'MARGIN', 'SWAP', 'FUTURES' or 'OPTION'
864
+ * @param {string} [params.marginMode] 'cross' or 'isolated', for automatically setting the type to spot margin
863
865
  * @returns {object[]} a list of [trade structures]{@link https://docs.ccxt.com/#/?id=trade-structure
864
866
  */
865
867
  // By default, receive order updates from any instrument type
@@ -881,7 +883,14 @@ export default class okx extends okxRest {
881
883
  if (type === 'future') {
882
884
  type = 'futures';
883
885
  }
884
- const uppercaseType = type.toUpperCase();
886
+ let uppercaseType = type.toUpperCase();
887
+ let marginMode = undefined;
888
+ [marginMode, params] = this.handleMarginModeAndParams('watchMyTrades', params);
889
+ if (uppercaseType === 'SPOT') {
890
+ if (marginMode !== undefined) {
891
+ uppercaseType = 'MARGIN';
892
+ }
893
+ }
885
894
  const request = {
886
895
  'instType': uppercaseType,
887
896
  };
@@ -1027,7 +1036,6 @@ export default class okx extends okxRest {
1027
1036
  */
1028
1037
  let type = undefined;
1029
1038
  // By default, receive order updates from any instrument type
1030
- [type, params] = this.handleOptionAndParams(params, 'watchOrders', 'defaultType');
1031
1039
  [type, params] = this.handleOptionAndParams(params, 'watchOrders', 'type', 'ANY');
1032
1040
  const isStop = this.safeValue2(params, 'stop', 'trigger', false);
1033
1041
  params = this.omit(params, ['stop', 'trigger']);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ccxt",
3
- "version": "4.2.22",
3
+ "version": "4.2.24",
4
4
  "description": "A JavaScript / TypeScript / Python / C# / PHP cryptocurrency trading library with support for 100+ exchanges",
5
5
  "unpkg": "dist/ccxt.browser.js",
6
6
  "type": "module",
package/skip-tests.json CHANGED
@@ -338,6 +338,7 @@
338
338
  }
339
339
  },
340
340
  "bitopro": {
341
+ "skipWs": true,
341
342
  "skipMethods": {
342
343
  "fetchCurrencies": {
343
344
  "precision": "not provided",