ccxt 4.1.97 → 4.1.99

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 (46) hide show
  1. package/README.md +3 -3
  2. package/build.sh +1 -1
  3. package/dist/ccxt.browser.js +524 -230
  4. package/dist/ccxt.browser.min.js +2 -2
  5. package/dist/cjs/ccxt.js +1 -1
  6. package/dist/cjs/src/base/Exchange.js +29 -0
  7. package/dist/cjs/src/binance.js +113 -91
  8. package/dist/cjs/src/bingx.js +58 -9
  9. package/dist/cjs/src/bitget.js +108 -51
  10. package/dist/cjs/src/bitmart.js +71 -17
  11. package/dist/cjs/src/bitvavo.js +52 -14
  12. package/dist/cjs/src/coinex.js +58 -21
  13. package/dist/cjs/src/kraken.js +21 -16
  14. package/dist/cjs/src/phemex.js +3 -3
  15. package/dist/cjs/src/pro/binance.js +1 -1
  16. package/dist/cjs/src/pro/bingx.js +6 -3
  17. package/dist/cjs/src/pro/bitget.js +1 -1
  18. package/dist/cjs/src/pro/bitmart.js +1 -1
  19. package/dist/cjs/src/pro/bybit.js +1 -1
  20. package/js/ccxt.d.ts +1 -1
  21. package/js/ccxt.js +1 -1
  22. package/js/src/abstract/binance.d.ts +16 -0
  23. package/js/src/abstract/binancecoinm.d.ts +16 -0
  24. package/js/src/abstract/binanceus.d.ts +16 -0
  25. package/js/src/abstract/binanceusdm.d.ts +16 -0
  26. package/js/src/abstract/coinex.d.ts +14 -1
  27. package/js/src/base/Exchange.d.ts +4 -0
  28. package/js/src/base/Exchange.js +29 -0
  29. package/js/src/binance.js +113 -91
  30. package/js/src/bingx.d.ts +1 -0
  31. package/js/src/bingx.js +58 -9
  32. package/js/src/bitget.js +108 -51
  33. package/js/src/bitmart.js +71 -17
  34. package/js/src/bitvavo.js +52 -14
  35. package/js/src/coinex.js +58 -21
  36. package/js/src/kraken.js +21 -16
  37. package/js/src/phemex.js +3 -3
  38. package/js/src/pro/binance.js +1 -1
  39. package/js/src/pro/bingx.js +6 -3
  40. package/js/src/pro/bitget.js +1 -1
  41. package/js/src/pro/bitmart.js +1 -1
  42. package/js/src/pro/bybit.js +1 -1
  43. package/js/src/static_dependencies/jsencrypt/lib/jsbn/jsbn.d.ts +1 -1
  44. package/package.json +13 -13
  45. package/skip-tests.json +119 -71
  46. package/run-tests-ws.js +0 -290
