ccxt 4.4.90 → 4.4.91

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 (55) hide show
  1. package/README.md +5 -6
  2. package/dist/ccxt.browser.min.js +2 -2
  3. package/dist/cjs/ccxt.js +1 -4
  4. package/dist/cjs/src/base/Exchange.js +9 -11
  5. package/dist/cjs/src/base/ws/Client.js +4 -34
  6. package/dist/cjs/src/binance.js +1 -1
  7. package/dist/cjs/src/bitmex.js +2 -1
  8. package/dist/cjs/src/cex.js +61 -0
  9. package/dist/cjs/src/cryptocom.js +21 -2
  10. package/dist/cjs/src/cryptomus.js +1 -1
  11. package/dist/cjs/src/exmo.js +14 -7
  12. package/dist/cjs/src/fmfwio.js +1 -1
  13. package/dist/cjs/src/gate.js +2 -2
  14. package/dist/cjs/src/hyperliquid.js +115 -59
  15. package/dist/cjs/src/kraken.js +29 -1
  16. package/dist/cjs/src/mexc.js +1 -0
  17. package/dist/cjs/src/modetrade.js +2 -2
  18. package/dist/cjs/src/paradex.js +1 -1
  19. package/dist/cjs/src/pro/bitstamp.js +1 -1
  20. package/dist/cjs/src/pro/bybit.js +6 -143
  21. package/dist/cjs/src/pro/kraken.js +251 -264
  22. package/dist/cjs/src/pro/mexc.js +0 -1
  23. package/js/ccxt.d.ts +2 -5
  24. package/js/ccxt.js +2 -4
  25. package/js/src/base/Exchange.d.ts +2 -1
  26. package/js/src/base/Exchange.js +10 -12
  27. package/js/src/base/ws/Client.d.ts +0 -2
  28. package/js/src/base/ws/Client.js +4 -34
  29. package/js/src/binance.js +1 -1
  30. package/js/src/bitmex.js +2 -1
  31. package/js/src/cex.js +61 -0
  32. package/js/src/cryptocom.js +21 -2
  33. package/js/src/cryptomus.js +1 -1
  34. package/js/src/exmo.js +14 -7
  35. package/js/src/fmfwio.js +2 -2
  36. package/js/src/gate.js +2 -2
  37. package/js/src/hyperliquid.d.ts +1 -0
  38. package/js/src/hyperliquid.js +115 -59
  39. package/js/src/kraken.js +29 -1
  40. package/js/src/mexc.js +1 -0
  41. package/js/src/modetrade.js +2 -2
  42. package/js/src/p2b.d.ts +1 -2
  43. package/js/src/paradex.js +1 -1
  44. package/js/src/pro/bitstamp.js +1 -1
  45. package/js/src/pro/bybit.d.ts +0 -1
  46. package/js/src/pro/bybit.js +6 -143
  47. package/js/src/pro/kraken.d.ts +17 -17
  48. package/js/src/pro/kraken.js +251 -264
  49. package/js/src/pro/mexc.js +0 -1
  50. package/js/src/tradeogre.d.ts +1 -2
  51. package/package.json +1 -1
  52. package/js/src/abstract/coinlist.d.ts +0 -60
  53. package/js/src/abstract/coinlist.js +0 -11
  54. package/js/src/coinlist.d.ts +0 -384
  55. package/js/src/coinlist.js +0 -2610
package/dist/cjs/ccxt.js CHANGED
@@ -53,7 +53,6 @@ var coinbaseinternational = require('./src/coinbaseinternational.js');
53
53
  var coincatch = require('./src/coincatch.js');
54
54
  var coincheck = require('./src/coincheck.js');
55
55
  var coinex = require('./src/coinex.js');
56
- var coinlist = require('./src/coinlist.js');
57
56
  var coinmate = require('./src/coinmate.js');
58
57
  var coinmetro = require('./src/coinmetro.js');
59
58
  var coinone = require('./src/coinone.js');
@@ -194,7 +193,7 @@ var xt$1 = require('./src/pro/xt.js');
194
193
 
195
194
  //-----------------------------------------------------------------------------
196
195
  // this is updated by vss.js when building
197
- const version = '4.4.90';
196
+ const version = '4.4.91';
198
197
  Exchange["default"].ccxtVersion = version;
