ccxt 4.4.6 → 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.
package/dist/cjs/ccxt.js CHANGED
@@ -194,7 +194,7 @@ var xt$1 = require('./src/pro/xt.js');
194
194
 
195
195
  //-----------------------------------------------------------------------------
196
196
  // this is updated by vss.js when building
197
- const version = '4.4.6';
197
+ const version = '4.4.7';
198
198
  Exchange["default"].ccxtVersion = version;
199
199
  const exchanges = {
200
200
  'ace': ace,
@@ -1237,6 +1237,13 @@ class Exchange {
1237
1237
  rng$1.nextBytes(x);
1238
1238
  return Buffer.from(x).toString('hex');
1239
1239
  }
1240
+ randNumber(size) {
1241
+ let number = '';
1242
+ for (let i = 0; i < size; i++) {
1243
+ number += Math.floor(Math.random() * 10);
1244
+ }
1245
+ return parseInt(number, 10);
1246
+ }
1240
1247
  /* eslint-enable */
1241
1248
  // ------------------------------------------------------------------------
1242
1249
  // ########################################################################
@@ -2265,6 +2272,7 @@ class Exchange {
2265
2272
  'ETH': { 'ERC20': 'ETH' },
2266
2273
  'TRX': { 'TRC20': 'TRX' },
2267
2274
  'CRO': { 'CRC20': 'CRONOS' },
2275
+ 'BRC20': { 'BRC20': 'BTC' },
2268
2276
  },
2269
2277
  };
2270
2278
  }
@@ -6122,8 +6130,19 @@ class Exchange {
6122
6130
  break;
6123
6131
  }
6124
6132
  result = this.arrayConcat(result, response);
6125
- const last = this.safeValue(response, responseLength - 1);
6126
- cursorValue = this.safeValue(last['info'], cursorReceived);
6133
+ const last = this.safeDict(response, responseLength - 1);
6134
+ // cursorValue = this.safeValue (last['info'], cursorReceived);
6135
+ cursorValue = undefined; // search for the cursor
6136
+ for (let j = 0; j < responseLength; j++) {
6137
+ const index = responseLength - j - 1;
6138
+ const entry = this.safeDict(response, index);
6139
+ const info = this.safeDict(entry, 'info');
6140
+ const cursor = this.safeValue(info, cursorReceived);
6141
+ if (cursor !== undefined) {
6142
+ cursorValue = cursor;
6143
+ break;
6144
+ }
6145
+ }
6127
6146
  if (cursorValue === undefined) {
6128
6147
  break;
6129
6148
  }
@@ -488,6 +488,9 @@ class bingx extends bingx$1 {
488
488
  'BTC': 'BTC',
489
489
  'LTC': 'LTC',
490
490
  },
491
+ 'networks': {
492
+ 'ARB': 'ARBITRUM',
493
+ },
491
494
  },
492
495
  });
493
496
  }
