ccxt 4.2.4 → 4.2.6

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.
@@ -2835,10 +2835,16 @@ class alpaca extends _abstract_alpaca_js__WEBPACK_IMPORTED_MODULE_0__/* ["defaul
2835
2835
  //
2836
2836
  const marketId = this.safeString(asset, 'symbol');
2837
2837
  const parts = marketId.split('/');
2838
+ const assetClass = this.safeString(asset, 'class');
2838
2839
  const baseId = this.safeString(parts, 0);
2839
2840
  const quoteId = this.safeString(parts, 1);
2840
2841
  const base = this.safeCurrencyCode(baseId);
2841
- const quote = this.safeCurrencyCode(quoteId);
2842
+ let quote = this.safeCurrencyCode(quoteId);
2843
+ // Us equity markets do not include quote in symbol.
2844
+ // We can safely coerce us_equity quote to USD
2845
+ if (quote === undefined && assetClass === 'us_equity') {
2846
+ quote = 'USD';
2847
+ }
2842
2848
  const symbol = base + '/' + quote;
2843
2849
  const status = this.safeString(asset, 'status');
2844
2850
  const active = (status === 'active');
@@ -8214,10 +8220,15 @@ class Exchange {
8214
8220
  const closedClients = [];
8215
8221
  for (let i = 0; i < clients.length; i++) {
8216
8222
  const client = clients[i];
8217
- delete this.clients[client.url];
8223
+ client.error = new _errors_js__WEBPACK_IMPORTED_MODULE_3__.ExchangeClosedByUser(this.id + ' closedByUser');
8218
8224
  closedClients.push(client.close());
8219
8225
  }
8220
- return Promise.all(closedClients);
8226
+ await Promise.all(closedClients);
8227
+ for (let i = 0; i < clients.length; i++) {
8228
+ const client = clients[i];
8229
+ delete this.clients[client.url];
8230
+ }
8231
+ return;
8221
8232
  }
8222
8233
  async loadOrderBook(client, messageHash, symbol, limit = undefined, params = {}) {
8223
8234
  if (!(symbol in this.orderbooks)) {
@@ -12244,6 +12255,7 @@ __webpack_require__.r(__webpack_exports__);
12244
12255
  /* harmony export */ ContractUnavailable: () => (/* binding */ ContractUnavailable),
12245
12256
  /* harmony export */ DDoSProtection: () => (/* binding */ DDoSProtection),
12246
12257
  /* harmony export */ DuplicateOrderId: () => (/* binding */ DuplicateOrderId),
12258
+ /* harmony export */ ExchangeClosedByUser: () => (/* binding */ ExchangeClosedByUser),
12247
12259
  /* harmony export */ ExchangeError: () => (/* binding */ ExchangeError),
12248
12260
  /* harmony export */ ExchangeNotAvailable: () => (/* binding */ ExchangeNotAvailable),
12249
12261
  /* harmony export */ InsufficientFunds: () => (/* binding */ InsufficientFunds),
@@ -12312,6 +12324,12 @@ class ExchangeError extends Error {
12312
12324
  this.name = 'ExchangeError';
12313
12325
  }
12314
12326
  }
