ccxt 4.4.5 → 4.4.7

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 (45) hide show
  1. package/README.md +3 -3
  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 +21 -2
  5. package/dist/cjs/src/bingx.js +3 -0
  6. package/dist/cjs/src/bitflyer.js +2 -2
  7. package/dist/cjs/src/bitget.js +19 -7
  8. package/dist/cjs/src/bitmart.js +310 -128
  9. package/dist/cjs/src/bybit.js +25 -11
  10. package/dist/cjs/src/coinbase.js +6 -8
  11. package/dist/cjs/src/gate.js +3 -0
  12. package/dist/cjs/src/kraken.js +6 -1
  13. package/dist/cjs/src/kucoin.js +2 -2
  14. package/dist/cjs/src/mexc.js +127 -19
  15. package/dist/cjs/src/pro/bitget.js +66 -0
  16. package/dist/cjs/src/pro/htx.js +14 -0
  17. package/dist/cjs/src/pro/kraken.js +60 -0
  18. package/dist/cjs/src/pro/okx.js +11 -5
  19. package/examples/js/cli.js +2 -0
  20. package/js/ccxt.d.ts +1 -1
  21. package/js/ccxt.js +1 -1
  22. package/js/src/abstract/bitmart.d.ts +4 -0
  23. package/js/src/base/Exchange.d.ts +4 -0
  24. package/js/src/base/Exchange.js +21 -2
  25. package/js/src/bingx.js +3 -0
  26. package/js/src/bitflyer.js +2 -2
  27. package/js/src/bitget.d.ts +1 -0
  28. package/js/src/bitget.js +19 -7
  29. package/js/src/bitmart.d.ts +1 -0
  30. package/js/src/bitmart.js +310 -128
  31. package/js/src/bybit.js +25 -11
  32. package/js/src/coinbase.js +6 -8
  33. package/js/src/gate.js +3 -0
  34. package/js/src/kraken.js +6 -1
  35. package/js/src/kucoin.js +2 -2
  36. package/js/src/mexc.d.ts +3 -0
  37. package/js/src/mexc.js +127 -19
  38. package/js/src/pro/bitget.d.ts +3 -0
  39. package/js/src/pro/bitget.js +66 -0
  40. package/js/src/pro/htx.js +14 -0
  41. package/js/src/pro/kraken.d.ts +3 -0
  42. package/js/src/pro/kraken.js +60 -0
  43. package/js/src/pro/okx.d.ts +1 -0
  44. package/js/src/pro/okx.js +11 -5
  45. package/package.json +1 -1
