ccxt 4.3.34 → 4.3.36

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 (59) hide show
  1. package/README.md +3 -3
  2. package/dist/ccxt.browser.min.js +3 -3
  3. package/dist/cjs/ccxt.js +1 -1
  4. package/dist/cjs/src/alpaca.js +1 -1
  5. package/dist/cjs/src/base/Exchange.js +11 -0
  6. package/dist/cjs/src/bingx.js +2 -2
  7. package/dist/cjs/src/bit2c.js +2 -1
  8. package/dist/cjs/src/bitget.js +11 -4
  9. package/dist/cjs/src/bitmart.js +2 -9
  10. package/dist/cjs/src/coinbase.js +63 -2
  11. package/dist/cjs/src/coinex.js +26 -19
  12. package/dist/cjs/src/kraken.js +3 -1
  13. package/dist/cjs/src/paymium.js +4 -1
  14. package/dist/cjs/src/pro/binance.js +4 -4
  15. package/dist/cjs/src/pro/bingx.js +10 -4
  16. package/dist/cjs/src/pro/bitfinex2.js +5 -5
  17. package/dist/cjs/src/pro/bitget.js +31 -1
  18. package/dist/cjs/src/pro/bitmart.js +9 -5
  19. package/dist/cjs/src/pro/bybit.js +6 -6
  20. package/dist/cjs/src/pro/htx.js +5 -6
  21. package/dist/cjs/src/pro/okx.js +4 -5
  22. package/dist/cjs/src/pro/woo.js +4 -4
  23. package/dist/cjs/src/whitebit.js +24 -3
  24. package/dist/cjs/src/zaif.js +30 -2
  25. package/dist/cjs/src/zonda.js +6 -0
  26. package/js/ccxt.d.ts +1 -1
  27. package/js/ccxt.js +1 -1
  28. package/js/src/abstract/bitbay.d.ts +6 -0
  29. package/js/src/abstract/zonda.d.ts +6 -0
  30. package/js/src/alpaca.d.ts +1 -1
  31. package/js/src/alpaca.js +1 -1
  32. package/js/src/base/Exchange.d.ts +1 -0
  33. package/js/src/base/Exchange.js +11 -0
  34. package/js/src/bingx.js +2 -2
  35. package/js/src/bit2c.d.ts +1 -1
  36. package/js/src/bit2c.js +2 -1
  37. package/js/src/bitget.js +11 -4
  38. package/js/src/bitmart.js +2 -9
  39. package/js/src/coinbase.d.ts +2 -1
  40. package/js/src/coinbase.js +63 -2
  41. package/js/src/coinex.js +26 -19
  42. package/js/src/kraken.js +3 -1
  43. package/js/src/paymium.d.ts +1 -1
  44. package/js/src/paymium.js +4 -1
  45. package/js/src/pro/binance.js +4 -4
  46. package/js/src/pro/bingx.js +10 -4
  47. package/js/src/pro/bitfinex2.js +5 -5
  48. package/js/src/pro/bitget.js +31 -1
  49. package/js/src/pro/bitmart.js +10 -6
  50. package/js/src/pro/bybit.js +6 -6
  51. package/js/src/pro/htx.js +5 -6
  52. package/js/src/pro/okx.js +4 -5
  53. package/js/src/pro/woo.js +4 -4
  54. package/js/src/whitebit.d.ts +2 -2
  55. package/js/src/whitebit.js +24 -3
  56. package/js/src/zaif.d.ts +1 -1
  57. package/js/src/zaif.js +30 -2
  58. package/js/src/zonda.js +6 -0
  59. package/package.json +1 -1
package/dist/cjs/ccxt.js CHANGED
@@ -185,7 +185,7 @@ var woofipro$1 = require('./src/pro/woofipro.js');
185
185
 
186
186
  //-----------------------------------------------------------------------------
187
187
  // this is updated by vss.js when building
188
- const version = '4.3.34';
188
+ const version = '4.3.36';
189
189
  Exchange["default"].ccxtVersion = version;