12327
+ class ExchangeClosedByUser extends Error {
12328
+ constructor(message) {
12329
+ super(message);
12330
+ this.name = 'ExchangeClosedByUser';
12331
+ }
12332
+ }
12315
12333
  class AuthenticationError extends ExchangeError {
12316
12334
  constructor(message) {
12317
12335
  super(message);
@@ -12518,7 +12536,7 @@ class RequestTimeout extends NetworkError {
12518
12536
  // // Derived class hierarchy
12519
12537
  // errorHierarchy
12520
12538
  // )
12521
- const errors = { 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, ContractUnavailable, NoChange, OperationRejected, OperationFailed, ProxyError };
12539
+ const errors = { BaseError, ExchangeClosedByUser, 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, ContractUnavailable, NoChange, OperationRejected, OperationFailed, ProxyError };
12522
12540
 
12523
12541
  /* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (errors);
12524
12542
 
@@ -14509,6 +14527,9 @@ class Client {
14509
14527
  // todo: exception types for server-side disconnects
14510
14528
  this.reset(new _base_errors_js__WEBPACK_IMPORTED_MODULE_3__.NetworkError('connection closed by remote server, closing code ' + String(event.code)));
14511
14529
  }
14530
+ if (this.error instanceof _base_errors_js__WEBPACK_IMPORTED_MODULE_3__.ExchangeClosedByUser) {
14531
+ this.reset(this.error);
14532
+ }
14512
14533
  if (this.disconnected !== undefined) {
14513
14534
  this.disconnected.resolve(true);
14514
14535
  }
@@ -14529,6 +14550,7 @@ class Client {
14529
14550
  const future = (0,_Future_js__WEBPACK_IMPORTED_MODULE_2__/* .Future */ .o)();
14530
14551
  if (_base_functions_js__WEBPACK_IMPORTED_MODULE_5__/* .isNode */ .UG) {
14531
14552
  /* eslint-disable no-inner-declarations */
14553
+ /* eslint-disable jsdoc/require-jsdoc */
14532
14554
  function onSendComplete(error) {
14533
14555
  if (error) {
14534
14556
  future.reject(error);
@@ -28389,18 +28411,11 @@ class bingx extends _abstract_bingx_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"
28389
28411
  const close = this.safeString(ticker, 'lastPrice');
28390
28412
  const quoteVolume = this.safeString(ticker, 'quoteVolume');
28391
28413
  const baseVolume = this.safeString(ticker, 'volume');
28392
- let percentage = undefined;
28393
- let change = undefined;
28394
- if (market['swap']) {
28395
- // right now only swap uses the 24h change, spot will be added soon
28396
- percentage = this.safeString(ticker, 'priceChangePercent');
28397
- change = this.safeString(ticker, 'priceChange');
28414
+ let percentage = this.safeString(ticker, 'priceChangePercent');
28415
+ if (percentage !== undefined) {
28416
+ percentage = percentage.replace('%', '');
28398
28417
  }
28399
- // let percentage = this.safeString (ticker, 'priceChangePercent');
28400
- // if (percentage !== undefined) {
28401
- // percentage = percentage.replace ('%', '');
28402
- // } similarly to change, it's not ccxt's percentage because it does priceChange/open, and priceChange is high-low
28403
- // const change = this.safeString (ticker, 'priceChange'); // this is not ccxt's change because it does high-low instead of last-open
28418
+ const change = this.safeString(ticker, 'priceChange');
28404
28419
  const ts = this.safeInteger(ticker, 'closeTime');
28405
28420
  const datetime = this.iso8601(ts);
28406
28421
  const bid = this.safeString(ticker, 'bidPrice');
@@ -28729,6 +28744,11 @@ class bingx extends _abstract_bingx_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"
28729
28744
  };
28730
28745
  const isMarketOrder = type === 'MARKET';
28731
28746
  const isSpot = marketType === 'spot';
28747
+ const exchangeClientOrderId = isSpot ? 'newClientOrderId' : 'clientOrderID';
28748
+ const clientOrderId = this.safeString2(params, exchangeClientOrderId, 'clientOrderId');
28749
+ if (clientOrderId !== undefined) {
28750
+ request[exchangeClientOrderId] = clientOrderId;
28751
+ }
28732
28752
  const timeInForce = this.safeStringUpper(params, 'timeInForce');
28733
28753
  if (timeInForce === 'IOC') {
28734
28754
  request['timeInForce'] = 'IOC';
@@ -28873,7 +28893,7 @@ class bingx extends _abstract_bingx_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"
28873
28893
  }
28874
28894
  request['positionSide'] = positionSide;
28875
28895
  request['quantity'] = this.parseToNumeric(this.amountToPrecision(symbol, amount));
28876
- params = this.omit(params, ['reduceOnly', 'triggerPrice', 'stopLossPrice', 'takeProfitPrice', 'trailingAmount', 'trailingPercent', 'takeProfit', 'stopLoss']);
28896
+ params = this.omit(params, ['reduceOnly', 'triggerPrice', 'stopLossPrice', 'takeProfitPrice', 'trailingAmount', 'trailingPercent', 'takeProfit', 'stopLoss', 'clientOrderId']);
28877
28897
  }
28878
28898
  return this.extend(request, params);
28879
28899
  }
@@ -28890,6 +28910,7 @@ class bingx extends _abstract_bingx_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"
28890
28910
  * @param {float} amount how much you want to trade in units of the base currency
28891
28911
  * @param {float} [price] the price at which the order is to be fullfilled, in units of the quote currency, ignored in market orders
28892
28912
  * @param {object} [params] extra parameters specific to the exchange API endpoint
28913
+ * @param {string} [params.clientOrderId] a unique id for the order
28893
28914
  * @param {bool} [params.postOnly] true to place a post only order
28894
28915
  * @param {string} [params.timeInForce] spot supports 'PO' and 'IOC', swap supports 'PO', 'GTC', 'IOC' and 'FOK'
28895
28916
  * @param {bool} [params.reduceOnly] *swap only* true or false whether the order is reduce only
@@ -28954,7 +28975,7 @@ class bingx extends _abstract_bingx_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"
28954
28975
  // }
28955
28976
  //
28956
28977
  if (typeof response === 'string') {
28957
- response = JSON.parse(response);
28978
+ response = this.parseJson(response);
28958
28979
  }
28959
28980
  const data = this.safeValue(response, 'data', {});
28960
28981
  const order = this.safeValue(data, 'order', data);
@@ -29215,7 +29236,7 @@ class bingx extends _abstract_bingx_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"
29215
29236
  'currency': feeCurrencyCode,
29216
29237
  'cost': _base_Precise_js__WEBPACK_IMPORTED_MODULE_3__/* .Precise */ .O.stringAbs(feeCost),
29217
29238
  };
29218
- const clientOrderId = this.safeString2(order, 'clientOrderId', 'c');
29239
+ const clientOrderId = this.safeStringN(order, ['clientOrderID', 'origClientOrderId', 'c']);
29219
29240
  let stopLoss = this.safeValue(order, 'stopLoss');
29220
29241
  let stopLossPrice = undefined;
29221
29242
  if (stopLoss !== undefined) {
@@ -29224,7 +29245,7 @@ class bingx extends _abstract_bingx_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"
29224
29245
  if ((stopLoss !== undefined) && (typeof stopLoss !== 'number')) {
29225
29246
  // stopLoss: '{"stopPrice":50,"workingType":"MARK_PRICE","type":"STOP_MARKET","quantity":1}',
29226
29247
  if (typeof stopLoss === 'string') {
29227
- stopLoss = JSON.parse(stopLoss);
29248
+ stopLoss = this.parseJson(stopLoss);
29228
29249
  }
29229
29250
  stopLossPrice = this.safeNumber(stopLoss, 'stopPrice');
29230
29251
  }
@@ -29236,7 +29257,7 @@ class bingx extends _abstract_bingx_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"
29236
29257
  if ((takeProfit !== undefined) && (typeof takeProfit !== 'number')) {
29237
29258
  // takeProfit: '{"stopPrice":150,"workingType":"MARK_PRICE","type":"TAKE_PROFIT_MARKET","quantity":1}',
29238
29259
  if (typeof takeProfit === 'string') {
29239
- takeProfit = JSON.parse(takeProfit);
29260
+ takeProfit = this.parseJson(takeProfit);
29240
29261
  }
29241
29262
  takeProfitPrice = this.safeNumber(takeProfit, 'stopPrice');
29242
29263
  }
@@ -29290,6 +29311,7 @@ class bingx extends _abstract_bingx_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"
29290
29311
  * @param {string} id order id
29291
29312
  * @param {string} symbol unified symbol of the market the order was made in
29292
29313
  * @param {object} [params] extra parameters specific to the exchange API endpoint
29314
+ * @param {string} [params.clientOrderId] a unique id for the order
29293
29315
  * @returns {object} An [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
29294
29316
  */
29295
29317
  if (symbol === undefined) {
@@ -29299,8 +29321,15 @@ class bingx extends _abstract_bingx_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"
29299
29321
  const market = this.market(symbol);
29300
29322
  const request = {
29301
29323
  'symbol': market['id'],
29302
- 'orderId': id,
29303
29324
  };
29325
+ const clientOrderId = this.safeString2(params, 'clientOrderId', 'clientOrderID');
29326
+ params = this.omit(params, ['clientOrderId']);
29327
+ if (clientOrderId !== undefined) {
29328
+ request['clientOrderID'] = clientOrderId;
29329
+ }
29330
+ else {
29331
+ request['orderId'] = id;
29332
+ }
29304
29333
  let response = undefined;
29305
29334
  const [marketType, query] = this.handleMarketTypeAndParams('cancelOrder', market, params);
29306
29335
  if (marketType === 'spot') {
@@ -29476,7 +29505,7 @@ class bingx extends _abstract_bingx_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"
29476
29505
  }
29477
29506
  let response = undefined;
29478
29507
  if (market['spot']) {
29479
- const spotReqKey = areClientOrderIds ? 'clientOrderIds' : 'orderIds';
29508
+ const spotReqKey = areClientOrderIds ? 'clientOrderIDs' : 'orderIds';
29480
29509
  request[spotReqKey] = parsedIds.join(',');
29481
29510
  response = await this.spotV1PrivatePostTradeCancelOrders(this.extend(request, params));
29482
29511
  }
@@ -56178,14 +56207,15 @@ class bitmex extends _abstract_bitmex_js__WEBPACK_IMPORTED_MODULE_0__/* ["defaul
56178
56207
  * @param {object} [params] extra parameters specific to the exchange API endpoint
56179
56208
  * @param {object} [params.triggerPrice] the price at which a trigger order is triggered at
56180
56209
  * @param {object} [params.triggerDirection] the direction whenever the trigger happens with relation to price - 'above' or 'below'
56210
+ * @param {float} [params.trailingAmount] the quote amount to trail away from the current market price
56181
56211
  * @returns {object} an [order structure]{@link https://github.com/ccxt/ccxt/wiki/Manual#order-structure}
56182
56212
  */
56183
56213
  await this.loadMarkets();
56184
56214
  const market = this.market(symbol);
56185
- const orderType = this.capitalize(type);
56215
+ let orderType = this.capitalize(type);
56186
56216
  const reduceOnly = this.safeValue(params, 'reduceOnly');
56187
56217
  if (reduceOnly !== undefined) {
56188
- if ((market['type'] !== 'swap') && (market['type'] !== 'future')) {
56218
+ if ((!market['swap']) && (!market['future'])) {
56189
56219
  throw new _base_errors_js__WEBPACK_IMPORTED_MODULE_1__.InvalidOrder(this.id + ' createOrder() does not support reduceOnly for ' + market['type'] + ' orders, reduceOnly orders are supported for swap and future markets only');
56190
56220
  }
56191
56221
  }
@@ -56198,44 +56228,54 @@ class bitmex extends _abstract_bitmex_js__WEBPACK_IMPORTED_MODULE_0__/* ["defaul
56198
56228
  'ordType': orderType,
56199
56229
  'text': brokerId,
56200
56230
  };
56201
- const customTriggerType = (orderType === 'Stop') || (orderType === 'StopLimit') || (orderType === 'MarketIfTouched') || (orderType === 'LimitIfTouched');
56202
56231
  // support for unified trigger format
56203
56232
  const triggerPrice = this.safeNumberN(params, ['triggerPrice', 'stopPx', 'stopPrice']);
56204
- if ((triggerPrice !== undefined) && !customTriggerType) {
56205
- request['stopPx'] = parseFloat(this.priceToPrecision(symbol, triggerPrice));
56233
+ let trailingAmount = this.safeString2(params, 'trailingAmount', 'pegOffsetValue');
56234
+ const isTriggerOrder = triggerPrice !== undefined;
56235
+ const isTrailingAmountOrder = trailingAmount !== undefined;
56236
+ if (isTriggerOrder || isTrailingAmountOrder) {
56206
56237
  const triggerDirection = this.safeString(params, 'triggerDirection');
56207
- params = this.omit(params, ['triggerPrice', 'stopPrice', 'stopPx', 'triggerDirection']);
56208
56238
  const triggerAbove = (triggerDirection === 'above');
56209
- this.checkRequiredArgument('createOrder', triggerDirection, 'triggerDirection', ['above', 'below']);
56210
- this.checkRequiredArgument('createOrder', side, 'side', ['buy', 'sell']);
56239
+ if ((type === 'limit') || (type === 'market')) {
56240
+ this.checkRequiredArgument('createOrder', triggerDirection, 'triggerDirection', ['above', 'below']);
56241
+ }
56211
56242
  if (type === 'limit') {
56212
- request['price'] = parseFloat(this.priceToPrecision(symbol, price));
56213
56243
  if (side === 'buy') {
56214
- request['ordType'] = triggerAbove ? 'StopLimit' : 'LimitIfTouched';
56244
+ orderType = triggerAbove ? 'StopLimit' : 'LimitIfTouched';
56215
56245
  }
56216
56246
  else {
56217
- request['ordType'] = triggerAbove ? 'LimitIfTouched' : 'StopLimit';
56247
+ orderType = triggerAbove ? 'LimitIfTouched' : 'StopLimit';
56218
56248
  }
56219
56249
  }
56220
56250
  else if (type === 'market') {
56221
56251
  if (side === 'buy') {
56222
- request['ordType'] = triggerAbove ? 'Stop' : 'MarketIfTouched';
56252
+ orderType = triggerAbove ? 'Stop' : 'MarketIfTouched';
56223
56253
  }
56224
56254
  else {
56225
- request['ordType'] = triggerAbove ? 'MarketIfTouched' : 'Stop';
56255
+ orderType = triggerAbove ? 'MarketIfTouched' : 'Stop';
56226
56256
  }
56227
56257
  }
56228
- }
56229
- else if (customTriggerType) {
56230
- if (triggerPrice === undefined) {
56231
- // if exchange specific trigger types were provided
56232
- throw new _base_errors_js__WEBPACK_IMPORTED_MODULE_1__.ArgumentsRequired(this.id + ' createOrder() requires a triggerPrice (stopPx|stopPrice) parameter for the ' + orderType + ' order type');
56258
+ if (isTrailingAmountOrder) {
56259
+ const isStopSellOrder = (side === 'sell') && ((orderType === 'Stop') || (orderType === 'StopLimit'));
56260
+ const isBuyIfTouchedOrder = (side === 'buy') && ((orderType === 'MarketIfTouched') || (orderType === 'LimitIfTouched'));
56261
+ if (isStopSellOrder || isBuyIfTouchedOrder) {
56262
+ trailingAmount = '-' + trailingAmount;
56263
+ }
56264
+ request['pegOffsetValue'] = this.parseToNumeric(trailingAmount);
56265
+ request['pegPriceType'] = 'TrailingStopPeg';
56266
+ }
56267
+ else {
56268
+ if (triggerPrice === undefined) {
56269
+ // if exchange specific trigger types were provided
56270
+ throw new _base_errors_js__WEBPACK_IMPORTED_MODULE_1__.ArgumentsRequired(this.id + ' createOrder() requires a triggerPrice (stopPx|stopPrice) parameter for the ' + orderType + ' order type');
56271
+ }
56272
+ request['stopPx'] = this.parseToNumeric(this.priceToPrecision(symbol, triggerPrice));
56233
56273
  }
56234
- params = this.omit(params, ['triggerPrice', 'stopPrice', 'stopPx']);
56235
- request['stopPx'] = parseFloat(this.priceToPrecision(symbol, triggerPrice));
56274
+ request['ordType'] = orderType;
56275
+ params = this.omit(params, ['triggerPrice', 'stopPrice', 'stopPx', 'triggerDirection', 'trailingAmount']);
56236
56276
  }
56237
56277
  if ((orderType === 'Limit') || (orderType === 'StopLimit') || (orderType === 'LimitIfTouched')) {
56238
- request['price'] = parseFloat(this.priceToPrecision(symbol, price));
56278
+ request['price'] = this.parseToNumeric(this.priceToPrecision(symbol, price));
56239
56279
  }
56240
56280
  const clientOrderId = this.safeString2(params, 'clOrdID', 'clientOrderId');
56241
56281
  if (clientOrderId !== undefined) {
@@ -56248,6 +56288,39 @@ class bitmex extends _abstract_bitmex_js__WEBPACK_IMPORTED_MODULE_0__/* ["defaul
56248
56288
  async editOrder(id, symbol, type, side, amount = undefined, price = undefined, params = {}) {
56249
56289
  await this.loadMarkets();
56250
56290
  const request = {};
56291
+ let trailingAmount = this.safeString2(params, 'trailingAmount', 'pegOffsetValue');
56292
+ const isTrailingAmountOrder = trailingAmount !== undefined;
56293
+ if (isTrailingAmountOrder) {
56294
+ const triggerDirection = this.safeString(params, 'triggerDirection');
56295
+ const triggerAbove = (triggerDirection === 'above');
56296
+ if ((type === 'limit') || (type === 'market')) {
56297
+ this.checkRequiredArgument('createOrder', triggerDirection, 'triggerDirection', ['above', 'below']);
56298
+ }
56299
+ let orderType = undefined;
56300
+ if (type === 'limit') {
56301
+ if (side === 'buy') {
56302
+ orderType = triggerAbove ? 'StopLimit' : 'LimitIfTouched';
56303
+ }
56304
+ else {
56305
+ orderType = triggerAbove ? 'LimitIfTouched' : 'StopLimit';
56306
+ }
56307
+ }
56308
+ else if (type === 'market') {
56309
+ if (side === 'buy') {
56310
+ orderType = triggerAbove ? 'Stop' : 'MarketIfTouched';
56311
+ }
56312
+ else {
56313
+ orderType = triggerAbove ? 'MarketIfTouched' : 'Stop';
56314
+ }
56315
+ }
56316
+ const isStopSellOrder = (side === 'sell') && ((orderType === 'Stop') || (orderType === 'StopLimit'));
56317
+ const isBuyIfTouchedOrder = (side === 'buy') && ((orderType === 'MarketIfTouched') || (orderType === 'LimitIfTouched'));
56318
+ if (isStopSellOrder || isBuyIfTouchedOrder) {
56319
+ trailingAmount = '-' + trailingAmount;
56320
+ }
56321
+ request['pegOffsetValue'] = this.parseToNumeric(trailingAmount);
56322
+ params = this.omit(params, ['triggerDirection', 'trailingAmount']);
56323
+ }
56251
56324
  const origClOrdID = this.safeString2(params, 'origClOrdID', 'clientOrderId');
56252
56325
  if (origClOrdID !== undefined) {
56253
56326
  request['origClOrdID'] = origClOrdID;
@@ -78053,6 +78126,7 @@ class bybit extends _abstract_bybit_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"
78053
78126
  'v5/position/list': 5,
78054
78127
  'v5/execution/list': 5,
78055
78128
  'v5/position/closed-pnl': 5,
78129
+ 'v5/position/move-history': 5,
78056
78130
  // pre-upgrade
78057
78131
  'v5/pre-upgrade/order/history': 5,
78058
78132
  'v5/pre-upgrade/execution/list': 5,
@@ -78217,6 +78291,7 @@ class bybit extends _abstract_bybit_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"
78217
78291
  'v5/position/trading-stop': 5,
78218
78292
  'v5/position/set-auto-add-margin': 5,
78219
78293
  'v5/position/add-margin': 5,
78294
+ 'v5/position/move-positions': 5,
78220
78295
  'v5/position/confirm-pending-mmr': 5,
78221
78296
  // account
78222
78297
  'v5/account/upgrade-to-uta': 5,
@@ -110952,14 +111027,14 @@ class delta extends _abstract_delta_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"
110952
111027
  const markets = this.markets_by_id[symbol];
110953
111028
  return markets[0];
110954
111029
  }
110955
- else if ((symbol.indexOf('-C') > -1) || (symbol.indexOf('-P') > -1) || (symbol.indexOf('C')) || (symbol.indexOf('P'))) {
111030
+ else if ((symbol.endsWith('-C')) || (symbol.endsWith('-P')) || (symbol.startsWith('C-')) || (symbol.startsWith('P-'))) {
110956
111031
  return this.createExpiredOptionMarket(symbol);
110957
111032
  }
110958
111033
  }
110959
111034
  throw new _base_errors_js__WEBPACK_IMPORTED_MODULE_2__.BadSymbol(this.id + ' does not have market symbol ' + symbol);
110960
111035
  }
110961
111036
  safeMarket(marketId = undefined, market = undefined, delimiter = undefined, marketType = undefined) {
110962
- const isOption = (marketId !== undefined) && ((marketId.indexOf('-C') > -1) || (marketId.indexOf('-P') > -1) || (marketId.indexOf('C')) || (marketId.indexOf('P')));
111037
+ const isOption = (marketId !== undefined) && ((marketId.endsWith('-C')) || (marketId.endsWith('-P')) || (marketId.startsWith('C-')) || (marketId.startsWith('P-')));
110963
111038
  if (isOption && !(marketId in this.markets_by_id)) {
110964
111039
  // handle expired option contracts
110965
111040
  return this.createExpiredOptionMarket(marketId);
@@ -138815,7 +138890,7 @@ class htx extends _abstract_htx_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */
138815
138890
  'repayIsolatedMargin': true,
138816
138891
  'setLeverage': true,
138817
138892
  'setMarginMode': false,
138818
- 'setPositionMode': false,
138893
+ 'setPositionMode': true,
138819
138894
  'signIn': undefined,
138820
138895
  'transfer': true,
138821
138896
  'withdraw': true,
@@ -142547,8 +142622,9 @@ class htx extends _abstract_htx_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */
142547
142622
  let response = undefined;
142548
142623
  const stop = this.safeValue(params, 'stop');
142549
142624
  const stopLossTakeProfit = this.safeValue(params, 'stopLossTakeProfit');
142550
- params = this.omit(params, ['stop', 'stopLossTakeProfit']);
142551
- if (stop || stopLossTakeProfit) {
142625
+ const trailing = this.safeValue(params, 'trailing', false);
142626
+ params = this.omit(params, ['stop', 'stopLossTakeProfit', 'trailing']);
142627
+ if (stop || stopLossTakeProfit || trailing) {
142552
142628
  if (limit !== undefined) {
142553
142629
  request['page_size'] = limit;
142554
142630
  }
@@ -142575,6 +142651,9 @@ class htx extends _abstract_htx_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */
142575
142651
  else if (stopLossTakeProfit) {
142576
142652
  response = await this.contractPrivatePostLinearSwapApiV1SwapTpslHisorders(this.extend(request, params));
142577
142653
  }
142654
+ else if (trailing) {
142655
+ response = await this.contractPrivatePostLinearSwapApiV1SwapTrackHisorders(this.extend(request, params));
142656
+ }
142578
142657
  else {
142579
142658
  response = await this.contractPrivatePostLinearSwapApiV3SwapHisorders(this.extend(request, params));
142580
142659
  }
@@ -142586,6 +142665,9 @@ class htx extends _abstract_htx_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */
142586
142665
  else if (stopLossTakeProfit) {
142587
142666
  response = await this.contractPrivatePostLinearSwapApiV1SwapCrossTpslHisorders(this.extend(request, params));
142588
142667
  }
142668
+ else if (trailing) {
142669
+ response = await this.contractPrivatePostLinearSwapApiV1SwapCrossTrackHisorders(this.extend(request, params));
142670
+ }
142589
142671
  else {
142590
142672
  response = await this.contractPrivatePostLinearSwapApiV3SwapCrossHisorders(this.extend(request, params));
142591
142673
  }
@@ -142599,6 +142681,9 @@ class htx extends _abstract_htx_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */
142599
142681
  else if (stopLossTakeProfit) {
142600
142682
  response = await this.contractPrivatePostSwapApiV1SwapTpslHisorders(this.extend(request, params));
142601
142683
  }
142684
+ else if (trailing) {
142685
+ response = await this.contractPrivatePostSwapApiV1SwapTrackHisorders(this.extend(request, params));
142686
+ }
142602
142687
  else {
142603
142688
  response = await this.contractPrivatePostSwapApiV3SwapHisorders(this.extend(request, params));
142604
142689
  }
@@ -142611,6 +142696,9 @@ class htx extends _abstract_htx_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */
142611
142696
  else if (stopLossTakeProfit) {
142612
142697
  response = await this.contractPrivatePostApiV1ContractTpslHisorders(this.extend(request, params));
142613
142698
  }
142699
+ else if (trailing) {
142700
+ response = await this.contractPrivatePostApiV1ContractTrackHisorders(this.extend(request, params));
142701
+ }
142614
142702
  else {
142615
142703
  response = await this.contractPrivatePostApiV3ContractHisorders(this.extend(request, params));
142616
142704
  }
@@ -142788,6 +142876,7 @@ class htx extends _abstract_htx_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */
142788
142876
  * @param {bool} [params.stop] *contract only* if the orders are stop trigger orders or not
142789
142877
  * @param {bool} [params.stopLossTakeProfit] *contract only* if the orders are stop-loss or take-profit orders
142790
142878
  * @param {int} [params.until] the latest time in ms to fetch entries for
142879
+ * @param {boolean} [params.trailing] *contract only* set to true if you want to fetch trailing stop orders
142791
142880
  * @returns {Order[]} a list of [order structures]{@link https://docs.ccxt.com/#/?id=order-structure}
142792
142881
  */
142793
142882
  await this.loadMarkets();
@@ -142860,6 +142949,7 @@ class htx extends _abstract_htx_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */
142860
142949
  * @param {object} [params] extra parameters specific to the exchange API endpoint
142861
142950
  * @param {bool} [params.stop] *contract only* if the orders are stop trigger orders or not
142862
142951
  * @param {bool} [params.stopLossTakeProfit] *contract only* if the orders are stop-loss or take-profit orders
142952
+ * @param {boolean} [params.trailing] *contract only* set to true if you want to fetch trailing stop orders
142863
142953
  * @returns {Order[]} a list of [order structures]{@link https://docs.ccxt.com/#/?id=order-structure}
142864
142954
  */
142865
142955
  await this.loadMarkets();
@@ -142907,7 +142997,8 @@ class htx extends _abstract_htx_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */
142907
142997
  request['contract_code'] = market['id'];
142908
142998
  const stop = this.safeValue(params, 'stop');
142909
142999
  const stopLossTakeProfit = this.safeValue(params, 'stopLossTakeProfit');
142910
- params = this.omit(params, ['stop', 'stopLossTakeProfit']);
143000
+ const trailing = this.safeValue(params, 'trailing', false);
143001
+ params = this.omit(params, ['stop', 'stopLossTakeProfit', 'trailing']);
142911
143002
  if (market['linear']) {
142912
143003
  let marginMode = undefined;
142913
143004
  [marginMode, params] = this.handleMarginModeAndParams('fetchOpenOrders', params);
@@ -142919,6 +143010,9 @@ class htx extends _abstract_htx_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */
142919
143010
  else if (stopLossTakeProfit) {
142920
143011
  response = await this.contractPrivatePostLinearSwapApiV1SwapTpslOpenorders(this.extend(request, params));
142921
143012
  }
143013
+ else if (trailing) {
143014
+ response = await this.contractPrivatePostLinearSwapApiV1SwapTrackOpenorders(this.extend(request, params));
143015
+ }
142922
143016
  else {
142923
143017
  response = await this.contractPrivatePostLinearSwapApiV1SwapOpenorders(this.extend(request, params));
142924
143018
  }
@@ -142930,6 +143024,9 @@ class htx extends _abstract_htx_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */
142930
143024
  else if (stopLossTakeProfit) {
142931
143025
  response = await this.contractPrivatePostLinearSwapApiV1SwapCrossTpslOpenorders(this.extend(request, params));
142932
143026
  }
143027
+ else if (trailing) {
143028
+ response = await this.contractPrivatePostLinearSwapApiV1SwapCrossTrackOpenorders(this.extend(request, params));
143029
+ }
142933
143030
  else {
142934
143031
  response = await this.contractPrivatePostLinearSwapApiV1SwapCrossOpenorders(this.extend(request, params));
142935
143032
  }
@@ -142943,6 +143040,9 @@ class htx extends _abstract_htx_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */
142943
143040
  else if (stopLossTakeProfit) {
142944
143041
  response = await this.contractPrivatePostSwapApiV1SwapTpslOpenorders(this.extend(request, params));
142945
143042
  }
143043
+ else if (trailing) {
143044
+ response = await this.contractPrivatePostSwapApiV1SwapTrackOpenorders(this.extend(request, params));
143045
+ }
142946
143046
  else {
142947
143047
  response = await this.contractPrivatePostSwapApiV1SwapOpenorders(this.extend(request, params));
142948
143048
  }
@@ -142955,6 +143055,9 @@ class htx extends _abstract_htx_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */
142955
143055
  else if (stopLossTakeProfit) {
142956
143056
  response = await this.contractPrivatePostApiV1ContractTpslOpenorders(this.extend(request, params));
142957
143057
  }
143058
+ else if (trailing) {
143059
+ response = await this.contractPrivatePostApiV1ContractTrackOpenorders(this.extend(request, params));
143060
+ }
142958
143061
  else {
142959
143062
  response = await this.contractPrivatePostApiV1ContractOpenorders(this.extend(request, params));
142960
143063
  }
@@ -143106,6 +143209,45 @@ class htx extends _abstract_htx_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */
143106
143209
  // "ts": 1683179527011
143107
143210
  // }
143108
143211
  //
143212
+ // trailing
143213
+ //
143214
+ // {
143215
+ // "status": "ok",
143216
+ // "data": {
143217
+ // "orders": [
143218
+ // {
143219
+ // "contract_type": "swap",
143220
+ // "business_type": "swap",
143221
+ // "pair": "BTC-USDT",
143222
+ // "symbol": "BTC",
143223
+ // "contract_code": "BTC-USDT",
143224
+ // "volume": 1.000000000000000000,
143225
+ // "order_type": 1,
143226
+ // "direction": "sell",
143227
+ // "offset": "close",
143228
+ // "lever_rate": 1,
143229
+ // "order_id": 1192021437253877761,
143230
+ // "order_id_str": "1192021437253877761",
143231
+ // "order_source": "api",
143232
+ // "created_at": 1704241657328,
143233
+ // "order_price_type": "formula_price",
143234
+ // "status": 2,
143235
+ // "callback_rate": 0.050000000000000000,
143236
+ // "active_price": 50000.000000000000000000,
143237
+ // "is_active": 0,
143238
+ // "margin_mode": "cross",
143239
+ // "margin_account": "USDT",
143240
+ // "trade_partition": "USDT",
143241
+ // "reduce_only": 1
143242
+ // },
143243
+ // ],
143244
+ // "total_page": 1,
143245
+ // "current_page": 1,
143246
+ // "total_size": 2
143247
+ // },
143248
+ // "ts": 1704242440106
143249
+ // }
143250
+ //
143109
143251
  let orders = this.safeValue(response, 'data');
143110
143252
  if (!Array.isArray(orders)) {
143111
143253
  orders = this.safeValue(orders, 'orders', []);
@@ -143365,6 +143507,33 @@ class htx extends _abstract_htx_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */
143365
143507
  // "trade_partition": "USDT"
143366
143508
  // }
143367
143509
  //
143510
+ // trailing: fetchOpenOrders
143511
+ //
143512
+ // {
143513
+ // "contract_type": "swap",
143514
+ // "business_type": "swap",
143515
+ // "pair": "BTC-USDT",
143516
+ // "symbol": "BTC",
143517
+ // "contract_code": "BTC-USDT",
143518
+ // "volume": 1.000000000000000000,
143519
+ // "order_type": 1,
143520
+ // "direction": "sell",
143521
+ // "offset": "close",
143522
+ // "lever_rate": 1,
143523
+ // "order_id": 1192021437253877761,
143524
+ // "order_id_str": "1192021437253877761",
143525
+ // "order_source": "api",
143526
+ // "created_at": 1704241657328,
143527
+ // "order_price_type": "formula_price",
143528
+ // "status": 2,
143529
+ // "callback_rate": 0.050000000000000000,
143530
+ // "active_price": 50000.000000000000000000,
143531
+ // "is_active": 0,
143532
+ // "margin_mode": "cross",
143533
+ // "margin_account": "USDT",
143534
+ // "trade_partition": "USDT",
143535
+ // "reduce_only": 1
143536
+ // }
143368
143537
  //
143369
143538
  // trigger: fetchOrders
143370
143539
  //
@@ -144129,8 +144298,9 @@ class htx extends _abstract_htx_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */
144129
144298
  * @param {string} id order id
144130
144299
  * @param {string} symbol unified symbol of the market the order was made in
144131
144300
  * @param {object} [params] extra parameters specific to the exchange API endpoint
144132
- * @param {bool} [params.stop] *contract only* if the order is a stop trigger order or not
144133
- * @param {bool} [params.stopLossTakeProfit] *contract only* if the order is a stop-loss or take-profit order
144301
+ * @param {boolean} [params.stop] *contract only* if the order is a stop trigger order or not
144302
+ * @param {boolean} [params.stopLossTakeProfit] *contract only* if the order is a stop-loss or take-profit order
144303
+ * @param {boolean} [params.trailing] *contract only* set to true if you want to cancel a trailing order
144134
144304
  * @returns {object} An [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
144135
144305
  */
144136
144306
  await this.loadMarkets();
@@ -144185,7 +144355,8 @@ class htx extends _abstract_htx_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */
144185
144355
  }
144186
144356
  const stop = this.safeValue(params, 'stop');
144187
144357
  const stopLossTakeProfit = this.safeValue(params, 'stopLossTakeProfit');
144188
- params = this.omit(params, ['stop', 'stopLossTakeProfit']);
144358
+ const trailing = this.safeValue(params, 'trailing', false);
144359
+ params = this.omit(params, ['stop', 'stopLossTakeProfit', 'trailing']);
144189
144360
  if (market['linear']) {
144190
144361
  let marginMode = undefined;
144191
144362
  [marginMode, params] = this.handleMarginModeAndParams('cancelOrder', params);
@@ -144197,6 +144368,9 @@ class htx extends _abstract_htx_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */
144197
144368
  else if (stopLossTakeProfit) {
144198
144369
  response = await this.contractPrivatePostLinearSwapApiV1SwapTpslCancel(this.extend(request, params));
144199
144370
  }
144371
+ else if (trailing) {
144372
+ response = await this.contractPrivatePostLinearSwapApiV1SwapTrackCancel(this.extend(request, params));
144373
+ }
144200
144374
  else {
144201
144375
  response = await this.contractPrivatePostLinearSwapApiV1SwapCancel(this.extend(request, params));
144202
144376
  }
@@ -144208,6 +144382,9 @@ class htx extends _abstract_htx_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */
144208
144382
  else if (stopLossTakeProfit) {
144209
144383
  response = await this.contractPrivatePostLinearSwapApiV1SwapCrossTpslCancel(this.extend(request, params));
144210
144384
  }
144385
+ else if (trailing) {
144386
+ response = await this.contractPrivatePostLinearSwapApiV1SwapCrossTrackCancel(this.extend(request, params));
144387
+ }
144211
144388
  else {
144212
144389
  response = await this.contractPrivatePostLinearSwapApiV1SwapCrossCancel(this.extend(request, params));
144213
144390
  }
@@ -144221,6 +144398,9 @@ class htx extends _abstract_htx_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */
144221
144398
  else if (stopLossTakeProfit) {
144222
144399
  response = await this.contractPrivatePostSwapApiV1SwapTpslCancel(this.extend(request, params));
144223
144400
  }
144401
+ else if (trailing) {
144402
+ response = await this.contractPrivatePostSwapApiV1SwapTrackCancel(this.extend(request, params));
144403
+ }
144224
144404
  else {
144225
144405
  response = await this.contractPrivatePostSwapApiV1SwapCancel(this.extend(request, params));
144226
144406
  }
@@ -144232,6 +144412,9 @@ class htx extends _abstract_htx_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */
144232
144412
  else if (stopLossTakeProfit) {
144233
144413
  response = await this.contractPrivatePostApiV1ContractTpslCancel(this.extend(request, params));
144234
144414
  }
144415
+ else if (trailing) {
144416
+ response = await this.contractPrivatePostApiV1ContractTrackCancel(this.extend(request, params));
144417
+ }
144235
144418
  else {
144236
144419
  response = await this.contractPrivatePostApiV1ContractCancel(this.extend(request, params));
144237
144420
  }
@@ -144454,8 +144637,9 @@ class htx extends _abstract_htx_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */
144454
144637
  * @description cancel all open orders
144455
144638
  * @param {string} symbol unified market symbol, only orders in the market of this symbol are cancelled when symbol is not undefined
144456
144639
  * @param {object} [params] extra parameters specific to the exchange API endpoint
144457
- * @param {bool} [params.stop] *contract only* if the orders are stop trigger orders or not
144458
- * @param {bool} [params.stopLossTakeProfit] *contract only* if the orders are stop-loss or take-profit orders
144640
+ * @param {boolean} [params.stop] *contract only* if the orders are stop trigger orders or not
144641
+ * @param {boolean} [params.stopLossTakeProfit] *contract only* if the orders are stop-loss or take-profit orders
144642
+ * @param {boolean} [params.trailing] *contract only* set to true if you want to cancel all trailing orders
144459
144643
  * @returns {object[]} a list of [order structures]{@link https://docs.ccxt.com/#/?id=order-structure}
144460
144644
  */
144461
144645
  await this.loadMarkets();
@@ -144496,7 +144680,8 @@ class htx extends _abstract_htx_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */
144496
144680
  request['contract_code'] = market['id'];
144497
144681
  const stop = this.safeValue(params, 'stop');
144498
144682
  const stopLossTakeProfit = this.safeValue(params, 'stopLossTakeProfit');
144499
- params = this.omit(params, ['stop', 'stopLossTakeProfit']);
144683
+ const trailing = this.safeValue(params, 'trailing', false);
144684
+ params = this.omit(params, ['stop', 'stopLossTakeProfit', 'trailing']);
144500
144685
  if (market['linear']) {
144501
144686
  let marginMode = undefined;
144502
144687
  [marginMode, params] = this.handleMarginModeAndParams('cancelAllOrders', params);
@@ -144508,6 +144693,9 @@ class htx extends _abstract_htx_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */
144508
144693
  else if (stopLossTakeProfit) {
144509
144694
  response = await this.contractPrivatePostLinearSwapApiV1SwapTpslCancelall(this.extend(request, params));
144510
144695
  }
144696
+ else if (trailing) {
144697
+ response = await this.contractPrivatePostLinearSwapApiV1SwapTrackCancelall(this.extend(request, params));
144698
+ }
144511
144699
  else {
144512
144700
  response = await this.contractPrivatePostLinearSwapApiV1SwapCancelall(this.extend(request, params));
144513
144701
  }
@@ -144519,6 +144707,9 @@ class htx extends _abstract_htx_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */
144519
144707
  else if (stopLossTakeProfit) {
144520
144708
  response = await this.contractPrivatePostLinearSwapApiV1SwapCrossTpslCancelall(this.extend(request, params));
144521
144709
  }
144710
+ else if (trailing) {
144711
+ response = await this.contractPrivatePostLinearSwapApiV1SwapCrossTrackCancelall(this.extend(request, params));
144712
+ }
144522
144713
  else {
144523
144714
  response = await this.contractPrivatePostLinearSwapApiV1SwapCrossCancelall(this.extend(request, params));
144524
144715
  }
@@ -144532,6 +144723,9 @@ class htx extends _abstract_htx_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */
144532
144723
  else if (stopLossTakeProfit) {
144533
144724
  response = await this.contractPrivatePostSwapApiV1SwapTpslCancelall(this.extend(request, params));
144534
144725
  }
144726
+ else if (trailing) {
144727
+ response = await this.contractPrivatePostSwapApiV1SwapTrackCancelall(this.extend(request, params));
144728
+ }
144535
144729
  else {
144536
144730
  response = await this.contractPrivatePostSwapApiV1SwapCancelall(this.extend(request, params));
144537
144731
  }
@@ -144543,6 +144737,9 @@ class htx extends _abstract_htx_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */
144543
144737
  else if (stopLossTakeProfit) {
144544
144738
  response = await this.contractPrivatePostApiV1ContractTpslCancelall(this.extend(request, params));
144545
144739
  }
144740
+ else if (trailing) {
144741
+ response = await this.contractPrivatePostApiV1ContractTrackCancelall(this.extend(request, params));
144742
+ }
144546
144743
  else {
144547
144744
  response = await this.contractPrivatePostApiV1ContractCancelall(this.extend(request, params));
144548
144745
  }
@@ -147530,6 +147727,71 @@ class htx extends _abstract_htx_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */
147530
147727
  'datetime': this.iso8601(timestamp),
147531
147728
  });
147532
147729
  }
147730
+ async setPositionMode(hedged, symbol = undefined, params = {}) {
147731
+ /**
147732
+ * @method
147733
+ * @name htx#setPositionMode
147734
+ * @description set hedged to true or false
147735
+ * @see https://huobiapi.github.io/docs/usdt_swap/v1/en/#isolated-switch-position-mode
147736
+ * @see https://huobiapi.github.io/docs/usdt_swap/v1/en/#cross-switch-position-mode
147737
+ * @param {bool} hedged set to true to for hedged mode, must be set separately for each market in isolated margin mode, only valid for linear markets
147738
+ * @param {string} [symbol] unified market symbol, required for isolated margin mode
147739
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
147740
+ * @param {string} [params.marginMode] "cross" (default) or "isolated"
147741
+ * @returns {object} response from the exchange
147742
+ */
147743
+ await this.loadMarkets();
147744
+ const posMode = hedged ? 'dual_side' : 'single_side';
147745
+ let market = undefined;
147746
+ if (symbol !== undefined) {
147747
+ market = this.market(symbol);
147748
+ }
147749
+ let marginMode = undefined;
147750
+ [marginMode, params] = this.handleMarginModeAndParams('setPositionMode', params, 'cross');
147751
+ const request = {
147752
+ 'position_mode': posMode,
147753
+ };
147754
+ let response = undefined;
147755
+ if ((market !== undefined) && (market['inverse'])) {
147756
+ throw new _base_errors_js__WEBPACK_IMPORTED_MODULE_1__.BadRequest(this.id + ' setPositionMode can only be used for linear markets');
147757
+ }
147758
+ if (marginMode === 'isolated') {
147759
+ if (symbol === undefined) {
147760
+ throw new _base_errors_js__WEBPACK_IMPORTED_MODULE_1__.ArgumentsRequired(this.id + ' setPositionMode requires a symbol argument for isolated margin mode');
147761
+ }
147762
+ request['margin_account'] = market['id'];
147763
+ response = await this.contractPrivatePostLinearSwapApiV1SwapSwitchPositionMode(this.extend(request, params));
147764
+ //
147765
+ // {
147766
+ // "status": "ok",
147767
+ // "data": [
147768
+ // {
147769
+ // "margin_account": "BTC-USDT",
147770
+ // "position_mode": "single_side"
147771
+ // }
147772
+ // ],
147773
+ // "ts": 1566899973811
147774
+ // }
147775
+ //
147776
+ }
147777
+ else {
147778
+ request['margin_account'] = 'USDT';
147779
+ response = await this.contractPrivatePostLinearSwapApiV1SwapCrossSwitchPositionMode(this.extend(request, params));
147780
+ //
147781
+ // {
147782
+ // "status": "ok",
147783
+ // "data": [
147784
+ // {
147785
+ // "margin_account": "USDT",
147786
+ // "position_mode": "single_side"
147787
+ // }
147788
+ // ],
147789
+ // "ts": 1566899973811
147790
+ // }
147791
+ //
147792
+ }
147793
+ return response;
147794
+ }
147533
147795
  }
147534
147796
 
147535
147797
 
@@ -198319,7 +198581,8 @@ class phemex extends _abstract_phemex_js__WEBPACK_IMPORTED_MODULE_0__/* ["defaul
198319
198581
  '34003': _base_errors_js__WEBPACK_IMPORTED_MODULE_2__.PermissionDenied,
198320
198582
  '35104': _base_errors_js__WEBPACK_IMPORTED_MODULE_2__.InsufficientFunds,
198321
198583
  '39995': _base_errors_js__WEBPACK_IMPORTED_MODULE_2__.RateLimitExceeded,
198322
- '39996': _base_errors_js__WEBPACK_IMPORTED_MODULE_2__.PermissionDenied, // {"code": "39996","msg": "Access denied."}
198584
+ '39996': _base_errors_js__WEBPACK_IMPORTED_MODULE_2__.PermissionDenied,
198585
+ '39997': _base_errors_js__WEBPACK_IMPORTED_MODULE_2__.BadSymbol, // {"code":39997,"msg":"Symbol not listed sMOVRUSDT","data":null}
198323
198586
  },
198324
198587
  'broad': {
198325
198588
  '401 Insufficient privilege': _base_errors_js__WEBPACK_IMPORTED_MODULE_2__.PermissionDenied,
@@ -280173,9 +280436,9 @@ class woo extends _abstract_woo_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */
280173
280436
  /**
280174
280437
  * @method
280175
280438
  * @name woo#createOrder
280439
+ * @description create a trade order
280176
280440
  * @see https://docs.woo.org/#send-order
280177
280441
  * @see https://docs.woo.org/#send-algo-order
280178
- * @description create a trade order
280179
280442
  * @param {string} symbol unified symbol of the market to create an order in
280180
280443
  * @param {string} type 'market' or 'limit'
280181
280444
  * @param {string} side 'buy' or 'sell'
@@ -280189,6 +280452,9 @@ class woo extends _abstract_woo_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */
280189
280452
  * @param {float} [params.stopLoss.triggerPrice] stop loss trigger price
280190
280453
  * @param {float} [params.algoType] 'STOP'or 'TRAILING_STOP' or 'OCO' or 'CLOSE_POSITION'
280191
280454
  * @param {float} [params.cost] *spot market buy only* the quote quantity that can be used as an alternative for the amount
280455
+ * @param {string} [params.trailingAmount] the quote amount to trail away from the current market price
280456
+ * @param {string} [params.trailingPercent] the percent to trail away from the current market price
280457
+ * @param {string} [params.trailingTriggerPrice] the price to trigger a trailing order, default uses the price argument
280192
280458
  * @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
280193
280459
  */
280194
280460
  const reduceOnly = this.safeValue2(params, 'reduceOnly', 'reduce_only');
@@ -280205,7 +280471,13 @@ class woo extends _abstract_woo_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */
280205
280471
  const stopLoss = this.safeValue(params, 'stopLoss');
280206
280472
  const takeProfit = this.safeValue(params, 'takeProfit');
280207
280473
  const algoType = this.safeString(params, 'algoType');
280208
- const isStop = stopPrice !== undefined || stopLoss !== undefined || takeProfit !== undefined || (this.safeValue(params, 'childOrders') !== undefined);
280474
+ const trailingTriggerPrice = this.safeString2(params, 'trailingTriggerPrice', 'activatedPrice', price);
280475
+ const trailingAmount = this.safeString2(params, 'trailingAmount', 'callbackValue');
280476
+ const trailingPercent = this.safeString2(params, 'trailingPercent', 'callbackRate');
280477
+ const isTrailingAmountOrder = trailingAmount !== undefined;
280478
+ const isTrailingPercentOrder = trailingPercent !== undefined;
280479
+ const isTrailing = isTrailingAmountOrder || isTrailingPercentOrder;
280480
+ const isStop = isTrailing || stopPrice !== undefined || stopLoss !== undefined || takeProfit !== undefined || (this.safeValue(params, 'childOrders') !== undefined);
280209
280481
  const isMarket = orderType === 'MARKET';
280210
280482
  const timeInForce = this.safeStringLower(params, 'timeInForce');
280211
280483
  const postOnly = this.isPostOnly(isMarket, undefined, params);
@@ -280270,7 +280542,21 @@ class woo extends _abstract_woo_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */
280270
280542
  if (clientOrderId !== undefined) {
280271
280543
  request[clientOrderIdKey] = clientOrderId;
280272
280544
  }
280273
- if (stopPrice !== undefined) {
280545
+ if (isTrailing) {
280546
+ if (trailingTriggerPrice === undefined) {
280547
+ throw new _base_errors_js__WEBPACK_IMPORTED_MODULE_1__.ArgumentsRequired(this.id + ' createOrder() requires a trailingTriggerPrice parameter for trailing orders');
280548
+ }
280549
+ request['activatedPrice'] = this.priceToPrecision(symbol, trailingTriggerPrice);
280550
+ request['algoType'] = 'TRAILING_STOP';
280551
+ if (isTrailingAmountOrder) {
280552
+ request['callbackValue'] = trailingAmount;
280553
+ }
280554
+ else if (isTrailingPercentOrder) {
280555
+ const convertedTrailingPercent = _base_Precise_js__WEBPACK_IMPORTED_MODULE_3__/* .Precise */ .O.stringDiv(trailingPercent, '100');
280556
+ request['callbackRate'] = convertedTrailingPercent;
280557
+ }
280558
+ }
280559
+ else if (stopPrice !== undefined) {
280274
280560
  if (algoType !== 'TRAILING_STOP') {
280275
280561
  request['triggerPrice'] = this.priceToPrecision(symbol, stopPrice);
280276
280562
  request['algoType'] = 'STOP';
@@ -280309,7 +280595,7 @@ class woo extends _abstract_woo_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */
280309
280595
  }
280310
280596
  request['childOrders'] = [outterOrder];
280311
280597
  }
280312
- params = this.omit(params, ['clOrdID', 'clientOrderId', 'client_order_id', 'postOnly', 'timeInForce', 'stopPrice', 'triggerPrice', 'stopLoss', 'takeProfit']);
280598
+ params = this.omit(params, ['clOrdID', 'clientOrderId', 'client_order_id', 'postOnly', 'timeInForce', 'stopPrice', 'triggerPrice', 'stopLoss', 'takeProfit', 'trailingPercent', 'trailingAmount', 'trailingTriggerPrice']);
280313
280599
  let response = undefined;
280314
280600
  if (isStop) {
280315
280601
  response = await this.v3PrivatePostAlgoOrder(this.extend(request, params));
@@ -280355,11 +280641,11 @@ class woo extends _abstract_woo_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */
280355
280641
  /**
280356
280642
  * @method
280357
280643
  * @name woo#editOrder
280644
+ * @description edit a trade order
280358
280645
  * @see https://docs.woo.org/#edit-order
280359
280646
  * @see https://docs.woo.org/#edit-order-by-client_order_id
280360
280647
  * @see https://docs.woo.org/#edit-algo-order
280361
280648
  * @see https://docs.woo.org/#edit-algo-order-by-client_order_id
280362
- * @description edit a trade order
280363
280649
  * @param {string} id order id
280364
280650
  * @param {string} symbol unified symbol of the market to create an order in
280365
280651
  * @param {string} type 'market' or 'limit'
@@ -280370,6 +280656,9 @@ class woo extends _abstract_woo_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */
280370
280656
  * @param {float} [params.triggerPrice] The price a trigger order is triggered at
280371
280657
  * @param {float} [params.stopLossPrice] price to trigger stop-loss orders
280372
280658
  * @param {float} [params.takeProfitPrice] price to trigger take-profit orders
280659
+ * @param {string} [params.trailingAmount] the quote amount to trail away from the current market price
280660
+ * @param {string} [params.trailingPercent] the percent to trail away from the current market price
280661
+ * @param {string} [params.trailingTriggerPrice] the price to trigger a trailing order, default uses the price argument
280373
280662
  * @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
280374
280663
  */
280375
280664
  await this.loadMarkets();
@@ -280391,8 +280680,26 @@ class woo extends _abstract_woo_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */
280391
280680
  if (stopPrice !== undefined) {
280392
280681
  request['triggerPrice'] = this.priceToPrecision(symbol, stopPrice);
280393
280682
  }
280394
- params = this.omit(params, ['clOrdID', 'clientOrderId', 'client_order_id', 'stopPrice', 'triggerPrice', 'takeProfitPrice', 'stopLossPrice']);
280395
- const isStop = (stopPrice !== undefined) || (this.safeValue(params, 'childOrders') !== undefined);
280683
+ const trailingTriggerPrice = this.safeString2(params, 'trailingTriggerPrice', 'activatedPrice', price);
280684
+ const trailingAmount = this.safeString2(params, 'trailingAmount', 'callbackValue');
280685
+ const trailingPercent = this.safeString2(params, 'trailingPercent', 'callbackRate');
280686
+ const isTrailingAmountOrder = trailingAmount !== undefined;
280687
+ const isTrailingPercentOrder = trailingPercent !== undefined;
280688
+ const isTrailing = isTrailingAmountOrder || isTrailingPercentOrder;
280689
+ if (isTrailing) {
280690
+ if (trailingTriggerPrice !== undefined) {
280691
+ request['activatedPrice'] = this.priceToPrecision(symbol, trailingTriggerPrice);
280692
+ }
280693
+ if (isTrailingAmountOrder) {
280694
+ request['callbackValue'] = trailingAmount;
280695
+ }
280696
+ else if (isTrailingPercentOrder) {
280697
+ const convertedTrailingPercent = _base_Precise_js__WEBPACK_IMPORTED_MODULE_3__/* .Precise */ .O.stringDiv(trailingPercent, '100');
280698
+ request['callbackRate'] = convertedTrailingPercent;
280699
+ }
280700
+ }
280701
+ params = this.omit(params, ['clOrdID', 'clientOrderId', 'client_order_id', 'stopPrice', 'triggerPrice', 'takeProfitPrice', 'stopLossPrice', 'trailingTriggerPrice', 'trailingAmount', 'trailingPercent']);
280702
+ const isStop = isTrailing || (stopPrice !== undefined) || (this.safeValue(params, 'childOrders') !== undefined);
280396
280703
  let response = undefined;
280397
280704
  if (isByClientOrder) {
280398
280705
  request['client_order_id'] = clientOrderIdExchangeSpecific;
@@ -280592,9 +280899,9 @@ class woo extends _abstract_woo_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */
280592
280899
  /**
280593
280900
  * @method
280594
280901
  * @name woo#fetchOrders
280902
+ * @description fetches information on multiple orders made by the user
280595
280903
  * @see https://docs.woo.org/#get-orders
280596
280904
  * @see https://docs.woo.org/#get-algo-orders
280597
- * @description fetches information on multiple orders made by the user
280598
280905
  * @param {string} symbol unified market symbol of the market orders were made in
280599
280906
  * @param {int} [since] the earliest time in ms to fetch orders for
280600
280907
  * @param {int} [limit] the maximum number of order structures to retrieve
@@ -280602,19 +280909,21 @@ class woo extends _abstract_woo_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */
280602
280909
  * @param {boolean} [params.stop] whether the order is a stop/algo order
280603
280910
  * @param {boolean} [params.isTriggered] whether the order has been triggered (false by default)
280604
280911
  * @param {string} [params.side] 'buy' or 'sell'
280912
+ * @param {boolean} [params.trailing] set to true if you want to fetch trailing orders
280605
280913
  * @returns {Order[]} a list of [order structures]{@link https://docs.ccxt.com/#/?id=order-structure}
280606
280914
  */
280607
280915
  await this.loadMarkets();
280608
280916
  const request = {};
280609
280917
  let market = undefined;
280610
280918
  const stop = this.safeValue(params, 'stop');
280611
- params = this.omit(params, 'stop');
280919
+ const trailing = this.safeValue(params, 'trailing', false);
280920
+ params = this.omit(params, ['stop', 'trailing']);
280612
280921
  if (symbol !== undefined) {
280613
280922
  market = this.market(symbol);
280614
280923
  request['symbol'] = market['id'];
280615
280924
  }
280616
280925
  if (since !== undefined) {
280617
- if (stop) {
280926
+ if (stop || trailing) {
280618
280927
  request['createdTimeStart'] = since;
280619
280928
  }
280620
280929
  else {
@@ -280624,8 +280933,11 @@ class woo extends _abstract_woo_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */
280624
280933
  if (stop) {
280625
280934
  request['algoType'] = 'stop';
280626
280935
  }
280936
+ else if (trailing) {
280937
+ request['algoType'] = 'TRAILING_STOP';
280938
+ }
280627
280939
  let response = undefined;
280628
- if (stop) {
280940
+ if (stop || trailing) {
280629
280941
  response = await this.v3PrivateGetAlgoOrders(this.extend(request, params));
280630
280942
  }
280631
280943
  else {
@@ -291588,7 +291900,7 @@ SOFTWARE.
291588
291900
 
291589
291901
  //-----------------------------------------------------------------------------
291590
291902
  // this is updated by vss.js when building
291591
- const version = '4.2.4';
291903
+ const version = '4.2.6';
291592
291904
  _src_base_Exchange_js__WEBPACK_IMPORTED_MODULE_0__/* .Exchange */ .e.ccxtVersion = version;
291593
291905
  //-----------------------------------------------------------------------------
291594
291906