ccxt 4.5.33 → 4.5.34

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 (184) hide show
  1. package/README.md +19 -5
  2. package/dist/ccxt.browser.min.js +3 -3
  3. package/dist/cjs/ccxt.js +4 -4
  4. package/dist/cjs/src/{btcalpha.js → alp.js} +45 -45
  5. package/dist/cjs/src/ascendex.js +2 -2
  6. package/dist/cjs/src/aster.js +15 -22
  7. package/dist/cjs/src/backpack.js +2 -2
  8. package/dist/cjs/src/binance.js +6 -4
  9. package/dist/cjs/src/bingx.js +2 -1
  10. package/dist/cjs/src/bitfinex.js +6 -11
  11. package/dist/cjs/src/bitget.js +4 -4
  12. package/dist/cjs/src/bitmart.js +1 -1
  13. package/dist/cjs/src/bitmex.js +1 -1
  14. package/dist/cjs/src/bitso.js +1 -1
  15. package/dist/cjs/src/bitstamp.js +1 -1
  16. package/dist/cjs/src/blofin.js +1 -1
  17. package/dist/cjs/src/bybit.js +49 -26
  18. package/dist/cjs/src/cex.js +1 -1
  19. package/dist/cjs/src/coinbase.js +7 -6
  20. package/dist/cjs/src/coinbaseexchange.js +1 -1
  21. package/dist/cjs/src/coincatch.js +3 -3
  22. package/dist/cjs/src/coinex.js +2 -2
  23. package/dist/cjs/src/coinmetro.js +1 -1
  24. package/dist/cjs/src/cryptocom.js +4 -1
  25. package/dist/cjs/src/deepcoin.js +1 -1
  26. package/dist/cjs/src/defx.js +1 -1
  27. package/dist/cjs/src/delta.js +3 -3
  28. package/dist/cjs/src/digifinex.js +1 -1
  29. package/dist/cjs/src/dydx.js +1 -1
  30. package/dist/cjs/src/exmo.js +2 -2
  31. package/dist/cjs/src/foxbit.js +1 -1
  32. package/dist/cjs/src/gate.js +23 -3
  33. package/dist/cjs/src/hashkey.js +1 -1
  34. package/dist/cjs/src/hibachi.js +1 -1
  35. package/dist/cjs/src/hitbtc.js +2 -2
  36. package/dist/cjs/src/htx.js +26 -1
  37. package/dist/cjs/src/hyperliquid.js +5 -4
  38. package/dist/cjs/src/kraken.js +1 -1
  39. package/dist/cjs/src/kucoin.js +1 -1
  40. package/dist/cjs/src/kucoinfutures.js +1 -1
  41. package/dist/cjs/src/luno.js +1 -1
  42. package/dist/cjs/src/mexc.js +2 -2
  43. package/dist/cjs/src/modetrade.js +1 -1
  44. package/dist/cjs/src/ndax.js +1 -1
  45. package/dist/cjs/src/okx.js +4 -4
  46. package/dist/cjs/src/paradex.js +1 -1
  47. package/dist/cjs/src/phemex.js +1 -1
  48. package/dist/cjs/src/poloniex.js +2 -2
  49. package/dist/cjs/src/pro/apex.js +5 -4
  50. package/dist/cjs/src/pro/arkham.js +1 -1
  51. package/dist/cjs/src/pro/aster.js +905 -33
  52. package/dist/cjs/src/pro/bitget.js +14 -1
  53. package/dist/cjs/src/pro/okx.js +1 -1
  54. package/dist/cjs/src/toobit.js +1 -1
  55. package/dist/cjs/src/whitebit.js +1 -1
  56. package/dist/cjs/src/woo.js +3 -3
  57. package/dist/cjs/src/woofipro.js +1 -1
  58. package/dist/cjs/src/xt.js +2 -2
  59. package/dist/cjs/src/zebpay.js +2 -2
  60. package/dist/cjs/src/zonda.js +1 -1
  61. package/js/ccxt.d.ts +5 -5
  62. package/js/ccxt.js +4 -4
  63. package/js/src/abstract/aster.d.ts +6 -8
  64. package/js/src/abstract/binance.d.ts +2 -0
  65. package/js/src/abstract/binancecoinm.d.ts +2 -0
  66. package/js/src/abstract/binanceus.d.ts +2 -0
  67. package/js/src/abstract/binanceusdm.d.ts +2 -0
  68. package/js/src/abstract/bingx.d.ts +1 -0
  69. package/js/src/abstract/bybit.d.ts +15 -0
  70. package/js/src/abstract/cryptocom.d.ts +3 -0
  71. package/js/src/abstract/gate.d.ts +13 -0
  72. package/js/src/abstract/gateio.d.ts +13 -0
  73. package/js/src/abstract/htx.d.ts +25 -0
  74. package/js/src/abstract/huobi.d.ts +25 -0
  75. package/js/src/{btcalpha.d.ts → alp.d.ts} +37 -37
  76. package/js/src/{btcalpha.js → alp.js} +44 -44
  77. package/js/src/ascendex.d.ts +2 -2
  78. package/js/src/ascendex.js +2 -2
  79. package/js/src/aster.js +15 -22
  80. package/js/src/backpack.js +2 -2
  81. package/js/src/binance.d.ts +4 -4
  82. package/js/src/binance.js +6 -4
  83. package/js/src/bingx.d.ts +1 -1
  84. package/js/src/bingx.js +2 -1
  85. package/js/src/bitfinex.d.ts +1 -2
  86. package/js/src/bitfinex.js +6 -11
  87. package/js/src/bitget.d.ts +3 -3
  88. package/js/src/bitget.js +4 -4
  89. package/js/src/bitmart.d.ts +1 -1
  90. package/js/src/bitmart.js +1 -1
  91. package/js/src/bitmex.d.ts +1 -1
  92. package/js/src/bitmex.js +1 -1
  93. package/js/src/bitso.d.ts +1 -1
  94. package/js/src/bitso.js +1 -1
  95. package/js/src/bitstamp.d.ts +1 -1
  96. package/js/src/bitstamp.js +1 -1
  97. package/js/src/blofin.d.ts +1 -1
  98. package/js/src/blofin.js +1 -1
  99. package/js/src/bybit.d.ts +1 -1
  100. package/js/src/bybit.js +49 -26
  101. package/js/src/cex.d.ts +1 -1
  102. package/js/src/cex.js +1 -1
  103. package/js/src/coinbase.d.ts +1 -1
  104. package/js/src/coinbase.js +7 -6
  105. package/js/src/coinbaseexchange.d.ts +1 -1
  106. package/js/src/coinbaseexchange.js +1 -1
  107. package/js/src/coincatch.d.ts +3 -3
  108. package/js/src/coincatch.js +3 -3
  109. package/js/src/coinex.d.ts +2 -2
  110. package/js/src/coinex.js +2 -2
  111. package/js/src/coinmetro.d.ts +1 -1
  112. package/js/src/coinmetro.js +1 -1
  113. package/js/src/cryptocom.d.ts +1 -1
  114. package/js/src/cryptocom.js +4 -1
  115. package/js/src/deepcoin.d.ts +1 -1
  116. package/js/src/deepcoin.js +1 -1
  117. package/js/src/defx.d.ts +1 -1
  118. package/js/src/defx.js +1 -1
  119. package/js/src/delta.d.ts +3 -3
  120. package/js/src/delta.js +3 -3
  121. package/js/src/digifinex.d.ts +1 -1
  122. package/js/src/digifinex.js +1 -1
  123. package/js/src/dydx.d.ts +1 -1
  124. package/js/src/dydx.js +1 -1
  125. package/js/src/exmo.d.ts +2 -2
  126. package/js/src/exmo.js +2 -2
  127. package/js/src/foxbit.js +1 -1
  128. package/js/src/gate.d.ts +3 -3
  129. package/js/src/gate.js +23 -3
  130. package/js/src/hashkey.d.ts +1 -1
  131. package/js/src/hashkey.js +1 -1
  132. package/js/src/hibachi.d.ts +1 -1
  133. package/js/src/hibachi.js +1 -1
  134. package/js/src/hitbtc.d.ts +2 -2
  135. package/js/src/hitbtc.js +2 -2
  136. package/js/src/htx.d.ts +1 -1
  137. package/js/src/htx.js +26 -1
  138. package/js/src/hyperliquid.d.ts +3 -3
  139. package/js/src/hyperliquid.js +5 -4
  140. package/js/src/kraken.d.ts +1 -1
  141. package/js/src/kraken.js +1 -1
  142. package/js/src/kucoin.d.ts +1 -1
  143. package/js/src/kucoin.js +1 -1
  144. package/js/src/kucoinfutures.d.ts +1 -1
  145. package/js/src/kucoinfutures.js +1 -1
  146. package/js/src/luno.d.ts +1 -1
  147. package/js/src/luno.js +1 -1
  148. package/js/src/mexc.d.ts +2 -2
  149. package/js/src/mexc.js +2 -2
  150. package/js/src/modetrade.d.ts +1 -1
  151. package/js/src/modetrade.js +1 -1
  152. package/js/src/ndax.d.ts +1 -1
  153. package/js/src/ndax.js +1 -1
  154. package/js/src/okx.d.ts +3 -3
  155. package/js/src/okx.js +4 -4
  156. package/js/src/paradex.js +1 -1
  157. package/js/src/phemex.d.ts +1 -1
  158. package/js/src/phemex.js +1 -1
  159. package/js/src/poloniex.d.ts +2 -2
  160. package/js/src/poloniex.js +2 -2
  161. package/js/src/pro/apex.js +5 -4
  162. package/js/src/pro/arkham.js +1 -1
  163. package/js/src/pro/aster.d.ts +68 -2
  164. package/js/src/pro/aster.js +906 -34
  165. package/js/src/pro/bitget.js +14 -1
  166. package/js/src/pro/okx.d.ts +1 -1
  167. package/js/src/pro/okx.js +1 -1
  168. package/js/src/toobit.d.ts +1 -1
  169. package/js/src/toobit.js +1 -1
  170. package/js/src/whitebit.js +1 -1
  171. package/js/src/woo.d.ts +3 -3
  172. package/js/src/woo.js +3 -3
  173. package/js/src/woofipro.d.ts +1 -1
  174. package/js/src/woofipro.js +1 -1
  175. package/js/src/xt.d.ts +2 -2
  176. package/js/src/xt.js +2 -2
  177. package/js/src/zebpay.d.ts +2 -2
  178. package/js/src/zebpay.js +2 -2
  179. package/js/src/zonda.d.ts +1 -1
  180. package/js/src/zonda.js +1 -1
  181. package/package.json +1 -1
  182. /package/dist/cjs/src/abstract/{btcalpha.js → alp.js} +0 -0
  183. /package/js/src/abstract/{btcalpha.d.ts → alp.d.ts} +0 -0
  184. /package/js/src/abstract/{btcalpha.js → alp.js} +0 -0
