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
package/js/src/bybit.js CHANGED
@@ -1645,13 +1645,20 @@ export default class bybit extends Exchange {
1645
1645
  async fetchFutureMarkets(params) {
1646
1646
  params = this.extend(params);
1647
1647
  params['limit'] = 1000; // minimize number of requests
1648
+ let preLaunchMarkets = [];
1648
1649
  const usePrivateInstrumentsInfo = this.safeBool(this.options, 'usePrivateInstrumentsInfo', false);
1649
1650
  let response = undefined;
1650
1651
  if (usePrivateInstrumentsInfo) {
1651
1652
  response = await this.privateGetV5MarketInstrumentsInfo(params);
1652
1653
  }
1653
1654
  else {
1654
- response = await this.publicGetV5MarketInstrumentsInfo(params);
1655
+ const linearPromises = [
1656
+ this.publicGetV5MarketInstrumentsInfo(params),
1657
+ this.publicGetV5MarketInstrumentsInfo(this.extend(params, { 'status': 'PreLaunch' })),
1658
+ ];
1659
+ const promises = await Promise.all(linearPromises);
1660
+ response = this.safeDict(promises, 0, {});
1661
+ preLaunchMarkets = this.safeDict(promises, 1, {});
1655
1662
  }
1656
1663
  const data = this.safeDict(response, 'result', {});
1657
1664
  let markets = this.safeList(data, 'list', []);
@@ -1720,6 +1727,9 @@ export default class bybit extends Exchange {
1720
1727
  // "time": 1672712495660
1721
1728
  // }
1722
1729
  //
1730
+ const preLaunchData = this.safeDict(preLaunchMarkets, 'result', {});
1731
+ const preLaunchMarketsList = this.safeList(preLaunchData, 'list', []);
1732
+ markets = this.arrayConcat(markets, preLaunchMarketsList);
1723
1733
  const result = [];
1724
1734
  let category = this.safeString(data, 'category');
1725
1735
  for (let i = 0; i < markets.length; i++) {
@@ -6216,13 +6226,17 @@ export default class bybit extends Exchange {
6216
6226
  const currencyId = this.safeString2(item, 'coin', 'currency');
6217
6227
  const code = this.safeCurrencyCode(currencyId, currency);
6218
6228
  currency = this.safeCurrency(currencyId, currency);
6219
- const amount = this.safeString2(item, 'amount', 'change');
6220
- const after = this.safeString2(item, 'wallet_balance', 'cashBalance');
6221
- const direction = Precise.stringLt(amount, '0') ? 'out' : 'in';
6229
+ const amountString = this.safeString2(item, 'amount', 'change');
6230
+ const afterString = this.safeString2(item, 'wallet_balance', 'cashBalance');
6231
+ const direction = Precise.stringLt(amountString, '0') ? 'out' : 'in';
6222
6232
  let before = undefined;
6223
- if (after !== undefined && amount !== undefined) {
6224
- const difference = (direction === 'out') ? amount : Precise.stringNeg(amount);
6225
- before = Precise.stringAdd(after, difference);
6233
+ let after = undefined;
6234
+ let amount = undefined;
6235
+ if (afterString !== undefined && amountString !== undefined) {
6236
+ const difference = (direction === 'out') ? amountString : Precise.stringNeg(amountString);
6237
+ before = this.parseToNumeric(Precise.stringAdd(afterString, difference));
6238
+ after = this.parseToNumeric(afterString);
6239
+ amount = this.parseToNumeric(Precise.stringAbs(amountString));
6226
6240
  }
6227
6241
  let timestamp = this.parse8601(this.safeString(item, 'exec_time'));
6228
6242
  if (timestamp === undefined) {
@@ -6237,15 +6251,15 @@ export default class bybit extends Exchange {
6237
6251
  'referenceAccount': undefined,
6238
6252
  'type': this.parseLedgerEntryType(this.safeString(item, 'type')),
6239
6253
  'currency': code,
6240
- 'amount': this.parseToNumeric(Precise.stringAbs(amount)),
6254
+ 'amount': amount,
6241
6255
  'timestamp': timestamp,
6242
6256
  'datetime': this.iso8601(timestamp),
6243
- 'before': this.parseToNumeric(before),
6244
- 'after': this.parseToNumeric(after),
6257
+ 'before': before,
6258
+ 'after': after,
6245
6259
  'status': 'ok',
6246
6260
  'fee': {
6247
6261
  'currency': code,
6248
- 'cost': this.parseToNumeric(this.safeString(item, 'fee')),
6262
+ 'cost': this.safeNumber(item, 'fee'),
6249
6263
  },
6250
6264
  }, currency);
6251
6265
  }
@@ -770,30 +770,28 @@ export default class coinbase extends Exchange {
770
770
  /**
771
771
  * @method
772
772
  * @name coinbase#fetchWithdrawals
773
- * @description fetch all withdrawals made from an account
774
- * @see https://docs.cloud.coinbase.com/sign-in-with-coinbase/docs/api-withdrawals#list-withdrawals
773
+ * @description Fetch all withdrawals made from an account. Won't return crypto withdrawals. Use fetchLedger for those.
774
+ * @see https://docs.cdp.coinbase.com/coinbase-app/docs/api-withdrawals#list-withdrawals
775
775
  * @param {string} code unified currency code
776
776
  * @param {int} [since] the earliest time in ms to fetch withdrawals for
777
777
  * @param {int} [limit] the maximum number of withdrawals structures to retrieve
778
778
  * @param {object} [params] extra parameters specific to the exchange API endpoint
779
779
  * @returns {object[]} a list of [transaction structures]{@link https://docs.ccxt.com/#/?id=transaction-structure}
780
780
  */
781
- // fiat only, for crypto transactions use fetchLedger
782
781
  return await this.fetchTransactionsWithMethod('v2PrivateGetAccountsAccountIdWithdrawals', code, since, limit, params);
783
782
  }
784
783
  async fetchDeposits(code = undefined, since = undefined, limit = undefined, params = {}) {
785
784
  /**
786
785
  * @method
787
786
  * @name coinbase#fetchDeposits
788
- * @description fetch all deposits made to an account
789
- * @see https://docs.cloud.coinbase.com/sign-in-with-coinbase/docs/api-deposits#list-deposits
787
+ * @description Fetch all fiat deposits made to an account. Won't return crypto deposits or staking rewards. Use fetchLedger for those.
788
+ * @see https://docs.cdp.coinbase.com/coinbase-app/docs/api-deposits#list-deposits
790
789
  * @param {string} code unified currency code
791
790
  * @param {int} [since] the earliest time in ms to fetch deposits for
792
791
  * @param {int} [limit] the maximum number of deposits structures to retrieve
793
792
  * @param {object} [params] extra parameters specific to the exchange API endpoint
794
793
  * @returns {object[]} a list of [transaction structures]{@link https://docs.ccxt.com/#/?id=transaction-structure}
795
794
  */
796
- // fiat only, for crypto transactions use fetchLedger
797
795
  return await this.fetchTransactionsWithMethod('v2PrivateGetAccountsAccountIdDeposits', code, since, limit, params);
798
796
  }
799
797
  parseTransactionStatus(status) {
@@ -2260,8 +2258,8 @@ export default class coinbase extends Exchange {
2260
2258
  /**
2261
2259
  * @method
2262
2260
  * @name coinbase#fetchLedger
2263
- * @description fetch the history of changes, actions done by the user or operations that altered the balance of the user
2264
- * @see https://docs.cloud.coinbase.com/sign-in-with-coinbase/docs/api-transactions#list-transactions
2261
+ * @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.
2262
+ * @see https://docs.cdp.coinbase.com/coinbase-app/docs/api-transactions#list-transactions
2265
2263
  * @param {string} [code] unified currency code, default is undefined
2266
2264
  * @param {int} [since] timestamp in ms of the earliest ledger entry, default is undefined
2267
2265
  * @param {int} [limit] max number of ledger entries to return, default is undefined
package/js/src/gate.js CHANGED
@@ -642,6 +642,9 @@ export default class gate extends Exchange {
642
642
  'OPTIMISM': 'OPETH',
643
643
  'POLKADOT': 'DOTSM',
644
644
  'TRC20': 'TRX',
645
+ 'LUNA': 'LUNC',
646
+ 'BASE': 'BASEEVM',
647
+ 'BRC20': 'BTCBRC',
645
648
  },
646
649
  'timeInForce': {
647
650
  'GTC': 'gtc',
package/js/src/kraken.js CHANGED
@@ -234,6 +234,8 @@ export default class kraken extends Exchange {
234
234
  'XDG': 'DOGE',
235
235
  },
236
236
  'options': {
237
+ 'timeDifference': 0,
238
+ 'adjustForTimeDifference': false,
237
239
  'marketsByAltname': {},
238
240
  'delistedMarketsById': {},
239
241
  // cannot withdraw/deposit these
@@ -464,6 +466,9 @@ export default class kraken extends Exchange {
464
466
  * @param {object} [params] extra parameters specific to the exchange API endpoint
465
467
  * @returns {object[]} an array of objects representing market data
466
468
  */
469
+ if (this.options['adjustForTimeDifference']) {
470
+ await this.loadTimeDifference();
471
+ }
467
472
  const response = await this.publicGetAssetPairs(params);
468
473
  //
469
474
  // {
@@ -3148,7 +3153,7 @@ export default class kraken extends Exchange {
3148
3153
  return { 'url': url, 'method': method, 'body': body, 'headers': headers };
3149
3154
  }
3150
3155
  nonce() {
3151
- return this.milliseconds();
3156
+ return this.milliseconds() - this.options['timeDifference'];
3152
3157
  }
3153
3158
  handleErrors(code, reason, url, method, headers, body, response, requestHeaders, requestBody) {
3154
3159
  if (code === 520) {
package/js/src/kucoin.js CHANGED
@@ -761,7 +761,7 @@ export default class kucoin extends Exchange {
761
761
  'hf': 'trade_hf',
762
762
  },
763
763
  'networks': {
764
- 'BTC': 'btc',
764
+ 'BRC20': 'btc',
765
765
  'BTCNATIVESEGWIT': 'bech32',
766
766
  'ERC20': 'eth',
767
767
  'TRC20': 'trx',
@@ -1343,7 +1343,7 @@ export default class kucoin extends Exchange {
1343
1343
  for (let j = 0; j < chainsLength; j++) {
1344
1344
  const chain = chains[j];
1345
1345
  const chainId = this.safeString(chain, 'chainId');
1346
- const networkCode = this.networkIdToCode(chainId);
1346
+ const networkCode = this.networkIdToCode(chainId, code);
1347
1347
  const chainWithdrawEnabled = this.safeBool(chain, 'isWithdrawEnabled', false);
1348
1348
  if (isWithdrawEnabled === undefined) {
1349
1349
  isWithdrawEnabled = chainWithdrawEnabled;
package/js/src/mexc.d.ts CHANGED
@@ -30,6 +30,7 @@ export default class mexc extends Exchange {
30
30
  parseTicker(ticker: Dict, market?: Market): Ticker;
31
31
  fetchBidsAsks(symbols?: Strings, params?: {}): Promise<Tickers>;
32
32
  createMarketBuyOrderWithCost(symbol: string, cost: number, params?: {}): Promise<Order>;
33
+ createMarketSellOrderWithCost(symbol: string, cost: number, params?: {}): Promise<Order>;
33
34
  createOrder(symbol: string, type: OrderType, side: OrderSide, amount: number, price?: Num, params?: {}): Promise<Order>;
34
35
  createSpotOrderRequest(market: any, type: any, side: any, amount: any, price?: any, marginMode?: any, params?: {}): any;
35
36
  createSpotOrder(market: any, type: any, side: any, amount: any, price?: any, marginMode?: any, params?: {}): Promise<Order>;
@@ -156,6 +157,8 @@ export default class mexc extends Exchange {
156
157
  parseLeverage(leverage: Dict, market?: Market): Leverage;
157
158
  handleMarginModeAndParams(methodName: any, params?: {}, defaultValue?: any): any[];
158
159
  fetchPositionsHistory(symbols?: Strings, since?: Int, limit?: Int, params?: {}): Promise<Position[]>;
160
+ setMarginMode(marginMode: string, symbol?: Str, params?: {}): Promise<Leverage>;
161
+ nonce(): number;
159
162
  sign(path: any, api?: string, method?: string, params?: {}, headers?: any, body?: any): {
160
163
  url: any;
161
164
  method: string;
package/js/src/mexc.js CHANGED
@@ -33,6 +33,9 @@ export default class mexc extends Exchange {
33
33
  'future': false,
34
34
  'option': false,
35
35
  'addMargin': true,
36
+ 'borrowCrossMargin': false,
37
+ 'borrowIsolatedMargin': false,
38
+ 'borrowMargin': false,
36
39
  'cancelAllOrders': true,
37
40
  'cancelOrder': true,
38
41
  'cancelOrders': undefined,
@@ -40,18 +43,27 @@ export default class mexc extends Exchange {
40
43
  'closePosition': false,
41
44
  'createDepositAddress': true,
42
45
  'createMarketBuyOrderWithCost': true,
43
- 'createMarketOrderWithCost': false,
44
- 'createMarketSellOrderWithCost': false,
46
+ 'createMarketOrderWithCost': true,
47
+ 'createMarketSellOrderWithCost': true,
45
48
  'createOrder': true,
46
49
  'createOrders': true,
47
50
  'createPostOnlyOrder': true,
48
51
  'createReduceOnlyOrder': true,
52
+ 'createStopLimitOrder': true,
53
+ 'createStopMarketOrder': true,
54
+ 'createStopOrder': true,
55
+ 'createTriggerOrder': true,
49
56
  'deposit': undefined,
50
57
  'editOrder': undefined,
51
58
  'fetchAccounts': true,
52
59
  'fetchBalance': true,
53
60
  'fetchBidsAsks': true,
54
- 'fetchBorrowRateHistory': undefined,
61
+ 'fetchBorrowInterest': false,
62
+ 'fetchBorrowRate': false,
63
+ 'fetchBorrowRateHistories': false,
64
+ 'fetchBorrowRateHistory': false,
65
+ 'fetchBorrowRates': false,
66
+ 'fetchBorrowRatesPerSymbol': false,
55
67
  'fetchCanceledOrders': true,
56
68
  'fetchClosedOrder': undefined,
57
69
  'fetchClosedOrders': true,
@@ -72,6 +84,7 @@ export default class mexc extends Exchange {
72
84
  'fetchIndexOHLCV': true,
73
85
  'fetchIsolatedBorrowRate': false,
74
86
  'fetchIsolatedBorrowRates': false,
87
+ 'fetchIsolatedPositions': false,
75
88
  'fetchL2OrderBook': true,
76
89
  'fetchLedger': undefined,
77
90
  'fetchLedgerEntry': undefined,
@@ -80,11 +93,13 @@ export default class mexc extends Exchange {
80
93
  'fetchLeverageTiers': true,
81
94
  'fetchMarginAdjustmentHistory': false,
82
95
  'fetchMarginMode': false,
83
- 'fetchMarketLeverageTiers': undefined,
96
+ 'fetchMarketLeverageTiers': 'emulated',
84
97
  'fetchMarkets': true,
85
98
  'fetchMarkOHLCV': true,
86
99
  'fetchMyTrades': true,
87
100
  'fetchOHLCV': true,
101
+ 'fetchOpenInterest': false,
102
+ 'fetchOpenInterestHistory': false,
88
103
  'fetchOpenOrder': undefined,
89
104
  'fetchOpenOrders': true,
90
105
  'fetchOrder': true,
@@ -118,7 +133,7 @@ export default class mexc extends Exchange {
118
133
  'repayCrossMargin': false,
119
134
  'repayIsolatedMargin': false,
120
135
  'setLeverage': true,
121
- 'setMarginMode': undefined,
136
+ 'setMarginMode': true,
122
137
  'setPositionMode': true,
123
138
  'signIn': undefined,
124
139
  'transfer': undefined,
@@ -402,7 +417,8 @@ export default class mexc extends Exchange {
402
417
  },
403
418
  },
404
419
  'options': {
405
- 'createMarketBuyOrderRequiresPrice': true,
420
+ 'adjustForTimeDifference': false,
421
+ 'timeDifference': 0,
406
422
  'unavailableContracts': {
407
423
  'BTC/USDT:USDT': true,
408
424
  'LTC/USDT:USDT': true,
@@ -451,11 +467,14 @@ export default class mexc extends Exchange {
451
467
  'LTC': 'LTC',
452
468
  },
453
469
  'networks': {
470
+ 'ZKSYNC': 'ZKSYNCERA',
454
471
  'TRC20': 'TRX',
455
472
  'TON': 'TONCOIN',
456
473
  'AVAXC': 'AVAX_CCHAIN',
457
474
  'ERC20': 'ETH',
458
475
  'ACA': 'ACALA',
476
+ 'BEP20': 'BSC',
477
+ 'OPTIMISM': 'OP',
459
478
  // 'ADA': 'Cardano(ADA)',
460
479
  // 'AE': 'AE',
461
480
  // 'ALGO': 'Algorand(ALGO)',
@@ -1017,6 +1036,9 @@ export default class mexc extends Exchange {
1017
1036
  * @param {object} [params] extra parameters specific to the exchange API endpoint
1018
1037
  * @returns {object[]} an array of objects representing market data
1019
1038
  */
1039
+ if (this.options['adjustForTimeDifference']) {
1040
+ await this.loadTimeDifference();
1041
+ }
1020
1042
  const spotMarketPromise = this.fetchSpotMarkets(params);
1021
1043
  const swapMarketPromise = this.fetchSwapMarkets(params);
1022
1044
  const [spotMarket, swapMarket] = await Promise.all([spotMarketPromise, swapMarketPromise]);
@@ -2088,8 +2110,27 @@ export default class mexc extends Exchange {
2088
2110
  if (!market['spot']) {
2089
2111
  throw new NotSupported(this.id + ' createMarketBuyOrderWithCost() supports spot orders only');
2090
2112
  }
2091
- params['createMarketBuyOrderRequiresPrice'] = false;
2092
- return await this.createOrder(symbol, 'market', 'buy', cost, undefined, params);
2113
+ params['cost'] = cost;
2114
+ return await this.createOrder(symbol, 'market', 'buy', 0, undefined, params);
2115
+ }
2116
+ async createMarketSellOrderWithCost(symbol, cost, params = {}) {
2117
+ /**
2118
+ * @method
2119
+ * @name mexc#createMarketSellOrderWithCost
2120
+ * @description create a market sell order by providing the symbol and cost
2121
+ * @see https://mexcdevelop.github.io/apidocs/spot_v3_en/#new-order
2122
+ * @param {string} symbol unified symbol of the market to create an order in
2123
+ * @param {float} cost how much you want to trade in units of the quote currency
2124
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
2125
+ * @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
2126
+ */
2127
+ await this.loadMarkets();
2128
+ const market = this.market(symbol);
2129
+ if (!market['spot']) {
2130
+ throw new NotSupported(this.id + ' createMarketBuyOrderWithCost() supports spot orders only');
2131
+ }
2132
+ params['cost'] = cost;
2133
+ return await this.createOrder(symbol, 'market', 'sell', 0, undefined, params);
2093
2134
  }
2094
2135
  async createOrder(symbol, type, side, amount, price = undefined, params = {}) {
2095
2136
  /**
@@ -2115,6 +2156,7 @@ export default class mexc extends Exchange {
2115
2156
  * @param {long} [params.positionId] *contract only* it is recommended to fill in this parameter when closing a position
2116
2157
  * @param {string} [params.externalOid] *contract only* external order ID
2117
2158
  * @param {int} [params.positionMode] *contract only* 1:hedge, 2:one-way, default: the user's current config
2159
+ * @param {boolean} [params.test] *spot only* whether to use the test endpoint or not, default is false
2118
2160
  * @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
2119
2161
  */
2120
2162
  await this.loadMarkets();
@@ -2135,26 +2177,25 @@ export default class mexc extends Exchange {
2135
2177
  'side': orderSide,
2136
2178
  'type': type.toUpperCase(),
2137
2179
  };
2138
- if (orderSide === 'BUY' && type === 'market') {
2139
- let createMarketBuyOrderRequiresPrice = true;
2140
- [createMarketBuyOrderRequiresPrice, params] = this.handleOptionAndParams(params, 'createOrder', 'createMarketBuyOrderRequiresPrice', true);
2180
+ if (type === 'market') {
2141
2181
  const cost = this.safeNumber2(params, 'cost', 'quoteOrderQty');
2142
2182
  params = this.omit(params, 'cost');
2143
2183
  if (cost !== undefined) {
2144
2184
  amount = cost;
2185
+ request['quoteOrderQty'] = this.costToPrecision(symbol, amount);
2145
2186
  }
2146
- else if (createMarketBuyOrderRequiresPrice) {
2187
+ else {
2147
2188
  if (price === undefined) {
2148
- throw new 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');
2189
+ request['quantity'] = this.amountToPrecision(symbol, amount);
2149
2190
  }
2150
2191
  else {
2151
2192
  const amountString = this.numberToString(amount);
2152
2193
  const priceString = this.numberToString(price);
2153
2194
  const quoteAmount = Precise.stringMul(amountString, priceString);
2154
2195
  amount = quoteAmount;
2196
+ request['quoteOrderQty'] = this.costToPrecision(symbol, amount);
2155
2197
  }
2156
2198
  }
2157
- request['quoteOrderQty'] = this.costToPrecision(symbol, amount);
2158
2199
  }
2159
2200
  else {
2160
2201
  request['quantity'] = this.amountToPrecision(symbol, amount);
@@ -2198,8 +2239,16 @@ export default class mexc extends Exchange {
2198
2239
  * @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
2199
2240
  */
2200
2241
  await this.loadMarkets();
2242
+ const test = this.safeBool(params, 'test', false);
2243
+ params = this.omit(params, 'test');
2201
2244
  const request = this.createSpotOrderRequest(market, type, side, amount, price, marginMode, params);
2202
- const response = await this.spotPrivatePostOrder(this.extend(request, params));
2245
+ let response = undefined;
2246
+ if (test) {
2247
+ response = await this.spotPrivatePostOrderTest(request);
2248
+ }
2249
+ else {
2250
+ response = await this.spotPrivatePostOrder(request);
2251
+ }
2203
2252
  //
2204
2253
  // spot
2205
2254
  //
@@ -2552,6 +2601,9 @@ export default class mexc extends Exchange {
2552
2601
  * @method
2553
2602
  * @name mexc#fetchOrders
2554
2603
  * @description fetches information on multiple orders made by the user
2604
+ * @see https://mexcdevelop.github.io/apidocs/spot_v3_en/#all-orders
2605
+ * @see https://mexcdevelop.github.io/apidocs/contract_v1_en/#get-all-of-the-user-39-s-historical-orders
2606
+ * @see https://mexcdevelop.github.io/apidocs/contract_v1_en/#gets-the-trigger-order-list
2555
2607
  * @param {string} symbol unified market symbol of the market orders were made in
2556
2608
  * @param {int} [since] the earliest time in ms to fetch orders for
2557
2609
  * @param {int} [limit] the maximum number of order structures to retrieve
@@ -2784,6 +2836,9 @@ export default class mexc extends Exchange {
2784
2836
  * @method
2785
2837
  * @name mexc#fetchOpenOrders
2786
2838
  * @description fetch all unfilled currently open orders
2839
+ * @see https://mexcdevelop.github.io/apidocs/spot_v3_en/#current-open-orders
2840
+ * @see https://mexcdevelop.github.io/apidocs/contract_v1_en/#get-all-of-the-user-39-s-historical-orders
2841
+ * @see https://mexcdevelop.github.io/apidocs/contract_v1_en/#gets-the-trigger-order-list
2787
2842
  * @param {string} symbol unified market symbol
2788
2843
  * @param {int} [since] the earliest time in ms to fetch open orders for
2789
2844
  * @param {int} [limit] the maximum number of open orders structures to retrieve
@@ -2875,6 +2930,9 @@ export default class mexc extends Exchange {
2875
2930
  * @method
2876
2931
  * @name mexc#fetchClosedOrders
2877
2932
  * @description fetches information on multiple closed orders made by the user
2933
+ * @see https://mexcdevelop.github.io/apidocs/spot_v3_en/#all-orders
2934
+ * @see https://mexcdevelop.github.io/apidocs/contract_v1_en/#get-all-of-the-user-39-s-historical-orders
2935
+ * @see https://mexcdevelop.github.io/apidocs/contract_v1_en/#gets-the-trigger-order-list
2878
2936
  * @param {string} symbol unified market symbol of the market orders were made in
2879
2937
  * @param {int} [since] the earliest time in ms to fetch orders for
2880
2938
  * @param {int} [limit] the maximum number of order structures to retrieve
@@ -2888,6 +2946,9 @@ export default class mexc extends Exchange {
2888
2946
  * @method
2889
2947
  * @name mexc#fetchCanceledOrders
2890
2948
  * @description fetches information on multiple canceled orders made by the user
2949
+ * @see https://mexcdevelop.github.io/apidocs/spot_v3_en/#all-orders
2950
+ * @see https://mexcdevelop.github.io/apidocs/contract_v1_en/#get-all-of-the-user-39-s-historical-orders
2951
+ * @see https://mexcdevelop.github.io/apidocs/contract_v1_en/#gets-the-trigger-order-list
2891
2952
  * @param {string} symbol unified market symbol of the market orders were made in
2892
2953
  * @param {int} [since] timestamp in ms of the earliest order, default is undefined
2893
2954
  * @param {int} [limit] max number of orders to return, default is undefined
@@ -4546,7 +4607,7 @@ export default class mexc extends Exchange {
4546
4607
  // 'coin': currency['id'] + network example: USDT-TRX,
4547
4608
  // 'status': 'status',
4548
4609
  // 'startTime': since, // default 90 days
4549
- // 'endTime': this.milliseconds (),
4610
+ // 'endTime': this.nonce(),
4550
4611
  // 'limit': limit, // default 1000, maximum 1000
4551
4612
  };
4552
4613
  let currency = undefined;
@@ -4606,7 +4667,7 @@ export default class mexc extends Exchange {
4606
4667
  // 'coin': currency['id'],
4607
4668
  // 'status': 'status',
4608
4669
  // 'startTime': since, // default 90 days
4609
- // 'endTime': this.milliseconds (),
4670
+ // 'endTime': this.nonce(),
4610
4671
  // 'limit': limit, // default 1000, maximum 1000
4611
4672
  };
4612
4673
  let currency = undefined;
@@ -5632,6 +5693,53 @@ export default class mexc extends Exchange {
5632
5693
  const positions = this.parsePositions(data, symbols, params);
5633
5694
  return this.filterBySinceLimit(positions, since, limit);
5634
5695
  }
5696
+ async setMarginMode(marginMode, symbol = undefined, params = {}) {
5697
+ /**
5698
+ * @method
5699
+ * @name mexc#setMarginMode
5700
+ * @description set margin mode to 'cross' or 'isolated'
5701
+ * @see https://mexcdevelop.github.io/apidocs/contract_v1_en/#switch-leverage
5702
+ * @param {string} marginMode 'cross' or 'isolated'
5703
+ * @param {string} [symbol] required when there is no position, else provide params["positionId"]
5704
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
5705
+ * @param {string} [params.positionId] required when a position is set
5706
+ * @param {string} [params.direction] "long" or "short" required when there is no position
5707
+ * @returns {object} response from the exchange
5708
+ */
5709
+ await this.loadMarkets();
5710
+ const market = this.market(symbol);
5711
+ if (market['spot']) {
5712
+ throw new BadSymbol(this.id + ' setMarginMode() supports contract markets only');
5713
+ }
5714
+ marginMode = marginMode.toLowerCase();
5715
+ if (marginMode !== 'isolated' && marginMode !== 'cross') {
5716
+ throw new BadRequest(this.id + ' setMarginMode() marginMode argument should be isolated or cross');
5717
+ }
5718
+ const leverage = this.safeInteger(params, 'leverage');
5719
+ if (leverage === undefined) {
5720
+ throw new ArgumentsRequired(this.id + ' setMarginMode() requires a leverage parameter');
5721
+ }
5722
+ const direction = this.safeStringLower2(params, 'direction', 'positionId');
5723
+ const request = {
5724
+ 'leverage': leverage,
5725
+ 'openType': (marginMode === 'isolated') ? 1 : 2,
5726
+ };
5727
+ if (symbol !== undefined) {
5728
+ request['symbol'] = market['id'];
5729
+ }
5730
+ if (direction !== undefined) {
5731
+ request['positionType'] = (direction === 'short') ? 2 : 1;
5732
+ }
5733
+ params = this.omit(params, 'direction');
5734
+ const response = await this.contractPrivatePostPositionChangeLeverage(this.extend(request, params));
5735
+ //
5736
+ // { success: true, code: '0' }
5737
+ //
5738
+ return this.parseLeverage(response, market);
5739
+ }
5740
+ nonce() {
5741
+ return this.milliseconds() - this.safeInteger(this.options, 'timeDifference', 0);
5742
+ }
5635
5743
  sign(path, api = 'public', method = 'GET', params = {}, headers = undefined, body = undefined) {
5636
5744
  const section = this.safeString(api, 0);
5637
5745
  const access = this.safeString(api, 1);
@@ -5646,7 +5754,7 @@ export default class mexc extends Exchange {
5646
5754
  }
5647
5755
  let paramsEncoded = '';
5648
5756
  if (access === 'private') {
5649
- params['timestamp'] = this.milliseconds();
5757
+ params['timestamp'] = this.nonce();
5650
5758
  params['recvWindow'] = this.safeInteger(this.options, 'recvWindow', 5000);
5651
5759
  }
5652
5760
  if (Object.keys(params).length) {
@@ -5676,7 +5784,7 @@ export default class mexc extends Exchange {
5676
5784
  }
5677
5785
  else {
5678
5786
  this.checkRequiredCredentials();
5679
- const timestamp = this.milliseconds().toString();
5787
+ const timestamp = this.nonce().toString();
5680
5788
  let auth = '';
5681
5789
  headers = {
5682
5790
  'ApiKey': this.apiKey,
@@ -14,6 +14,9 @@ export default class bitget extends bitgetRest {
14
14
  watchTickers(symbols?: Strings, params?: {}): Promise<Tickers>;
15
15
  handleTicker(client: Client, message: any): void;
16
16
  parseWsTicker(message: any, market?: any): Ticker;
17
+ watchBidsAsks(symbols?: Strings, params?: {}): Promise<Tickers>;
18
+ handleBidAsk(client: Client, message: any): void;
19
+ parseWsBidAsk(message: any, market?: any): Ticker;
17
20
  watchOHLCV(symbol: string, timeframe?: string, since?: Int, limit?: Int, params?: {}): Promise<OHLCV[]>;
18
21
  unWatchOHLCV(symbol: string, timeframe?: string, params?: {}): Promise<any>;
19
22
  handleOHLCV(client: Client, message: any): void;
@@ -37,6 +37,7 @@ export default class bitget extends bitgetRest {
37
37
  'watchOrders': true,
38
38
  'watchTicker': true,
39
39
  'watchTickers': true,
40
+ 'watchBidsAsks': true,
40
41
  'watchTrades': true,
41
42
  'watchTradesForSymbols': true,
42
43
  'watchPositions': true,
@@ -215,6 +216,7 @@ export default class bitget extends bitgetRest {
215
216
  // "ts": 1701842994341
216
217
  // }
217
218
  //
219
+ this.handleBidAsk(client, message);
218
220
  const ticker = this.parseWsTicker(message);
219
221
  const symbol = ticker['symbol'];
220
222
  this.tickers[symbol] = ticker;
@@ -326,6 +328,70 @@ export default class bitget extends bitgetRest {
326
328
  'info': ticker,
327
329
  }, market);
328
330
  }
331
+ async watchBidsAsks(symbols = undefined, params = {}) {
332
+ /**
333
+ * @method
334
+ * @name bitget#watchBidsAsks
335
+ * @see https://www.bitget.com/api-doc/spot/websocket/public/Tickers-Channel
336
+ * @see https://www.bitget.com/api-doc/contract/websocket/public/Tickers-Channel
337
+ * @description watches best bid & ask for symbols
338
+ * @param {string[]} symbols unified symbol of the market to fetch the ticker for
339
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
340
+ * @returns {object} a [ticker structure]{@link https://docs.ccxt.com/#/?id=ticker-structure}
341
+ */
342
+ await this.loadMarkets();
343
+ symbols = this.marketSymbols(symbols, undefined, false);
344
+ const market = this.market(symbols[0]);
345
+ let instType = undefined;
346
+ [instType, params] = this.getInstType(market, params);
347
+ const topics = [];
348
+ const messageHashes = [];
349
+ for (let i = 0; i < symbols.length; i++) {
350
+ const symbol = symbols[i];
351
+ const marketInner = this.market(symbol);
352
+ const args = {
353
+ 'instType': instType,
354
+ 'channel': 'ticker',
355
+ 'instId': marketInner['id'],
356
+ };
357
+ topics.push(args);
358
+ messageHashes.push('bidask:' + symbol);
359
+ }
360
+ const tickers = await this.watchPublicMultiple(messageHashes, topics, params);
361
+ if (this.newUpdates) {
362
+ const result = {};
363
+ result[tickers['symbol']] = tickers;
364
+ return result;
365
+ }
366
+ return this.filterByArray(this.bidsasks, 'symbol', symbols);
367
+ }
368
+ handleBidAsk(client, message) {
369
+ const ticker = this.parseWsBidAsk(message);
370
+ const symbol = ticker['symbol'];
371
+ this.bidsasks[symbol] = ticker;
372
+ const messageHash = 'bidask:' + symbol;
373
+ client.resolve(ticker, messageHash);
374
+ }
375
+ parseWsBidAsk(message, market = undefined) {
376
+ const arg = this.safeValue(message, 'arg', {});
377
+ const data = this.safeValue(message, 'data', []);
378
+ const ticker = this.safeValue(data, 0, {});
379
+ const timestamp = this.safeInteger(ticker, 'ts');
380
+ const instType = this.safeString(arg, 'instType');
381
+ const marketType = (instType === 'SPOT') ? 'spot' : 'contract';
382
+ const marketId = this.safeString(ticker, 'instId');
383
+ market = this.safeMarket(marketId, market, undefined, marketType);
384
+ return this.safeTicker({
385
+ 'symbol': market['symbol'],
386
+ 'timestamp': timestamp,
387
+ 'datetime': this.iso8601(timestamp),
388
+ 'ask': this.safeString(ticker, 'askPr'),
389
+ 'askVolume': this.safeString(ticker, 'askSz'),
390
+ 'bid': this.safeString(ticker, 'bidPr'),
391
+ 'bidVolume': this.safeString(ticker, 'bidSz'),
392
+ 'info': ticker,
393
+ }, market);
394
+ }
329
395
  async watchOHLCV(symbol, timeframe = '1m', since = undefined, limit = undefined, params = {}) {
330
396
  /**
331
397
  * @method