@@ -1642,13 +1642,20 @@ class bybit extends bybit$1 {
1642
1642
  async fetchFutureMarkets(params) {
1643
1643
  params = this.extend(params);
1644
1644
  params['limit'] = 1000; // minimize number of requests
1645
+ let preLaunchMarkets = [];
1645
1646
  const usePrivateInstrumentsInfo = this.safeBool(this.options, 'usePrivateInstrumentsInfo', false);
1646
1647
  let response = undefined;
1647
1648
  if (usePrivateInstrumentsInfo) {
1648
1649
  response = await this.privateGetV5MarketInstrumentsInfo(params);
1649
1650
  }
1650
1651
  else {
1651
- response = await this.publicGetV5MarketInstrumentsInfo(params);
1652
+ const linearPromises = [
1653
+ this.publicGetV5MarketInstrumentsInfo(params),
1654
+ this.publicGetV5MarketInstrumentsInfo(this.extend(params, { 'status': 'PreLaunch' })),
1655
+ ];
1656
+ const promises = await Promise.all(linearPromises);
1657
+ response = this.safeDict(promises, 0, {});
1658
+ preLaunchMarkets = this.safeDict(promises, 1, {});
1652
1659
  }
1653
1660
  const data = this.safeDict(response, 'result', {});
1654
1661
  let markets = this.safeList(data, 'list', []);
@@ -1717,6 +1724,9 @@ class bybit extends bybit$1 {
1717
1724
  // "time": 1672712495660
1718
1725
  // }
1719
1726
  //
1727
+ const preLaunchData = this.safeDict(preLaunchMarkets, 'result', {});
1728
+ const preLaunchMarketsList = this.safeList(preLaunchData, 'list', []);
1729
+ markets = this.arrayConcat(markets, preLaunchMarketsList);
1720
1730
  const result = [];
1721
1731
  let category = this.safeString(data, 'category');
1722
1732
  for (let i = 0; i < markets.length; i++) {
@@ -6213,13 +6223,17 @@ class bybit extends bybit$1 {
6213
6223
  const currencyId = this.safeString2(item, 'coin', 'currency');
6214
6224
  const code = this.safeCurrencyCode(currencyId, currency);
6215
6225
  currency = this.safeCurrency(currencyId, currency);
6216
- const amount = this.safeString2(item, 'amount', 'change');
6217
- const after = this.safeString2(item, 'wallet_balance', 'cashBalance');
6218
- const direction = Precise["default"].stringLt(amount, '0') ? 'out' : 'in';
6226
+ const amountString = this.safeString2(item, 'amount', 'change');
6227
+ const afterString = this.safeString2(item, 'wallet_balance', 'cashBalance');
6228
+ const direction = Precise["default"].stringLt(amountString, '0') ? 'out' : 'in';
6219
6229
  let before = undefined;
6220
- if (after !== undefined && amount !== undefined) {
6221
- const difference = (direction === 'out') ? amount : Precise["default"].stringNeg(amount);
6222
- before = Precise["default"].stringAdd(after, difference);
6230
+ let after = undefined;
6231
+ let amount = undefined;
6232
+ if (afterString !== undefined && amountString !== undefined) {
6233
+ const difference = (direction === 'out') ? amountString : Precise["default"].stringNeg(amountString);
6234
+ before = this.parseToNumeric(Precise["default"].stringAdd(afterString, difference));
6235
+ after = this.parseToNumeric(afterString);
6236
+ amount = this.parseToNumeric(Precise["default"].stringAbs(amountString));
6223
6237
  }
6224
6238
  let timestamp = this.parse8601(this.safeString(item, 'exec_time'));
6225
6239
  if (timestamp === undefined) {
@@ -6234,15 +6248,15 @@ class bybit extends bybit$1 {
6234
6248
  'referenceAccount': undefined,
6235
6249
  'type': this.parseLedgerEntryType(this.safeString(item, 'type')),
6236
6250
  'currency': code,
6237
- 'amount': this.parseToNumeric(Precise["default"].stringAbs(amount)),
6251
+ 'amount': amount,
6238
6252
  'timestamp': timestamp,
6239
6253
  'datetime': this.iso8601(timestamp),
6240
- 'before': this.parseToNumeric(before),
6241
- 'after': this.parseToNumeric(after),
6254
+ 'before': before,
6255
+ 'after': after,
6242
6256
  'status': 'ok',
6243
6257
  'fee': {
6244
6258
  'currency': code,
6245
- 'cost': this.parseToNumeric(this.safeString(item, 'fee')),
6259
+ 'cost': this.safeNumber(item, 'fee'),
6246
6260
  },
6247
6261
  }, currency);
6248
6262
  }
@@ -767,30 +767,28 @@ class coinbase extends coinbase$1 {
767
767
  /**
768
768
  * @method
769
769
  * @name coinbase#fetchWithdrawals
770
- * @description fetch all withdrawals made from an account
771
- * @see https://docs.cloud.coinbase.com/sign-in-with-coinbase/docs/api-withdrawals#list-withdrawals
770
+ * @description Fetch all withdrawals made from an account. Won't return crypto withdrawals. Use fetchLedger for those.
771
+ * @see https://docs.cdp.coinbase.com/coinbase-app/docs/api-withdrawals#list-withdrawals
772
772
  * @param {string} code unified currency code
773
773
  * @param {int} [since] the earliest time in ms to fetch withdrawals for
774
774
  * @param {int} [limit] the maximum number of withdrawals structures to retrieve
775
775
  * @param {object} [params] extra parameters specific to the exchange API endpoint
776
776
  * @returns {object[]} a list of [transaction structures]{@link https://docs.ccxt.com/#/?id=transaction-structure}
777
777
  */
778
- // fiat only, for crypto transactions use fetchLedger
779
778
  return await this.fetchTransactionsWithMethod('v2PrivateGetAccountsAccountIdWithdrawals', code, since, limit, params);
780
779
  }
781
780
  async fetchDeposits(code = undefined, since = undefined, limit = undefined, params = {}) {
782
781
  /**
783
782
  * @method
784
783
  * @name coinbase#fetchDeposits
785
- * @description fetch all deposits made to an account
786
- * @see https://docs.cloud.coinbase.com/sign-in-with-coinbase/docs/api-deposits#list-deposits
784
+ * @description Fetch all fiat deposits made to an account. Won't return crypto deposits or staking rewards. Use fetchLedger for those.
785
+ * @see https://docs.cdp.coinbase.com/coinbase-app/docs/api-deposits#list-deposits
787
786
  * @param {string} code unified currency code
788
787
  * @param {int} [since] the earliest time in ms to fetch deposits for
789
788
  * @param {int} [limit] the maximum number of deposits structures to retrieve
790
789
  * @param {object} [params] extra parameters specific to the exchange API endpoint
791
790
  * @returns {object[]} a list of [transaction structures]{@link https://docs.ccxt.com/#/?id=transaction-structure}
792
791
  */
793
- // fiat only, for crypto transactions use fetchLedger
794
792
  return await this.fetchTransactionsWithMethod('v2PrivateGetAccountsAccountIdDeposits', code, since, limit, params);
795
793
  }
796
794
  parseTransactionStatus(status) {
@@ -2257,8 +2255,8 @@ class coinbase extends coinbase$1 {
2257
2255
  /**
2258
2256
  * @method
2259
2257
  * @name coinbase#fetchLedger
2260
- * @description fetch the history of changes, actions done by the user or operations that altered the balance of the user
2261
- * @see https://docs.cloud.coinbase.com/sign-in-with-coinbase/docs/api-transactions#list-transactions
2258
+ * @description Fetch the history of changes, i.e. actions done by the user or operations that altered the balance. Will return staking rewards, and crypto deposits or withdrawals.
2259
+ * @see https://docs.cdp.coinbase.com/coinbase-app/docs/api-transactions#list-transactions
2262
2260
  * @param {string} [code] unified currency code, default is undefined
2263
2261
  * @param {int} [since] timestamp in ms of the earliest ledger entry, default is undefined
2264
2262
  * @param {int} [limit] max number of ledger entries to return, default is undefined
@@ -639,6 +639,9 @@ class gate extends gate$1 {
639
639
  'OPTIMISM': 'OPETH',
640
640
  'POLKADOT': 'DOTSM',
641
641
  'TRC20': 'TRX',
642
+ 'LUNA': 'LUNC',
643
+ 'BASE': 'BASEEVM',
644
+ 'BRC20': 'BTCBRC',
642
645
  },
643
646
  'timeInForce': {
644
647
  'GTC': 'gtc',
@@ -231,6 +231,8 @@ class kraken extends kraken$1 {
231
231
  'XDG': 'DOGE',
232
232
  },
233
233
  'options': {
234
+ 'timeDifference': 0,
235
+ 'adjustForTimeDifference': false,
234
236
  'marketsByAltname': {},
235
237
  'delistedMarketsById': {},
236
238
  // cannot withdraw/deposit these
@@ -461,6 +463,9 @@ class kraken extends kraken$1 {
461
463
  * @param {object} [params] extra parameters specific to the exchange API endpoint
462
464
  * @returns {object[]} an array of objects representing market data
463
465
  */
466
+ if (this.options['adjustForTimeDifference']) {
467
+ await this.loadTimeDifference();
468
+ }
464
469
  const response = await this.publicGetAssetPairs(params);
465
470
  //
466
471
  // {
@@ -3145,7 +3150,7 @@ class kraken extends kraken$1 {
3145
3150
  return { 'url': url, 'method': method, 'body': body, 'headers': headers };
3146
3151
  }
3147
3152
  nonce() {
3148
- return this.milliseconds();
3153
+ return this.milliseconds() - this.options['timeDifference'];
3149
3154
  }
3150
3155
  handleErrors(code, reason, url, method, headers, body, response, requestHeaders, requestBody) {
3151
3156
  if (code === 520) {
@@ -758,7 +758,7 @@ class kucoin extends kucoin$1 {
758
758
  'hf': 'trade_hf',
759
759
  },
760
760
  'networks': {
761
- 'BTC': 'btc',
761
+ 'BRC20': 'btc',
762
762
  'BTCNATIVESEGWIT': 'bech32',
763
763
  'ERC20': 'eth',
764
764
  'TRC20': 'trx',
@@ -1340,7 +1340,7 @@ class kucoin extends kucoin$1 {
1340
1340
  for (let j = 0; j < chainsLength; j++) {
1341
1341
  const chain = chains[j];
1342
1342
  const chainId = this.safeString(chain, 'chainId');
1343
- const networkCode = this.networkIdToCode(chainId);
1343
+ const networkCode = this.networkIdToCode(chainId, code);
1344
1344
  const chainWithdrawEnabled = this.safeBool(chain, 'isWithdrawEnabled', false);
1345
1345
  if (isWithdrawEnabled === undefined) {
1346
1346
  isWithdrawEnabled = chainWithdrawEnabled;
@@ -30,6 +30,9 @@ class mexc extends mexc$1 {
30
30
  'future': false,
31
31
  'option': false,
32
32
  'addMargin': true,
33
+ 'borrowCrossMargin': false,
34
+ 'borrowIsolatedMargin': false,
35
+ 'borrowMargin': false,
33
36
  'cancelAllOrders': true,
34
37
  'cancelOrder': true,
35
38
  'cancelOrders': undefined,
@@ -37,18 +40,27 @@ class mexc extends mexc$1 {
37
40
  'closePosition': false,
38
41
  'createDepositAddress': true,
39
42
  'createMarketBuyOrderWithCost': true,
40
- 'createMarketOrderWithCost': false,
41
- 'createMarketSellOrderWithCost': false,
43
+ 'createMarketOrderWithCost': true,
44
+ 'createMarketSellOrderWithCost': true,
42
45
  'createOrder': true,
43
46
  'createOrders': true,
44
47
  'createPostOnlyOrder': true,
45
48
  'createReduceOnlyOrder': true,
49
+ 'createStopLimitOrder': true,
50
+ 'createStopMarketOrder': true,
51
+ 'createStopOrder': true,
52
+ 'createTriggerOrder': true,
46
53
  'deposit': undefined,
47
54
  'editOrder': undefined,
48
55
  'fetchAccounts': true,
49
56
  'fetchBalance': true,
50
57
  'fetchBidsAsks': true,
51
- 'fetchBorrowRateHistory': undefined,
58
+ 'fetchBorrowInterest': false,
59
+ 'fetchBorrowRate': false,
60
+ 'fetchBorrowRateHistories': false,
61
+ 'fetchBorrowRateHistory': false,
62
+ 'fetchBorrowRates': false,
63
+ 'fetchBorrowRatesPerSymbol': false,
52
64
  'fetchCanceledOrders': true,
53
65
  'fetchClosedOrder': undefined,
54
66
  'fetchClosedOrders': true,
@@ -69,6 +81,7 @@ class mexc extends mexc$1 {
69
81
  'fetchIndexOHLCV': true,
70
82
  'fetchIsolatedBorrowRate': false,
71
83
  'fetchIsolatedBorrowRates': false,
84
+ 'fetchIsolatedPositions': false,
72
85
  'fetchL2OrderBook': true,
73
86
  'fetchLedger': undefined,
74
87
  'fetchLedgerEntry': undefined,
@@ -77,11 +90,13 @@ class mexc extends mexc$1 {
77
90
  'fetchLeverageTiers': true,
78
91
  'fetchMarginAdjustmentHistory': false,
79
92
  'fetchMarginMode': false,
80
- 'fetchMarketLeverageTiers': undefined,
93
+ 'fetchMarketLeverageTiers': 'emulated',
81
94
  'fetchMarkets': true,
82
95
  'fetchMarkOHLCV': true,
83
96
  'fetchMyTrades': true,
84
97
  'fetchOHLCV': true,
98
+ 'fetchOpenInterest': false,
99
+ 'fetchOpenInterestHistory': false,
85
100
  'fetchOpenOrder': undefined,
86
101
  'fetchOpenOrders': true,
87
102
  'fetchOrder': true,
@@ -115,7 +130,7 @@ class mexc extends mexc$1 {
115
130
  'repayCrossMargin': false,
116
131
  'repayIsolatedMargin': false,
117
132
  'setLeverage': true,
118
- 'setMarginMode': undefined,
133
+ 'setMarginMode': true,
119
134
  'setPositionMode': true,
120
135
  'signIn': undefined,
121
136
  'transfer': undefined,
@@ -399,7 +414,8 @@ class mexc extends mexc$1 {
399
414
  },
400
415
  },
401
416
  'options': {
402
- 'createMarketBuyOrderRequiresPrice': true,
417
+ 'adjustForTimeDifference': false,
418
+ 'timeDifference': 0,
403
419
  'unavailableContracts': {
404
420
  'BTC/USDT:USDT': true,
405
421
  'LTC/USDT:USDT': true,
@@ -448,11 +464,14 @@ class mexc extends mexc$1 {
448
464
  'LTC': 'LTC',
449
465
  },
450
466
  'networks': {
467
+ 'ZKSYNC': 'ZKSYNCERA',
451
468
  'TRC20': 'TRX',
452
469
  'TON': 'TONCOIN',
453
470
  'AVAXC': 'AVAX_CCHAIN',
454
471
  'ERC20': 'ETH',
455
472
  'ACA': 'ACALA',
473
+ 'BEP20': 'BSC',
474
+ 'OPTIMISM': 'OP',
456
475
  // 'ADA': 'Cardano(ADA)',
457
476
  // 'AE': 'AE',
458
477
  // 'ALGO': 'Algorand(ALGO)',
@@ -1014,6 +1033,9 @@ class mexc extends mexc$1 {
1014
1033
  * @param {object} [params] extra parameters specific to the exchange API endpoint
1015
1034
  * @returns {object[]} an array of objects representing market data
1016
1035
  */
1036
+ if (this.options['adjustForTimeDifference']) {
1037
+ await this.loadTimeDifference();
1038
+ }
1017
1039
  const spotMarketPromise = this.fetchSpotMarkets(params);
1018
1040
  const swapMarketPromise = this.fetchSwapMarkets(params);
1019
1041
  const [spotMarket, swapMarket] = await Promise.all([spotMarketPromise, swapMarketPromise]);
@@ -2085,8 +2107,27 @@ class mexc extends mexc$1 {
2085
2107
  if (!market['spot']) {
2086
2108
  throw new errors.NotSupported(this.id + ' createMarketBuyOrderWithCost() supports spot orders only');
2087
2109
  }
2088
- params['createMarketBuyOrderRequiresPrice'] = false;
2089
- return await this.createOrder(symbol, 'market', 'buy', cost, undefined, params);
2110
+ params['cost'] = cost;
2111
+ return await this.createOrder(symbol, 'market', 'buy', 0, undefined, params);
2112
+ }
2113
+ async createMarketSellOrderWithCost(symbol, cost, params = {}) {
2114
+ /**
2115
+ * @method
2116
+ * @name mexc#createMarketSellOrderWithCost
2117
+ * @description create a market sell order by providing the symbol and cost
2118
+ * @see https://mexcdevelop.github.io/apidocs/spot_v3_en/#new-order
2119
+ * @param {string} symbol unified symbol of the market to create an order in
2120
+ * @param {float} cost how much you want to trade in units of the quote currency
2121
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
2122
+ * @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
2123
+ */
2124
+ await this.loadMarkets();
2125
+ const market = this.market(symbol);
2126
+ if (!market['spot']) {
2127
+ throw new errors.NotSupported(this.id + ' createMarketBuyOrderWithCost() supports spot orders only');
2128
+ }
2129
+ params['cost'] = cost;
2130
+ return await this.createOrder(symbol, 'market', 'sell', 0, undefined, params);
2090
2131
  }
2091
2132
  async createOrder(symbol, type, side, amount, price = undefined, params = {}) {
2092
2133
  /**
@@ -2112,6 +2153,7 @@ class mexc extends mexc$1 {
2112
2153
  * @param {long} [params.positionId] *contract only* it is recommended to fill in this parameter when closing a position
2113
2154
  * @param {string} [params.externalOid] *contract only* external order ID
2114
2155
  * @param {int} [params.positionMode] *contract only* 1:hedge, 2:one-way, default: the user's current config
2156
+ * @param {boolean} [params.test] *spot only* whether to use the test endpoint or not, default is false
2115
2157
  * @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
2116
2158
  */
2117
2159
  await this.loadMarkets();
@@ -2132,26 +2174,25 @@ class mexc extends mexc$1 {
2132
2174
  'side': orderSide,
2133
2175
  'type': type.toUpperCase(),
2134
2176
  };
2135
- if (orderSide === 'BUY' && type === 'market') {
2136
- let createMarketBuyOrderRequiresPrice = true;
2137
- [createMarketBuyOrderRequiresPrice, params] = this.handleOptionAndParams(params, 'createOrder', 'createMarketBuyOrderRequiresPrice', true);
2177
+ if (type === 'market') {
2138
2178
  const cost = this.safeNumber2(params, 'cost', 'quoteOrderQty');
2139
2179
  params = this.omit(params, 'cost');
2140
2180
  if (cost !== undefined) {
2141
2181
  amount = cost;
2182
+ request['quoteOrderQty'] = this.costToPrecision(symbol, amount);
2142
2183
  }
2143
- else if (createMarketBuyOrderRequiresPrice) {
2184
+ else {
2144
2185
  if (price === undefined) {
2145
- throw new errors.InvalidOrder(this.id + ' createOrder() requires the price argument for market buy orders to calculate the total cost to spend (amount * price), alternatively set the createMarketBuyOrderRequiresPrice option or param to false and pass the cost to spend in the amount argument');
2186
+ request['quantity'] = this.amountToPrecision(symbol, amount);
2146
2187
  }
2147
2188
  else {
2148
2189
  const amountString = this.numberToString(amount);
2149
2190
  const priceString = this.numberToString(price);
2150
2191
  const quoteAmount = Precise["default"].stringMul(amountString, priceString);
2151
2192
  amount = quoteAmount;
2193
+ request['quoteOrderQty'] = this.costToPrecision(symbol, amount);
2152
2194
  }
2153
2195
  }
2154
- request['quoteOrderQty'] = this.costToPrecision(symbol, amount);
2155
2196
  }
2156
2197
  else {
2157
2198
  request['quantity'] = this.amountToPrecision(symbol, amount);
@@ -2195,8 +2236,16 @@ class mexc extends mexc$1 {
2195
2236
  * @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
2196
2237
  */
2197
2238
  await this.loadMarkets();
2239
+ const test = this.safeBool(params, 'test', false);
2240
+ params = this.omit(params, 'test');
2198
2241
  const request = this.createSpotOrderRequest(market, type, side, amount, price, marginMode, params);
2199
- const response = await this.spotPrivatePostOrder(this.extend(request, params));
2242
+ let response = undefined;
2243
+ if (test) {
2244
+ response = await this.spotPrivatePostOrderTest(request);
2245
+ }
2246
+ else {
2247
+ response = await this.spotPrivatePostOrder(request);
2248
+ }
2200
2249
  //
2201
2250
  // spot
2202
2251
  //
@@ -2549,6 +2598,9 @@ class mexc extends mexc$1 {
2549
2598
  * @method
2550
2599
  * @name mexc#fetchOrders
2551
2600
  * @description fetches information on multiple orders made by the user
2601
+ * @see https://mexcdevelop.github.io/apidocs/spot_v3_en/#all-orders
2602
+ * @see https://mexcdevelop.github.io/apidocs/contract_v1_en/#get-all-of-the-user-39-s-historical-orders
2603
+ * @see https://mexcdevelop.github.io/apidocs/contract_v1_en/#gets-the-trigger-order-list
2552
2604
  * @param {string} symbol unified market symbol of the market orders were made in
2553
2605
  * @param {int} [since] the earliest time in ms to fetch orders for
2554
2606
  * @param {int} [limit] the maximum number of order structures to retrieve
@@ -2781,6 +2833,9 @@ class mexc extends mexc$1 {
2781
2833
  * @method
2782
2834
  * @name mexc#fetchOpenOrders
2783
2835
  * @description fetch all unfilled currently open orders
2836
+ * @see https://mexcdevelop.github.io/apidocs/spot_v3_en/#current-open-orders
2837
+ * @see https://mexcdevelop.github.io/apidocs/contract_v1_en/#get-all-of-the-user-39-s-historical-orders
2838
+ * @see https://mexcdevelop.github.io/apidocs/contract_v1_en/#gets-the-trigger-order-list
2784
2839
  * @param {string} symbol unified market symbol
2785
2840
  * @param {int} [since] the earliest time in ms to fetch open orders for
2786
2841
  * @param {int} [limit] the maximum number of open orders structures to retrieve
@@ -2872,6 +2927,9 @@ class mexc extends mexc$1 {
2872
2927
  * @method
2873
2928
  * @name mexc#fetchClosedOrders
2874
2929
  * @description fetches information on multiple closed orders made by the user
2930
+ * @see https://mexcdevelop.github.io/apidocs/spot_v3_en/#all-orders
2931
+ * @see https://mexcdevelop.github.io/apidocs/contract_v1_en/#get-all-of-the-user-39-s-historical-orders
2932
+ * @see https://mexcdevelop.github.io/apidocs/contract_v1_en/#gets-the-trigger-order-list
2875
2933
  * @param {string} symbol unified market symbol of the market orders were made in
2876
2934
  * @param {int} [since] the earliest time in ms to fetch orders for
2877
2935
  * @param {int} [limit] the maximum number of order structures to retrieve
@@ -2885,6 +2943,9 @@ class mexc extends mexc$1 {
2885
2943
  * @method
2886
2944
  * @name mexc#fetchCanceledOrders
2887
2945
  * @description fetches information on multiple canceled orders made by the user
2946
+ * @see https://mexcdevelop.github.io/apidocs/spot_v3_en/#all-orders
2947
+ * @see https://mexcdevelop.github.io/apidocs/contract_v1_en/#get-all-of-the-user-39-s-historical-orders
2948
+ * @see https://mexcdevelop.github.io/apidocs/contract_v1_en/#gets-the-trigger-order-list
2888
2949
  * @param {string} symbol unified market symbol of the market orders were made in
2889
2950
  * @param {int} [since] timestamp in ms of the earliest order, default is undefined
2890
2951
  * @param {int} [limit] max number of orders to return, default is undefined
@@ -4542,7 +4603,7 @@ class mexc extends mexc$1 {
4542
4603
  // 'coin': currency['id'] + network example: USDT-TRX,
4543
4604
  // 'status': 'status',
4544
4605
  // 'startTime': since, // default 90 days
4545
- // 'endTime': this.milliseconds (),
4606
+ // 'endTime': this.nonce(),
4546
4607
  // 'limit': limit, // default 1000, maximum 1000
4547
4608
  };
4548
4609
  let currency = undefined;
@@ -4602,7 +4663,7 @@ class mexc extends mexc$1 {
4602
4663
  // 'coin': currency['id'],
4603
4664
  // 'status': 'status',
4604
4665
  // 'startTime': since, // default 90 days
4605
- // 'endTime': this.milliseconds (),
4666
+ // 'endTime': this.nonce(),
4606
4667
  // 'limit': limit, // default 1000, maximum 1000
4607
4668
  };
4608
4669
  let currency = undefined;
@@ -5628,6 +5689,53 @@ class mexc extends mexc$1 {
5628
5689
  const positions = this.parsePositions(data, symbols, params);
5629
5690
  return this.filterBySinceLimit(positions, since, limit);
5630
5691
  }
5692
+ async setMarginMode(marginMode, symbol = undefined, params = {}) {
5693
+ /**
5694
+ * @method
5695
+ * @name mexc#setMarginMode
5696
+ * @description set margin mode to 'cross' or 'isolated'
5697
+ * @see https://mexcdevelop.github.io/apidocs/contract_v1_en/#switch-leverage
5698
+ * @param {string} marginMode 'cross' or 'isolated'
5699
+ * @param {string} [symbol] required when there is no position, else provide params["positionId"]
5700
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
5701
+ * @param {string} [params.positionId] required when a position is set
5702
+ * @param {string} [params.direction] "long" or "short" required when there is no position
5703
+ * @returns {object} response from the exchange
5704
+ */
5705
+ await this.loadMarkets();
5706
+ const market = this.market(symbol);
5707
+ if (market['spot']) {
5708
+ throw new errors.BadSymbol(this.id + ' setMarginMode() supports contract markets only');
5709
+ }
5710
+ marginMode = marginMode.toLowerCase();
5711
+ if (marginMode !== 'isolated' && marginMode !== 'cross') {
5712
+ throw new errors.BadRequest(this.id + ' setMarginMode() marginMode argument should be isolated or cross');
5713
+ }
5714
+ const leverage = this.safeInteger(params, 'leverage');
5715
+ if (leverage === undefined) {
5716
+ throw new errors.ArgumentsRequired(this.id + ' setMarginMode() requires a leverage parameter');
5717
+ }
5718
+ const direction = this.safeStringLower2(params, 'direction', 'positionId');
5719
+ const request = {
5720
+ 'leverage': leverage,
5721
+ 'openType': (marginMode === 'isolated') ? 1 : 2,
5722
+ };
5723
+ if (symbol !== undefined) {
5724
+ request['symbol'] = market['id'];
5725
+ }
5726
+ if (direction !== undefined) {
5727
+ request['positionType'] = (direction === 'short') ? 2 : 1;
5728
+ }
5729
+ params = this.omit(params, 'direction');
5730
+ const response = await this.contractPrivatePostPositionChangeLeverage(this.extend(request, params));
5731
+ //
5732
+ // { success: true, code: '0' }
5733
+ //
5734
+ return this.parseLeverage(response, market);
5735
+ }
5736
+ nonce() {
5737
+ return this.milliseconds() - this.safeInteger(this.options, 'timeDifference', 0);
5738
+ }
5631
5739
  sign(path, api = 'public', method = 'GET', params = {}, headers = undefined, body = undefined) {
5632
5740
  const section = this.safeString(api, 0);
5633
5741
  const access = this.safeString(api, 1);
@@ -5642,7 +5750,7 @@ class mexc extends mexc$1 {
5642
5750
  }
5643
5751
  let paramsEncoded = '';
5644
5752
  if (access === 'private') {
5645
- params['timestamp'] = this.milliseconds();
5753
+ params['timestamp'] = this.nonce();
5646
5754
  params['recvWindow'] = this.safeInteger(this.options, 'recvWindow', 5000);
5647
5755
  }
5648
5756
  if (Object.keys(params).length) {
@@ -5672,7 +5780,7 @@ class mexc extends mexc$1 {
5672
5780
  }
5673
5781
  else {
5674
5782
  this.checkRequiredCredentials();
5675
- const timestamp = this.milliseconds().toString();
5783
+ const timestamp = this.nonce().toString();
5676
5784
  let auth = '';
5677
5785
  headers = {
5678
5786
  'ApiKey': this.apiKey,
@@ -34,6 +34,7 @@ class bitget extends bitget$1 {
34
34
  'watchOrders': true,
35
35
  'watchTicker': true,
36
36
  'watchTickers': true,
37
+ 'watchBidsAsks': true,
37
38
  'watchTrades': true,
38
39
  'watchTradesForSymbols': true,
39
40
  'watchPositions': true,
@@ -212,6 +213,7 @@ class bitget extends bitget$1 {
212
213
  // "ts": 1701842994341
213
214
  // }
214
215
  //
216
+ this.handleBidAsk(client, message);
215
217
  const ticker = this.parseWsTicker(message);
216
218
  const symbol = ticker['symbol'];
217
219
  this.tickers[symbol] = ticker;
@@ -323,6 +325,70 @@ class bitget extends bitget$1 {
323
325
  'info': ticker,
324
326
  }, market);
325
327
  }
328
+ async watchBidsAsks(symbols = undefined, params = {}) {
329
+ /**
330
+ * @method
331
+ * @name bitget#watchBidsAsks
332
+ * @see https://www.bitget.com/api-doc/spot/websocket/public/Tickers-Channel
333
+ * @see https://www.bitget.com/api-doc/contract/websocket/public/Tickers-Channel
334
+ * @description watches best bid & ask for symbols
335
+ * @param {string[]} symbols unified symbol of the market to fetch the ticker for
336
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
337
+ * @returns {object} a [ticker structure]{@link https://docs.ccxt.com/#/?id=ticker-structure}
338
+ */
339
+ await this.loadMarkets();
340
+ symbols = this.marketSymbols(symbols, undefined, false);
341
+ const market = this.market(symbols[0]);
342
+ let instType = undefined;
343
+ [instType, params] = this.getInstType(market, params);
344
+ const topics = [];
345
+ const messageHashes = [];
346
+ for (let i = 0; i < symbols.length; i++) {
347
+ const symbol = symbols[i];
348
+ const marketInner = this.market(symbol);
349
+ const args = {
350
+ 'instType': instType,
351
+ 'channel': 'ticker',
352
+ 'instId': marketInner['id'],
353
+ };
354
+ topics.push(args);
355
+ messageHashes.push('bidask:' + symbol);
356
+ }
357
+ const tickers = await this.watchPublicMultiple(messageHashes, topics, params);
358
+ if (this.newUpdates) {
359
+ const result = {};
360
+ result[tickers['symbol']] = tickers;
361
+ return result;
362
+ }
363
+ return this.filterByArray(this.bidsasks, 'symbol', symbols);
364
+ }
365
+ handleBidAsk(client, message) {
366
+ const ticker = this.parseWsBidAsk(message);
367
+ const symbol = ticker['symbol'];
368
+ this.bidsasks[symbol] = ticker;
369
+ const messageHash = 'bidask:' + symbol;
370
+ client.resolve(ticker, messageHash);
371
+ }
372
+ parseWsBidAsk(message, market = undefined) {
373
+ const arg = this.safeValue(message, 'arg', {});
374
+ const data = this.safeValue(message, 'data', []);
375
+ const ticker = this.safeValue(data, 0, {});
376
+ const timestamp = this.safeInteger(ticker, 'ts');
377
+ const instType = this.safeString(arg, 'instType');
378
+ const marketType = (instType === 'SPOT') ? 'spot' : 'contract';
379
+ const marketId = this.safeString(ticker, 'instId');
380
+ market = this.safeMarket(marketId, market, undefined, marketType);
381
+ return this.safeTicker({
382
+ 'symbol': market['symbol'],
383
+ 'timestamp': timestamp,
384
+ 'datetime': this.iso8601(timestamp),
385
+ 'ask': this.safeString(ticker, 'askPr'),
386
+ 'askVolume': this.safeString(ticker, 'askSz'),
387
+ 'bid': this.safeString(ticker, 'bidPr'),
388
+ 'bidVolume': this.safeString(ticker, 'bidSz'),
389
+ 'info': ticker,
390
+ }, market);
391
+ }
326
392
  async watchOHLCV(symbol, timeframe = '1m', since = undefined, limit = undefined, params = {}) {
327
393
  /**
328
394
  * @method
@@ -132,6 +132,8 @@ class htx extends htx$1 {
132
132
  * @method
133
133
  * @name huobi#watchTicker
134
134
  * @description watches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market
135
+ * @see https://www.htx.com/en-us/opend/newApiPages/?id=7ec53561-7773-11ed-9966-0242ac110003
136
+ * @see https://www.htx.com/en-us/opend/newApiPages/?id=28c33ab2-77ae-11ed-9966-0242ac110003
135
137
  * @param {string} symbol unified symbol of the market to fetch the ticker for
136
138
  * @param {object} [params] extra parameters specific to the exchange API endpoint
137
139
  * @returns {object} a [ticker structure]{@link https://docs.ccxt.com/#/?id=ticker-structure}
@@ -200,6 +202,9 @@ class htx extends htx$1 {
200
202
  * @method
201
203
  * @name huobi#watchTrades
202
204
  * @description get the list of most recent trades for a particular symbol
205
+ * @see https://www.htx.com/en-us/opend/newApiPages/?id=7ec53b69-7773-11ed-9966-0242ac110003
206
+ * @see https://www.htx.com/en-us/opend/newApiPages/?id=28c33c21-77ae-11ed-9966-0242ac110003
207
+ * @see https://www.htx.com/en-us/opend/newApiPages/?id=28c33cfe-77ae-11ed-9966-0242ac110003
203
208
  * @param {string} symbol unified symbol of the market to fetch trades for
204
209
  * @param {int} [since] timestamp in ms of the earliest trade to fetch
205
210
  * @param {int} [limit] the maximum amount of trades to fetch
@@ -263,6 +268,9 @@ class htx extends htx$1 {
263
268
  * @method
264
269
  * @name huobi#watchOHLCV
265
270
  * @description watches historical candlestick data containing the open, high, low, and close price, and the volume of a market
271
+ * @see https://www.htx.com/en-us/opend/newApiPages/?id=7ec53241-7773-11ed-9966-0242ac110003
272
+ * @see https://www.htx.com/en-us/opend/newApiPages/?id=28c3346a-77ae-11ed-9966-0242ac110003
273
+ * @see https://www.htx.com/en-us/opend/newApiPages/?id=28c33563-77ae-11ed-9966-0242ac110003
266
274
  * @param {string} symbol unified symbol of the market to fetch OHLCV data for
267
275
  * @param {string} timeframe the length of time each candle represents
268
276
  * @param {int} [since] timestamp in ms of the earliest candle to fetch
@@ -669,6 +677,7 @@ class htx extends htx$1 {
669
677
  * @method
670
678
  * @name huobi#watchMyTrades
671
679
  * @description watches information on multiple trades made by the user
680
+ * @see https://www.htx.com/en-us/opend/newApiPages/?id=7ec53dd5-7773-11ed-9966-0242ac110003
672
681
  * @param {string} symbol unified market symbol of the market trades were made in
673
682
  * @param {int} [since] the earliest time in ms to fetch trades for
674
683
  * @param {int} [limit] the maximum number of trade structures to retrieve
@@ -772,6 +781,7 @@ class htx extends htx$1 {
772
781
  * @method
773
782
  * @name huobi#watchOrders
774
783
  * @description watches information on multiple orders made by the user
784
+ * @see https://www.htx.com/en-us/opend/newApiPages/?id=7ec53c8f-7773-11ed-9966-0242ac110003
775
785
  * @param {string} symbol unified market symbol of the market orders were made in
776
786
  * @param {int} [since] the earliest time in ms to fetch orders for
777
787
  * @param {int} [limit] the maximum number of order structures to retrieve
@@ -1346,6 +1356,10 @@ class htx extends htx$1 {
1346
1356
  * @method
1347
1357
  * @name huobi#watchBalance
1348
1358
  * @description watch balance and get the amount of funds available for trading or funds locked in orders
1359
+ * @see https://www.htx.com/en-us/opend/newApiPages/?id=7ec52e28-7773-11ed-9966-0242ac110003
1360
+ * @see https://www.htx.com/en-us/opend/newApiPages/?id=10000084-77b7-11ed-9966-0242ac110003
1361
+ * @see https://www.htx.com/en-us/opend/newApiPages/?id=8cb7dcca-77b5-11ed-9966-0242ac110003
1362
+ * @see https://www.htx.com/en-us/opend/newApiPages/?id=28c34995-77ae-11ed-9966-0242ac110003
1349
1363
  * @param {object} [params] extra parameters specific to the exchange API endpoint
1350
1364
  * @returns {object} a [balance structure]{@link https://docs.ccxt.com/#/?id=balance-structure}
1351
1365
  */