ccxt 4.0.110 → 4.0.111

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
@@ -179,7 +179,7 @@ var woo$1 = require('./src/pro/woo.js');
179
179
 
180
180
  //-----------------------------------------------------------------------------
181
181
  // this is updated by vss.js when building
182
- const version = '4.0.110';
182
+ const version = '4.0.111';
183
183
  Exchange["default"].ccxtVersion = version;
184
184
  const exchanges = {
185
185
  'ace': ace,
@@ -69,7 +69,7 @@ class binance extends binance$1 {
69
69
  'fetchFundingRateHistory': true,
70
70
  'fetchFundingRates': true,
71
71
  'fetchIndexOHLCV': true,
72
- 'fetchL3OrderBook': undefined,
72
+ 'fetchL3OrderBook': false,
73
73
  'fetchLastPrices': true,
74
74
  'fetchLedger': true,
75
75
  'fetchLeverage': false,
@@ -108,6 +108,7 @@ class binance extends binance$1 {
108
108
  'fetchTransfers': true,
109
109
  'fetchUnderlyingAssets': false,
110
110
  'fetchVolatilityHistory': false,
111
+ 'fetchWithdrawAddresses': false,
111
112
  'fetchWithdrawal': false,
112
113
  'fetchWithdrawals': true,
113
114
  'fetchWithdrawalWhitelist': false,
@@ -1312,7 +1312,7 @@ class bitmart extends bitmart$1 {
1312
1312
  // "type": "buy"
1313
1313
  // }
1314
1314
  //
1315
- // private fetchMyTrades spot
1315
+ // spot: fetchMyTrades
1316
1316
  //
1317
1317
  // {
1318
1318
  // "tradeId":"182342999769370687",
@@ -1331,28 +1331,42 @@ class bitmart extends bitmart$1 {
1331
1331
  // "createTime":1695658457836,
1332
1332
  // }
1333
1333
  //
1334
- const id = this.safeString(trade, 'tradeId');
1335
- const timestamp = this.safeInteger2(trade, 'order_time', 'createTime');
1336
- const side = this.safeStringLower2(trade, 'side', 'type');
1337
- const takerOrMaker = this.safeString(trade, 'tradeRole');
1334
+ // swap: fetchMyTrades
1335
+ //
1336
+ // {
1337
+ // "order_id": "230930336848609",
1338
+ // "trade_id": "6212604014",
1339
+ // "symbol": "BTCUSDT",
1340
+ // "side": 3,
1341
+ // "price": "26910.4",
1342
+ // "vol": "1",
1343
+ // "exec_type": "Taker",
1344
+ // "profit": false,
1345
+ // "create_time": 1695961596692,
1346
+ // "realised_profit": "-0.0003",
1347
+ // "paid_fees": "0.01614624"
1348
+ // }
1349
+ //
1350
+ const timestamp = this.safeIntegerN(trade, ['order_time', 'createTime', 'create_time']);
1338
1351
  const isPublicTrade = ('order_time' in trade);
1339
- const price = this.safeString(trade, 'price');
1340
1352
  let amount = undefined;
1341
1353
  let cost = undefined;
1342
1354
  let type = undefined;
1355
+ let side = undefined;
1343
1356
  if (isPublicTrade) {
1344
1357
  amount = this.safeString(trade, 'count');
1345
1358
  cost = this.safeString(trade, 'amount');
1359
+ side = this.safeString(trade, 'type');
1346
1360
  }
1347
1361
  else {
1348
- amount = this.safeString(trade, 'size');
1362
+ amount = this.safeString2(trade, 'size', 'vol');
1349
1363
  cost = this.safeString(trade, 'notional');
1350
1364
  type = this.safeString(trade, 'type');
1365
+ side = this.parseOrderSide(this.safeString(trade, 'side'));
1351
1366
  }
1352
- const orderId = this.safeString(trade, 'orderId');
1353
1367
  const marketId = this.safeString(trade, 'symbol');
1354
- market = this.safeMarket(marketId, market, '_');
1355
- const feeCostString = this.safeString(trade, 'fee');
1368
+ market = this.safeMarket(marketId, market);
1369
+ const feeCostString = this.safeString2(trade, 'fee', 'paid_fees');
1356
1370
  let fee = undefined;
1357
1371
  if (feeCostString !== undefined) {
1358
1372
  const feeCurrencyId = this.safeString(trade, 'feeCoinName');
@@ -1367,17 +1381,17 @@ class bitmart extends bitmart$1 {
1367
1381
  }
1368
1382
  return this.safeTrade({
1369
1383
  'info': trade,
1370
- 'id': id,
1371
- 'order': orderId,
1384
+ 'id': this.safeString2(trade, 'tradeId', 'trade_id'),
1385
+ 'order': this.safeString2(trade, 'orderId', 'order_id'),
1372
1386
  'timestamp': timestamp,
1373
1387
  'datetime': this.iso8601(timestamp),
1374
1388
  'symbol': market['symbol'],
1375
1389
  'type': type,
1376
1390
  'side': side,
1377
- 'price': price,
1391
+ 'price': this.safeString(trade, 'price'),
1378
1392
  'amount': amount,
1379
1393
  'cost': cost,
1380
- 'takerOrMaker': takerOrMaker,
1394
+ 'takerOrMaker': this.safeStringLower2(trade, 'tradeRole', 'exec_type'),
1381
1395
  'fee': fee,
1382
1396
  }, market);
1383
1397
  }
@@ -1580,6 +1594,7 @@ class bitmart extends bitmart$1 {
1580
1594
  * @method
1581
1595
  * @name bitmart#fetchMyTrades
1582
1596
  * @see https://developer-pro.bitmart.com/en/spot/#account-trade-list-v4-signed
1597
+ * @see https://developer-pro.bitmart.com/en/futures/#get-order-trade-keyed
1583
1598
  * @description fetch all trades made by the user
1584
1599
  * @param {string} symbol unified market symbol
1585
1600
  * @param {int} [since] the earliest time in ms to fetch trades for
@@ -1594,32 +1609,46 @@ class bitmart extends bitmart$1 {
1594
1609
  const request = {};
1595
1610
  if (symbol !== undefined) {
1596
1611
  market = this.market(symbol);
1612
+ request['symbol'] = market['id'];
1597
1613
  }
1598
1614
  let type = undefined;
1615
+ let response = undefined;
1599
1616
  [type, params] = this.handleMarketTypeAndParams('fetchMyTrades', market, params);
1600
- if (type !== 'spot') {
1601
- throw new errors.NotSupported(this.id + ' fetchMyTrades() does not support ' + type + ' orders, only spot orders are accepted');
1602
- }
1603
- let marginMode = undefined;
1604
- [marginMode, params] = this.handleMarginModeAndParams('fetchMyTrades', params);
1605
- if (marginMode === 'isolated') {
1606
- request['orderMode'] = 'iso_margin';
1607
- }
1608
- const options = this.safeValue(this.options, 'fetchMyTrades', {});
1609
- const defaultLimit = this.safeInteger(options, 'limit', 200);
1610
- if (limit === undefined) {
1611
- limit = defaultLimit;
1617
+ const until = this.safeIntegerN(params, ['until', 'endTime', 'end_time']);
1618
+ params = this.omit(params, ['until']);
1619
+ if (type === 'spot') {
1620
+ let marginMode = undefined;
1621
+ [marginMode, params] = this.handleMarginModeAndParams('fetchMyTrades', params);
1622
+ if (marginMode === 'isolated') {
1623
+ request['orderMode'] = 'iso_margin';
1624
+ }
1625
+ const options = this.safeValue(this.options, 'fetchMyTrades', {});
1626
+ const defaultLimit = this.safeInteger(options, 'limit', 200);
1627
+ if (limit === undefined) {
1628
+ limit = defaultLimit;
1629
+ }
1630
+ request['limit'] = limit;
1631
+ if (since !== undefined) {
1632
+ request['startTime'] = since;
1633
+ }
1634
+ if (until !== undefined) {
1635
+ request['endTime'] = until;
1636
+ }
1637
+ response = await this.privatePostSpotV4QueryTrades(this.extend(request, params));
1612
1638
  }
1613
- request['limit'] = limit;
1614
- if (symbol !== undefined) {
1615
- request['symbol'] = market['id'];
1639
+ else if (type === 'swap') {
1640
+ this.checkRequiredSymbol('fetchMyTrades', symbol);
1641
+ if (since !== undefined) {
1642
+ request['start_time'] = since;
1643
+ }
1644
+ if (until !== undefined) {
1645
+ request['end_time'] = until;
1646
+ }
1647
+ response = await this.privateGetContractPrivateTrades(this.extend(request, params));
1616
1648
  }
1617
- const until = this.safeInteger2(params, 'until', 'endTime');
1618
- if (until !== undefined) {
1619
- params = this.omit(params, ['endTime']);
1620
- request['endTime'] = until;
1649
+ else {
1650
+ throw new errors.NotSupported(this.id + ' fetchMyTrades() does not support ' + type + ' orders, only spot and swap orders are accepted');
1621
1651
  }
1622
- const response = await this.privatePostSpotV4QueryTrades(this.extend(request, params));
1623
1652
  //
1624
1653
  // spot
1625
1654
  //
@@ -1648,7 +1677,30 @@ class bitmart extends bitmart$1 {
1648
1677
  // "trace":"fbaee9e0e2f5442fba5b3262fc86b0ac.65.16956593456523085"
1649
1678
  // }
1650
1679
  //
1651
- const data = this.safeValue(response, 'data', {});
1680
+ // swap
1681
+ //
1682
+ // {
1683
+ // "code": 1000,
1684
+ // "message": "Ok",
1685
+ // "data": [
1686
+ // {
1687
+ // "order_id": "230930336848609",
1688
+ // "trade_id": "6212604014",
1689
+ // "symbol": "BTCUSDT",
1690
+ // "side": 3,
1691
+ // "price": "26910.4",
1692
+ // "vol": "1",
1693
+ // "exec_type": "Taker",
1694
+ // "profit": false,
1695
+ // "create_time": 1695961596692,
1696
+ // "realised_profit": "-0.0003",
1697
+ // "paid_fees": "0.01614624"
1698
+ // },
1699
+ // ],
1700
+ // "trace": "4cad855074634097ac6ba5257c47305d.62.16959616054873723"
1701
+ // }
1702
+ //
1703
+ const data = this.safeValue(response, 'data', []);
1652
1704
  return this.parseTrades(data, market, since, limit);
1653
1705
  }
1654
1706
  async fetchOrderTrades(id, symbol = undefined, since = undefined, limit = undefined, params = {}) {
@@ -2017,10 +2069,10 @@ class bitmart extends bitmart$1 {
2017
2069
  }
2018
2070
  parseOrderSide(side) {
2019
2071
  const sides = {
2020
- '1': 'open long',
2021
- '2': 'close short',
2022
- '3': 'close long',
2023
- '4': 'open short',
2072
+ '1': 'buy',
2073
+ '2': 'buy',
2074
+ '3': 'sell',
2075
+ '4': 'sell',
2024
2076
  };
2025
2077
  return this.safeString(sides, side, side);
2026
2078
  }
@@ -2159,25 +2211,47 @@ class bitmart extends bitmart$1 {
2159
2211
  /**
2160
2212
  * @method
2161
2213
  * @name bitmart#cancelOrder
2214
+ * @see https://developer-pro.bitmart.com/en/futures/#cancel-order-signed
2215
+ * @see https://developer-pro.bitmart.com/en/spot/#cancel-order-v3-signed
2216
+ * @see https://developer-pro.bitmart.com/en/futures/#cancel-plan-order-signed
2162
2217
  * @description cancels an open order
2163
2218
  * @param {string} id order id
2164
2219
  * @param {string} symbol unified symbol of the market the order was made in
2165
2220
  * @param {object} [params] extra parameters specific to the bitmart api endpoint
2221
+ * @param {string} [params.clientOrderId] *spot only* the client order id of the order to cancel
2222
+ * @param {boolean} [params.stop] *swap only* whether the order is a stop order
2166
2223
  * @returns {object} An [order structure]{@link https://github.com/ccxt/ccxt/wiki/Manual#order-structure}
2167
2224
  */
2168
- if (symbol === undefined) {
2169
- throw new errors.ArgumentsRequired(this.id + ' cancelOrder() requires a symbol argument');
2170
- }
2225
+ this.checkRequiredSymbol('cancelOrder', symbol);
2171
2226
  await this.loadMarkets();
2172
2227
  const market = this.market(symbol);
2173
- if (!market['spot']) {
2174
- throw new errors.NotSupported(this.id + ' cancelOrder() does not support ' + market['type'] + ' orders, only spot orders are accepted');
2175
- }
2176
2228
  const request = {
2177
- 'order_id': id.toString(),
2178
2229
  'symbol': market['id'],
2179
2230
  };
2180
- const response = await this.privatePostSpotV3CancelOrder(this.extend(request, params));
2231
+ const clientOrderId = this.safeString2(params, 'clientOrderId', 'client_order_id');
2232
+ if (clientOrderId !== undefined) {
2233
+ request['client_order_id'] = clientOrderId;
2234
+ }
2235
+ else {
2236
+ request['order_id'] = id.toString();
2237
+ }
2238
+ params = this.omit(params, ['clientOrderId']);
2239
+ let response = undefined;
2240
+ if (market['spot']) {
2241
+ response = await this.privatePostSpotV3CancelOrder(this.extend(request, params));
2242
+ }
2243
+ else {
2244
+ const stop = this.safeValue(params, 'stop');
2245
+ params = this.omit(params, ['stop']);
2246
+ if (!stop) {
2247
+ response = await this.privatePostContractPrivateCancelOrder(this.extend(request, params));
2248
+ }
2249
+ else {
2250
+ response = await this.privatePostContractPrivateCancelPlanOrder(this.extend(request, params));
2251
+ }
2252
+ }
2253
+ // swap
2254
+ // {"code":1000,"message":"Ok","trace":"7f9c94e10f9d4513bc08a7bfc2a5559a.55.16959817848001851"}
2181
2255
  //
2182
2256
  // spot
2183
2257
  //
@@ -2199,6 +2273,9 @@ class bitmart extends bitmart$1 {
2199
2273
  // "data": true
2200
2274
  // }
2201
2275
  //
2276
+ if (market['swap']) {
2277
+ return response;
2278
+ }
2202
2279
  const data = this.safeValue(response, 'data');
2203
2280
  if (data === true) {
2204
2281
  return this.parseOrder(id, market);
@@ -245,6 +245,7 @@ class bybit extends bybit$1 {
245
245
  'v5/market/insurance': 2.5,
246
246
  'v5/market/risk-limit': 2.5,
247
247
  'v5/market/delivery-price': 2.5,
248
+ 'v5/market/account-ratio': 2.5,
248
249
  // spot leverage token
249
250
  'v5/spot-lever-token/info': 2.5,
250
251
  'v5/spot-lever-token/reference': 2.5,
@@ -646,6 +647,7 @@ class bybit extends bybit$1 {
646
647
  // c2c lending
647
648
  'v5/lending/purchase': 2.5,
648
649
  'v5/lending/redeem': 2.5,
650
+ 'v5/lending/redeem-cancel': 2.5,
649
651
  },
650
652
  'delete': {
651
653
  // spot
package/js/ccxt.d.ts CHANGED
@@ -4,7 +4,7 @@ import * as functions from './src/base/functions.js';
4
4
  import * as errors from './src/base/errors.js';
5
5
  import { Market, Trade, Fee, Ticker, OrderBook, Order, Transaction, Tickers, Currency, Balance, DepositAddress, WithdrawalResponse, DepositAddressResponse, OHLCV, Balances, PartialBalances, Dictionary, MinMax, Position } from './src/base/types.js';
6
6
  import { BaseError, ExchangeError, PermissionDenied, AccountNotEnabled, AccountSuspended, ArgumentsRequired, BadRequest, BadSymbol, MarginModeAlreadySet, BadResponse, NullResponse, InsufficientFunds, InvalidAddress, InvalidOrder, OrderNotFound, OrderNotCached, CancelPending, OrderImmediatelyFillable, OrderNotFillable, DuplicateOrderId, NotSupported, NetworkError, DDoSProtection, RateLimitExceeded, ExchangeNotAvailable, OnMaintenance, InvalidNonce, RequestTimeout, AuthenticationError, AddressPending, NoChange } from './src/base/errors.js';
7
- declare const version = "4.0.109";
7
+ declare const version = "4.0.110";
8
8
  import ace from './src/ace.js';
9
9
  import alpaca from './src/alpaca.js';
10
10
  import ascendex from './src/ascendex.js';
package/js/ccxt.js CHANGED
@@ -38,7 +38,7 @@ import * as errors from './src/base/errors.js';
38
38
  import { BaseError, ExchangeError, PermissionDenied, AccountNotEnabled, AccountSuspended, ArgumentsRequired, BadRequest, BadSymbol, MarginModeAlreadySet, BadResponse, NullResponse, InsufficientFunds, InvalidAddress, InvalidOrder, OrderNotFound, OrderNotCached, CancelPending, OrderImmediatelyFillable, OrderNotFillable, DuplicateOrderId, NotSupported, NetworkError, DDoSProtection, RateLimitExceeded, ExchangeNotAvailable, OnMaintenance, InvalidNonce, RequestTimeout, AuthenticationError, AddressPending, NoChange } from './src/base/errors.js';
39
39
  //-----------------------------------------------------------------------------
40
40
  // this is updated by vss.js when building
41
- const version = '4.0.110';
41
+ const version = '4.0.111';
42
42
  Exchange.ccxtVersion = version;
43
43
  //-----------------------------------------------------------------------------
44
44
  import ace from './src/ace.js';
@@ -96,6 +96,7 @@ interface Exchange {
96
96
  publicGetV5MarketInsurance(params?: {}): Promise<implicitReturnType>;
97
97
  publicGetV5MarketRiskLimit(params?: {}): Promise<implicitReturnType>;
98
98
  publicGetV5MarketDeliveryPrice(params?: {}): Promise<implicitReturnType>;
99
+ publicGetV5MarketAccountRatio(params?: {}): Promise<implicitReturnType>;
99
100
  publicGetV5SpotLeverTokenInfo(params?: {}): Promise<implicitReturnType>;
100
101
  publicGetV5SpotLeverTokenReference(params?: {}): Promise<implicitReturnType>;
101
102
  publicGetV5SpotMarginTradeData(params?: {}): Promise<implicitReturnType>;
@@ -451,6 +452,7 @@ interface Exchange {
451
452
  privatePostV5SpotCrossMarginTradeSwitch(params?: {}): Promise<implicitReturnType>;
452
453
  privatePostV5LendingPurchase(params?: {}): Promise<implicitReturnType>;
453
454
  privatePostV5LendingRedeem(params?: {}): Promise<implicitReturnType>;
455
+ privatePostV5LendingRedeemCancel(params?: {}): Promise<implicitReturnType>;
454
456
  privateDeleteSpotV1Order(params?: {}): Promise<implicitReturnType>;
455
457
  privateDeleteSpotV1OrderFast(params?: {}): Promise<implicitReturnType>;
456
458
  privateDeleteSpotOrderBatchCancel(params?: {}): Promise<implicitReturnType>;
package/js/src/binance.js CHANGED
@@ -72,7 +72,7 @@ export default class binance extends Exchange {
72
72
  'fetchFundingRateHistory': true,
73
73
  'fetchFundingRates': true,
74
74
  'fetchIndexOHLCV': true,
75
- 'fetchL3OrderBook': undefined,
75
+ 'fetchL3OrderBook': false,
76
76
  'fetchLastPrices': true,
77
77
  'fetchLedger': true,
78
78
  'fetchLeverage': false,
@@ -111,6 +111,7 @@ export default class binance extends Exchange {
111
111
  'fetchTransfers': true,
112
112
  'fetchUnderlyingAssets': false,
113
113
  'fetchVolatilityHistory': false,
114
+ 'fetchWithdrawAddresses': false,
114
115
  'fetchWithdrawal': false,
115
116
  'fetchWithdrawals': true,
116
117
  'fetchWithdrawalWhitelist': false,
package/js/src/bitmart.js CHANGED
@@ -1315,7 +1315,7 @@ export default class bitmart extends Exchange {
1315
1315
  // "type": "buy"
1316
1316
  // }
1317
1317
  //
1318
- // private fetchMyTrades spot
1318
+ // spot: fetchMyTrades
1319
1319
  //
1320
1320
  // {
1321
1321
  // "tradeId":"182342999769370687",
@@ -1334,28 +1334,42 @@ export default class bitmart extends Exchange {
1334
1334
  // "createTime":1695658457836,
1335
1335
  // }
1336
1336
  //
1337
- const id = this.safeString(trade, 'tradeId');
1338
- const timestamp = this.safeInteger2(trade, 'order_time', 'createTime');
1339
- const side = this.safeStringLower2(trade, 'side', 'type');
1340
- const takerOrMaker = this.safeString(trade, 'tradeRole');
1337
+ // swap: fetchMyTrades
1338
+ //
1339
+ // {
1340
+ // "order_id": "230930336848609",
1341
+ // "trade_id": "6212604014",
1342
+ // "symbol": "BTCUSDT",
1343
+ // "side": 3,
1344
+ // "price": "26910.4",
1345
+ // "vol": "1",
1346
+ // "exec_type": "Taker",
1347
+ // "profit": false,
1348
+ // "create_time": 1695961596692,
1349
+ // "realised_profit": "-0.0003",
1350
+ // "paid_fees": "0.01614624"
1351
+ // }
1352
+ //
1353
+ const timestamp = this.safeIntegerN(trade, ['order_time', 'createTime', 'create_time']);
1341
1354
  const isPublicTrade = ('order_time' in trade);
1342
- const price = this.safeString(trade, 'price');
1343
1355
  let amount = undefined;
1344
1356
  let cost = undefined;
1345
1357
  let type = undefined;
1358
+ let side = undefined;
1346
1359
  if (isPublicTrade) {
1347
1360
  amount = this.safeString(trade, 'count');
1348
1361
  cost = this.safeString(trade, 'amount');
1362
+ side = this.safeString(trade, 'type');
1349
1363
  }
1350
1364
  else {
1351
- amount = this.safeString(trade, 'size');
1365
+ amount = this.safeString2(trade, 'size', 'vol');
1352
1366
  cost = this.safeString(trade, 'notional');
1353
1367
  type = this.safeString(trade, 'type');
1368
+ side = this.parseOrderSide(this.safeString(trade, 'side'));
1354
1369
  }
1355
- const orderId = this.safeString(trade, 'orderId');
1356
1370
  const marketId = this.safeString(trade, 'symbol');
1357
- market = this.safeMarket(marketId, market, '_');
1358
- const feeCostString = this.safeString(trade, 'fee');
1371
+ market = this.safeMarket(marketId, market);
1372
+ const feeCostString = this.safeString2(trade, 'fee', 'paid_fees');
1359
1373
  let fee = undefined;
1360
1374
  if (feeCostString !== undefined) {
1361
1375
  const feeCurrencyId = this.safeString(trade, 'feeCoinName');
@@ -1370,17 +1384,17 @@ export default class bitmart extends Exchange {
1370
1384
  }
1371
1385
  return this.safeTrade({
1372
1386
  'info': trade,
1373
- 'id': id,
1374
- 'order': orderId,
1387
+ 'id': this.safeString2(trade, 'tradeId', 'trade_id'),
1388
+ 'order': this.safeString2(trade, 'orderId', 'order_id'),
1375
1389
  'timestamp': timestamp,
1376
1390
  'datetime': this.iso8601(timestamp),
1377
1391
  'symbol': market['symbol'],
1378
1392
  'type': type,
1379
1393
  'side': side,
1380
- 'price': price,
1394
+ 'price': this.safeString(trade, 'price'),
1381
1395
  'amount': amount,
1382
1396
  'cost': cost,
1383
- 'takerOrMaker': takerOrMaker,
1397
+ 'takerOrMaker': this.safeStringLower2(trade, 'tradeRole', 'exec_type'),
1384
1398
  'fee': fee,
1385
1399
  }, market);
1386
1400
  }
@@ -1583,6 +1597,7 @@ export default class bitmart extends Exchange {
1583
1597
  * @method
1584
1598
  * @name bitmart#fetchMyTrades
1585
1599
  * @see https://developer-pro.bitmart.com/en/spot/#account-trade-list-v4-signed
1600
+ * @see https://developer-pro.bitmart.com/en/futures/#get-order-trade-keyed
1586
1601
  * @description fetch all trades made by the user
1587
1602
  * @param {string} symbol unified market symbol
1588
1603
  * @param {int} [since] the earliest time in ms to fetch trades for
@@ -1597,32 +1612,46 @@ export default class bitmart extends Exchange {
1597
1612
  const request = {};
1598
1613
  if (symbol !== undefined) {
1599
1614
  market = this.market(symbol);
1615
+ request['symbol'] = market['id'];
1600
1616
  }
1601
1617
  let type = undefined;
1618
+ let response = undefined;
1602
1619
  [type, params] = this.handleMarketTypeAndParams('fetchMyTrades', market, params);
1603
- if (type !== 'spot') {
1604
- throw new NotSupported(this.id + ' fetchMyTrades() does not support ' + type + ' orders, only spot orders are accepted');
1605
- }
1606
- let marginMode = undefined;
1607
- [marginMode, params] = this.handleMarginModeAndParams('fetchMyTrades', params);
1608
- if (marginMode === 'isolated') {
1609
- request['orderMode'] = 'iso_margin';
1610
- }
1611
- const options = this.safeValue(this.options, 'fetchMyTrades', {});
1612
- const defaultLimit = this.safeInteger(options, 'limit', 200);
1613
- if (limit === undefined) {
1614
- limit = defaultLimit;
1620
+ const until = this.safeIntegerN(params, ['until', 'endTime', 'end_time']);
1621
+ params = this.omit(params, ['until']);
1622
+ if (type === 'spot') {
1623
+ let marginMode = undefined;
1624
+ [marginMode, params] = this.handleMarginModeAndParams('fetchMyTrades', params);
1625
+ if (marginMode === 'isolated') {
1626
+ request['orderMode'] = 'iso_margin';
1627
+ }
1628
+ const options = this.safeValue(this.options, 'fetchMyTrades', {});
1629
+ const defaultLimit = this.safeInteger(options, 'limit', 200);
1630
+ if (limit === undefined) {
1631
+ limit = defaultLimit;
1632
+ }
1633
+ request['limit'] = limit;
1634
+ if (since !== undefined) {
1635
+ request['startTime'] = since;
1636
+ }
1637
+ if (until !== undefined) {
1638
+ request['endTime'] = until;
1639
+ }
1640
+ response = await this.privatePostSpotV4QueryTrades(this.extend(request, params));
1615
1641
  }
1616
- request['limit'] = limit;
1617
- if (symbol !== undefined) {
1618
- request['symbol'] = market['id'];
1642
+ else if (type === 'swap') {
1643
+ this.checkRequiredSymbol('fetchMyTrades', symbol);
1644
+ if (since !== undefined) {
1645
+ request['start_time'] = since;
1646
+ }
1647
+ if (until !== undefined) {
1648
+ request['end_time'] = until;
1649
+ }
1650
+ response = await this.privateGetContractPrivateTrades(this.extend(request, params));
1619
1651
  }
1620
- const until = this.safeInteger2(params, 'until', 'endTime');
1621
- if (until !== undefined) {
1622
- params = this.omit(params, ['endTime']);
1623
- request['endTime'] = until;
1652
+ else {
1653
+ throw new NotSupported(this.id + ' fetchMyTrades() does not support ' + type + ' orders, only spot and swap orders are accepted');
1624
1654
  }
1625
- const response = await this.privatePostSpotV4QueryTrades(this.extend(request, params));
1626
1655
  //
1627
1656
  // spot
1628
1657
  //
@@ -1651,7 +1680,30 @@ export default class bitmart extends Exchange {
1651
1680
  // "trace":"fbaee9e0e2f5442fba5b3262fc86b0ac.65.16956593456523085"
1652
1681
  // }
1653
1682
  //
1654
- const data = this.safeValue(response, 'data', {});
1683
+ // swap
1684
+ //
1685
+ // {
1686
+ // "code": 1000,
1687
+ // "message": "Ok",
1688
+ // "data": [
1689
+ // {
1690
+ // "order_id": "230930336848609",
1691
+ // "trade_id": "6212604014",
1692
+ // "symbol": "BTCUSDT",
1693
+ // "side": 3,
1694
+ // "price": "26910.4",
1695
+ // "vol": "1",
1696
+ // "exec_type": "Taker",
1697
+ // "profit": false,
1698
+ // "create_time": 1695961596692,
1699
+ // "realised_profit": "-0.0003",
1700
+ // "paid_fees": "0.01614624"
1701
+ // },
1702
+ // ],
1703
+ // "trace": "4cad855074634097ac6ba5257c47305d.62.16959616054873723"
1704
+ // }
1705
+ //
1706
+ const data = this.safeValue(response, 'data', []);
1655
1707
  return this.parseTrades(data, market, since, limit);
1656
1708
  }
1657
1709
  async fetchOrderTrades(id, symbol = undefined, since = undefined, limit = undefined, params = {}) {
@@ -2020,10 +2072,10 @@ export default class bitmart extends Exchange {
2020
2072
  }
2021
2073
  parseOrderSide(side) {
2022
2074
  const sides = {
2023
- '1': 'open long',
2024
- '2': 'close short',
2025
- '3': 'close long',
2026
- '4': 'open short',
2075
+ '1': 'buy',
2076
+ '2': 'buy',
2077
+ '3': 'sell',
2078
+ '4': 'sell',
2027
2079
  };
2028
2080
  return this.safeString(sides, side, side);
2029
2081
  }
@@ -2162,25 +2214,47 @@ export default class bitmart extends Exchange {
2162
2214
  /**
2163
2215
  * @method
2164
2216
  * @name bitmart#cancelOrder
2217
+ * @see https://developer-pro.bitmart.com/en/futures/#cancel-order-signed
2218
+ * @see https://developer-pro.bitmart.com/en/spot/#cancel-order-v3-signed
2219
+ * @see https://developer-pro.bitmart.com/en/futures/#cancel-plan-order-signed
2165
2220
  * @description cancels an open order
2166
2221
  * @param {string} id order id
2167
2222
  * @param {string} symbol unified symbol of the market the order was made in
2168
2223
  * @param {object} [params] extra parameters specific to the bitmart api endpoint
2224
+ * @param {string} [params.clientOrderId] *spot only* the client order id of the order to cancel
2225
+ * @param {boolean} [params.stop] *swap only* whether the order is a stop order
2169
2226
  * @returns {object} An [order structure]{@link https://github.com/ccxt/ccxt/wiki/Manual#order-structure}
2170
2227
  */
2171
- if (symbol === undefined) {
2172
- throw new ArgumentsRequired(this.id + ' cancelOrder() requires a symbol argument');
2173
- }
2228
+ this.checkRequiredSymbol('cancelOrder', symbol);
2174
2229
  await this.loadMarkets();
2175
2230
  const market = this.market(symbol);
2176
- if (!market['spot']) {
2177
- throw new NotSupported(this.id + ' cancelOrder() does not support ' + market['type'] + ' orders, only spot orders are accepted');
2178
- }
2179
2231
  const request = {
2180
- 'order_id': id.toString(),
2181
2232
  'symbol': market['id'],
2182
2233
  };
2183
- const response = await this.privatePostSpotV3CancelOrder(this.extend(request, params));
2234
+ const clientOrderId = this.safeString2(params, 'clientOrderId', 'client_order_id');
2235
+ if (clientOrderId !== undefined) {
2236
+ request['client_order_id'] = clientOrderId;
2237
+ }
2238
+ else {
2239
+ request['order_id'] = id.toString();
2240
+ }
2241
+ params = this.omit(params, ['clientOrderId']);
2242
+ let response = undefined;
2243
+ if (market['spot']) {
2244
+ response = await this.privatePostSpotV3CancelOrder(this.extend(request, params));
2245
+ }
2246
+ else {
2247
+ const stop = this.safeValue(params, 'stop');
2248
+ params = this.omit(params, ['stop']);
2249
+ if (!stop) {
2250
+ response = await this.privatePostContractPrivateCancelOrder(this.extend(request, params));
2251
+ }
2252
+ else {
2253
+ response = await this.privatePostContractPrivateCancelPlanOrder(this.extend(request, params));
2254
+ }
2255
+ }
2256
+ // swap
2257
+ // {"code":1000,"message":"Ok","trace":"7f9c94e10f9d4513bc08a7bfc2a5559a.55.16959817848001851"}
2184
2258
  //
2185
2259
  // spot
2186
2260
  //
@@ -2202,6 +2276,9 @@ export default class bitmart extends Exchange {
2202
2276
  // "data": true
2203
2277
  // }
2204
2278
  //
2279
+ if (market['swap']) {
2280
+ return response;
2281
+ }
2205
2282
  const data = this.safeValue(response, 'data');
2206
2283
  if (data === true) {
2207
2284
  return this.parseOrder(id, market);