190
190
  const exchanges = {
191
191
  'ace': ace,
@@ -791,7 +791,7 @@ class alpaca extends alpaca$1 {
791
791
  // "message": "order is not found."
792
792
  // }
793
793
  //
794
- return this.safeValue(response, 'message', {});
794
+ return this.parseOrder(response);
795
795
  }
796
796
  async cancelAllOrders(symbol = undefined, params = {}) {
797
797
  /**
@@ -2962,6 +2962,17 @@ class Exchange {
2962
2962
  trade['cost'] = this.parseNumber(cost);
2963
2963
  return trade;
2964
2964
  }
2965
+ findNearestCeiling(arr, providedValue) {
2966
+ // i.e. findNearestCeiling ([ 10, 30, 50], 23) returns 30
2967
+ const length = arr.length;
2968
+ for (let i = 0; i < length; i++) {
2969
+ const current = arr[i];
2970
+ if (providedValue <= current) {
2971
+ return current;
2972
+ }
2973
+ }
2974
+ return arr[length - 1];
2975
+ }
2965
2976
  invertFlatStringDictionary(dict) {
2966
2977
  const reversed = {};
2967
2978
  const keys = Object.keys(dict);
@@ -1036,7 +1036,7 @@ class bingx extends bingx$1 {
1036
1036
  time = undefined;
1037
1037
  }
1038
1038
  const cost = this.safeString(trade, 'quoteQty');
1039
- const type = (cost === undefined) ? 'spot' : 'swap';
1039
+ // const type = (cost === undefined) ? 'spot' : 'swap'; this is not reliable
1040
1040
  const currencyId = this.safeStringN(trade, ['currency', 'N', 'commissionAsset']);
1041
1041
  const currencyCode = this.safeCurrencyCode(currencyId);
1042
1042
  const m = this.safeBool(trade, 'm');
@@ -1073,7 +1073,7 @@ class bingx extends bingx$1 {
1073
1073
  'info': trade,
1074
1074
  'timestamp': time,
1075
1075
  'datetime': this.iso8601(time),
1076
- 'symbol': this.safeSymbol(marketId, market, '-', type),
1076
+ 'symbol': this.safeSymbol(marketId, market, '-'),
1077
1077
  'order': this.safeString2(trade, 'orderId', 'i'),
1078
1078
  'type': this.safeStringLower(trade, 'o'),
1079
1079
  'side': this.parseOrderSide(side),
@@ -464,7 +464,8 @@ class bit2c extends bit2c$1 {
464
464
  const request = {
465
465
  'id': id,
466
466
  };
467
- return await this.privatePostOrderCancelOrder(this.extend(request, params));
467
+ const response = await this.privatePostOrderCancelOrder(this.extend(request, params));
468
+ return this.parseOrder(response);
468
469
  }
469
470
  async fetchOpenOrders(symbol = undefined, since = undefined, limit = undefined, params = {}) {
470
471
  /**
@@ -1228,6 +1228,7 @@ class bitget extends bitget$1 {
1228
1228
  '40712': errors.InsufficientFunds,
1229
1229
  '40713': errors.ExchangeError,
1230
1230
  '40714': errors.ExchangeError,
1231
+ '40762': errors.InsufficientFunds,
1231
1232
  '40768': errors.OrderNotFound,
1232
1233
  '41114': errors.OnMaintenance,
1233
1234
  '43011': errors.InvalidOrder,
@@ -4343,11 +4344,17 @@ class bitget extends bitget$1 {
4343
4344
  }
4344
4345
  const marginModeRequest = (marginMode === 'cross') ? 'crossed' : 'isolated';
4345
4346
  request['marginMode'] = marginModeRequest;
4346
- const oneWayMode = this.safeBool(params, 'oneWayMode', false);
4347
- params = this.omit(params, 'oneWayMode');
4347
+ let hedged = undefined;
4348
+ [hedged, params] = this.handleParamBool(params, 'hedged', false);
4349
+ // backward compatibility for `oneWayMode`
4350
+ let oneWayMode = undefined;
4351
+ [oneWayMode, params] = this.handleParamBool(params, 'oneWayMode');
4352
+ if (oneWayMode !== undefined) {
4353
+ hedged = !oneWayMode;
4354
+ }
4348
4355
  let requestSide = side;
4349
4356
  if (reduceOnly) {
4350
- if (oneWayMode) {
4357
+ if (!hedged) {
4351
4358
  request['reduceOnly'] = 'YES';
4352
4359
  }
4353
4360
  else {
@@ -4357,7 +4364,7 @@ class bitget extends bitget$1 {
4357
4364
  }
4358
4365
  }
4359
4366
  else {
4360
- if (!oneWayMode) {
4367
+ if (hedged) {
4361
4368
  request['tradeSide'] = 'Open';
4362
4369
  }
4363
4370
  }
@@ -1182,16 +1182,9 @@ class bitmart extends bitmart$1 {
1182
1182
  market = this.safeMarket(marketId, market);
1183
1183
  const symbol = market['symbol'];
1184
1184
  const last = this.safeString2(ticker, 'close_24h', 'last_price');
1185
- let percentage = this.safeString(ticker, 'price_change_percent_24h');
1185
+ let percentage = Precise["default"].stringAbs(this.safeString(ticker, 'price_change_percent_24h'));
1186
1186
  if (percentage === undefined) {
1187
- const percentageRaw = this.safeString(ticker, 'fluctuation');
1188
- if ((percentageRaw !== undefined) && (percentageRaw !== '0')) { // a few tickers show strictly '0' in fluctuation field
1189
- const direction = percentageRaw[0];
1190
- percentage = direction + Precise["default"].stringMul(percentageRaw.replace(direction, ''), '100');
1191
- }
1192
- else if (percentageRaw === '0') {
1193
- percentage = '0';
1194
- }
1187
+ percentage = Precise["default"].stringAbs(Precise["default"].stringMul(this.safeString(ticker, 'fluctuation'), '100'));
1195
1188
  }
1196
1189
  let baseVolume = this.safeString(ticker, 'base_volume_24h');
1197
1190
  let quoteVolume = this.safeString(ticker, 'quote_volume_24h');
@@ -111,8 +111,8 @@ class coinbase extends coinbase$1 {
111
111
  'fetchTickers': true,
112
112
  'fetchTime': true,
113
113
  'fetchTrades': true,
114
- 'fetchTradingFee': false,
115
- 'fetchTradingFees': false,
114
+ 'fetchTradingFee': 'emulated',
115
+ 'fetchTradingFees': true,
116
116
  'fetchWithdrawals': true,
117
117
  'reduceMargin': false,
118
118
  'setLeverage': false,
@@ -4537,6 +4537,67 @@ class coinbase extends coinbase$1 {
4537
4537
  'takeProfitPrice': undefined,
4538
4538
  });
4539
4539
  }
4540
+ async fetchTradingFees(params = {}) {
4541
+ /**
4542
+ * @method
4543
+ * @name coinbase#fetchTradingFees
4544
+ * @see https://docs.cdp.coinbase.com/advanced-trade/reference/retailbrokerageapi_gettransactionsummary/
4545
+ * @description fetch the trading fees for multiple markets
4546
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
4547
+ * @param {string} [params.type] 'spot' or 'swap'
4548
+ * @returns {object} a dictionary of [fee structures]{@link https://docs.ccxt.com/#/?id=fee-structure} indexed by market symbols
4549
+ */
4550
+ await this.loadMarkets();
4551
+ let type = undefined;
4552
+ [type, params] = this.handleMarketTypeAndParams('fetchTradingFees', undefined, params);
4553
+ const isSpot = (type === 'spot');
4554
+ const productType = isSpot ? 'SPOT' : 'FUTURE';
4555
+ const request = {
4556
+ 'product_type': productType,
4557
+ };
4558
+ const response = await this.v3PrivateGetBrokerageTransactionSummary(this.extend(request, params));
4559
+ //
4560
+ // {
4561
+ // total_volume: '0',
4562
+ // total_fees: '0',
4563
+ // fee_tier: {
4564
+ // pricing_tier: 'Advanced 1',
4565
+ // usd_from: '0',
4566
+ // usd_to: '1000',
4567
+ // taker_fee_rate: '0.008',
4568
+ // maker_fee_rate: '0.006',
4569
+ // aop_from: '',
4570
+ // aop_to: ''
4571
+ // },
4572
+ // margin_rate: null,
4573
+ // goods_and_services_tax: null,
4574
+ // advanced_trade_only_volume: '0',
4575
+ // advanced_trade_only_fees: '0',
4576
+ // coinbase_pro_volume: '0',
4577
+ // coinbase_pro_fees: '0',
4578
+ // total_balance: '',
4579
+ // has_promo_fee: false
4580
+ // }
4581
+ //
4582
+ const data = this.safeDict(response, 'fee_tier', {});
4583
+ const taker_fee = this.safeNumber(data, 'taker_fee_rate');
4584
+ const marker_fee = this.safeNumber(data, 'maker_fee_rate');
4585
+ const result = {};
4586
+ for (let i = 0; i < this.symbols.length; i++) {
4587
+ const symbol = this.symbols[i];
4588
+ const market = this.market(symbol);
4589
+ if ((isSpot && market['spot']) || (!isSpot && !market['spot'])) {
4590
+ result[symbol] = {
4591
+ 'info': response,
4592
+ 'symbol': symbol,
4593
+ 'maker': taker_fee,
4594
+ 'taker': marker_fee,
4595
+ 'percentage': true,
4596
+ };
4597
+ }
4598
+ }
4599
+ return result;
4600
+ }
4540
4601
  createAuthToken(seconds, method = undefined, url = undefined) {
4541
4602
  // it may not work for v2
4542
4603
  let uri = undefined;
@@ -4643,7 +4643,7 @@ class coinex extends coinex$1 {
4643
4643
  * @method
4644
4644
  * @name coinex#withdraw
4645
4645
  * @description make a withdrawal
4646
- * @see https://viabtc.github.io/coinex_api_en_doc/spot/#docsspot002_account015_submit_withdraw
4646
+ * @see https://docs.coinex.com/api/v2/assets/deposit-withdrawal/http/withdrawal
4647
4647
  * @param {string} code unified currency code
4648
4648
  * @param {float} amount the amount to withdraw
4649
4649
  * @param {string} address the address to withdraw to
@@ -4656,37 +4656,44 @@ class coinex extends coinex$1 {
4656
4656
  this.checkAddress(address);
4657
4657
  await this.loadMarkets();
4658
4658
  const currency = this.currency(code);
4659
- const networkCode = this.safeStringUpper(params, 'network');
4659
+ const networkCode = this.safeStringUpper2(params, 'network', 'chain');
4660
4660
  params = this.omit(params, 'network');
4661
4661
  if (tag) {
4662
4662
  address = address + ':' + tag;
4663
4663
  }
4664
4664
  const request = {
4665
- 'coin_type': currency['id'],
4666
- 'coin_address': address,
4667
- 'actual_amount': parseFloat(this.numberToString(amount)),
4668
- 'transfer_method': 'onchain', // onchain, local
4665
+ 'ccy': currency['id'],
4666
+ 'to_address': address,
4667
+ 'amount': this.numberToString(amount), // the actual amount without fees, https://www.coinex.com/fees
4669
4668
  };
4670
4669
  if (networkCode !== undefined) {
4671
- request['smart_contract_name'] = this.networkCodeToId(networkCode);
4670
+ request['chain'] = this.networkCodeToId(networkCode); // required for on-chain, not required for inter-user transfer
4672
4671
  }
4673
- const response = await this.v1PrivatePostBalanceCoinWithdraw(this.extend(request, params));
4672
+ const response = await this.v2PrivatePostAssetsWithdraw(this.extend(request, params));
4674
4673
  //
4675
4674
  // {
4676
4675
  // "code": 0,
4677
4676
  // "data": {
4678
- // "actual_amount": "1.00000000",
4679
- // "amount": "1.00000000",
4680
- // "coin_address": "1KAv3pazbTk2JnQ5xTo6fpKK7p1it2RzD4",
4681
- // "coin_type": "BCH",
4682
- // "coin_withdraw_id": 206,
4677
+ // "withdraw_id": 31193755,
4678
+ // "created_at": 1716874165038,
4679
+ // "withdraw_method": "ON_CHAIN",
4680
+ // "ccy": "USDT",
4681
+ // "amount": "17.3",
4682
+ // "actual_amount": "15",
4683
+ // "chain": "TRC20",
4684
+ // "tx_fee": "2.3",
4685
+ // "fee_asset": "USDT",
4686
+ // "fee_amount": "2.3",
4687
+ // "to_address": "TY5vq3MT6b5cQVAHWHtpGyPg1ERcQgi3UN",
4688
+ // "memo": "",
4689
+ // "tx_id": "",
4683
4690
  // "confirmations": 0,
4684
- // "create_time": 1524228297,
4685
- // "status": "audit",
4686
- // "tx_fee": "0",
4687
- // "tx_id": ""
4691
+ // "explorer_address_url": "https://tronscan.org/#/address/TY5vq3MT6b5cQVAHWHtpGyPg1ERcQgi3UN",
4692
+ // "explorer_tx_url": "https://tronscan.org/#/transaction/",
4693
+ // "remark": "",
4694
+ // "status": "audit_required"
4688
4695
  // },
4689
- // "message": "Ok"
4696
+ // "message": "OK"
4690
4697
  // }
4691
4698
  //
4692
4699
  const transaction = this.safeDict(response, 'data', {});
@@ -4797,7 +4804,7 @@ class coinex extends coinex$1 {
4797
4804
  // "remark": ""
4798
4805
  // }
4799
4806
  //
4800
- // fetchWithdrawals
4807
+ // fetchWithdrawals and withdraw
4801
4808
  //
4802
4809
  // {
4803
4810
  // "withdraw_id": 259364,
@@ -986,7 +986,9 @@ class kraken extends kraken$1 {
986
986
  request['interval'] = timeframe;
987
987
  }
988
988
  if (since !== undefined) {
989
- request['since'] = this.numberToString(this.parseToInt(since / 1000)); // expected to be in seconds
989
+ const scaledSince = this.parseToInt(since / 1000);
990
+ const timeFrameInSeconds = parsedTimeframe * 60;
991
+ request['since'] = this.numberToString(scaledSince - timeFrameInSeconds); // expected to be in seconds
990
992
  }
991
993
  const response = await this.publicGetOHLC(this.extend(request, params));
992
994
  //
@@ -426,7 +426,10 @@ class paymium extends paymium$1 {
426
426
  const request = {
427
427
  'uuid': id,
428
428
  };
429
- return await this.privateDeleteUserOrdersUuidCancel(this.extend(request, params));
429
+ const response = await this.privateDeleteUserOrdersUuidCancel(this.extend(request, params));
430
+ return this.safeOrder({
431
+ 'info': response,
432
+ });
430
433
  }
431
434
  async transfer(code, amount, fromAccount, toAccount, params = {}) {
432
435
  /**
@@ -723,11 +723,11 @@ class binance extends binance$1 {
723
723
  // todo: this is a synch blocking call - make it async
724
724
  // default 100, max 1000, valid limits 5, 10, 20, 50, 100, 500, 1000
725
725
  const snapshot = await this.fetchRestOrderBookSafe(symbol, limit, params);
726
- const orderbook = this.safeValue(this.orderbooks, symbol);
727
- if (orderbook === undefined) {
726
+ if (this.safeValue(this.orderbooks, symbol) === undefined) {
728
727
  // if the orderbook is dropped before the snapshot is received
729
728
  return;
730
729
  }
730
+ const orderbook = this.orderbooks[symbol];
731
731
  orderbook.reset(snapshot);
732
732
  // unroll the accumulated deltas
733
733
  const messages = orderbook.cache;
@@ -813,8 +813,7 @@ class binance extends binance$1 {
813
813
  const symbol = market['symbol'];
814
814
  const name = 'depth';
815
815
  const messageHash = market['lowercaseId'] + '@' + name;
816
- const orderbook = this.safeValue(this.orderbooks, symbol);
817
- if (orderbook === undefined) {
816
+ if (!(symbol in this.orderbooks)) {
818
817
  //
819
818
  // https://github.com/ccxt/ccxt/issues/6672
820
819
  //
@@ -825,6 +824,7 @@ class binance extends binance$1 {
825
824
  //
826
825
  return;
827
826
  }
827
+ const orderbook = this.orderbooks[symbol];
828
828
  const nonce = this.safeInteger(orderbook, 'nonce');
829
829
  if (nonce === undefined) {
830
830
  // 2. Buffer the events you receive from the stream.
@@ -988,14 +988,17 @@ class bingx extends bingx$1 {
988
988
  // }
989
989
  //
990
990
  const isSpot = ('dataType' in message);
991
- const result = this.safeValue2(message, 'data', 'o', {});
991
+ const result = this.safeDict2(message, 'data', 'o', {});
992
992
  let cachedTrades = this.myTrades;
993
993
  if (cachedTrades === undefined) {
994
994
  const limit = this.safeInteger(this.options, 'tradesLimit', 1000);
995
995
  cachedTrades = new Cache.ArrayCacheBySymbolById(limit);
996
996
  this.myTrades = cachedTrades;
997
997
  }
998
- const parsed = this.parseTrade(result);
998
+ const type = isSpot ? 'spot' : 'swap';
999
+ const marketId = this.safeString(result, 's');
1000
+ const market = this.safeMarket(marketId, undefined, '-', type);
1001
+ const parsed = this.parseTrade(result, market);
999
1002
  const symbol = parsed['symbol'];
1000
1003
  const spotHash = 'spot:mytrades';
1001
1004
  const swapHash = 'swap:mytrades';
@@ -1041,10 +1044,13 @@ class bingx extends bingx$1 {
1041
1044
  // }
1042
1045
  // }
1043
1046
  //
1044
- const a = this.safeValue(message, 'a', {});
1045
- const data = this.safeValue(a, 'B', []);
1047
+ const a = this.safeDict(message, 'a', {});
1048
+ const data = this.safeList(a, 'B', []);
1046
1049
  const timestamp = this.safeInteger2(message, 'T', 'E');
1047
1050
  const type = ('P' in a) ? 'swap' : 'spot';
1051
+ if (!(type in this.balance)) {
1052
+ this.balance[type] = {};
1053
+ }
1048
1054
  this.balance[type]['info'] = data;
1049
1055
  this.balance[type]['timestamp'] = timestamp;
1050
1056
  this.balance[type]['datetime'] = this.iso8601(timestamp);
@@ -577,8 +577,7 @@ class bitfinex2 extends bitfinex2$1 {
577
577
  const prec = this.safeString(subscription, 'prec', 'P0');
578
578
  const isRaw = (prec === 'R0');
579
579
  // if it is an initial snapshot
580
- let orderbook = this.safeValue(this.orderbooks, symbol);
581
- if (orderbook === undefined) {
580
+ if (!(symbol in this.orderbooks)) {
582
581
  const limit = this.safeInteger(subscription, 'len');
583
582
  if (isRaw) {
584
583
  // raw order books
@@ -588,7 +587,7 @@ class bitfinex2 extends bitfinex2$1 {
588
587
  // P0, P1, P2, P3, P4
589
588
  this.orderbooks[symbol] = this.countedOrderBook({}, limit);
590
589
  }
591
- orderbook = this.orderbooks[symbol];
590
+ const orderbook = this.orderbooks[symbol];
592
591
  if (isRaw) {
593
592
  const deltas = message[1];
594
593
  for (let i = 0; i < deltas.length; i++) {
@@ -599,7 +598,7 @@ class bitfinex2 extends bitfinex2$1 {
599
598
  const bookside = orderbook[side];
600
599
  const idString = this.safeString(delta, 0);
601
600
  const price = this.safeFloat(delta, 1);
602
- bookside.store(price, size, idString);
601
+ bookside.storeArray([price, size, idString]);
603
602
  }
604
603
  }
605
604
  else {
@@ -612,13 +611,14 @@ class bitfinex2 extends bitfinex2$1 {
612
611
  const size = (amount < 0) ? -amount : amount;
613
612
  const side = (amount < 0) ? 'asks' : 'bids';
614
613
  const bookside = orderbook[side];
615
- bookside.store(price, size, counter);
614
+ bookside.storeArray([price, size, counter]);
616
615
  }
617
616
  }
618
617
  orderbook['symbol'] = symbol;
619
618
  client.resolve(orderbook, messageHash);
620
619
  }
621
620
  else {
621
+ const orderbook = this.orderbooks[symbol];
622
622
  const deltas = message[1];
623
623
  const orderbookItem = this.orderbooks[symbol];
624
624
  if (isRaw) {
@@ -966,7 +966,9 @@ class bitget extends bitget$1 {
966
966
  * @param {int} [limit] the maximum number of order structures to retrieve
967
967
  * @param {object} [params] extra parameters specific to the exchange API endpoint
968
968
  * @param {boolean} [params.stop] *contract only* set to true for watching trigger orders
969
- * @param {string} [params.marginMode] 'isolated' or 'cross' for watching spot margin orders
969
+ * @param {string} [params.marginMode] 'isolated' or 'cross' for watching spot margin orders]
970
+ * @param {string} [params.type] 'spot', 'swap'
971
+ * @param {string} [params.subType] 'linear', 'inverse'
970
972
  * @returns {object[]} a list of [order structures]{@link https://docs.ccxt.com/#/?id=order-structure
971
973
  */
972
974
  await this.loadMarkets();
@@ -982,11 +984,26 @@ class bitget extends bitget$1 {
982
984
  marketId = market['id'];
983
985
  messageHash = messageHash + ':' + symbol;
984
986
  }
987
+ const productType = this.safeString(params, 'productType');
985
988
  let type = undefined;
986
989
  [type, params] = this.handleMarketTypeAndParams('watchOrders', market, params);
990
+ let subType = undefined;
991
+ [subType, params] = this.handleSubTypeAndParams('watchOrders', market, params, 'linear');
987
992
  if ((type === 'spot') && (symbol === undefined)) {
988
993
  throw new errors.ArgumentsRequired(this.id + ' watchOrders requires a symbol argument for ' + type + ' markets.');
989
994
  }
995
+ if ((productType === undefined) && (type !== 'spot') && (symbol === undefined)) {
996
+ messageHash = messageHash + ':' + subType;
997
+ }
998
+ else if (productType === 'USDT-FUTURES') {
999
+ messageHash = messageHash + ':linear';
1000
+ }
1001
+ else if (productType === 'COIN-FUTURES') {
1002
+ messageHash = messageHash + ':inverse';
1003
+ }
1004
+ else if (productType === 'USDC-FUTURES') {
1005
+ messageHash = messageHash + ':usdcfutures'; // non unified channel
1006
+ }
990
1007
  let instType = undefined;
991
1008
  [instType, params] = this.getInstType(market, params);
992
1009
  if (type === 'spot') {
@@ -1008,6 +1025,7 @@ class bitget extends bitget$1 {
1008
1025
  channel = 'orders-crossed';
1009
1026
  }
1010
1027
  }
1028
+ subscriptionHash = subscriptionHash + ':' + instType;
1011
1029
  const args = {
1012
1030
  'instType': instType,
1013
1031
  'channel': channel,
@@ -1067,6 +1085,9 @@ class bitget extends bitget$1 {
1067
1085
  else {
1068
1086
  marketType = 'contract';
1069
1087
  }
1088
+ const isLinearSwap = (instType === 'USDT-FUTURES');
1089
+ const isInverseSwap = (instType === 'COIN-FUTURES');
1090
+ const isUSDCFutures = (instType === 'USDC-FUTURES');
1070
1091
  const data = this.safeValue(message, 'data', []);
1071
1092
  if (this.orders === undefined) {
1072
1093
  const limit = this.safeInteger(this.options, 'ordersLimit', 1000);
@@ -1093,6 +1114,15 @@ class bitget extends bitget$1 {
1093
1114
  client.resolve(stored, innerMessageHash);
1094
1115
  }
1095
1116
  client.resolve(stored, messageHash);
1117
+ if (isLinearSwap) {
1118
+ client.resolve(stored, 'order:linear');
1119
+ }
1120
+ if (isInverseSwap) {
1121
+ client.resolve(stored, 'order:inverse');
1122
+ }
1123
+ if (isUSDCFutures) {
1124
+ client.resolve(stored, 'order:usdcfutures');
1125
+ }
1096
1126
  }
1097
1127
  parseWsOrder(order, market = undefined) {
1098
1128
  //
@@ -355,9 +355,9 @@ class bitmart extends bitmart$1 {
355
355
  /**
356
356
  * @method
357
357
  * @name bitmart#watchOrders
358
- * @see https://developer-pro.bitmart.com/en/spot/#private-order-channel
359
- * @see https://developer-pro.bitmart.com/en/futures/#private-order-channel
360
358
  * @description watches information on multiple orders made by the user
359
+ * @see https://developer-pro.bitmart.com/en/spot/#private-order-progress
360
+ * @see https://developer-pro.bitmart.com/en/futures/#private-order-channel
361
361
  * @param {string} symbol unified market symbol of the market orders were made in
362
362
  * @param {int} [since] the earliest time in ms to fetch orders for
363
363
  * @param {int} [limit] the maximum number of order structures to retrieve
@@ -377,12 +377,16 @@ class bitmart extends bitmart$1 {
377
377
  await this.authenticate(type, params);
378
378
  let request = undefined;
379
379
  if (type === 'spot') {
380
- if (symbol === undefined) {
381
- throw new errors.ArgumentsRequired(this.id + ' watchOrders() requires a symbol argument for spot markets');
380
+ let argsRequest = 'spot/user/order:';
381
+ if (symbol !== undefined) {
382
+ argsRequest += market['id'];
383
+ }
384
+ else {
385
+ argsRequest = 'spot/user/orders:ALL_SYMBOLS';
382
386
  }
383
387
  request = {
384
388
  'op': 'subscribe',
385
- 'args': ['spot/user/order:' + market['id']],
389
+ 'args': [argsRequest],
386
390
  };
387
391
  }
388
392
  else {
@@ -707,23 +707,23 @@ class bybit extends bybit$1 {
707
707
  const isSpot = client.url.indexOf('spot') >= 0;
708
708
  const type = this.safeString(message, 'type');
709
709
  const isSnapshot = (type === 'snapshot');
710
- const data = this.safeValue(message, 'data', {});
710
+ const data = this.safeDict(message, 'data', {});
711
711
  const marketId = this.safeString(data, 's');
712
712
  const marketType = isSpot ? 'spot' : 'contract';
713
713
  const market = this.safeMarket(marketId, undefined, undefined, marketType);
714
714
  const symbol = market['symbol'];
715
715
  const timestamp = this.safeInteger(message, 'ts');
716
- let orderbook = this.safeValue(this.orderbooks, symbol);
717
- if (orderbook === undefined) {
718
- orderbook = this.orderBook();
716
+ if (!(symbol in this.orderbooks)) {
717
+ this.orderbooks[symbol] = this.orderBook();
719
718
  }
719
+ const orderbook = this.orderbooks[symbol];
720
720
  if (isSnapshot) {
721
721
  const snapshot = this.parseOrderBook(data, symbol, timestamp, 'b', 'a');
722
722
  orderbook.reset(snapshot);
723
723
  }
724
724
  else {
725
- const asks = this.safeValue(data, 'a', []);
726
- const bids = this.safeValue(data, 'b', []);
725
+ const asks = this.safeList(data, 'a', []);
726
+ const bids = this.safeList(data, 'b', []);
727
727
  this.handleDeltas(orderbook['asks'], asks);
728
728
  this.handleDeltas(orderbook['bids'], bids);
729
729
  orderbook['timestamp'] = timestamp;
@@ -629,20 +629,19 @@ class htx extends htx$1 {
629
629
  // }
630
630
  //
631
631
  const messageHash = this.safeString(message, 'ch');
632
- const tick = this.safeValue(message, 'tick');
632
+ const tick = this.safeDict(message, 'tick');
633
633
  const event = this.safeString(tick, 'event');
634
- const ch = this.safeValue(message, 'ch');
634
+ const ch = this.safeString(message, 'ch');
635
635
  const parts = ch.split('.');
636
636
  const marketId = this.safeString(parts, 1);
637
637
  const symbol = this.safeSymbol(marketId);
638
- let orderbook = this.safeValue(this.orderbooks, symbol);
639
- if (orderbook === undefined) {
638
+ if (!(symbol in this.orderbooks)) {
640
639
  const size = this.safeString(parts, 3);
641
640
  const sizeParts = size.split('_');
642
641
  const limit = this.safeInteger(sizeParts, 1);
643
- orderbook = this.orderBook({}, limit);
644
- this.orderbooks[symbol] = orderbook;
642
+ this.orderbooks[symbol] = this.orderBook({}, limit);
645
643
  }
644
+ const orderbook = this.orderbooks[symbol];
646
645
  if ((event === undefined) && (orderbook['nonce'] === undefined)) {
647
646
  orderbook.cache.push(message);
648
647
  }
@@ -159,7 +159,7 @@ class okx extends okx$1 {
159
159
  this.deepExtend(firstArgument, params),
160
160
  ],
161
161
  };
162
- return this.watch(url, messageHash, request, messageHash);
162
+ return await this.watch(url, messageHash, request, messageHash);
163
163
  }
164
164
  async watchTrades(symbol, since = undefined, limit = undefined, params = {}) {
165
165
  /**
@@ -1072,11 +1072,10 @@ class okx extends okx$1 {
1072
1072
  }
1073
1073
  }
1074
1074
  else if ((channel === 'books5') || (channel === 'bbo-tbt')) {
1075
- let orderbook = this.safeValue(this.orderbooks, symbol);
1076
- if (orderbook === undefined) {
1077
- orderbook = this.orderBook({}, limit);
1075
+ if (!(symbol in this.orderbooks)) {
1076
+ this.orderbooks[symbol] = this.orderBook({}, limit);
1078
1077
  }
1079
- this.orderbooks[symbol] = orderbook;
1078
+ const orderbook = this.orderbooks[symbol];
1080
1079
  for (let i = 0; i < data.length; i++) {
1081
1080
  const update = data[i];
1082
1081
  const timestamp = this.safeInteger(update, 'ts');
@@ -125,15 +125,15 @@ class woo extends woo$1 {
125
125
  // }
126
126
  // }
127
127
  //
128
- const data = this.safeValue(message, 'data');
128
+ const data = this.safeDict(message, 'data');
129
129
  const marketId = this.safeString(data, 'symbol');
130
130
  const market = this.safeMarket(marketId);
131
131
  const symbol = market['symbol'];
132
132
  const topic = this.safeString(message, 'topic');
133
- let orderbook = this.safeValue(this.orderbooks, symbol);
134
- if (orderbook === undefined) {
135
- orderbook = this.orderBook({});
133
+ if (!(symbol in this.orderbooks)) {
134
+ this.orderbooks[symbol] = this.orderBook({});
136
135
  }
136
+ const orderbook = this.orderbooks[symbol];
137
137
  const timestamp = this.safeInteger(message, 'ts');
138
138
  const snapshot = this.parseOrderBook(data, symbol, timestamp, 'bids', 'asks');
139
139
  orderbook.reset(snapshot);