@@ -2125,7 +2125,7 @@ class bitmart extends bitmart$1 {
2125
2125
  if (priceString === 'market price') {
2126
2126
  priceString = undefined;
2127
2127
  }
2128
- const trailingStopActivationPrice = this.safeNumber(order, 'activation_price');
2128
+ const trailingActivationPrice = this.safeNumber(order, 'activation_price');
2129
2129
  return this.safeOrder({
2130
2130
  'id': id,
2131
2131
  'clientOrderId': this.safeString(order, 'client_order_id'),
@@ -2139,8 +2139,8 @@ class bitmart extends bitmart$1 {
2139
2139
  'postOnly': postOnly,
2140
2140
  'side': this.parseOrderSide(this.safeString(order, 'side')),
2141
2141
  'price': this.omitZero(priceString),
2142
- 'stopPrice': trailingStopActivationPrice,
2143
- 'triggerPrice': trailingStopActivationPrice,
2142
+ 'stopPrice': trailingActivationPrice,
2143
+ 'triggerPrice': trailingActivationPrice,
2144
2144
  'amount': this.omitZero(this.safeString(order, 'size')),
2145
2145
  'cost': this.safeString2(order, 'filled_notional', 'filledNotional'),
2146
2146
  'average': this.safeStringN(order, ['price_avg', 'priceAvg', 'deal_avg_price']),
@@ -2212,6 +2212,7 @@ class bitmart extends bitmart$1 {
2212
2212
  * @see https://developer-pro.bitmart.com/en/spot/#new-order-v2-signed
2213
2213
  * @see https://developer-pro.bitmart.com/en/spot/#place-margin-order
2214
2214
  * @see https://developer-pro.bitmart.com/en/futures/#submit-order-signed
2215
+ * @see https://developer-pro.bitmart.com/en/futures/#submit-plan-order-signed
2215
2216
  * @param {string} symbol unified symbol of the market to create an order in
2216
2217
  * @param {string} type 'market', 'limit' or 'trailing' for swap markets only
2217
2218
  * @param {string} side 'buy' or 'sell'
@@ -2223,12 +2224,20 @@ class bitmart extends bitmart$1 {
2223
2224
  * @param {string} [params.clientOrderId] client order id of the order
2224
2225
  * @param {boolean} [params.reduceOnly] *swap only* reduce only
2225
2226
  * @param {boolean} [params.postOnly] make sure the order is posted to the order book and not matched immediately
2227
+ * @param {string} [params.triggerPrice] *swap only* the price to trigger a stop order
2228
+ * @param {int} [params.price_type] *swap only* 1: last price, 2: fair price, default is 1
2229
+ * @param {int} [params.price_way] *swap only* 1: price way long, 2: price way short
2230
+ * @param {int} [params.activation_price_type] *swap trailing order only* 1: last price, 2: fair price, default is 1
2231
+ * @param {string} [params.trailingPercent] *swap only* the percent to trail away from the current market price, min 0.1 max 5
2232
+ * @param {string} [params.trailingTriggerPrice] *swap only* the price to trigger a trailing order, default uses the price argument
2226
2233
  * @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
2227
2234
  */
2228
2235
  await this.loadMarkets();
2229
2236
  const market = this.market(symbol);
2230
2237
  const result = this.handleMarginModeAndParams('createOrder', params);
2231
2238
  const marginMode = this.safeString(result, 0);
2239
+ const triggerPrice = this.safeStringN(params, ['triggerPrice', 'stopPrice', 'trigger_price']);
2240
+ const isTriggerOrder = triggerPrice !== undefined;
2232
2241
  let response = undefined;
2233
2242
  if (market['spot']) {
2234
2243
  const spotRequest = this.createSpotOrderRequest(symbol, type, side, amount, price, params);
@@ -2241,7 +2250,12 @@ class bitmart extends bitmart$1 {
2241
2250
  }
2242
2251
  else {
2243
2252
  const swapRequest = this.createSwapOrderRequest(symbol, type, side, amount, price, params);
2244
- response = await this.privatePostContractPrivateSubmitOrder(swapRequest);
2253
+ if (isTriggerOrder) {
2254
+ response = await this.privatePostContractPrivateSubmitPlanOrder(swapRequest);
2255
+ }
2256
+ else {
2257
+ response = await this.privatePostContractPrivateSubmitOrder(swapRequest);
2258
+ }
2245
2259
  }
2246
2260
  //
2247
2261
  // spot and margin
@@ -2273,6 +2287,7 @@ class bitmart extends bitmart$1 {
2273
2287
  * @ignore
2274
2288
  * @description create a trade order
2275
2289
  * @see https://developer-pro.bitmart.com/en/futures/#submit-order-signed
2290
+ * @see https://developer-pro.bitmart.com/en/futures/#submit-plan-order-signed
2276
2291
  * @param {string} symbol unified symbol of the market to create an order in
2277
2292
  * @param {string} type 'market', 'limit' or 'trailing'
2278
2293
  * @param {string} side 'buy' or 'sell'
@@ -2283,8 +2298,12 @@ class bitmart extends bitmart$1 {
2283
2298
  * @param {boolean} [params.reduceOnly] *swap only* reduce only
2284
2299
  * @param {string} [params.marginMode] 'cross' or 'isolated', default is 'cross'
2285
2300
  * @param {string} [params.clientOrderId] client order id of the order
2301
+ * @param {string} [params.triggerPrice] *swap only* the price to trigger a stop order
2302
+ * @param {int} [params.price_type] *swap only* 1: last price, 2: fair price, default is 1
2303
+ * @param {int} [params.price_way] *swap only* 1: price way long, 2: price way short
2286
2304
  * @param {int} [params.activation_price_type] *swap trailing order only* 1: last price, 2: fair price, default is 1
2287
- * @param {string} [params.callback_rate] *swap trailing order only* min 0.1, max 5 where 1 is 1%, default is "1"
2305
+ * @param {string} [params.trailingPercent] *swap only* the percent to trail away from the current market price, min 0.1 max 5
2306
+ * @param {string} [params.trailingTriggerPrice] *swap only* the price to trigger a trailing order, default uses the price argument
2288
2307
  * @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
2289
2308
  */
2290
2309
  const market = this.market(symbol);
@@ -2297,10 +2316,9 @@ class bitmart extends bitmart$1 {
2297
2316
  const mode = this.safeInteger(params, 'mode'); // only for swap
2298
2317
  const isMarketOrder = type === 'market';
2299
2318
  let postOnly = undefined;
2300
- let reduceOnly = this.safeValue(params, 'reduceOnly');
2319
+ const reduceOnly = this.safeValue(params, 'reduceOnly');
2301
2320
  const isExchangeSpecificPo = (mode === 4);
2302
2321
  [postOnly, params] = this.handlePostOnly(isMarketOrder, isExchangeSpecificPo, params);
2303
- params = this.omit(params, ['timeInForce', 'postOnly', 'reduceOnly']);
2304
2322
  const ioc = ((timeInForce === 'IOC') || (mode === 3));
2305
2323
  const isLimitOrder = (type === 'limit') || postOnly || ioc;
2306
2324
  if (timeInForce === 'GTC') {
@@ -2315,14 +2333,39 @@ class bitmart extends bitmart$1 {
2315
2333
  if (postOnly) {
2316
2334
  request['mode'] = 4;
2317
2335
  }
2336
+ const triggerPrice = this.safeStringN(params, ['triggerPrice', 'stopPrice', 'trigger_price']);
2337
+ const isTriggerOrder = triggerPrice !== undefined;
2338
+ const trailingTriggerPrice = this.safeString2(params, 'trailingTriggerPrice', 'activation_price', price);
2339
+ const trailingPercent = this.safeString2(params, 'trailingPercent', 'callback_rate');
2340
+ const isTrailingPercentOrder = trailingPercent !== undefined;
2318
2341
  if (isLimitOrder) {
2319
2342
  request['price'] = this.priceToPrecision(symbol, price);
2320
2343
  }
2321
- else if (type === 'trailing') {
2322
- reduceOnly = true;
2323
- request['activation_price'] = this.priceToPrecision(symbol, price);
2344
+ else if (type === 'trailing' || isTrailingPercentOrder) {
2345
+ request['callback_rate'] = trailingPercent;
2346
+ request['activation_price'] = this.priceToPrecision(symbol, trailingTriggerPrice);
2324
2347
  request['activation_price_type'] = this.safeInteger(params, 'activation_price_type', 1);
2325
- request['callback_rate'] = this.safeString(params, 'callback_rate', '1');
2348
+ }
2349
+ if (isTriggerOrder) {
2350
+ request['executive_price'] = this.priceToPrecision(symbol, price);
2351
+ request['trigger_price'] = this.priceToPrecision(symbol, triggerPrice);
2352
+ request['price_type'] = this.safeInteger(params, 'price_type', 1);
2353
+ if (side === 'buy') {
2354
+ if (reduceOnly) {
2355
+ request['price_way'] = 2;
2356
+ }
2357
+ else {
2358
+ request['price_way'] = 1;
2359
+ }
2360
+ }
2361
+ else if (side === 'sell') {
2362
+ if (reduceOnly) {
2363
+ request['price_way'] = 1;
2364
+ }
2365
+ else {
2366
+ request['price_way'] = 2;
2367
+ }
2368
+ }
2326
2369
  }
2327
2370
  if (side === 'buy') {
2328
2371
  if (reduceOnly) {
@@ -2349,7 +2392,7 @@ class bitmart extends bitmart$1 {
2349
2392
  request['client_order_id'] = clientOrderId;
2350
2393
  }
2351
2394
  const leverage = this.safeInteger(params, 'leverage', 1);
2352
- params = this.omit(params, 'leverage');
2395
+ params = this.omit(params, ['timeInForce', 'postOnly', 'reduceOnly', 'leverage', 'trailingTriggerPrice', 'trailingPercent', 'triggerPrice', 'stopPrice']);
2353
2396
  request['leverage'] = this.numberToString(leverage);
2354
2397
  return this.extend(request, params);
2355
2398
  }
@@ -2431,10 +2474,11 @@ class bitmart extends bitmart$1 {
2431
2474
  /**
2432
2475
  * @method
2433
2476
  * @name bitmart#cancelOrder
2477
+ * @description cancels an open order
2434
2478
  * @see https://developer-pro.bitmart.com/en/futures/#cancel-order-signed
2435
2479
  * @see https://developer-pro.bitmart.com/en/spot/#cancel-order-v3-signed
2436
2480
  * @see https://developer-pro.bitmart.com/en/futures/#cancel-plan-order-signed
2437
- * @description cancels an open order
2481
+ * @see https://developer-pro.bitmart.com/en/futures/#cancel-plan-order-signed
2438
2482
  * @param {string} id order id
2439
2483
  * @param {string} symbol unified symbol of the market the order was made in
2440
2484
  * @param {object} [params] extra parameters specific to the exchange API endpoint
@@ -2644,6 +2688,7 @@ class bitmart extends bitmart$1 {
2644
2688
  * @param {string} [params.type] *swap* order type, 'limit' or 'market'
2645
2689
  * @param {string} [params.order_state] *swap* the order state, 'all' or 'partially_filled', default is 'all'
2646
2690
  * @param {string} [params.orderType] *swap only* 'limit', 'market', or 'trailing'
2691
+ * @param {boolean} [params.trailing] *swap only* set to true if you want to fetch trailing orders
2647
2692
  * @returns {Order[]} a list of [order structures]{@link https://docs.ccxt.com/#/?id=order-structure}
2648
2693
  */
2649
2694
  await this.loadMarkets();
@@ -2676,8 +2721,12 @@ class bitmart extends bitmart$1 {
2676
2721
  response = await this.privatePostSpotV4QueryOpenOrders(this.extend(request, params));
2677
2722
  }
2678
2723
  else if (type === 'swap') {
2679
- const orderType = this.safeString(params, 'orderType');
2680
- params = this.omit(params, 'orderType');
2724
+ const trailing = this.safeValue(params, 'trailing', false);
2725
+ let orderType = this.safeString(params, 'orderType');
2726
+ params = this.omit(params, ['orderType', 'trailing']);
2727
+ if (trailing) {
2728
+ orderType = 'trailing';
2729
+ }
2681
2730
  if (orderType !== undefined) {
2682
2731
  request['type'] = orderType;
2683
2732
  }
@@ -2823,6 +2872,7 @@ class bitmart extends bitmart$1 {
2823
2872
  * @param {object} [params] extra parameters specific to the exchange API endpoint
2824
2873
  * @param {string} [params.clientOrderId] *spot* fetch the order by client order id instead of order id
2825
2874
  * @param {string} [params.orderType] *swap only* 'limit', 'market', 'liquidate', 'bankruptcy', 'adl' or 'trailing'
2875
+ * @param {boolean} [params.trailing] *swap only* set to true if you want to fetch a trailing order
2826
2876
  * @returns {object} An [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
2827
2877
  */
2828
2878
  await this.loadMarkets();
@@ -2850,8 +2900,12 @@ class bitmart extends bitmart$1 {
2850
2900
  if (symbol === undefined) {
2851
2901
  throw new errors.ArgumentsRequired(this.id + ' fetchOrder() requires a symbol argument');
2852
2902
  }
2853
- const orderType = this.safeString(params, 'orderType');
2854
- params = this.omit(params, 'orderType');
2903
+ const trailing = this.safeValue(params, 'trailing', false);
2904
+ let orderType = this.safeString(params, 'orderType');
2905
+ params = this.omit(params, ['orderType', 'trailing']);
2906
+ if (trailing) {
2907
+ orderType = 'trailing';
2908
+ }
2855
2909
  if (orderType !== undefined) {
2856
2910
  request['type'] = orderType;
2857
2911
  }
@@ -989,7 +989,7 @@ class bitvavo extends bitvavo$1 {
989
989
  * @method
990
990
  * @name bitvavo#createOrder
991
991
  * @description create a trade order
992
- * @see https://docs.bitvavo.com/#tag/Orders/paths/~1order/post
992
+ * @see https://docs.bitvavo.com/#tag/Trading-endpoints/paths/~1order/post
993
993
  * @param {string} symbol unified symbol of the market to create an order in
994
994
  * @param {string} type 'market' or 'limit'
995
995
  * @param {string} side 'buy' or 'sell'
@@ -1007,6 +1007,7 @@ class bitvavo extends bitvavo$1 {
1007
1007
  * @param {string} [params.selfTradePrevention] "decrementAndCancel", "cancelOldest", "cancelNewest", "cancelBoth"
1008
1008
  * @param {bool} [params.disableMarketProtection] don't cancel if the next fill price is 10% worse than the best fill price
1009
1009
  * @param {bool} [params.responseRequired] Set this to 'false' when only an acknowledgement of success or failure is required, this is faster.
1010
+ * @param {string} [params.clientOrderId] An ID supplied by the client that must be unique among all open orders for the same market
1010
1011
  * @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
1011
1012
  */
1012
1013
  await this.loadMarkets();
@@ -1117,25 +1118,54 @@ class bitvavo extends bitvavo$1 {
1117
1118
  return this.parseOrder(response, market);
1118
1119
  }
1119
1120
  async editOrder(id, symbol, type, side, amount = undefined, price = undefined, params = {}) {
1121
+ /**
1122
+ * @method
1123
+ * @name bitvavo#editOrder
1124
+ * @description edit a trade order
1125
+ * @see https://docs.bitvavo.com/#tag/Trading-endpoints/paths/~1order/put
1126
+ * @param {string} symbol unified symbol of the market to create an order in
1127
+ * @param {string} type 'market' or 'limit'
1128
+ * @param {string} side 'buy' or 'sell'
1129
+ * @param {float} amount how much of currency you want to trade in units of base currency
1130
+ * @param {float} [price] the price at which the order is to be fullfilled, in units of the quote currency, ignored in market orders
1131
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
1132
+ * @param {string} [params.timeInForce] "GTC", "IOC", or "PO"
1133
+ * @param {bool} [params.postOnly] If true, the order will only be posted to the order book and not executed immediately
1134
+ * @param {float} [params.stopPrice] The price at which a trigger order is triggered at
1135
+ * @param {float} [params.triggerPrice] The price at which a trigger order is triggered at
1136
+ * @param {string} [params.selfTradePrevention] "decrementAndCancel", "cancelOldest", "cancelNewest", "cancelBoth"
1137
+ * @param {bool} [params.responseRequired] Set this to 'false' when only an acknowledgement of success or failure is required, this is faster.
1138
+ * @param {string} [params.clientOrderId] An ID supplied by the client
1139
+ * @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
1140
+ */
1120
1141
  await this.loadMarkets();
1121
1142
  const market = this.market(symbol);
1122
- let request = {};
1143
+ const request = {
1144
+ 'market': market['id'],
1145
+ };
1146
+ const clientOrderId = this.safeString(params, 'clientOrderId');
1147
+ if (clientOrderId === undefined) {
1148
+ request['orderId'] = id;
1149
+ }
1123
1150
  const amountRemaining = this.safeNumber(params, 'amountRemaining');
1124
- params = this.omit(params, 'amountRemaining');
1151
+ const triggerPrice = this.safeStringN(params, ['triggerPrice', 'stopPrice', 'triggerAmount']);
1152
+ params = this.omit(params, ['amountRemaining', 'triggerPrice', 'stopPrice', 'triggerAmount']);
1153
+ let updateRequest = {};
1125
1154
  if (price !== undefined) {
1126
- request['price'] = this.priceToPrecision(symbol, price);
1155
+ updateRequest['price'] = this.priceToPrecision(symbol, price);
1127
1156
  }
1128
1157
  if (amount !== undefined) {
1129
- request['amount'] = this.amountToPrecision(symbol, amount);
1158
+ updateRequest['amount'] = this.amountToPrecision(symbol, amount);
1130
1159
  }
1131
1160
  if (amountRemaining !== undefined) {
1132
- request['amountRemaining'] = this.amountToPrecision(symbol, amountRemaining);
1161
+ updateRequest['amountRemaining'] = this.amountToPrecision(symbol, amountRemaining);
1133
1162
  }
1134
- request = this.extend(request, params);
1135
- if (Object.keys(request).length) {
1136
- request['orderId'] = id;
1137
- request['market'] = market['id'];
1138
- const response = await this.privatePutOrder(this.extend(request, params));
1163
+ if (triggerPrice !== undefined) {
1164
+ updateRequest['triggerAmount'] = this.priceToPrecision(symbol, triggerPrice);
1165
+ }
1166
+ updateRequest = this.extend(updateRequest, params);
1167
+ if (Object.keys(updateRequest).length) {
1168
+ const response = await this.privatePutOrder(this.extend(request, updateRequest));
1139
1169
  return this.parseOrder(response, market);
1140
1170
  }
1141
1171
  else {
@@ -1147,6 +1177,7 @@ class bitvavo extends bitvavo$1 {
1147
1177
  * @method
1148
1178
  * @name bitvavo#cancelOrder
1149
1179
  * @description cancels an open order
1180
+ * @see https://docs.bitvavo.com/#tag/Trading-endpoints/paths/~1order/delete
1150
1181
  * @param {string} id order id
1151
1182
  * @param {string} symbol unified symbol of the market the order was made in
1152
1183
  * @param {object} [params] extra parameters specific to the exchange API endpoint
@@ -1158,9 +1189,12 @@ class bitvavo extends bitvavo$1 {
1158
1189
  await this.loadMarkets();
1159
1190
  const market = this.market(symbol);
1160
1191
  const request = {
1161
- 'orderId': id,
1162
1192
  'market': market['id'],
1163
1193
  };
1194
+ const clientOrderId = this.safeString(params, 'clientOrderId');
1195
+ if (clientOrderId === undefined) {
1196
+ request['orderId'] = id;
1197
+ }
1164
1198
  const response = await this.privateDeleteOrder(this.extend(request, params));
1165
1199
  //
1166
1200
  // {
@@ -1200,6 +1234,7 @@ class bitvavo extends bitvavo$1 {
1200
1234
  * @method
1201
1235
  * @name bitvavo#fetchOrder
1202
1236
  * @description fetches information on an order made by the user
1237
+ * @see https://docs.bitvavo.com/#tag/Trading-endpoints/paths/~1order/get
1203
1238
  * @param {string} symbol unified symbol of the market the order was made in
1204
1239
  * @param {object} [params] extra parameters specific to the exchange API endpoint
1205
1240
  * @returns {object} An [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
@@ -1210,9 +1245,12 @@ class bitvavo extends bitvavo$1 {
1210
1245
  await this.loadMarkets();
1211
1246
  const market = this.market(symbol);
1212
1247
  const request = {
1213
- 'orderId': id,
1214
1248
  'market': market['id'],
1215
1249
  };
1250
+ const clientOrderId = this.safeString(params, 'clientOrderId');
1251
+ if (clientOrderId === undefined) {
1252
+ request['orderId'] = id;
1253
+ }
1216
1254
  const response = await this.privateGetOrder(this.extend(request, params));
1217
1255
  //
1218
1256
  // {
@@ -1254,7 +1292,7 @@ class bitvavo extends bitvavo$1 {
1254
1292
  /**
1255
1293
  * @method
1256
1294
  * @name bitvavo#fetchOrders
1257
- * @see https://docs.bitvavo.com/#tag/Orders/paths/~1orders/get
1295
+ * @see https://docs.bitvavo.com/#tag/Trading-endpoints/paths/~1orders/get
1258
1296
  * @description fetches information on multiple orders made by the user
1259
1297
  * @param {string} symbol unified market symbol of the market orders were made in
1260
1298
  * @param {int} [since] the earliest time in ms to fetch orders for
@@ -208,6 +208,8 @@ class coinex extends coinex$1 {
208
208
  },
209
209
  'put': {
210
210
  'balance/deposit/address/{coin_type}': 40,
211
+ 'sub_account/unfrozen': 40,
212
+ 'sub_account/frozen': 40,
211
213
  'sub_account/auth/api/{user_auth_id}': 40,
212
214
  'v1/account/settings': 40,
213
215
  },
@@ -217,7 +219,10 @@ class coinex extends coinex$1 {
217
219
  'order/pending': 13.334,
218
220
  'order/stop/pending': 40,
219
221
  'order/stop/pending/{id}': 13.334,
222
+ 'order/pending/by_client_id': 40,
223
+ 'order/stop/pending/by_client_id': 40,
220
224
  'sub_account/auth/api/{user_auth_id}': 40,
225
+ 'sub_account/authorize/{id}': 40,
221
226
  },
222
227
  },
223
228
  'perpetualPublic': {
@@ -231,12 +236,12 @@ class coinex extends coinex$1 {
231
236
  'market/depth': 1,
232
237
  'market/deals': 1,
233
238
  'market/funding_history': 1,
234
- 'market/user_deals': 1,
235
239
  'market/kline': 1,
236
240
  },
237
241
  },
238
242
  'perpetualPrivate': {
239
243
  'get': {
244
+ 'market/user_deals': 1,
240
245
  'asset/query': 40,
241
246
  'order/pending': 8,
242
247
  'order/finished': 40,
@@ -244,8 +249,13 @@ class coinex extends coinex$1 {
244
249
  'order/stop_pending': 8,
245
250
  'order/status': 8,
246
251
  'order/stop_status': 8,
252
+ 'position/finished': 40,
247
253
  'position/pending': 40,
248
254
  'position/funding': 40,
255
+ 'position/adl_history': 40,
256
+ 'market/preference': 40,
257
+ 'position/margin_history': 40,
258
+ 'position/settle_history': 40,
249
259
  },
250
260
  'post': {
251
261
  'market/adjust_leverage': 1,
@@ -267,6 +277,9 @@ class coinex extends coinex$1 {
267
277
  'position/stop_loss': 20,
268
278
  'position/take_profit': 20,
269
279
  'position/market_close': 20,
280
+ 'order/cancel/by_client_id': 20,
281
+ 'order/cancel_stop/by_client_id': 20,
282
+ 'market/preference': 20,
270
283
  },
271
284
  },
272
285
  },
@@ -1087,9 +1100,10 @@ class coinex extends coinex$1 {
1087
1100
  const priceString = this.safeString(trade, 'price');
1088
1101
  const amountString = this.safeString(trade, 'amount');
1089
1102
  const marketId = this.safeString(trade, 'market');
1090
- const defaultType = this.safeString(this.options, 'defaultType');
1103
+ const marketType = this.safeString(trade, 'market_type');
1104
+ const defaultType = (marketType === undefined) ? 'spot' : 'swap';
1091
1105
  market = this.safeMarket(marketId, market, undefined, defaultType);
1092
- const symbol = this.safeSymbol(marketId, market, undefined, defaultType);
1106
+ const symbol = market['symbol'];
1093
1107
  const costString = this.safeString(trade, 'deal_money');
1094
1108
  let fee = undefined;
1095
1109
  const feeCostString = this.safeString2(trade, 'fee', 'deal_fee');
@@ -2587,11 +2601,17 @@ class coinex extends coinex$1 {
2587
2601
  * @description cancels an open order
2588
2602
  * @see https://viabtc.github.io/coinex_api_en_doc/spot/#docsspot003_trade018_cancle_stop_pending_order
2589
2603
  * @see https://viabtc.github.io/coinex_api_en_doc/spot/#docsspot003_trade015_cancel_order
2604
+ * @see https://viabtc.github.io/coinex_api_en_doc/spot/#docsspot003_trade024_cancel_order_by_client_id
2605
+ * @see https://viabtc.github.io/coinex_api_en_doc/spot/#docsspot003_trade025_cancel_stop_order_by_client_id
2590
2606
  * @see https://viabtc.github.io/coinex_api_en_doc/futures/#docsfutures001_http023_cancel_stop_order
2591
2607
  * @see https://viabtc.github.io/coinex_api_en_doc/futures/#docsfutures001_http021_cancel_order
2608
+ * @see https://viabtc.github.io/coinex_api_en_doc/futures/#docsfutures001_http042_cancel_order_by_client_id
2609
+ * @see https://viabtc.github.io/coinex_api_en_doc/futures/#docsfutures001_http043_cancel_stop_order_by_client_id
2592
2610
  * @param {string} id order id
2593
2611
  * @param {string} symbol unified symbol of the market the order was made in
2594
2612
  * @param {object} [params] extra parameters specific to the exchange API endpoint
2613
+ * @param {string} [params.clientOrderId] client order id, defaults to id if not passed
2614
+ * @param {boolean} [params.stop] if stop order = true, default = false
2595
2615
  * @returns {object} An [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
2596
2616
  */
2597
2617
  if (symbol === undefined) {
@@ -2604,32 +2624,54 @@ class coinex extends coinex$1 {
2604
2624
  const request = {
2605
2625
  'market': market['id'],
2606
2626
  };
2607
- const idRequest = swap ? 'order_id' : 'id';
2608
- request[idRequest] = id;
2609
2627
  const accountId = this.safeInteger(params, 'account_id');
2610
2628
  const defaultType = this.safeString(this.options, 'defaultType');
2629
+ const clientOrderId = this.safeString2(params, 'client_id', 'clientOrderId');
2611
2630
  if (defaultType === 'margin') {
2612
2631
  if (accountId === undefined) {
2613
2632
  throw new errors.BadRequest(this.id + ' cancelOrder() requires an account_id parameter for margin orders');
2614
2633
  }
2615
2634
  request['account_id'] = accountId;
2616
2635
  }
2617
- const query = this.omit(params, ['stop', 'account_id']);
2636
+ const query = this.omit(params, ['stop', 'account_id', 'clientOrderId']);
2618
2637
  let response = undefined;
2619
- if (stop) {
2620
- if (swap) {
2621
- response = await this.perpetualPrivatePostOrderCancelStop(this.extend(request, query));
2638
+ if (clientOrderId !== undefined) {
2639
+ request['client_id'] = clientOrderId;
2640
+ if (stop) {
2641
+ if (swap) {
2642
+ response = await this.perpetualPrivatePostOrderCancelStopByClientId(this.extend(request, query));
2643
+ }
2644
+ else {
2645
+ response = await this.privateDeleteOrderStopPendingByClientId(this.extend(request, query));
2646
+ }
2622
2647
  }
2623
2648
  else {
2624
- response = await this.privateDeleteOrderStopPendingId(this.extend(request, query));
2649
+ if (swap) {
2650
+ response = await this.perpetualPrivatePostOrderCancelByClientId(this.extend(request, query));
2651
+ }
2652
+ else {
2653
+ response = await this.privateDeleteOrderPendingByClientId(this.extend(request, query));
2654
+ }
2625
2655
  }
2626
2656
  }
2627
2657
  else {
2628
- if (swap) {
2629
- response = await this.perpetualPrivatePostOrderCancel(this.extend(request, query));
2658
+ const idRequest = swap ? 'order_id' : 'id';
2659
+ request[idRequest] = id;
2660
+ if (stop) {
2661
+ if (swap) {
2662
+ response = await this.perpetualPrivatePostOrderCancelStop(this.extend(request, query));
2663
+ }
2664
+ else {
2665
+ response = await this.privateDeleteOrderStopPendingId(this.extend(request, query));
2666
+ }
2630
2667
  }
2631
2668
  else {
2632
- response = await this.privateDeleteOrderPending(this.extend(request, query));
2669
+ if (swap) {
2670
+ response = await this.perpetualPrivatePostOrderCancel(this.extend(request, query));
2671
+ }
2672
+ else {
2673
+ response = await this.privateDeleteOrderPending(this.extend(request, query));
2674
+ }
2633
2675
  }
2634
2676
  }
2635
2677
  //
@@ -3371,16 +3413,11 @@ class coinex extends coinex$1 {
3371
3413
  }
3372
3414
  let response = undefined;
3373
3415
  if (swap) {
3374
- const side = this.safeInteger(params, 'side');
3375
- if (side === undefined) {
3376
- throw new errors.ArgumentsRequired(this.id + ' fetchMyTrades() requires a side parameter for swap markets');
3377
- }
3378
3416
  if (since !== undefined) {
3379
3417
  request['start_time'] = since;
3380
3418
  }
3381
- request['side'] = side;
3382
- params = this.omit(params, 'side');
3383
- response = await this.perpetualPublicGetMarketUserDeals(this.extend(request, params));
3419
+ request['side'] = 0;
3420
+ response = await this.perpetualPrivateGetMarketUserDeals(this.extend(request, params));
3384
3421
  }
3385
3422
  else {
3386
3423
  request['page'] = 1;
@@ -5309,7 +5346,7 @@ class coinex extends coinex$1 {
5309
5346
  }
5310
5347
  }
5311
5348
  }
5312
- if (api === 'perpetualPrivate' || url === 'https://api.coinex.com/perpetual/v1/market/user_deals') {
5349
+ if (api === 'perpetualPrivate') {
5313
5350
  this.checkRequiredCredentials();
5314
5351
  query = this.extend({
5315
5352
  'access_id': this.apiKey,
@@ -1357,7 +1357,9 @@ class kraken extends kraken$1 {
1357
1357
  * @param {bool} [params.reduceOnly] *margin only* indicates if this order is to reduce the size of a position
1358
1358
  * @param {float} [params.stopLossPrice] *margin only* the price that a stop loss order is triggered at
1359
1359
  * @param {float} [params.takeProfitPrice] *margin only* the price that a take profit order is triggered at
1360
- * @param {string} [params.trailingStopPrice] *margin only* the quote amount to trail away from the current market price
1360
+ * @param {string} [params.trailingAmount] *margin only* the quote amount to trail away from the current market price
1361
+ * @param {string} [params.trailingLimitAmount] *margin only* the quote amount away from the trailingAmount
1362
+ * @param {string} [params.offset] *margin only* '+' or '-' whether you want the trailingLimitAmount value to be positive or negative, default is negative '-'
1361
1363
  * @param {string} [params.trigger] *margin only* the activation price type, 'last' or 'index', default is 'last'
1362
1364
  * @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
1363
1365
  */
@@ -1618,9 +1620,10 @@ class kraken extends kraken$1 {
1618
1620
  const isStopLossTriggerOrder = stopLossTriggerPrice !== undefined;
1619
1621
  const isTakeProfitTriggerOrder = takeProfitTriggerPrice !== undefined;
1620
1622
  const isStopLossOrTakeProfitTrigger = isStopLossTriggerOrder || isTakeProfitTriggerOrder;
1621
- const trailingStopPrice = this.safeString(params, 'trailingStopPrice');
1622
- const isTrailingStopPriceOrder = trailingStopPrice !== undefined;
1623
- if (type === 'limit') {
1623
+ const trailingAmount = this.safeString(params, 'trailingAmount');
1624
+ const trailingLimitAmount = this.safeString(params, 'trailingLimitAmount');
1625
+ const isTrailingAmountOrder = trailingAmount !== undefined;
1626
+ if ((type === 'limit') && !isTrailingAmountOrder) {
1624
1627
  request['price'] = this.priceToPrecision(symbol, price);
1625
1628
  }
1626
1629
  let reduceOnly = this.safeValue2(params, 'reduceOnly', 'reduce_only');
@@ -1636,19 +1639,19 @@ class kraken extends kraken$1 {
1636
1639
  request['price2'] = this.priceToPrecision(symbol, price);
1637
1640
  reduceOnly = true;
1638
1641
  }
1639
- else if (isTrailingStopPriceOrder) {
1640
- const trailingStopActivationPriceType = this.safeString(params, 'trigger', 'last');
1641
- const trailingStopPriceString = '+' + trailingStopPrice;
1642
- request['trigger'] = trailingStopActivationPriceType;
1643
- reduceOnly = true;
1644
- if (type === 'limit') {
1645
- const trailingStopLimitPriceString = '+' + this.numberToString(price);
1646
- request['price'] = trailingStopPriceString;
1647
- request['price2'] = trailingStopLimitPriceString;
1642
+ else if (isTrailingAmountOrder) {
1643
+ const trailingActivationPriceType = this.safeString(params, 'trigger', 'last');
1644
+ const trailingAmountString = '+' + trailingAmount;
1645
+ request['trigger'] = trailingActivationPriceType;
1646
+ if ((type === 'limit') || (trailingLimitAmount !== undefined)) {
1647
+ const offset = this.safeString(params, 'offset', '-');
1648
+ const trailingLimitAmountString = offset + this.numberToString(trailingLimitAmount);
1649
+ request['price'] = trailingAmountString;
1650
+ request['price2'] = trailingLimitAmountString;
1648
1651
  request['ordertype'] = 'trailing-stop-limit';
1649
1652
  }
1650
1653
  else {
1651
- request['price'] = trailingStopPriceString;
1654
+ request['price'] = trailingAmountString;
1652
1655
  request['ordertype'] = 'trailing-stop';
1653
1656
  }
1654
1657
  }
@@ -1678,7 +1681,7 @@ class kraken extends kraken$1 {
1678
1681
  if (postOnly) {
1679
1682
  request['oflags'] = 'post';
1680
1683
  }
1681
- params = this.omit(params, ['timeInForce', 'reduceOnly', 'stopLossPrice', 'takeProfitPrice', 'trailingStopPrice']);
1684
+ params = this.omit(params, ['timeInForce', 'reduceOnly', 'stopLossPrice', 'takeProfitPrice', 'trailingAmount', 'trailingLimitAmount', 'offset']);
1682
1685
  return [request, params];
1683
1686
  }
1684
1687
  async editOrder(id, symbol, type, side, amount = undefined, price = undefined, params = {}) {
@@ -1696,7 +1699,9 @@ class kraken extends kraken$1 {
1696
1699
  * @param {object} [params] extra parameters specific to the exchange API endpoint
1697
1700
  * @param {float} [params.stopLossPrice] *margin only* the price that a stop loss order is triggered at
1698
1701
  * @param {float} [params.takeProfitPrice] *margin only* the price that a take profit order is triggered at
1699
- * @param {string} [params.trailingStopPrice] *margin only* the quote price away from the current market price
1702
+ * @param {string} [params.trailingAmount] *margin only* the quote price away from the current market price
1703
+ * @param {string} [params.trailingLimitAmount] *margin only* the quote amount away from the trailingAmount
1704
+ * @param {string} [params.offset] *margin only* '+' or '-' whether you want the trailingLimitAmount value to be positive or negative, default is negative '-'
1700
1705
  * @param {string} [params.trigger] *margin only* the activation price type, 'last' or 'index', default is 'last'
1701
1706
  * @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
1702
1707
  */
@@ -4288,7 +4288,7 @@ class phemex extends phemex$1 {
4288
4288
  * @name phemex#setLeverage
4289
4289
  * @description set the level of leverage for a market
4290
4290
  * @see https://github.com/phemex/phemex-api-docs/blob/master/Public-Hedged-Perpetual-API.md#set-leverage
4291
- * @param {float} leverage the rate of leverage
4291
+ * @param {float} leverage the rate of leverage, 100 > leverage > -100 excluding numbers between -1 to 1
4292
4292
  * @param {string} symbol unified market symbol
4293
4293
  * @param {object} [params] extra parameters specific to the exchange API endpoint
4294
4294
  * @param {bool} [params.hedged] set to true if hedged position mode is enabled (by default long and short leverage are set to the same value)
@@ -4301,8 +4301,8 @@ class phemex extends phemex$1 {
4301
4301
  if (symbol === undefined) {
4302
4302
  throw new errors.ArgumentsRequired(this.id + ' setLeverage() requires a symbol argument');
4303
4303
  }
4304
- if ((leverage < 1) || (leverage > 100)) {
4305
- throw new errors.BadRequest(this.id + ' setLeverage() leverage should be between 1 and 100');
4304
+ if ((leverage < -100) || (leverage > 100)) {
4305
+ throw new errors.BadRequest(this.id + ' setLeverage() leverage should be between -100 and 100');
4306
4306
  }
4307
4307
  await this.loadMarkets();
4308
4308
  const isHedged = this.safeValue(params, 'hedged', false);
@@ -19,7 +19,7 @@ class binance extends binance$1 {
19
19
  'watchBalance': true,
20
20
  'watchMyTrades': true,
21
21
  'watchOHLCV': true,
22
- 'watchOHLCVForSymbols': true,
22
+ 'watchOHLCVForSymbols': false,
23
23
  'watchOrderBook': true,
24
24
  'watchOrderBookForSymbols': true,
25
25
  'watchOrders': true,