@@ -1415,12 +1415,13 @@ class bitget extends bitget$1 {
1415
1415
  'networks': {
1416
1416
  'TRX': 'TRC20',
1417
1417
  'ETH': 'ERC20',
1418
- 'BSC': 'BEP20',
1419
- },
1420
- 'networksById': {
1421
- 'TRC20': 'TRX',
1422
- 'BSC': 'BEP20',
1418
+ 'BEP20': 'BSC',
1419
+ 'ZKSYNC': 'zkSyncEra',
1420
+ 'STARKNET': 'Starknet',
1421
+ 'OPTIMISM': 'Optimism',
1422
+ 'ARBITRUM': 'Arbitrum',
1423
1423
  },
1424
+ 'networksById': {},
1424
1425
  'fetchPositions': {
1425
1426
  'method': 'privateMixGetV2MixPositionAllPosition', // or privateMixGetV2MixPositionHistoryPosition
1426
1427
  },
@@ -1862,7 +1863,10 @@ class bitget extends bitget$1 {
1862
1863
  for (let j = 0; j < chains.length; j++) {
1863
1864
  const chain = chains[j];
1864
1865
  const networkId = this.safeString(chain, 'chain');
1865
- const network = this.safeCurrencyCode(networkId);
1866
+ let network = this.networkIdToCode(networkId, code);
1867
+ if (network !== undefined) {
1868
+ network = network.toUpperCase();
1869
+ }
1866
1870
  const withdrawEnabled = this.safeString(chain, 'withdrawable');
1867
1871
  const canWithdraw = withdrawEnabled === 'true';
1868
1872
  withdraw = (canWithdraw) ? canWithdraw : withdraw;
@@ -2294,7 +2294,7 @@ class bitmart extends bitmart$1 {
2294
2294
  }
2295
2295
  parseOrder(order, market = undefined) {
2296
2296
  //
2297
- // createOrder
2297
+ // createOrder, editOrder
2298
2298
  //
2299
2299
  // {
2300
2300
  // "order_id": 2707217580
@@ -4777,6 +4777,129 @@ class bitmart extends bitmart$1 {
4777
4777
  'datetime': this.iso8601(timestamp),
4778
4778
  });
4779
4779
  }
4780
+ async editOrder(id, symbol, type, side, amount = undefined, price = undefined, params = {}) {
4781
+ /**
4782
+ * @method
4783
+ * @name bitmart#editOrder
4784
+ * @description edits an open order
4785
+ * @see https://developer-pro.bitmart.com/en/futuresv2/#modify-plan-order-signed
4786
+ * @see https://developer-pro.bitmart.com/en/futuresv2/#modify-tp-sl-order-signed
4787
+ * @see https://developer-pro.bitmart.com/en/futuresv2/#modify-preset-plan-order-signed
4788
+ * @param {string} id order id
4789
+ * @param {string} symbol unified symbol of the market to edit an order in
4790
+ * @param {string} type 'market' or 'limit'
4791
+ * @param {string} side 'buy' or 'sell'
4792
+ * @param {float} [amount] how much you want to trade in units of the base currency
4793
+ * @param {float} [price] the price to fulfill the order, in units of the quote currency, ignored in market orders
4794
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
4795
+ * @param {string} [params.triggerPrice] *swap only* the price to trigger a stop order
4796
+ * @param {string} [params.stopLossPrice] *swap only* the price to trigger a stop-loss order
4797
+ * @param {string} [params.takeProfitPrice] *swap only* the price to trigger a take-profit order
4798
+ * @param {string} [params.stopLoss.triggerPrice] *swap only* the price to trigger a preset stop-loss order
4799
+ * @param {string} [params.takeProfit.triggerPrice] *swap only* the price to trigger a preset take-profit order
4800
+ * @param {string} [params.clientOrderId] client order id of the order
4801
+ * @param {int} [params.price_type] *swap only* 1: last price, 2: fair price, default is 1
4802
+ * @param {int} [params.plan_category] *swap tp/sl only* 1: tp/sl, 2: position tp/sl, default is 1
4803
+ * @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
4804
+ */
4805
+ await this.loadMarkets();
4806
+ const market = this.market(symbol);
4807
+ if (!market['swap']) {
4808
+ throw new errors.NotSupported(this.id + ' editOrder() does not support ' + market['type'] + ' markets, only swap markets are supported');
4809
+ }
4810
+ const stopLossPrice = this.safeString(params, 'stopLossPrice');
4811
+ const takeProfitPrice = this.safeString(params, 'takeProfitPrice');
4812
+ const triggerPrice = this.safeStringN(params, ['triggerPrice', 'stopPrice', 'trigger_price']);
4813
+ const stopLoss = this.safeDict(params, 'stopLoss', {});
4814
+ const takeProfit = this.safeDict(params, 'takeProfit', {});
4815
+ const presetStopLoss = this.safeString(stopLoss, 'triggerPrice');
4816
+ const presetTakeProfit = this.safeString(takeProfit, 'triggerPrice');
4817
+ const isTriggerOrder = triggerPrice !== undefined;
4818
+ const isStopLoss = stopLossPrice !== undefined;
4819
+ const isTakeProfit = takeProfitPrice !== undefined;
4820
+ const isPresetStopLoss = presetStopLoss !== undefined;
4821
+ const isPresetTakeProfit = presetTakeProfit !== undefined;
4822
+ const request = {
4823
+ 'symbol': market['id'],
4824
+ };
4825
+ const clientOrderId = this.safeString(params, 'clientOrderId');
4826
+ if (clientOrderId !== undefined) {
4827
+ params = this.omit(params, 'clientOrderId');
4828
+ request['client_order_id'] = clientOrderId;
4829
+ }
4830
+ if (id !== undefined) {
4831
+ request['order_id'] = id;
4832
+ }
4833
+ params = this.omit(params, ['triggerPrice', 'stopPrice', 'stopLossPrice', 'takeProfitPrice', 'stopLoss', 'takeProfit']);
4834
+ let response = undefined;
4835
+ if (isTriggerOrder || isStopLoss || isTakeProfit) {
4836
+ request['price_type'] = this.safeInteger(params, 'price_type', 1);
4837
+ if (price !== undefined) {
4838
+ request['executive_price'] = this.priceToPrecision(symbol, price);
4839
+ }
4840
+ }
4841
+ if (isTriggerOrder) {
4842
+ request['type'] = type;
4843
+ request['trigger_price'] = this.priceToPrecision(symbol, triggerPrice);
4844
+ response = await this.privatePostContractPrivateModifyPlanOrder(this.extend(request, params));
4845
+ //
4846
+ // {
4847
+ // "code": 1000,
4848
+ // "message": "Ok",
4849
+ // "data": {
4850
+ // "order_id": "3000023150003503"
4851
+ // },
4852
+ // "trace": "324523453245.108.1734567125596324575"
4853
+ // }
4854
+ //
4855
+ }
4856
+ else if (isStopLoss || isTakeProfit) {
4857
+ request['category'] = type;
4858
+ if (isStopLoss) {
4859
+ request['trigger_price'] = this.priceToPrecision(symbol, stopLossPrice);
4860
+ }
4861
+ else {
4862
+ request['trigger_price'] = this.priceToPrecision(symbol, takeProfitPrice);
4863
+ }
4864
+ response = await this.privatePostContractPrivateModifyTpSlOrder(this.extend(request, params));
4865
+ //
4866
+ // {
4867
+ // "code": 1000,
4868
+ // "message": "Ok",
4869
+ // "data": {
4870
+ // "order_id": "3000023150003480"
4871
+ // },
4872
+ // "trace": "23452345.104.1724536582682345459"
4873
+ // }
4874
+ //
4875
+ }
4876
+ else if (isPresetStopLoss || isPresetTakeProfit) {
4877
+ if (isPresetStopLoss) {
4878
+ request['preset_stop_loss_price_type'] = this.safeInteger(params, 'price_type', 1);
4879
+ request['preset_stop_loss_price'] = this.priceToPrecision(symbol, presetStopLoss);
4880
+ }
4881
+ else {
4882
+ request['preset_take_profit_price_type'] = this.safeInteger(params, 'price_type', 1);
4883
+ request['preset_take_profit_price'] = this.priceToPrecision(symbol, presetTakeProfit);
4884
+ }
4885
+ response = await this.privatePostContractPrivateModifyPresetPlanOrder(this.extend(request, params));
4886
+ //
4887
+ // {
4888
+ // "code": 1000,
4889
+ // "message": "Ok",
4890
+ // "data": {
4891
+ // "order_id": "3000023150003496"
4892
+ // },
4893
+ // "trace": "a5c3234534534a836bc476a203.123452.172716624359200197"
4894
+ // }
4895
+ //
4896
+ }
4897
+ else {
4898
+ throw new errors.NotSupported(this.id + ' editOrder() only supports trigger, stop loss and take profit orders');
4899
+ }
4900
+ const data = this.safeDict(response, 'data', {});
4901
+ return this.parseOrder(data, market);
4902
+ }
4780
4903
  nonce() {
4781
4904
  return this.milliseconds();
4782
4905
  }
@@ -6223,13 +6223,17 @@ class bybit extends bybit$1 {
6223
6223
  const currencyId = this.safeString2(item, 'coin', 'currency');
6224
6224
  const code = this.safeCurrencyCode(currencyId, currency);
6225
6225
  currency = this.safeCurrency(currencyId, currency);
6226
- const amount = this.safeString2(item, 'amount', 'change');
6227
- const after = this.safeString2(item, 'wallet_balance', 'cashBalance');
6228
- 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';
6229
6229
  let before = undefined;
6230
- if (after !== undefined && amount !== undefined) {
6231
- const difference = (direction === 'out') ? amount : Precise["default"].stringNeg(amount);
6232
- 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));
6233
6237
  }
6234
6238
  let timestamp = this.parse8601(this.safeString(item, 'exec_time'));
6235
6239
  if (timestamp === undefined) {
@@ -6244,15 +6248,15 @@ class bybit extends bybit$1 {
6244
6248
  'referenceAccount': undefined,
6245
6249
  'type': this.parseLedgerEntryType(this.safeString(item, 'type')),
6246
6250
  'currency': code,
6247
- 'amount': this.parseToNumeric(Precise["default"].stringAbs(amount)),
6251
+ 'amount': amount,
6248
6252
  'timestamp': timestamp,
6249
6253
  'datetime': this.iso8601(timestamp),
6250
- 'before': this.parseToNumeric(before),
6251
- 'after': this.parseToNumeric(after),
6254
+ 'before': before,
6255
+ 'after': after,
6252
6256
  'status': 'ok',
6253
6257
  'fee': {
6254
6258
  'currency': code,
6255
- 'cost': this.parseToNumeric(this.safeString(item, 'fee')),
6259
+ 'cost': this.safeNumber(item, 'fee'),
6256
6260
  },
6257
6261
  }, currency);
6258
6262
  }