199
198
  const exchanges = {
200
199
  'alpaca': alpaca,
@@ -238,7 +237,6 @@ const exchanges = {
238
237
  'coincatch': coincatch,
239
238
  'coincheck': coincheck,
240
239
  'coinex': coinex,
241
- 'coinlist': coinlist,
242
240
  'coinmate': coinmate,
243
241
  'coinmetro': coinmetro,
244
242
  'coinone': coinone,
@@ -470,7 +468,6 @@ exports.coinbaseinternational = coinbaseinternational;
470
468
  exports.coincatch = coincatch;
471
469
  exports.coincheck = coincheck;
472
470
  exports.coinex = coinex;
473
- exports.coinlist = coinlist;
474
471
  exports.coinmate = coinmate;
475
472
  exports.coinmetro = coinmetro;
476
473
  exports.coinone = coinone;
@@ -1112,17 +1112,12 @@ class Exchange {
1112
1112
  async close() {
1113
1113
  const clients = Object.values(this.clients || {});
1114
1114
  const closedClients = [];
1115
- for (let i = 0; i < clients.length; i++) {
1116
- const client = clients[i];
1117
- client.error = new errors.ExchangeClosedByUser(this.id + ' closedByUser');
1118
- closedClients.push(client.close());
1119
- }
1120
- await Promise.all(closedClients);
1121
1115
  for (let i = 0; i < clients.length; i++) {
1122
1116
  const client = clients[i];
1123
1117
  delete this.clients[client.url];
1118
+ closedClients.push(client.close());
1124
1119
  }
1125
- return;
1120
+ return Promise.all(closedClients);
1126
1121
  }
1127
1122
  async loadOrderBook(client, messageHash, symbol, limit = undefined, params = {}) {
1128
1123
  if (!(symbol in this.orderbooks)) {
@@ -2108,6 +2103,9 @@ class Exchange {
2108
2103
  async watchTrades(symbol, since = undefined, limit = undefined, params = {}) {
2109
2104
  throw new errors.NotSupported(this.id + ' watchTrades() is not supported yet');
2110
2105
  }
2106
+ async unWatchOrders(symbol = undefined, params = {}) {
2107
+ throw new errors.NotSupported(this.id + ' unWatchOrders() is not supported yet');
2108
+ }
2111
2109
  async unWatchTrades(symbol, params = {}) {
2112
2110
  throw new errors.NotSupported(this.id + ' unWatchTrades() is not supported yet');
2113
2111
  }
@@ -7172,7 +7170,7 @@ class Exchange {
7172
7170
  const symbolAndTimeFrame = symbolsAndTimeFrames[i];
7173
7171
  const symbol = this.safeString(symbolAndTimeFrame, 0);
7174
7172
  const timeframe = this.safeString(symbolAndTimeFrame, 1);
7175
- if (symbol in this.ohlcvs) {
7173
+ if ((this.ohlcvs !== undefined) && (symbol in this.ohlcvs)) {
7176
7174
  if (timeframe in this.ohlcvs[symbol]) {
7177
7175
  delete this.ohlcvs[symbol][timeframe];
7178
7176
  }
@@ -7200,7 +7198,7 @@ class Exchange {
7200
7198
  }
7201
7199
  }
7202
7200
  else {
7203
- if (topic === 'myTrades') {
7201
+ if (topic === 'myTrades' && (this.myTrades !== undefined)) {
7204
7202
  // don't reset this.myTrades directly here
7205
7203
  // because in c# we need to use a different object (thread-safe dict)
7206
7204
  const keys = Object.keys(this.myTrades);
@@ -7211,7 +7209,7 @@ class Exchange {
7211
7209
  }
7212
7210
  }
7213
7211
  }
7214
- else if (topic === 'orders') {
7212
+ else if (topic === 'orders' && (this.orders !== undefined)) {
7215
7213
  const orderSymbols = Object.keys(this.orders);
7216
7214
  for (let i = 0; i < orderSymbols.length; i++) {
7217
7215
  const orderSymbol = orderSymbols[i];
@@ -7220,7 +7218,7 @@ class Exchange {
7220
7218
  }
7221
7219
  }
7222
7220
  }
7223
- else if (topic === 'ticker') {
7221
+ else if (topic === 'ticker' && (this.tickers !== undefined)) {
7224
7222
  const tickerSymbols = Object.keys(this.tickers);
7225
7223
  for (let i = 0; i < tickerSymbols.length; i++) {
7226
7224
  const tickerSymbol = tickerSymbols[i];
@@ -13,7 +13,6 @@ var index = require('../../static_dependencies/scure-base/index.js');
13
13
  // ----------------------------------------------------------------------------
14
14
  class Client {
15
15
  constructor(url, onMessageCallback, onErrorCallback, onCloseCallback, onConnectedCallback, config = {}) {
16
- this.useMessageQueue = false;
17
16
  this.verbose = false;
18
17
  const defaults = {
19
18
  url,
@@ -27,8 +26,6 @@ class Client {
27
26
  futures: {},
28
27
  subscriptions: {},
29
28
  rejections: {},
30
- messageQueue: {},
31
- useMessageQueue: false,
32
29
  connected: undefined,
33
30
  error: undefined,
34
31
  connectionStarted: undefined,
@@ -59,15 +56,6 @@ class Client {
59
56
  if (messageHash in this.rejections) {
60
57
  future.reject(this.rejections[messageHash]);
61
58
  delete this.rejections[messageHash];
62
- delete this.messageQueue[messageHash];
63
- return future;
64
- }
65
- if (this.useMessageQueue) {
66
- const queue = this.messageQueue[messageHash];
67
- if (queue && queue.length) {
68
- future.resolve(queue.shift());
69
- delete this.futures[messageHash];
70
- }
71
59
  }
72
60
  return future;
73
61
  }
@@ -75,27 +63,10 @@ class Client {
75
63
  if (this.verbose && (messageHash === undefined)) {
76
64
  this.log(new Date(), 'resolve received undefined messageHash');
77
65
  }
78
- if (this.useMessageQueue === true) {
79
- if (!(messageHash in this.messageQueue)) {
80
- this.messageQueue[messageHash] = [];
81
- }
82
- const queue = this.messageQueue[messageHash];
83
- queue.push(result);
84
- while (queue.length > 10) { // limit size to 10 messages in the queue
85
- queue.shift();
86
- }
87
- if ((messageHash !== undefined) && (messageHash in this.futures)) {
88
- const promise = this.futures[messageHash];
89
- promise.resolve(queue.shift());
90
- delete this.futures[messageHash];
91
- }
92
- }
93
- else {
94
- if (messageHash in this.futures) {
95
- const promise = this.futures[messageHash];
96
- promise.resolve(result);
97
- delete this.futures[messageHash];
98
- }
66
+ if ((messageHash !== undefined) && (messageHash in this.futures)) {
67
+ const promise = this.futures[messageHash];
68
+ promise.resolve(result);
69
+ delete this.futures[messageHash];
99
70
  }
100
71
  return result;
101
72
  }
@@ -136,7 +107,6 @@ class Client {
136
107
  reset(error) {
137
108
  this.clearConnectionTimeout();
138
109
  this.clearPingInterval();
139
- this.messageQueue = {};
140
110
  this.reject(error);
141
111
  }
142
112
  onConnectionTimeout() {
@@ -3997,7 +3997,7 @@ class binance extends binance$1 {
3997
3997
  //
3998
3998
  // {
3999
3999
  // "symbol": "BTCUSDT",
4000
- // "markPrice": "11793.63104562", // mark price
4000
+ // "markPrice": "11793.63104561", // mark price
4001
4001
  // "indexPrice": "11781.80495970", // index price
4002
4002
  // "estimatedSettlePrice": "11781.16138815", // Estimated Settle Price, only useful in the last hour before the settlement starts
4003
4003
  // "lastFundingRate": "0.00038246", // This is the lastest estimated funding rate
@@ -35,6 +35,7 @@ class bitmex extends bitmex$1 {
35
35
  'swap': true,
36
36
  'future': true,
37
37
  'option': false,
38
+ 'index': true,
38
39
  'addMargin': undefined,
39
40
  'cancelAllOrders': true,
40
41
  'cancelAllOrdersAfter': true,
@@ -416,8 +417,8 @@ class bitmex extends bitmex$1 {
416
417
  // // "mediumPrecision": "8",
417
418
  // // "shorterPrecision": "4",
418
419
  // // "symbol": "₿",
419
- // // "weight": "1",
420
420
  // // "tickLog": "0",
421
+ // // "weight": "1",
421
422
  // "enabled": true,
422
423
  // "isMarginCurrency": true,
423
424
  // "minDepositAmount": "10000",
@@ -27,34 +27,95 @@ class cex extends cex$1 {
27
27
  'swap': false,
28
28
  'future': false,
29
29
  'option': false,
30
+ 'addMargin': false,
31
+ 'borrowCrossMargin': false,
32
+ 'borrowIsolatedMargin': false,
33
+ 'borrowMargin': false,
30
34
  'cancelAllOrders': true,
31
35
  'cancelOrder': true,
36
+ 'closeAllPositions': false,
37
+ 'closePosition': false,
32
38
  'createOrder': true,
39
+ 'createOrderWithTakeProfitAndStopLoss': false,
40
+ 'createOrderWithTakeProfitAndStopLossWs': false,
41
+ 'createPostOnlyOrder': false,
33
42
  'createReduceOnlyOrder': false,
34
43
  'createStopOrder': true,
35
44
  'createTriggerOrder': true,
36
45
  'fetchAccounts': true,
37
46
  'fetchBalance': true,
47
+ 'fetchBorrowInterest': false,
48
+ 'fetchBorrowRate': false,
49
+ 'fetchBorrowRateHistories': false,
50
+ 'fetchBorrowRateHistory': false,
51
+ 'fetchBorrowRates': false,
52
+ 'fetchBorrowRatesPerSymbol': false,
38
53
  'fetchClosedOrder': true,
39
54
  'fetchClosedOrders': true,
55
+ 'fetchCrossBorrowRate': false,
56
+ 'fetchCrossBorrowRates': false,
40
57
  'fetchCurrencies': true,
41
58
  'fetchDepositAddress': true,
42
59
  'fetchDepositsWithdrawals': true,
43
60
  'fetchFundingHistory': false,
61
+ 'fetchFundingInterval': false,
62
+ 'fetchFundingIntervals': false,
44
63
  'fetchFundingRate': false,
45
64
  'fetchFundingRateHistory': false,
46
65
  'fetchFundingRates': false,
66
+ 'fetchGreeks': false,
67
+ 'fetchIndexOHLCV': false,
68
+ 'fetchIsolatedBorrowRate': false,
69
+ 'fetchIsolatedBorrowRates': false,
70
+ 'fetchIsolatedPositions': false,
47
71
  'fetchLedger': true,
72
+ 'fetchLeverage': false,
73
+ 'fetchLeverages': false,
74
+ 'fetchLeverageTiers': false,
75
+ 'fetchLiquidations': false,
76
+ 'fetchLongShortRatio': false,
77
+ 'fetchLongShortRatioHistory': false,
78
+ 'fetchMarginAdjustmentHistory': false,
79
+ 'fetchMarginMode': false,
80
+ 'fetchMarginModes': false,
81
+ 'fetchMarketLeverageTiers': false,
48
82
  'fetchMarkets': true,
83
+ 'fetchMarkOHLCV': false,
84
+ 'fetchMarkPrices': false,
85
+ 'fetchMyLiquidations': false,
86
+ 'fetchMySettlementHistory': false,
49
87
  'fetchOHLCV': true,
88
+ 'fetchOpenInterest': false,
89
+ 'fetchOpenInterestHistory': false,
90
+ 'fetchOpenInterests': false,
50
91
  'fetchOpenOrder': true,
51
92
  'fetchOpenOrders': true,
93
+ 'fetchOption': false,
94
+ 'fetchOptionChain': false,
52
95
  'fetchOrderBook': true,
96
+ 'fetchPosition': false,
97
+ 'fetchPositionHistory': false,
98
+ 'fetchPositionMode': false,
99
+ 'fetchPositions': false,
100
+ 'fetchPositionsForSymbol': false,
101
+ 'fetchPositionsHistory': false,
102
+ 'fetchPositionsRisk': false,
103
+ 'fetchPremiumIndexOHLCV': false,
104
+ 'fetchSettlementHistory': false,
53
105
  'fetchTicker': true,
54
106
  'fetchTickers': true,
55
107
  'fetchTime': true,
56
108
  'fetchTrades': true,
57
109
  'fetchTradingFees': true,
110
+ 'fetchVolatilityHistory': false,
111
+ 'reduceMargin': false,
112
+ 'repayCrossMargin': false,
113
+ 'repayIsolatedMargin': false,
114
+ 'repayMargin': false,
115
+ 'setLeverage': false,
116
+ 'setMargin': false,
117
+ 'setMarginMode': false,
118
+ 'setPositionMode': false,
58
119
  'transfer': true,
59
120
  },
60
121
  'urls': {
@@ -531,7 +531,26 @@ class cryptocom extends cryptocom$1 {
531
531
  if (!this.checkRequiredCredentials(false)) {
532
532
  return undefined;
533
533
  }
534
- const response = await this.v1PrivatePostPrivateGetCurrencyNetworks(params);
534
+ let skipFetchCurrencies = false;
535
+ [skipFetchCurrencies, params] = this.handleOptionAndParams(params, 'fetchCurrencies', 'skipFetchCurrencies', false);
536
+ if (skipFetchCurrencies) {
537
+ // sub-accounts can't access this endpoint
538
+ return undefined;
539
+ }
540
+ let response = {};
541
+ try {
542
+ response = await this.v1PrivatePostPrivateGetCurrencyNetworks(params);
543
+ }
544
+ catch (e) {
545
+ if (e instanceof errors.ExchangeError) {
546
+ // sub-accounts can't access this endpoint
547
+ // {"code":"10001","msg":"SYS_ERROR"}
548
+ return undefined;
549
+ }
550
+ throw e;
551
+ // do nothing
552
+ // sub-accounts can't access this endpoint
553
+ }
535
554
  //
536
555
  // {
537
556
  // "id": "1747502328559",
@@ -556,7 +575,7 @@ class cryptocom extends cryptocom$1 {
556
575
  // "network_id": "CRONOS",
557
576
  // "withdrawal_fee": "0.18000000",
558
577
  // "withdraw_enabled": true,
559
- // "min_withdrawal_amount": "0.36",
578
+ // "min_withdrawal_amount": "0.35",
560
579
  // "deposit_enabled": true,
561
580
  // "confirmation_required": "15"
562
581
  // },
@@ -460,7 +460,7 @@ class cryptomus extends cryptomus$1 {
460
460
  //
461
461
  // {
462
462
  // "currency_pair": "XMR_USDT",
463
- // "last_price": "158.04829771",
463
+ // "last_price": "158.04829772",
464
464
  // "base_volume": "0.35185785",
465
465
  // "quote_volume": "55.523761128544"
466
466
  // }
@@ -797,7 +797,8 @@ class exmo extends exmo$1 {
797
797
  * @returns {object[]} an array of objects representing market data
798
798
  */
799
799
  async fetchMarkets(params = {}) {
800
- const response = await this.publicGetPairSettings(params);
800
+ const promises = [];
801
+ promises.push(this.publicGetPairSettings(params));
801
802
  //
802
803
  // {
803
804
  // "BTC_USD":{
@@ -814,8 +815,9 @@ class exmo extends exmo$1 {
814
815
  // }
815
816
  //
816
817
  let marginPairsDict = {};
817
- if (this.checkRequiredCredentials(false)) {
818
- const marginPairs = await this.privatePostMarginPairList(params);
818
+ const fetchMargin = this.checkRequiredCredentials(false);
819
+ if (fetchMargin) {
820
+ promises.push(this.privatePostMarginPairList(params));
819
821
  //
820
822
  // {
821
823
  // "pairs": [
@@ -845,15 +847,20 @@ class exmo extends exmo$1 {
845
847
  // ]
846
848
  // }
847
849
  //
848
- const pairs = this.safeValue(marginPairs, 'pairs');
850
+ }
851
+ const responses = await Promise.all(promises);
852
+ const spotResponse = responses[0];
853
+ if (fetchMargin) {
854
+ const marginPairs = responses[1];
855
+ const pairs = this.safeList(marginPairs, 'pairs');
849
856
  marginPairsDict = this.indexBy(pairs, 'name');
850
857
  }
851
- const keys = Object.keys(response);
858
+ const keys = Object.keys(spotResponse);
852
859
  const result = [];
853
860
  for (let i = 0; i < keys.length; i++) {
854
861
  const id = keys[i];
855
- const market = response[id];
856
- const marginMarket = this.safeValue(marginPairsDict, id);
862
+ const market = spotResponse[id];
863
+ const marginMarket = this.safeDict(marginPairsDict, id);
857
864
  const symbol = id.replace('_', '/');
858
865
  const [baseId, quoteId] = symbol.split('/');
859
866
  const base = this.safeCurrencyCode(baseId);
@@ -3,7 +3,7 @@
3
3
  var hitbtc = require('./hitbtc.js');
4
4
 
5
5
  // ----------------------------------------------------------------------------
6
- // ---------------------------------------------------------------------------
6
+ // ----------------------------------------------------------------------------
7
7
  class fmfwio extends hitbtc {
8
8
  describe() {
9
9
  return this.deepExtend(super.describe(), {
@@ -1232,7 +1232,7 @@ class gate extends gate$1 {
1232
1232
  this.fetchOptionMarkets(params),
1233
1233
  ];
1234
1234
  if (!sandboxMode) {
1235
- // gate does not have a sandbox for spot markets
1235
+ // gate doesn't have a sandbox for spot markets
1236
1236
  const mainnetOnly = [this.fetchSpotMarkets(params)];
1237
1237
  rawPromises = this.arrayConcat(rawPromises, mainnetOnly);
1238
1238
  }
@@ -1652,7 +1652,7 @@ class gate extends gate$1 {
1652
1652
  'contractSize': this.parseNumber('1'),
1653
1653
  'expiry': expiry,
1654
1654
  'expiryDatetime': this.iso8601(expiry),
1655
- 'strike': strike,
1655
+ 'strike': this.parseNumber(strike),
1656
1656
  'optionType': optionType,
1657
1657
  'precision': {
1658
1658
  'amount': this.parseNumber('1'),
@@ -45,6 +45,7 @@ class hyperliquid extends hyperliquid$1 {
45
45
  'createMarketBuyOrderWithCost': false,
46
46
  'createMarketOrderWithCost': false,
47
47
  'createMarketSellOrderWithCost': false,
48
+ 'createOrderWithTakeProfitAndStopLoss': true,
48
49
  'createOrder': true,
49
50
  'createOrders': true,
50
51
  'createReduceOnlyOrder': true,
@@ -228,7 +229,16 @@ class hyperliquid extends hyperliquid$1 {
228
229
  'triggerDirection': false,
229
230
  'stopLossPrice': false,
230
231
  'takeProfitPrice': false,
231
- 'attachedStopLossTakeProfit': undefined,
232
+ 'attachedStopLossTakeProfit': {
233
+ 'triggerPriceType': {
234
+ 'last': false,
235
+ 'mark': false,
236
+ 'index': false,
237
+ },
238
+ 'triggerPrice': true,
239
+ 'type': true,
240
+ 'price': true,
241
+ },
232
242
  'timeInForce': {
233
243
  'IOC': true,
234
244
  'FOK': false,
@@ -1418,6 +1428,74 @@ class hyperliquid extends hyperliquid$1 {
1418
1428
  const statuses = this.safeList(data, 'statuses', []);
1419
1429
  return this.parseOrders(statuses, undefined);
1420
1430
  }
1431
+ createOrderRequest(symbol, type, side, amount, price = undefined, params = {}) {
1432
+ const market = this.market(symbol);
1433
+ type = type.toUpperCase();
1434
+ side = side.toUpperCase();
1435
+ const isMarket = (type === 'MARKET');
1436
+ const isBuy = (side === 'BUY');
1437
+ const clientOrderId = this.safeString2(params, 'clientOrderId', 'client_id');
1438
+ const slippage = this.safeString(params, 'slippage');
1439
+ let defaultTimeInForce = (isMarket) ? 'ioc' : 'gtc';
1440
+ const postOnly = this.safeBool(params, 'postOnly', false);
1441
+ if (postOnly) {
1442
+ defaultTimeInForce = 'alo';
1443
+ }
1444
+ let timeInForce = this.safeStringLower(params, 'timeInForce', defaultTimeInForce);
1445
+ timeInForce = this.capitalize(timeInForce);
1446
+ let triggerPrice = this.safeString2(params, 'triggerPrice', 'stopPrice');
1447
+ const stopLossPrice = this.safeString(params, 'stopLossPrice', triggerPrice);
1448
+ const takeProfitPrice = this.safeString(params, 'takeProfitPrice');
1449
+ const isTrigger = (stopLossPrice || takeProfitPrice);
1450
+ let px = undefined;
1451
+ if (isMarket) {
1452
+ if (price === undefined) {
1453
+ throw new errors.ArgumentsRequired(this.id + ' market orders require price to calculate the max slippage price. Default slippage can be set in options (default is 5%).');
1454
+ }
1455
+ px = (isBuy) ? Precise["default"].stringMul(price, Precise["default"].stringAdd('1', slippage)) : Precise["default"].stringMul(price, Precise["default"].stringSub('1', slippage));
1456
+ px = this.priceToPrecision(symbol, px); // round after adding slippage
1457
+ }
1458
+ else {
1459
+ px = this.priceToPrecision(symbol, price);
1460
+ }
1461
+ const sz = this.amountToPrecision(symbol, amount);
1462
+ const reduceOnly = this.safeBool(params, 'reduceOnly', false);
1463
+ const orderType = {};
1464
+ if (isTrigger) {
1465
+ let isTp = false;
1466
+ if (takeProfitPrice !== undefined) {
1467
+ triggerPrice = this.priceToPrecision(symbol, takeProfitPrice);
1468
+ isTp = true;
1469
+ }
1470
+ else {
1471
+ triggerPrice = this.priceToPrecision(symbol, stopLossPrice);
1472
+ }
1473
+ orderType['trigger'] = {
1474
+ 'isMarket': isMarket,
1475
+ 'triggerPx': triggerPrice,
1476
+ 'tpsl': (isTp) ? 'tp' : 'sl',
1477
+ };
1478
+ }
1479
+ else {
1480
+ orderType['limit'] = {
1481
+ 'tif': timeInForce,
1482
+ };
1483
+ }
1484
+ params = this.omit(params, ['clientOrderId', 'slippage', 'triggerPrice', 'stopPrice', 'stopLossPrice', 'takeProfitPrice', 'timeInForce', 'client_id', 'reduceOnly', 'postOnly']);
1485
+ const orderObj = {
1486
+ 'a': this.parseToInt(market['baseId']),
1487
+ 'b': isBuy,
1488
+ 'p': px,
1489
+ 's': sz,
1490
+ 'r': reduceOnly,
1491
+ 't': orderType,
1492
+ // 'c': clientOrderId,
1493
+ };
1494
+ if (clientOrderId !== undefined) {
1495
+ orderObj['c'] = clientOrderId;
1496
+ }
1497
+ return orderObj;
1498
+ }
1421
1499
  createOrdersRequest(orders, params = {}) {
1422
1500
  /**
1423
1501
  * @method
@@ -1452,79 +1530,57 @@ class hyperliquid extends hyperliquid$1 {
1452
1530
  params = this.omit(params, ['slippage', 'clientOrderId', 'client_id', 'slippage', 'triggerPrice', 'stopPrice', 'stopLossPrice', 'takeProfitPrice', 'timeInForce']);
1453
1531
  const nonce = this.milliseconds();
1454
1532
  const orderReq = [];
1533
+ let grouping = 'na';
1455
1534
  for (let i = 0; i < orders.length; i++) {
1456
1535
  const rawOrder = orders[i];
1457
1536
  const marketId = this.safeString(rawOrder, 'symbol');
1458
1537
  const market = this.market(marketId);
1459
1538
  const symbol = market['symbol'];
1460
1539
  const type = this.safeStringUpper(rawOrder, 'type');
1461
- const isMarket = (type === 'MARKET');
1462
1540
  const side = this.safeStringUpper(rawOrder, 'side');
1463
- const isBuy = (side === 'BUY');
1464
1541
  const amount = this.safeString(rawOrder, 'amount');
1465
1542
  const price = this.safeString(rawOrder, 'price');
1466
1543
  let orderParams = this.safeDict(rawOrder, 'params', {});
1467
- const clientOrderId = this.safeString2(orderParams, 'clientOrderId', 'client_id');
1468
1544
  const slippage = this.safeString(orderParams, 'slippage', defaultSlippage);
1469
- let defaultTimeInForce = (isMarket) ? 'ioc' : 'gtc';
1470
- const postOnly = this.safeBool(orderParams, 'postOnly', false);
1471
- if (postOnly) {
1472
- defaultTimeInForce = 'alo';
1473
- }
1474
- let timeInForce = this.safeStringLower(orderParams, 'timeInForce', defaultTimeInForce);
1475
- timeInForce = this.capitalize(timeInForce);
1476
- let triggerPrice = this.safeString2(orderParams, 'triggerPrice', 'stopPrice');
1477
- const stopLossPrice = this.safeString(orderParams, 'stopLossPrice', triggerPrice);
1478
- const takeProfitPrice = this.safeString(orderParams, 'takeProfitPrice');
1479
- const isTrigger = (stopLossPrice || takeProfitPrice);
1480
- let px = undefined;
1481
- if (isMarket) {
1482
- if (price === undefined) {
1483
- throw new errors.ArgumentsRequired(this.id + ' market orders require price to calculate the max slippage price. Default slippage can be set in options (default is 5%).');
1484
- }
1485
- px = (isBuy) ? Precise["default"].stringMul(price, Precise["default"].stringAdd('1', slippage)) : Precise["default"].stringMul(price, Precise["default"].stringSub('1', slippage));
1486
- px = this.priceToPrecision(symbol, px); // round after adding slippage
1487
- }
1488
- else {
1489
- px = this.priceToPrecision(symbol, price);
1490
- }
1491
- const sz = this.amountToPrecision(symbol, amount);
1492
- const reduceOnly = this.safeBool(orderParams, 'reduceOnly', false);
1493
- const orderType = {};
1545
+ orderParams['slippage'] = slippage;
1546
+ const stopLoss = this.safeValue(orderParams, 'stopLoss');
1547
+ const takeProfit = this.safeValue(orderParams, 'takeProfit');
1548
+ const isTrigger = (stopLoss || takeProfit);
1549
+ orderParams = this.omit(orderParams, ['stopLoss', 'takeProfit']);
1550
+ const mainOrderObj = this.createOrderRequest(symbol, type, side, amount, price, orderParams);
1551
+ orderReq.push(mainOrderObj);
1494
1552
  if (isTrigger) {
1495
- let isTp = false;
1496
- if (takeProfitPrice !== undefined) {
1497
- triggerPrice = this.priceToPrecision(symbol, takeProfitPrice);
1498
- isTp = true;
1553
+ // grouping opposed orders for sl/tp
1554
+ const stopLossOrderTriggerPrice = this.safeStringN(stopLoss, ['triggerPrice', 'stopPrice']);
1555
+ const stopLossOrderType = this.safeString(stopLoss, 'type');
1556
+ const stopLossOrderLimitPrice = this.safeStringN(stopLoss, ['price', 'stopLossPrice'], stopLossOrderTriggerPrice);
1557
+ const takeProfitOrderTriggerPrice = this.safeStringN(takeProfit, ['triggerPrice', 'stopPrice']);
1558
+ const takeProfitOrderType = this.safeString(takeProfit, 'type');
1559
+ const takeProfitOrderLimitPrice = this.safeStringN(takeProfit, ['price', 'takeProfitPrice'], takeProfitOrderTriggerPrice);
1560
+ grouping = 'normalTpsl';
1561
+ orderParams = this.omit(orderParams, ['stopLoss', 'takeProfit']);
1562
+ let triggerOrderSide = '';
1563
+ if (side === 'BUY') {
1564
+ triggerOrderSide = 'sell';
1499
1565
  }
1500
1566
  else {
1501
- triggerPrice = this.priceToPrecision(symbol, stopLossPrice);
1567
+ triggerOrderSide = 'buy';
1568
+ }
1569
+ if (takeProfit !== undefined) {
1570
+ const orderObj = this.createOrderRequest(symbol, takeProfitOrderType, triggerOrderSide, amount, takeProfitOrderLimitPrice, this.extend(orderParams, {
1571
+ 'takeProfitPrice': takeProfitOrderTriggerPrice,
1572
+ 'reduceOnly': true,
1573
+ }));
1574
+ orderReq.push(orderObj);
1575
+ }
1576
+ if (stopLoss !== undefined) {
1577
+ const orderObj = this.createOrderRequest(symbol, stopLossOrderType, triggerOrderSide, amount, stopLossOrderLimitPrice, this.extend(orderParams, {
1578
+ 'stopLossPrice': stopLossOrderTriggerPrice,
1579
+ 'reduceOnly': true,
1580
+ }));
1581
+ orderReq.push(orderObj);
1502
1582
  }
1503
- orderType['trigger'] = {
1504
- 'isMarket': isMarket,
1505
- 'triggerPx': triggerPrice,
1506
- 'tpsl': (isTp) ? 'tp' : 'sl',
1507
- };
1508
- }
1509
- else {
1510
- orderType['limit'] = {
1511
- 'tif': timeInForce,
1512
- };
1513
- }
1514
- orderParams = this.omit(orderParams, ['clientOrderId', 'slippage', 'triggerPrice', 'stopPrice', 'stopLossPrice', 'takeProfitPrice', 'timeInForce', 'client_id', 'reduceOnly', 'postOnly']);
1515
- const orderObj = {
1516
- 'a': this.parseToInt(market['baseId']),
1517
- 'b': isBuy,
1518
- 'p': px,
1519
- 's': sz,
1520
- 'r': reduceOnly,
1521
- 't': orderType,
1522
- // 'c': clientOrderId,
1523
- };
1524
- if (clientOrderId !== undefined) {
1525
- orderObj['c'] = clientOrderId;
1526
1583
  }
1527
- orderReq.push(orderObj);
1528
1584
  }
1529
1585
  let vaultAddress = undefined;
1530
1586
  [vaultAddress, params] = this.handleOptionAndParams(params, 'createOrder', 'vaultAddress');
@@ -1532,7 +1588,7 @@ class hyperliquid extends hyperliquid$1 {
1532
1588
  const orderAction = {
1533
1589
  'type': 'order',
1534
1590
  'orders': orderReq,
1535
- 'grouping': 'na',
1591
+ 'grouping': grouping,
1536
1592
  // 'brokerCode': 1, // cant
1537
1593
  };
1538
1594
  if (vaultAddress === undefined) {