@@ -3,6 +3,7 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var aster$1 = require('../aster.js');
6
+ var Precise = require('../base/Precise.js');
6
7
  var errors = require('../base/errors.js');
7
8
  var Cache = require('../base/ws/Cache.js');
8
9
 
@@ -13,18 +14,21 @@ class aster extends aster$1["default"] {
13
14
  return this.deepExtend(super.describe(), {
14
15
  'has': {
15
16
  'ws': true,
16
- 'watchBalance': false,
17
+ 'watchBalance': true,
17
18
  'watchBidsAsks': true,
18
- 'watchTicker': true,
19
- 'watchTickers': true,
20
19
  'watchMarkPrice': true,
21
20
  'watchMarkPrices': true,
22
21
  'watchTrades': true,
23
22
  'watchTradesForSymbols': true,
23
+ 'watchOrders': true,
24
24
  'watchOrderBook': true,
25
25
  'watchOrderBookForSymbols': true,
26
26
  'watchOHLCV': true,
27
27
  'watchOHLCVForSymbols': true,
28
+ 'watchPositions': true,
29
+ 'watchTicker': true,
30
+ 'watchTickers': true,
31
+ 'watchMyTrades': true,
28
32
  'unWatchTicker': true,
29
33
  'unWatchTickers': true,
30
34
  'unWatchMarkPrice': true,
@@ -40,12 +44,40 @@ class aster extends aster$1["default"] {
40
44
  'urls': {
41
45
  'api': {
42
46
  'ws': {
43
- 'spot': 'wss://sstream.asterdex.com/stream',
44
- 'swap': 'wss://fstream.asterdex.com/stream',
47
+ 'public': {
48
+ 'spot': 'wss://sstream.asterdex.com/stream',
49
+ 'swap': 'wss://fstream.asterdex.com/stream',
50
+ },
51
+ 'private': {
52
+ 'spot': 'wss://sstream.asterdex.com/ws',
53
+ 'swap': 'wss://fstream.asterdex.com/ws',
54
+ },
45
55
  },
46
56
  },
47
57
  },
48
- 'options': {},
58
+ 'options': {
59
+ 'listenKey': {
60
+ 'spot': undefined,
61
+ 'swap': undefined,
62
+ },
63
+ 'lastAuthenticatedTime': {
64
+ 'spot': 0,
65
+ 'swap': 0,
66
+ },
67
+ 'listenKeyRefreshRate': {
68
+ 'spot': 3600000,
69
+ 'swap': 3600000,
70
+ },
71
+ 'watchBalance': {
72
+ 'fetchBalanceSnapshot': false,
73
+ 'awaitBalanceSnapshot': true, // whether to wait for the balance snapshot before providing updates
74
+ },
75
+ 'wallet': 'wb',
76
+ 'watchPositions': {
77
+ 'fetchPositionsSnapshot': true,
78
+ 'awaitPositionsSnapshot': true, // whether to wait for the positions snapshot before providing updates
79
+ },
80
+ },
49
81
  'streaming': {},
50
82
  'exceptions': {},
51
83
  });
@@ -114,7 +146,7 @@ class aster extends aster$1["default"] {
114
146
  if (symbolsLength === 0) {
115
147
  throw new errors.ArgumentsRequired(this.id + ' ' + methodName + '() requires a non-empty array of symbols');
116
148
  }
117
- const url = this.urls['api']['ws'][type];
149
+ const url = this.urls['api']['ws']['public'][type];
118
150
  const subscriptionArgs = [];
119
151
  const messageHashes = [];
120
152
  const request = {
@@ -157,7 +189,7 @@ class aster extends aster$1["default"] {
157
189
  if (symbolsLength === 0) {
158
190
  throw new errors.ArgumentsRequired(this.id + ' ' + methodName + '() requires a non-empty array of symbols');
159
191
  }
160
- const url = this.urls['api']['ws'][type];
192
+ const url = this.urls['api']['ws']['public'][type];
161
193
  const subscriptionArgs = [];
162
194
  const messageHashes = [];
163
195
  const request = {
@@ -225,7 +257,7 @@ class aster extends aster$1["default"] {
225
257
  if (symbolsLength === 0) {
226
258
  throw new errors.ArgumentsRequired(this.id + ' ' + methodName + '() requires a non-empty array of symbols');
227
259
  }
228
- const url = this.urls['api']['ws'][type];
260
+ const url = this.urls['api']['ws']['public'][type];
229
261
  const subscriptionArgs = [];
230
262
  const messageHashes = [];
231
263
  const request = {
@@ -270,7 +302,7 @@ class aster extends aster$1["default"] {
270
302
  if (symbolsLength === 0) {
271
303
  throw new errors.ArgumentsRequired(this.id + ' ' + methodName + '() requires a non-empty array of symbols');
272
304
  }
273
- const url = this.urls['api']['ws'][type];
305
+ const url = this.urls['api']['ws']['public'][type];
274
306
  const subscriptionArgs = [];
275
307
  const messageHashes = [];
276
308
  const request = {
@@ -396,7 +428,7 @@ class aster extends aster$1["default"] {
396
428
  if (symbolsLength === 0) {
397
429
  throw new errors.ArgumentsRequired(this.id + ' watchBidsAsks() requires a non-empty array of symbols');
398
430
  }
399
- const url = this.urls['api']['ws'][type];
431
+ const url = this.urls['api']['ws']['public'][type];
400
432
  const subscriptionArgs = [];
401
433
  const messageHashes = [];
402
434
  const request = {
@@ -436,7 +468,7 @@ class aster extends aster$1["default"] {
436
468
  if (symbolsLength === 0) {
437
469
  throw new errors.ArgumentsRequired(this.id + ' unWatchBidsAsks() requires a non-empty array of symbols');
438
470
  }
439
- const url = this.urls['api']['ws'][type];
471
+ const url = this.urls['api']['ws']['public'][type];
440
472
  const subscriptionArgs = [];
441
473
  const messageHashes = [];
442
474
  const request = {
@@ -547,7 +579,7 @@ class aster extends aster$1["default"] {
547
579
  if (symbolsLength === 0) {
548
580
  throw new errors.ArgumentsRequired(this.id + ' ' + methodName + '() requires a non-empty array of symbols');
549
581
  }
550
- const url = this.urls['api']['ws'][type];
582
+ const url = this.urls['api']['ws']['public'][type];
551
583
  const subscriptionArgs = [];
552
584
  const messageHashes = [];
553
585
  const request = {
@@ -590,7 +622,7 @@ class aster extends aster$1["default"] {
590
622
  if (symbolsLength === 0) {
591
623
  throw new errors.ArgumentsRequired(this.id + ' ' + methodName + '() requires a non-empty array of symbols');
592
624
  }
593
- const url = this.urls['api']['ws'][type];
625
+ const url = this.urls['api']['ws']['public'][type];
594
626
  const subscriptionArgs = [];
595
627
  const messageHashes = [];
596
628
  const request = {
@@ -642,30 +674,158 @@ class aster extends aster$1["default"] {
642
674
  client.resolve(stored, messageHash);
643
675
  }
644
676
  parseWsTrade(trade, market = undefined) {
677
+ //
678
+ // public watchTrades
679
+ //
680
+ // {
681
+ // "e": "trade", // event type
682
+ // "E": 1579481530911, // event time
683
+ // "s": "ETHBTC", // symbol
684
+ // "t": 158410082, // trade id
685
+ // "p": "0.01914100", // price
686
+ // "q": "0.00700000", // quantity
687
+ // "b": 586187049, // buyer order id
688
+ // "a": 586186710, // seller order id
689
+ // "T": 1579481530910, // trade time
690
+ // "m": false, // is the buyer the market maker
691
+ // "M": true // binance docs say it should be ignored
692
+ // }
693
+ //
694
+ // {
695
+ // "e": "aggTrade", // Event type
696
+ // "E": 123456789, // Event time
697
+ // "s": "BNBBTC", // Symbol
698
+ // "a": 12345, // Aggregate trade ID
699
+ // "p": "0.001", // Price
700
+ // "q": "100", // Quantity
701
+ // "f": 100, // First trade ID
702
+ // "l": 105, // Last trade ID
703
+ // "T": 123456785, // Trade time
704
+ // "m": true, // Is the buyer the market maker?
705
+ // "M": true // Ignore
706
+ // }
707
+ //
708
+ // private watchMyTrades spot
709
+ //
710
+ // {
711
+ // "e": "executionReport",
712
+ // "E": 1611063861489,
713
+ // "s": "BNBUSDT",
714
+ // "c": "m4M6AD5MF3b1ERe65l4SPq",
715
+ // "S": "BUY",
716
+ // "o": "MARKET",
717
+ // "f": "GTC",
718
+ // "q": "2.00000000",
719
+ // "p": "0.00000000",
720
+ // "P": "0.00000000",
721
+ // "F": "0.00000000",
722
+ // "g": -1,
723
+ // "C": '',
724
+ // "x": "TRADE",
725
+ // "X": "PARTIALLY_FILLED",
726
+ // "r": "NONE",
727
+ // "i": 1296882607,
728
+ // "l": "0.33200000",
729
+ // "z": "0.33200000",
730
+ // "L": "46.86600000",
731
+ // "n": "0.00033200",
732
+ // "N": "BNB",
733
+ // "T": 1611063861488,
734
+ // "t": 109747654,
735
+ // "I": 2696953381,
736
+ // "w": false,
737
+ // "m": false,
738
+ // "M": true,
739
+ // "O": 1611063861488,
740
+ // "Z": "15.55951200",
741
+ // "Y": "15.55951200",
742
+ // "Q": "0.00000000"
743
+ // }
744
+ //
745
+ // private watchMyTrades future/delivery
746
+ //
747
+ // {
748
+ // "s": "BTCUSDT",
749
+ // "c": "pb2jD6ZQHpfzSdUac8VqMK",
750
+ // "S": "SELL",
751
+ // "o": "MARKET",
752
+ // "f": "GTC",
753
+ // "q": "0.001",
754
+ // "p": "0",
755
+ // "ap": "33468.46000",
756
+ // "sp": "0",
757
+ // "x": "TRADE",
758
+ // "X": "FILLED",
759
+ // "i": 13351197194,
760
+ // "l": "0.001",
761
+ // "z": "0.001",
762
+ // "L": "33468.46",
763
+ // "n": "0.00027086",
764
+ // "N": "BNB",
765
+ // "T": 1612095165362,
766
+ // "t": 458032604,
767
+ // "b": "0",
768
+ // "a": "0",
769
+ // "m": false,
770
+ // "R": false,
771
+ // "wt": "CONTRACT_PRICE",
772
+ // "ot": "MARKET",
773
+ // "ps": "BOTH",
774
+ // "cp": false,
775
+ // "rp": "0.00335000",
776
+ // "pP": false,
777
+ // "si": 0,
778
+ // "ss": 0
779
+ // }
780
+ //
781
+ const id = this.safeString2(trade, 't', 'a');
645
782
  const timestamp = this.safeInteger(trade, 'T');
646
- const symbol = market['symbol'];
647
- const amountString = this.safeString(trade, 'q');
648
- const priceString = this.safeString(trade, 'p');
649
- const isMaker = this.safeBool(trade, 'm');
783
+ const price = this.safeString2(trade, 'L', 'p');
784
+ const amount = this.safeString2(trade, 'q', 'l');
785
+ let cost = this.safeString(trade, 'Y');
786
+ if (cost === undefined) {
787
+ if ((price !== undefined) && (amount !== undefined)) {
788
+ cost = Precise["default"].stringMul(price, amount);
789
+ }
790
+ }
791
+ const marketId = this.safeString(trade, 's');
792
+ const defaultType = (market === undefined) ? this.safeString(this.options, 'defaultType', 'spot') : market['type'];
793
+ const symbol = this.safeSymbol(marketId, market, undefined, defaultType);
794
+ let side = this.safeStringLower(trade, 'S');
650
795
  let takerOrMaker = undefined;
651
- if (isMaker !== undefined) {
652
- takerOrMaker = isMaker ? 'maker' : 'taker';
796
+ const orderId = this.safeString(trade, 'i');
797
+ if ('m' in trade) {
798
+ if (side === undefined) {
799
+ side = trade['m'] ? 'sell' : 'buy'; // this is reversed intentionally
800
+ }
801
+ takerOrMaker = trade['m'] ? 'maker' : 'taker';
802
+ }
803
+ let fee = undefined;
804
+ const feeCost = this.safeString(trade, 'n');
805
+ if (feeCost !== undefined) {
806
+ const feeCurrencyId = this.safeString(trade, 'N');
807
+ const feeCurrencyCode = this.safeCurrencyCode(feeCurrencyId);
808
+ fee = {
809
+ 'cost': feeCost,
810
+ 'currency': feeCurrencyCode,
811
+ };
653
812
  }
813
+ const type = this.safeStringLower(trade, 'o');
654
814
  return this.safeTrade({
655
- 'id': this.safeString(trade, 'a'),
656
815
  'info': trade,
657
816
  'timestamp': timestamp,
658
817
  'datetime': this.iso8601(timestamp),
659
818
  'symbol': symbol,
660
- 'order': undefined,
661
- 'type': undefined,
662
- 'side': undefined,
819
+ 'id': id,
820
+ 'order': orderId,
821
+ 'type': type,
663
822
  'takerOrMaker': takerOrMaker,
664
- 'price': priceString,
665
- 'amount': amountString,
666
- 'cost': undefined,
667
- 'fee': undefined,
668
- }, market);
823
+ 'side': side,
824
+ 'price': price,
825
+ 'amount': amount,
826
+ 'cost': cost,
827
+ 'fee': fee,
828
+ });
669
829
  }
670
830
  /**
671
831
  * @method
@@ -720,7 +880,7 @@ class aster extends aster$1["default"] {
720
880
  if (symbolsLength === 0) {
721
881
  throw new errors.ArgumentsRequired(this.id + ' ' + methodName + '() requires a non-empty array of symbols');
722
882
  }
723
- const url = this.urls['api']['ws'][type];
883
+ const url = this.urls['api']['ws']['public'][type];
724
884
  const subscriptionArgs = [];
725
885
  const messageHashes = [];
726
886
  const request = {
@@ -762,7 +922,7 @@ class aster extends aster$1["default"] {
762
922
  if (symbolsLength === 0) {
763
923
  throw new errors.ArgumentsRequired(this.id + ' ' + methodName + '() requires a non-empty array of symbols');
764
924
  }
765
- const url = this.urls['api']['ws'][type];
925
+ const url = this.urls['api']['ws']['public'][type];
766
926
  const subscriptionArgs = [];
767
927
  const messageHashes = [];
768
928
  const request = {
@@ -887,7 +1047,7 @@ class aster extends aster$1["default"] {
887
1047
  const marketSymbols = this.marketSymbols(symbols, undefined, false, true, true);
888
1048
  const firstMarket = this.market(marketSymbols[0]);
889
1049
  const type = this.safeString(firstMarket, 'type', 'swap');
890
- const url = this.urls['api']['ws'][type];
1050
+ const url = this.urls['api']['ws']['public'][type];
891
1051
  const subscriptionArgs = [];
892
1052
  const messageHashes = [];
893
1053
  const request = {
@@ -934,7 +1094,7 @@ class aster extends aster$1["default"] {
934
1094
  const marketSymbols = this.marketSymbols(symbols, undefined, false, true, true);
935
1095
  const firstMarket = this.market(marketSymbols[0]);
936
1096
  const type = this.safeString(firstMarket, 'type', 'swap');
937
- const url = this.urls['api']['ws'][type];
1097
+ const url = this.urls['api']['ws']['public'][type];
938
1098
  const subscriptionArgs = [];
939
1099
  const messageHashes = [];
940
1100
  const request = {
@@ -1018,6 +1178,704 @@ class aster extends aster$1["default"] {
1018
1178
  this.safeNumber(ohlcv, 'v'),
1019
1179
  ];
1020
1180
  }
1181
+ async authenticate(type = 'spot', params = {}) {
1182
+ const time = this.milliseconds();
1183
+ const lastAuthenticatedTimeOptions = this.safeDict(this.options, 'lastAuthenticatedTime', {});
1184
+ const lastAuthenticatedTime = this.safeInteger(lastAuthenticatedTimeOptions, type, 0);
1185
+ const listenKeyRefreshRateOptions = this.safeDict(this.options, 'listenKeyRefreshRate', {});
1186
+ const listenKeyRefreshRate = this.safeInteger(listenKeyRefreshRateOptions, type, 3600000); // 1 hour
1187
+ if (time - lastAuthenticatedTime > listenKeyRefreshRate) {
1188
+ let response = undefined;
1189
+ if (type === 'spot') {
1190
+ response = await this.sapiPrivatePostV1ListenKey(params);
1191
+ }
1192
+ else {
1193
+ response = await this.fapiPrivatePostV1ListenKey(params);
1194
+ }
1195
+ this.options['listenKey'][type] = this.safeString(response, 'listenKey');
1196
+ this.options['lastAuthenticatedTime'][type] = time;
1197
+ params = this.extend({ 'type': type }, params);
1198
+ this.delay(listenKeyRefreshRate, this.keepAliveListenKey, params);
1199
+ }
1200
+ }
1201
+ async keepAliveListenKey(params = {}) {
1202
+ const type = this.safeString(params, 'type', 'spot');
1203
+ const listenKeyOptions = this.safeDict(this.options, 'listenKey', {});
1204
+ const listenKey = this.safeString(listenKeyOptions, type);
1205
+ if (listenKey === undefined) {
1206
+ return;
1207
+ }
1208
+ try {
1209
+ await this.sapiPrivatePutV1ListenKey(); // extend the expiry
1210
+ }
1211
+ catch (error) {
1212
+ const url = this.urls['api']['ws']['private'][type] + '/' + listenKey;
1213
+ const client = this.client(url);
1214
+ const messageHashes = Object.keys(client.futures);
1215
+ for (let i = 0; i < messageHashes.length; i++) {
1216
+ const messageHash = messageHashes[i];
1217
+ client.reject(error, messageHash);
1218
+ }
1219
+ this.options['listenKey'][type] = undefined;
1220
+ this.options['lastAuthenticatedTime'][type] = 0;
1221
+ return;
1222
+ }
1223
+ // whether or not to schedule another listenKey keepAlive request
1224
+ const listenKeyRefreshOptions = this.safeDict(this.options, 'listenKeyRefresh', {});
1225
+ const listenKeyRefreshRate = this.safeInteger(listenKeyRefreshOptions, 'listenKeyRefreshRate', 3600000);
1226
+ this.delay(listenKeyRefreshRate, this.keepAliveListenKey, params);
1227
+ }
1228
+ getPrivateUrl(type = 'spot') {
1229
+ const listenKeyOptions = this.safeDict(this.options, 'listenKey', {});
1230
+ const listenKey = this.safeString(listenKeyOptions, type);
1231
+ const url = this.urls['api']['ws']['private'][type] + '/' + listenKey;
1232
+ return url;
1233
+ }
1234
+ /**
1235
+ * @method
1236
+ * @name aster#watchBalance
1237
+ * @description query for balance and get the amount of funds available for trading or funds locked in orders
1238
+ * @see https://github.com/asterdex/api-docs/blob/master/aster-finance-spot-api.md#payload-account_update
1239
+ * @see https://github.com/asterdex/api-docs/blob/master/aster-finance-futures-api.md#event-balance-and-position-update
1240
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
1241
+ * @param {string} [params.type] 'spot' or 'swap', default is 'spot'
1242
+ * @returns {object} a [balance structure]{@link https://docs.ccxt.com/?id=balance-structure}
1243
+ */
1244
+ async watchBalance(params = {}) {
1245
+ await this.loadMarkets();
1246
+ let type = undefined;
1247
+ [type, params] = this.handleMarketTypeAndParams('watchBalance', undefined, params, type);
1248
+ await this.authenticate(type, params);
1249
+ const url = this.getPrivateUrl(type);
1250
+ const client = this.client(url);
1251
+ this.setBalanceCache(client, type);
1252
+ const options = this.safeDict(this.options, 'watchBalance');
1253
+ const fetchBalanceSnapshot = this.safeBool(options, 'fetchBalanceSnapshot', false);
1254
+ const awaitBalanceSnapshot = this.safeBool(options, 'awaitBalanceSnapshot', true);
1255
+ if (fetchBalanceSnapshot && awaitBalanceSnapshot) {
1256
+ await client.future(type + ':fetchBalanceSnapshot');
1257
+ }
1258
+ const messageHash = type + ':balance';
1259
+ const message = undefined;
1260
+ return await this.watch(url, messageHash, message, type);
1261
+ }
1262
+ setBalanceCache(client, type) {
1263
+ if ((type in client.subscriptions) && (type in this.balance)) {
1264
+ return;
1265
+ }
1266
+ const options = this.safeValue(this.options, 'watchBalance');
1267
+ const fetchBalanceSnapshot = this.safeBool(options, 'fetchBalanceSnapshot', false);
1268
+ if (fetchBalanceSnapshot) {
1269
+ const messageHash = type + ':fetchBalanceSnapshot';
1270
+ if (!(messageHash in client.futures)) {
1271
+ client.future(messageHash);
1272
+ this.spawn(this.loadBalanceSnapshot, client, messageHash, type);
1273
+ }
1274
+ }
1275
+ else {
1276
+ this.balance[type] = {};
1277
+ }
1278
+ }
1279
+ async loadBalanceSnapshot(client, messageHash, type) {
1280
+ const params = {
1281
+ 'type': type,
1282
+ };
1283
+ const response = await this.fetchBalance(params);
1284
+ this.balance[type] = this.extend(response, this.safeValue(this.balance, type, {}));
1285
+ // don't remove the future from the .futures cache
1286
+ if (messageHash in client.futures) {
1287
+ const future = client.futures[messageHash];
1288
+ future.resolve();
1289
+ client.resolve(this.balance[type], type + ':balance');
1290
+ }
1291
+ }
1292
+ handleBalance(client, message) {
1293
+ //
1294
+ // spot balance update
1295
+ // {
1296
+ // "B": [
1297
+ // {
1298
+ // "a": "USDT",
1299
+ // "f": "16.29445191",
1300
+ // "l": "0"
1301
+ // },
1302
+ // {
1303
+ // "a": "ETH",
1304
+ // "f": "0.00199920",
1305
+ // "l": "0"
1306
+ // }
1307
+ // ],
1308
+ // "e": "outboundAccountPosition",
1309
+ // "T": 1768547778317,
1310
+ // "u": 1768547778317,
1311
+ // "E": 1768547778321,
1312
+ // "m": "ORDER"
1313
+ // }
1314
+ //
1315
+ // swap balance and position update
1316
+ // {
1317
+ // "e": "ACCOUNT_UPDATE",
1318
+ // "T": 1768551627708,
1319
+ // "E": 1768551627710,
1320
+ // "a": {
1321
+ // "B": [
1322
+ // {
1323
+ // "a": "USDT",
1324
+ // "wb": "39.41184271",
1325
+ // "cw": "39.41184271",
1326
+ // "bc": "0"
1327
+ // }
1328
+ // ],
1329
+ // "P": [
1330
+ // {
1331
+ // "s": "ETHUSDT",
1332
+ // "pa": "0",
1333
+ // "ep": "0.00000000",
1334
+ // "cr": "-0.59070000",
1335
+ // "up": "0",
1336
+ // "mt": "isolated",
1337
+ // "iw": "0",
1338
+ // "ps": "BOTH",
1339
+ // "ma": "USDT"
1340
+ // }
1341
+ // ],
1342
+ // "m": "ORDER"
1343
+ // }
1344
+ // }
1345
+ //
1346
+ const subscriptions = client.subscriptions;
1347
+ const subscriptionsKeys = Object.keys(subscriptions);
1348
+ const accountType = this.getAccountTypeFromSubscriptions(subscriptionsKeys);
1349
+ const messageHash = accountType + ':balance';
1350
+ if (this.balance[accountType] === undefined) {
1351
+ this.balance[accountType] = {};
1352
+ }
1353
+ this.balance[accountType]['info'] = message;
1354
+ message = this.safeDict(message, 'a', message);
1355
+ const B = this.safeList(message, 'B', []);
1356
+ const wallet = this.safeString(this.options, 'wallet', 'wb');
1357
+ for (let i = 0; i < B.length; i++) {
1358
+ const entry = B[i];
1359
+ const currencyId = this.safeString(entry, 'a');
1360
+ const code = this.safeCurrencyCode(currencyId);
1361
+ const account = this.account();
1362
+ account['free'] = this.safeString(entry, 'f');
1363
+ account['used'] = this.safeString(entry, 'l');
1364
+ account['total'] = this.safeString(entry, wallet);
1365
+ this.balance[accountType][code] = account;
1366
+ }
1367
+ const timestamp = this.safeInteger(message, 'E');
1368
+ this.balance[accountType]['timestamp'] = timestamp;
1369
+ this.balance[accountType]['datetime'] = this.iso8601(timestamp);
1370
+ this.balance[accountType] = this.safeBalance(this.balance[accountType]);
1371
+ client.resolve(this.balance[accountType], messageHash);
1372
+ }
1373
+ /**
1374
+ * @method
1375
+ * @name aster#watchPositions
1376
+ * @description watch all open positions
1377
+ * @see https://github.com/asterdex/api-docs/blob/master/aster-finance-futures-api.md#event-balance-and-position-update
1378
+ * @param {string[]|undefined} symbols list of unified market symbols
1379
+ * @param {number} [since] since timestamp
1380
+ * @param {number} [limit] limit
1381
+ * @param {object} params extra parameters specific to the exchange API endpoint
1382
+ * @returns {object[]} a list of [position structure]{@link https://docs.ccxt.com/en/latest/manual.html#position-structure}
1383
+ */
1384
+ async watchPositions(symbols = undefined, since = undefined, limit = undefined, params = {}) {
1385
+ await this.loadMarkets();
1386
+ const type = 'swap';
1387
+ await this.authenticate(type, params);
1388
+ const url = this.getPrivateUrl(type);
1389
+ const client = this.client(url);
1390
+ this.setPositionsCache(client);
1391
+ const messageHashes = [];
1392
+ const messageHash = 'positions';
1393
+ symbols = this.marketSymbols(symbols, 'swap', true, true);
1394
+ if (symbols === undefined) {
1395
+ messageHashes.push(messageHash);
1396
+ }
1397
+ else {
1398
+ for (let i = 0; i < symbols.length; i++) {
1399
+ const symbol = symbols[i];
1400
+ messageHashes.push(messageHash + '::' + symbol);
1401
+ }
1402
+ }
1403
+ const fetchPositionsSnapshot = this.handleOption('watchPositions', 'fetchPositionsSnapshot', true);
1404
+ const awaitPositionsSnapshot = this.handleOption('watchPositions', 'awaitPositionsSnapshot', true);
1405
+ const cache = this.positions;
1406
+ if (fetchPositionsSnapshot && awaitPositionsSnapshot && cache === undefined) {
1407
+ const snapshot = await client.future('fetchPositionsSnapshot');
1408
+ return this.filterBySymbolsSinceLimit(snapshot, symbols, since, limit, true);
1409
+ }
1410
+ const newPositions = await this.watchMultiple(url, messageHashes, undefined, [type]);
1411
+ if (this.newUpdates) {
1412
+ return newPositions;
1413
+ }
1414
+ return this.filterBySymbolsSinceLimit(cache, symbols, since, limit, true);
1415
+ }
1416
+ setPositionsCache(client) {
1417
+ if (this.positions !== undefined) {
1418
+ return;
1419
+ }
1420
+ const fetchPositionsSnapshot = this.handleOption('watchPositions', 'fetchPositionsSnapshot', false);
1421
+ if (fetchPositionsSnapshot) {
1422
+ const messageHash = 'fetchPositionsSnapshot';
1423
+ if (!(messageHash in client.futures)) {
1424
+ client.future(messageHash);
1425
+ this.spawn(this.loadPositionsSnapshot, client, messageHash);
1426
+ }
1427
+ }
1428
+ else {
1429
+ this.positions = new Cache.ArrayCacheBySymbolBySide();
1430
+ }
1431
+ }
1432
+ async loadPositionsSnapshot(client, messageHash) {
1433
+ const positions = await this.fetchPositions();
1434
+ this.positions = new Cache.ArrayCacheBySymbolBySide();
1435
+ const cache = this.positions;
1436
+ for (let i = 0; i < positions.length; i++) {
1437
+ const position = positions[i];
1438
+ const contracts = this.safeNumber(position, 'contracts', 0);
1439
+ if (contracts > 0) {
1440
+ cache.append(position);
1441
+ }
1442
+ }
1443
+ // don't remove the future from the .futures cache
1444
+ if (messageHash in client.futures) {
1445
+ const future = client.futures[messageHash];
1446
+ future.resolve(cache);
1447
+ client.resolve(cache, 'positions');
1448
+ }
1449
+ }
1450
+ handlePositions(client, message) {
1451
+ //
1452
+ // {
1453
+ // "e": "ACCOUNT_UPDATE",
1454
+ // "T": 1768551627708,
1455
+ // "E": 1768551627710,
1456
+ // "a": {
1457
+ // "B": [
1458
+ // {
1459
+ // "a": "USDT",
1460
+ // "wb": "39.41184271",
1461
+ // "cw": "39.41184271",
1462
+ // "bc": "0"
1463
+ // }
1464
+ // ],
1465
+ // "P": [
1466
+ // {
1467
+ // "s": "ETHUSDT",
1468
+ // "pa": "0",
1469
+ // "ep": "0.00000000",
1470
+ // "cr": "-0.59070000",
1471
+ // "up": "0",
1472
+ // "mt": "isolated",
1473
+ // "iw": "0",
1474
+ // "ps": "BOTH",
1475
+ // "ma": "USDT"
1476
+ // }
1477
+ // ],
1478
+ // "m": "ORDER"
1479
+ // }
1480
+ // }
1481
+ //
1482
+ const messageHash = 'positions';
1483
+ const messageHashes = this.findMessageHashes(client, messageHash);
1484
+ if (!this.isEmpty(messageHashes)) {
1485
+ if (this.positions === undefined) {
1486
+ this.positions = new Cache.ArrayCacheBySymbolBySide();
1487
+ }
1488
+ const cache = this.positions;
1489
+ const data = this.safeDict(message, 'a', {});
1490
+ const rawPositions = this.safeList(data, 'P', []);
1491
+ const newPositions = [];
1492
+ for (let i = 0; i < rawPositions.length; i++) {
1493
+ const rawPosition = rawPositions[i];
1494
+ const position = this.parseWsPosition(rawPosition);
1495
+ const timestamp = this.safeInteger(message, 'E');
1496
+ position['timestamp'] = timestamp;
1497
+ position['datetime'] = this.iso8601(timestamp);
1498
+ newPositions.push(position);
1499
+ cache.append(position);
1500
+ const symbol = position['symbol'];
1501
+ const symbolMessageHash = messageHash + '::' + symbol;
1502
+ client.resolve(position, symbolMessageHash);
1503
+ }
1504
+ client.resolve(newPositions, 'positions');
1505
+ }
1506
+ }
1507
+ parseWsPosition(position, market = undefined) {
1508
+ //
1509
+ // {
1510
+ // "s": "BTCUSDT", // Symbol
1511
+ // "pa": "0", // Position Amount
1512
+ // "ep": "0.00000", // Entry Price
1513
+ // "cr": "200", // (Pre-fee) Accumulated Realized
1514
+ // "up": "0", // Unrealized PnL
1515
+ // "mt": "isolated", // Margin Type
1516
+ // "iw": "0.00000000", // Isolated Wallet (if isolated position)
1517
+ // "ps": "BOTH" // Position Side
1518
+ // }
1519
+ //
1520
+ const marketId = this.safeString(position, 's');
1521
+ const contracts = this.safeString(position, 'pa');
1522
+ const contractsAbs = Precise["default"].stringAbs(this.safeString(position, 'pa'));
1523
+ let positionSide = this.safeStringLower(position, 'ps');
1524
+ let hedged = true;
1525
+ if (positionSide === 'both') {
1526
+ hedged = false;
1527
+ if (!Precise["default"].stringEq(contracts, '0')) {
1528
+ if (Precise["default"].stringLt(contracts, '0')) {
1529
+ positionSide = 'short';
1530
+ }
1531
+ else {
1532
+ positionSide = 'long';
1533
+ }
1534
+ }
1535
+ }
1536
+ return this.safePosition({
1537
+ 'info': position,
1538
+ 'id': undefined,
1539
+ 'symbol': this.safeSymbol(marketId, undefined, undefined, 'swap'),
1540
+ 'notional': undefined,
1541
+ 'marginMode': this.safeString(position, 'mt'),
1542
+ 'liquidationPrice': undefined,
1543
+ 'entryPrice': this.safeNumber(position, 'ep'),
1544
+ 'unrealizedPnl': this.safeNumber(position, 'up'),
1545
+ 'percentage': undefined,
1546
+ 'contracts': this.parseNumber(contractsAbs),
1547
+ 'contractSize': undefined,
1548
+ 'markPrice': undefined,
1549
+ 'side': positionSide,
1550
+ 'hedged': hedged,
1551
+ 'timestamp': undefined,
1552
+ 'datetime': undefined,
1553
+ 'maintenanceMargin': undefined,
1554
+ 'maintenanceMarginPercentage': undefined,
1555
+ 'collateral': undefined,
1556
+ 'initialMargin': undefined,
1557
+ 'initialMarginPercentage': undefined,
1558
+ 'leverage': undefined,
1559
+ 'marginRatio': undefined,
1560
+ });
1561
+ }
1562
+ /**
1563
+ * @method
1564
+ * @name aster#watchOrders
1565
+ * @description watches information on multiple orders made by the user
1566
+ * @see https://github.com/asterdex/api-docs/blob/master/aster-finance-spot-api.md#payload-order-update
1567
+ * @see https://github.com/asterdex/api-docs/blob/master/aster-finance-futures-api.md#event-order-update
1568
+ * @param {string} [symbol] unified market symbol of the market orders were made in
1569
+ * @param {int} [since] the earliest time in ms to fetch orders for
1570
+ * @param {int} [limit] the maximum number of order structures to retrieve
1571
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
1572
+ * @param {string} [params.type] 'spot' or 'swap', default is 'spot' if symbol is not provided
1573
+ * @returns {object[]} a list of [order structures]{@link https://docs.ccxt.com/?id=order-structure}
1574
+ */
1575
+ async watchOrders(symbol = undefined, since = undefined, limit = undefined, params = {}) {
1576
+ await this.loadMarkets();
1577
+ let market = undefined;
1578
+ if (symbol !== undefined) {
1579
+ market = this.market(symbol);
1580
+ symbol = market['symbol'];
1581
+ }
1582
+ let messageHash = 'orders';
1583
+ let type = undefined;
1584
+ [type, params] = this.handleMarketTypeAndParams('watchOrders', market, params, type);
1585
+ await this.authenticate(type, params);
1586
+ if (market !== undefined) {
1587
+ messageHash += '::' + symbol;
1588
+ }
1589
+ const url = this.getPrivateUrl(type);
1590
+ const client = this.client(url);
1591
+ this.setBalanceCache(client, type);
1592
+ const orders = await this.watchMultiple(url, [messageHash], undefined, [type]);
1593
+ if (this.newUpdates) {
1594
+ limit = orders.getLimit(symbol, limit);
1595
+ }
1596
+ return this.filterBySymbolSinceLimit(orders, symbol, since, limit, true);
1597
+ }
1598
+ /**
1599
+ * @method
1600
+ * @name aster#watchMyTrades
1601
+ * @description watches information on multiple trades made by the user
1602
+ * @see https://github.com/asterdex/api-docs/blob/master/aster-finance-spot-api.md#payload-order-update
1603
+ * @see https://github.com/asterdex/api-docs/blob/master/aster-finance-futures-api.md#event-order-update
1604
+ * @param {string} [symbol] unified market symbol of the market orders were made in
1605
+ * @param {int} [since] the earliest time in ms to fetch orders for
1606
+ * @param {int} [limit] the maximum number of order structures to retrieve
1607
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
1608
+ * @param {string} [params.type] 'spot' or 'swap', default is 'spot' if symbol is not provided
1609
+ * @returns {object[]} a list of [trade structures]{@link https://docs.ccxt.com/?id=trade-structure}
1610
+ */
1611
+ async watchMyTrades(symbol = undefined, since = undefined, limit = undefined, params = {}) {
1612
+ await this.loadMarkets();
1613
+ let market = undefined;
1614
+ if (symbol !== undefined) {
1615
+ market = this.market(symbol);
1616
+ symbol = market['symbol'];
1617
+ }
1618
+ let messageHash = 'myTrades';
1619
+ let type = undefined;
1620
+ [type, params] = this.handleMarketTypeAndParams('watchOrders', market, params, type);
1621
+ await this.authenticate(type, params);
1622
+ if (market !== undefined) {
1623
+ messageHash += '::' + symbol;
1624
+ }
1625
+ const url = this.getPrivateUrl(type);
1626
+ const client = this.client(url);
1627
+ this.setBalanceCache(client, type);
1628
+ const trades = await this.watchMultiple(url, [messageHash], undefined, [type]);
1629
+ if (this.newUpdates) {
1630
+ limit = trades.getLimit(symbol, limit);
1631
+ }
1632
+ return this.filterBySymbolSinceLimit(trades, symbol, since, limit, true);
1633
+ }
1634
+ handleOrderUpdate(client, message) {
1635
+ const rawOrder = this.safeDict(message, 'o', message);
1636
+ const e = this.safeString(message, 'e');
1637
+ if ((e === 'ORDER_TRADE_UPDATE') || (e === 'ALGO_UPDATE')) {
1638
+ message = this.safeDict(message, 'o', message);
1639
+ }
1640
+ this.handleOrder(client, rawOrder);
1641
+ this.handleMyTrade(client, message);
1642
+ }
1643
+ handleMyTrade(client, message) {
1644
+ const messageHash = 'myTrades';
1645
+ const executionType = this.safeString(message, 'x');
1646
+ if (executionType === 'TRADE') {
1647
+ const isSwap = client.url.indexOf('fstream') >= 0;
1648
+ const type = isSwap ? 'swap' : 'spot';
1649
+ const fakeMarket = this.safeMarketStructure({ 'type': type });
1650
+ const trade = this.parseWsTrade(message, fakeMarket);
1651
+ const orderId = this.safeString(trade, 'order');
1652
+ let tradeFee = this.safeDict(trade, 'fee', {});
1653
+ tradeFee = this.extend({}, tradeFee);
1654
+ const symbol = this.safeString(trade, 'symbol');
1655
+ if (orderId !== undefined && tradeFee !== undefined && symbol !== undefined) {
1656
+ const cachedOrders = this.orders;
1657
+ if (cachedOrders !== undefined) {
1658
+ const orders = this.safeValue(cachedOrders.hashmap, symbol, {});
1659
+ const order = this.safeValue(orders, orderId);
1660
+ if (order !== undefined) {
1661
+ // accumulate order fees
1662
+ const fees = this.safeValue(order, 'fees');
1663
+ const fee = this.safeValue(order, 'fee');
1664
+ if (!this.isEmpty(fees)) {
1665
+ let insertNewFeeCurrency = true;
1666
+ for (let i = 0; i < fees.length; i++) {
1667
+ const orderFee = fees[i];
1668
+ if (orderFee['currency'] === tradeFee['currency']) {
1669
+ const feeCost = this.sum(tradeFee['cost'], orderFee['cost']);
1670
+ order['fees'][i]['cost'] = parseFloat(this.currencyToPrecision(tradeFee['currency'], feeCost));
1671
+ insertNewFeeCurrency = false;
1672
+ break;
1673
+ }
1674
+ }
1675
+ if (insertNewFeeCurrency) {
1676
+ order['fees'].push(tradeFee);
1677
+ }
1678
+ }
1679
+ else if (fee !== undefined) {
1680
+ if (fee['currency'] === tradeFee['currency']) {
1681
+ const feeCost = this.sum(fee['cost'], tradeFee['cost']);
1682
+ order['fee']['cost'] = parseFloat(this.currencyToPrecision(tradeFee['currency'], feeCost));
1683
+ }
1684
+ else if (fee['currency'] === undefined) {
1685
+ order['fee'] = tradeFee;
1686
+ }
1687
+ else {
1688
+ order['fees'] = [fee, tradeFee];
1689
+ order['fee'] = undefined;
1690
+ }
1691
+ }
1692
+ else {
1693
+ order['fee'] = tradeFee;
1694
+ }
1695
+ // save this trade in the order
1696
+ const orderTrades = this.safeList(order, 'trades', []);
1697
+ orderTrades.push(trade);
1698
+ order['trades'] = orderTrades;
1699
+ // don't append twice cause it breaks newUpdates mode
1700
+ // this order already exists in the cache
1701
+ }
1702
+ }
1703
+ }
1704
+ if (this.myTrades === undefined) {
1705
+ const limit = this.safeInteger(this.options, 'tradesLimit', 1000);
1706
+ this.myTrades = new Cache.ArrayCacheBySymbolById(limit);
1707
+ }
1708
+ const myTrades = this.myTrades;
1709
+ myTrades.append(trade);
1710
+ client.resolve(this.myTrades, messageHash);
1711
+ const messageHashSymbol = messageHash + ':' + symbol;
1712
+ client.resolve(this.myTrades, messageHashSymbol);
1713
+ }
1714
+ }
1715
+ handleOrder(client, message) {
1716
+ //
1717
+ // spot
1718
+ // {
1719
+ // "e": "executionReport", // Event type
1720
+ // "E": 1499405658658, // Event time
1721
+ // "s": "ETHBTC", // Symbol
1722
+ // "c": "mUvoqJxFIILMdfAW5iGSOW", // Client order ID
1723
+ // "S": "BUY", // Side
1724
+ // "o": "LIMIT", // Order type
1725
+ // "f": "GTC", // Time in force
1726
+ // "q": "1.00000000", // Order quantity
1727
+ // "p": "0.10264410", // Order price
1728
+ // "P": "0.00000000", // Stop price
1729
+ // "F": "0.00000000", // Iceberg quantity
1730
+ // "g": -1, // OrderListId
1731
+ // "C": null, // Original client order ID; This is the ID of the order being canceled
1732
+ // "x": "NEW", // Current execution type
1733
+ // "X": "NEW", // Current order status
1734
+ // "r": "NONE", // Order reject reason; will be an error code.
1735
+ // "i": 4293153, // Order ID
1736
+ // "l": "0.00000000", // Last executed quantity
1737
+ // "z": "0.00000000", // Cumulative filled quantity
1738
+ // "L": "0.00000000", // Last executed price
1739
+ // "n": "0", // Commission amount
1740
+ // "N": null, // Commission asset
1741
+ // "T": 1499405658657, // Transaction time
1742
+ // "t": -1, // Trade ID
1743
+ // "I": 8641984, // Ignore
1744
+ // "w": true, // Is the order on the book?
1745
+ // "m": false, // Is this trade the maker side?
1746
+ // "M": false, // Ignore
1747
+ // "O": 1499405658657, // Order creation time
1748
+ // "Z": "0.00000000", // Cumulative quote asset transacted quantity
1749
+ // "Y": "0.00000000" // Last quote asset transacted quantity (i.e. lastPrice * lastQty),
1750
+ // "Q": "0.00000000" // Quote Order Qty
1751
+ // }
1752
+ //
1753
+ // swap
1754
+ // {
1755
+ // "s":"BTCUSDT", // Symbol
1756
+ // "c":"TEST", // Client Order Id
1757
+ // // special client order id:
1758
+ // // starts with "autoclose-": liquidation order
1759
+ // // "adl_autoclose": ADL auto close order
1760
+ // "S":"SELL", // Side
1761
+ // "o":"TRAILING_STOP_MARKET", // Order Type
1762
+ // "f":"GTC", // Time in Force
1763
+ // "q":"0.001", // Original Quantity
1764
+ // "p":"0", // Original Price
1765
+ // "ap":"0", // Average Price
1766
+ // "sp":"7103.04", // Stop Price. Please ignore with TRAILING_STOP_MARKET order
1767
+ // "x":"NEW", // Execution Type
1768
+ // "X":"NEW", // Order Status
1769
+ // "i":8886774, // Order Id
1770
+ // "l":"0", // Order Last Filled Quantity
1771
+ // "z":"0", // Order Filled Accumulated Quantity
1772
+ // "L":"0", // Last Filled Price
1773
+ // "N":"USDT", // Commission Asset, will not push if no commission
1774
+ // "n":"0", // Commission, will not push if no commission
1775
+ // "T":1568879465651, // Order Trade Time
1776
+ // "t":0, // Trade Id
1777
+ // "b":"0", // Bids Notional
1778
+ // "a":"9.91", // Ask Notional
1779
+ // "m":false, // Is this trade the maker side?
1780
+ // "R":false, // Is this reduce only
1781
+ // "wt":"CONTRACT_PRICE", // Stop Price Working Type
1782
+ // "ot":"TRAILING_STOP_MARKET", // Original Order Type
1783
+ // "ps":"LONG", // Position Side
1784
+ // "cp":false, // If Close-All, pushed with conditional order
1785
+ // "AP":"7476.89", // Activation Price, only puhed with TRAILING_STOP_MARKET order
1786
+ // "cr":"5.0", // Callback Rate, only puhed with TRAILING_STOP_MARKET order
1787
+ // "rp":"0" // Realized Profit of the trade
1788
+ // }
1789
+ //
1790
+ const messageHash = 'orders';
1791
+ const messageHashes = this.findMessageHashes(client, messageHash);
1792
+ if (!this.isEmpty(messageHashes)) {
1793
+ const market = this.getMarketFromOrder(client, message);
1794
+ if (this.orders === undefined) {
1795
+ const limit = this.safeInteger(this.options, 'ordersLimit', 1000);
1796
+ this.orders = new Cache.ArrayCacheBySymbolById(limit);
1797
+ }
1798
+ const cache = this.orders;
1799
+ const parsed = this.parseWsOrder(message, market);
1800
+ const symbol = market['symbol'];
1801
+ const symbolMessageHash = messageHash + '::' + symbol;
1802
+ cache.append(parsed);
1803
+ client.resolve(cache, symbolMessageHash);
1804
+ client.resolve(cache, messageHash);
1805
+ }
1806
+ }
1807
+ parseWsOrder(order, market = undefined) {
1808
+ const executionType = this.safeString(order, 'x');
1809
+ const marketId = this.safeString(order, 's');
1810
+ market = this.safeMarket(marketId, market);
1811
+ let timestamp = this.safeInteger(order, 'O');
1812
+ const T = this.safeInteger(order, 'T');
1813
+ let lastTradeTimestamp = undefined;
1814
+ if (executionType === 'NEW' || executionType === 'AMENDMENT' || executionType === 'CANCELED') {
1815
+ if (timestamp === undefined) {
1816
+ timestamp = T;
1817
+ }
1818
+ }
1819
+ else if (executionType === 'TRADE') {
1820
+ lastTradeTimestamp = T;
1821
+ }
1822
+ const lastUpdateTimestamp = T;
1823
+ let fee = undefined;
1824
+ const feeCost = this.safeString(order, 'n');
1825
+ if ((feeCost !== undefined) && (Precise["default"].stringGt(feeCost, '0'))) {
1826
+ const feeCurrencyId = this.safeString(order, 'N');
1827
+ const feeCurrency = this.safeCurrencyCode(feeCurrencyId);
1828
+ fee = {
1829
+ 'cost': feeCost,
1830
+ 'currency': feeCurrency,
1831
+ };
1832
+ }
1833
+ const rawStatus = this.safeString(order, 'X');
1834
+ const status = this.parseOrderStatus(rawStatus);
1835
+ let clientOrderId = this.safeString2(order, 'C', 'caid');
1836
+ if ((clientOrderId === undefined) || (clientOrderId.length === 0)) {
1837
+ clientOrderId = this.safeString(order, 'c');
1838
+ }
1839
+ const stopPrice = this.safeStringN(order, ['P', 'sp', 'tp']);
1840
+ let timeInForce = this.safeString(order, 'f');
1841
+ if (timeInForce === 'GTX') {
1842
+ // GTX means "Good Till Crossing" and is an equivalent way of saying Post Only
1843
+ timeInForce = 'PO';
1844
+ }
1845
+ return this.safeOrder({
1846
+ 'info': order,
1847
+ 'symbol': market['symbol'],
1848
+ 'id': this.safeString2(order, 'i', 'aid'),
1849
+ 'clientOrderId': clientOrderId,
1850
+ 'timestamp': timestamp,
1851
+ 'datetime': this.iso8601(timestamp),
1852
+ 'lastTradeTimestamp': lastTradeTimestamp,
1853
+ 'lastUpdateTimestamp': lastUpdateTimestamp,
1854
+ 'type': this.parseOrderType(this.safeStringLower(order, 'o')),
1855
+ 'timeInForce': timeInForce,
1856
+ 'postOnly': undefined,
1857
+ 'reduceOnly': this.safeBool(order, 'R'),
1858
+ 'side': this.safeStringLower(order, 'S'),
1859
+ 'price': this.safeString(order, 'p'),
1860
+ 'stopPrice': stopPrice,
1861
+ 'triggerPrice': stopPrice,
1862
+ 'amount': this.safeString(order, 'q'),
1863
+ 'cost': this.safeString(order, 'Z'),
1864
+ 'average': this.safeString(order, 'ap'),
1865
+ 'filled': this.safeString(order, 'z'),
1866
+ 'remaining': undefined,
1867
+ 'status': status,
1868
+ 'fee': fee,
1869
+ 'trades': undefined,
1870
+ });
1871
+ }
1872
+ getMarketFromOrder(client, order) {
1873
+ const marketId = this.safeString(order, 's');
1874
+ const subscriptions = client.subscriptions;
1875
+ const subscriptionsKeys = Object.keys(subscriptions);
1876
+ const marketType = this.getAccountTypeFromSubscriptions(subscriptionsKeys);
1877
+ return this.safeMarket(marketId, undefined, undefined, marketType);
1878
+ }
1021
1879
  handleMessage(client, message) {
1022
1880
  const stream = this.safeString(message, 'stream');
1023
1881
  if (stream !== undefined) {
@@ -1040,6 +1898,20 @@ class aster extends aster$1["default"] {
1040
1898
  method.call(this, client, message);
1041
1899
  }
1042
1900
  }
1901
+ else {
1902
+ // private messages
1903
+ const event = this.safeString(message, 'e');
1904
+ if (event === 'outboundAccountPosition') {
1905
+ this.handleBalance(client, message);
1906
+ }
1907
+ else if (event === 'ACCOUNT_UPDATE') {
1908
+ this.handleBalance(client, message);
1909
+ this.handlePositions(client, message);
1910
+ }
1911
+ else if ((event === 'ORDER_TRADE_UPDATE') || (event === 'executionReport')) {
1912
+ this.handleOrderUpdate(client, message);
1913
+ }
1914
+ }
1043
1915
  }
1044
1916
  }
1045
1917