@@ -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',
@@ -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;
@@ -40,8 +40,8 @@ class mexc extends mexc$1 {
40
40
  'closePosition': false,
41
41
  'createDepositAddress': true,
42
42
  'createMarketBuyOrderWithCost': true,
43
- 'createMarketOrderWithCost': false,
44
- 'createMarketSellOrderWithCost': false,
43
+ 'createMarketOrderWithCost': true,
44
+ 'createMarketSellOrderWithCost': true,
45
45
  'createOrder': true,
46
46
  'createOrders': true,
47
47
  'createPostOnlyOrder': true,
@@ -130,7 +130,7 @@ class mexc extends mexc$1 {
130
130
  'repayCrossMargin': false,
131
131
  'repayIsolatedMargin': false,
132
132
  'setLeverage': true,
133
- 'setMarginMode': undefined,
133
+ 'setMarginMode': true,
134
134
  'setPositionMode': true,
135
135
  'signIn': undefined,
136
136
  'transfer': undefined,
@@ -416,7 +416,6 @@ class mexc extends mexc$1 {
416
416
  'options': {
417
417
  'adjustForTimeDifference': false,
418
418
  'timeDifference': 0,
419
- 'createMarketBuyOrderRequiresPrice': true,
420
419
  'unavailableContracts': {
421
420
  'BTC/USDT:USDT': true,
422
421
  'LTC/USDT:USDT': true,
@@ -465,12 +464,14 @@ class mexc extends mexc$1 {
465
464
  'LTC': 'LTC',
466
465
  },
467
466
  'networks': {
467
+ 'ZKSYNC': 'ZKSYNCERA',
468
468
  'TRC20': 'TRX',
469
469
  'TON': 'TONCOIN',
470
470
  'AVAXC': 'AVAX_CCHAIN',
471
471
  'ERC20': 'ETH',
472
472
  'ACA': 'ACALA',
473
473
  'BEP20': 'BSC',
474
+ 'OPTIMISM': 'OP',
474
475
  // 'ADA': 'Cardano(ADA)',
475
476
  // 'AE': 'AE',
476
477
  // 'ALGO': 'Algorand(ALGO)',
@@ -2106,8 +2107,27 @@ class mexc extends mexc$1 {
2106
2107
  if (!market['spot']) {
2107
2108
  throw new errors.NotSupported(this.id + ' createMarketBuyOrderWithCost() supports spot orders only');
2108
2109
  }
2109
- params['createMarketBuyOrderRequiresPrice'] = false;
2110
- 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);
2111
2131
  }
2112
2132
  async createOrder(symbol, type, side, amount, price = undefined, params = {}) {
2113
2133
  /**
@@ -2133,6 +2153,7 @@ class mexc extends mexc$1 {
2133
2153
  * @param {long} [params.positionId] *contract only* it is recommended to fill in this parameter when closing a position
2134
2154
  * @param {string} [params.externalOid] *contract only* external order ID
2135
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
2136
2157
  * @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
2137
2158
  */
2138
2159
  await this.loadMarkets();
@@ -2153,26 +2174,25 @@ class mexc extends mexc$1 {
2153
2174
  'side': orderSide,
2154
2175
  'type': type.toUpperCase(),
2155
2176
  };
2156
- if (orderSide === 'BUY' && type === 'market') {
2157
- let createMarketBuyOrderRequiresPrice = true;
2158
- [createMarketBuyOrderRequiresPrice, params] = this.handleOptionAndParams(params, 'createOrder', 'createMarketBuyOrderRequiresPrice', true);
2177
+ if (type === 'market') {
2159
2178
  const cost = this.safeNumber2(params, 'cost', 'quoteOrderQty');
2160
2179
  params = this.omit(params, 'cost');
2161
2180
  if (cost !== undefined) {
2162
2181
  amount = cost;
2182
+ request['quoteOrderQty'] = this.costToPrecision(symbol, amount);
2163
2183
  }
2164
- else if (createMarketBuyOrderRequiresPrice) {
2184
+ else {
2165
2185
  if (price === undefined) {
2166
- 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);
2167
2187
  }
2168
2188
  else {
2169
2189
  const amountString = this.numberToString(amount);
2170
2190
  const priceString = this.numberToString(price);
2171
2191
  const quoteAmount = Precise["default"].stringMul(amountString, priceString);
2172
2192
  amount = quoteAmount;
2193
+ request['quoteOrderQty'] = this.costToPrecision(symbol, amount);
2173
2194
  }
2174
2195
  }
2175
- request['quoteOrderQty'] = this.costToPrecision(symbol, amount);
2176
2196
  }
2177
2197
  else {
2178
2198
  request['quantity'] = this.amountToPrecision(symbol, amount);
@@ -2216,8 +2236,16 @@ class mexc extends mexc$1 {
2216
2236
  * @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
2217
2237
  */
2218
2238
  await this.loadMarkets();
2239
+ const test = this.safeBool(params, 'test', false);
2240
+ params = this.omit(params, 'test');
2219
2241
  const request = this.createSpotOrderRequest(market, type, side, amount, price, marginMode, params);
2220
- 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
+ }
2221
2249
  //
2222
2250
  // spot
2223
2251
  //
@@ -2570,6 +2598,9 @@ class mexc extends mexc$1 {
2570
2598
  * @method
2571
2599
  * @name mexc#fetchOrders
2572
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
2573
2604
  * @param {string} symbol unified market symbol of the market orders were made in
2574
2605
  * @param {int} [since] the earliest time in ms to fetch orders for
2575
2606
  * @param {int} [limit] the maximum number of order structures to retrieve
@@ -2802,6 +2833,9 @@ class mexc extends mexc$1 {
2802
2833
  * @method
2803
2834
  * @name mexc#fetchOpenOrders
2804
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
2805
2839
  * @param {string} symbol unified market symbol
2806
2840
  * @param {int} [since] the earliest time in ms to fetch open orders for
2807
2841
  * @param {int} [limit] the maximum number of open orders structures to retrieve
@@ -2893,6 +2927,9 @@ class mexc extends mexc$1 {
2893
2927
  * @method
2894
2928
  * @name mexc#fetchClosedOrders
2895
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
2896
2933
  * @param {string} symbol unified market symbol of the market orders were made in
2897
2934
  * @param {int} [since] the earliest time in ms to fetch orders for
2898
2935
  * @param {int} [limit] the maximum number of order structures to retrieve
@@ -2906,6 +2943,9 @@ class mexc extends mexc$1 {
2906
2943
  * @method
2907
2944
  * @name mexc#fetchCanceledOrders
2908
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
2909
2949
  * @param {string} symbol unified market symbol of the market orders were made in
2910
2950
  * @param {int} [since] timestamp in ms of the earliest order, default is undefined
2911
2951
  * @param {int} [limit] max number of orders to return, default is undefined
@@ -5649,6 +5689,50 @@ class mexc extends mexc$1 {
5649
5689
  const positions = this.parsePositions(data, symbols, params);
5650
5690
  return this.filterBySinceLimit(positions, since, limit);
5651
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
+ }
5652
5736
  nonce() {
5653
5737
  return this.milliseconds() - this.safeInteger(this.options, 'timeDifference', 0);
5654
5738
  }
@@ -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