ccxt 4.5.63 → 4.5.64

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 (124) hide show
  1. package/README.md +6 -8
  2. package/dist/ccxt.browser.min.js +4 -4
  3. package/dist/cjs/ccxt.js +6 -12
  4. package/dist/cjs/src/aster.js +2 -2
  5. package/dist/cjs/src/base/Exchange.js +34 -3
  6. package/dist/cjs/src/bitget.js +5 -3
  7. package/dist/cjs/src/bitmex.js +1 -1
  8. package/dist/cjs/src/bitstamp.js +2 -1
  9. package/dist/cjs/src/bitvavo.js +1 -0
  10. package/dist/cjs/src/btcbox.js +1 -1
  11. package/dist/cjs/src/bullish.js +1 -1
  12. package/dist/cjs/src/bybiteu.js +3 -0
  13. package/dist/cjs/src/coinbase.js +3 -2
  14. package/dist/cjs/src/coinbaseinternational.js +1 -1
  15. package/dist/cjs/src/delta.js +23 -1
  16. package/dist/cjs/src/derive.js +1 -1
  17. package/dist/cjs/src/digifinex.js +12 -0
  18. package/dist/cjs/src/dydx.js +2 -2
  19. package/dist/cjs/src/extended.js +1 -1
  20. package/dist/cjs/src/gateeu.js +1 -0
  21. package/dist/cjs/src/grvt.js +1 -1
  22. package/dist/cjs/src/hashkey.js +127 -6
  23. package/dist/cjs/src/hibachi.js +20 -10
  24. package/dist/cjs/src/hyperliquid.js +1 -1
  25. package/dist/cjs/src/kraken.js +2 -0
  26. package/dist/cjs/src/kucoin.js +1 -1
  27. package/dist/cjs/src/kucoineu.js +3 -0
  28. package/dist/cjs/src/lighter.js +6 -4
  29. package/dist/cjs/src/mudrex.js +1328 -0
  30. package/dist/cjs/src/myokx.js +3 -0
  31. package/dist/cjs/src/okxus.js +1 -5
  32. package/dist/cjs/src/onetrading.js +1 -0
  33. package/dist/cjs/src/pacifica.js +1 -1
  34. package/dist/cjs/src/poloniex.js +1 -1
  35. package/dist/cjs/src/pro/bingx.js +4 -2
  36. package/dist/cjs/src/pro/bitget.js +9 -7
  37. package/dist/cjs/src/pro/grvt.js +1 -1
  38. package/dist/cjs/src/pro/hashkey.js +1 -1
  39. package/dist/cjs/src/pro/kraken.js +1 -1
  40. package/dist/cjs/src/pro/mudrex.js +226 -0
  41. package/dist/cjs/src/pro/okxus.js +1 -1
  42. package/js/ccxt.d.ts +8 -14
  43. package/js/ccxt.js +6 -10
  44. package/js/src/abstract/binance.d.ts +3 -0
  45. package/js/src/abstract/binancecoinm.d.ts +3 -0
  46. package/js/src/abstract/binanceus.d.ts +3 -0
  47. package/js/src/abstract/binanceusdm.d.ts +3 -0
  48. package/js/src/abstract/bybit.d.ts +39 -0
  49. package/js/src/abstract/bybiteu.d.ts +39 -0
  50. package/js/src/abstract/coincheck.d.ts +3 -0
  51. package/js/src/abstract/coinsph.d.ts +8 -1
  52. package/js/src/abstract/kucoineu.js +0 -6
  53. package/js/src/abstract/mudrex.d.ts +33 -0
  54. package/js/src/aster.js +2 -2
  55. package/js/src/base/Exchange.d.ts +10 -1
  56. package/js/src/base/Exchange.js +34 -3
  57. package/js/src/bitget.js +5 -3
  58. package/js/src/bitmex.js +1 -1
  59. package/js/src/bitstamp.js +2 -1
  60. package/js/src/bitvavo.js +1 -0
  61. package/js/src/btcbox.js +1 -1
  62. package/js/src/bullish.js +1 -1
  63. package/js/src/bybiteu.js +3 -0
  64. package/js/src/coinbase.js +3 -2
  65. package/js/src/coinbaseinternational.js +1 -1
  66. package/js/src/delta.d.ts +12 -0
  67. package/js/src/delta.js +23 -1
  68. package/js/src/derive.js +1 -1
  69. package/js/src/digifinex.d.ts +12 -0
  70. package/js/src/digifinex.js +12 -0
  71. package/js/src/dydx.d.ts +2 -2
  72. package/js/src/dydx.js +2 -2
  73. package/js/src/extended.js +1 -1
  74. package/js/src/gateeu.js +1 -0
  75. package/js/src/grvt.d.ts +1 -1
  76. package/js/src/grvt.js +1 -1
  77. package/js/src/hashkey.d.ts +40 -3
  78. package/js/src/hashkey.js +127 -6
  79. package/js/src/hibachi.d.ts +9 -5
  80. package/js/src/hibachi.js +20 -10
  81. package/js/src/hyperliquid.js +1 -1
  82. package/js/src/kraken.js +2 -0
  83. package/js/src/kucoin.js +1 -1
  84. package/js/src/kucoineu.js +3 -0
  85. package/js/src/lighter.js +6 -4
  86. package/js/src/mudrex.d.ts +310 -0
  87. package/js/src/mudrex.js +1321 -0
  88. package/js/src/myokx.js +3 -0
  89. package/js/src/okxus.js +1 -5
  90. package/js/src/onetrading.js +1 -0
  91. package/js/src/pacifica.js +1 -1
  92. package/js/src/poloniex.js +1 -1
  93. package/js/src/pro/bingx.js +4 -2
  94. package/js/src/pro/bitget.js +9 -7
  95. package/js/src/pro/grvt.d.ts +1 -1
  96. package/js/src/pro/grvt.js +1 -1
  97. package/js/src/pro/hashkey.d.ts +1 -1
  98. package/js/src/pro/hashkey.js +1 -1
  99. package/js/src/pro/kraken.js +1 -1
  100. package/js/src/pro/mudrex.d.ts +23 -0
  101. package/js/src/pro/mudrex.js +219 -0
  102. package/js/src/pro/okxus.js +1 -1
  103. package/package.json +3 -3
  104. package/dist/cjs/src/abstract/coinmetro.js +0 -11
  105. package/dist/cjs/src/abstract/novadax.js +0 -11
  106. package/dist/cjs/src/ascendex.js +0 -3780
  107. package/dist/cjs/src/coinmetro.js +0 -2030
  108. package/dist/cjs/src/novadax.js +0 -1678
  109. package/dist/cjs/src/pro/ascendex.js +0 -1013
  110. package/js/src/abstract/ascendex.d.ts +0 -80
  111. package/js/src/abstract/coinmetro.d.ts +0 -37
  112. package/js/src/abstract/coinmetro.js +0 -5
  113. package/js/src/abstract/novadax.d.ts +0 -32
  114. package/js/src/abstract/novadax.js +0 -5
  115. package/js/src/ascendex.d.ts +0 -436
  116. package/js/src/ascendex.js +0 -3773
  117. package/js/src/coinmetro.d.ts +0 -245
  118. package/js/src/coinmetro.js +0 -2023
  119. package/js/src/novadax.d.ts +0 -279
  120. package/js/src/novadax.js +0 -1671
  121. package/js/src/pro/ascendex.d.ts +0 -99
  122. package/js/src/pro/ascendex.js +0 -1006
  123. /package/dist/cjs/src/abstract/{ascendex.js → mudrex.js} +0 -0
  124. /package/js/src/abstract/{ascendex.js → mudrex.js} +0 -0
@@ -1,1013 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var sha2_js = require('@noble/hashes/sha2.js');
6
- var ascendex$1 = require('../ascendex.js');
7
- var errors = require('../base/errors.js');
8
- var Cache = require('../base/ws/Cache.js');
9
-
10
- // ---------------------------------------------------------------------------
11
- // ---------------------------------------------------------------------------
12
- class ascendex extends ascendex$1["default"] {
13
- describe() {
14
- return this.deepExtend(super.describe(), {
15
- 'has': {
16
- 'ws': true,
17
- 'watchBalance': true,
18
- 'watchOHLCV': true,
19
- 'watchOrderBook': true,
20
- 'watchOrders': true,
21
- 'watchTicker': false,
22
- 'watchTrades': true,
23
- 'watchTradesForSymbols': true,
24
- },
25
- 'urls': {
26
- 'api': {
27
- 'ws': {
28
- 'public': 'wss://ascendex.com:443/api/pro/v2/stream',
29
- 'private': 'wss://ascendex.com:443/{accountGroup}/api/pro/v2/stream',
30
- },
31
- },
32
- 'test': {
33
- 'ws': {
34
- 'public': 'wss://api-test.ascendex-sandbox.com:443/api/pro/v2/stream',
35
- 'private': 'wss://api-test.ascendex-sandbox.com:443/{accountGroup}/api/pro/v2/stream',
36
- },
37
- },
38
- },
39
- 'options': {
40
- 'tradesLimit': 1000,
41
- 'ordersLimit': 1000,
42
- 'OHLCVLimit': 1000,
43
- 'categoriesAccount': {
44
- 'cash': 'spot',
45
- 'futures': 'swap',
46
- 'margin': 'margin',
47
- },
48
- },
49
- });
50
- }
51
- async watchPublic(messageHash, params = {}) {
52
- const url = this.urls['api']['ws']['public'];
53
- const id = this.nonce();
54
- const request = {
55
- 'id': id.toString(),
56
- 'op': 'sub',
57
- };
58
- const message = this.extend(request, params);
59
- return await this.watch(url, messageHash, message, messageHash);
60
- }
61
- async watchPublicMultiple(messageHashes, params = {}) {
62
- const url = this.urls['api']['ws']['public'];
63
- const id = this.nonce();
64
- const request = {
65
- 'id': id.toString(),
66
- 'op': 'sub',
67
- };
68
- const message = this.extend(request, params);
69
- return await this.watchMultiple(url, messageHashes, message, messageHashes);
70
- }
71
- async watchPrivate(channel, messageHash, params = {}) {
72
- await this.loadAccounts();
73
- const accountGroup = this.safeString(this.options, 'account-group');
74
- let url = this.urls['api']['ws']['private'];
75
- url = this.implodeParams(url, { 'accountGroup': accountGroup });
76
- const id = this.nonce();
77
- const request = {
78
- 'id': id.toString(),
79
- 'op': 'sub',
80
- 'ch': channel,
81
- };
82
- const message = this.extend(request, params);
83
- await this.authenticate(url, params);
84
- return await this.watch(url, messageHash, message, channel);
85
- }
86
- /**
87
- * @method
88
- * @name ascendex#watchOHLCV
89
- * @description watches historical candlestick data containing the open, high, low, and close price, and the volume of a market
90
- * @see https://ascendex.github.io/ascendex-pro-api/#channel-bar-data
91
- * @param {string} symbol unified symbol of the market to fetch OHLCV data for
92
- * @param {string} timeframe the length of time each candle represents
93
- * @param {int} [since] timestamp in ms of the earliest candle to fetch
94
- * @param {int} [limit] the maximum amount of candles to fetch
95
- * @param {object} [params] extra parameters specific to the exchange API endpoint
96
- * @returns {int[][]} A list of candles ordered as timestamp, open, high, low, close, volume
97
- */
98
- async watchOHLCV(symbol, timeframe = '1m', since = undefined, limit = undefined, params = {}) {
99
- await this.loadMarkets();
100
- const market = this.market(symbol);
101
- symbol = market['symbol'];
102
- if ((limit === undefined) || (limit > 1440)) {
103
- limit = 100;
104
- }
105
- const interval = this.safeString(this.timeframes, timeframe, timeframe);
106
- const channel = 'bar' + ':' + interval + ':' + market['id'];
107
- params = {
108
- 'ch': channel,
109
- };
110
- const ohlcv = await this.watchPublic(channel, params);
111
- if (this.newUpdates) {
112
- limit = ohlcv.getLimit(symbol, limit);
113
- }
114
- return this.filterBySinceLimit(ohlcv, since, limit, 0, true);
115
- }
116
- handleOHLCV(client, message) {
117
- //
118
- // {
119
- // "m": "bar",
120
- // "s": "ASD/USDT",
121
- // "data": {
122
- // "i": "1",
123
- // "ts": 1575398940000,
124
- // "o": "0.04993",
125
- // "c": "0.04970",
126
- // "h": "0.04993",
127
- // "l": "0.04970",
128
- // "v": "8052"
129
- // }
130
- // }
131
- //
132
- const marketId = this.safeString(message, 's');
133
- const symbol = this.safeSymbol(marketId);
134
- const channel = this.safeString(message, 'm');
135
- const data = this.safeValue(message, 'data', {});
136
- const interval = this.safeString(data, 'i');
137
- const messageHash = channel + ':' + interval + ':' + marketId;
138
- const timeframe = this.findTimeframe(interval);
139
- const market = this.market(symbol);
140
- const parsed = this.parseOHLCV(message, market);
141
- this.ohlcvs[symbol] = this.safeValue(this.ohlcvs, symbol, {});
142
- let stored = this.safeValue(this.ohlcvs[symbol], timeframe);
143
- if (stored === undefined) {
144
- const limit = this.safeInteger(this.options, 'OHLCVLimit', 1000);
145
- stored = new Cache.ArrayCacheByTimestamp(limit);
146
- this.ohlcvs[symbol][timeframe] = stored;
147
- }
148
- stored.append(parsed);
149
- client.resolve(stored, messageHash);
150
- return message;
151
- }
152
- /**
153
- * @method
154
- * @name ascendex#watchTrades
155
- * @description get the list of most recent trades for a particular symbol
156
- * @see https://ascendex.github.io/ascendex-pro-api/#channel-market-trades
157
- * @param {string} symbol unified symbol of the market to fetch trades for
158
- * @param {int} [since] timestamp in ms of the earliest trade to fetch
159
- * @param {int} [limit] the maximum amount of trades to fetch
160
- * @param {object} [params] extra parameters specific to the exchange API endpoint
161
- * @returns {object[]} a list of [trade structures]{@link https://docs.ccxt.com/?id=public-trades}
162
- */
163
- async watchTrades(symbol, since = undefined, limit = undefined, params = {}) {
164
- return await this.watchTradesForSymbols([symbol], since, limit, params);
165
- }
166
- /**
167
- * @method
168
- * @name ascendex#watchTradesForSymbols
169
- * @description get the list of most recent trades for a list of symbols
170
- * @see https://ascendex.github.io/ascendex-pro-api/#channel-market-trades
171
- * @param {string[]} symbols unified symbol of the market to fetch trades for
172
- * @param {int} [since] timestamp in ms of the earliest trade to fetch
173
- * @param {int} [limit] the maximum amount of trades to fetch
174
- * @param {object} [params] extra parameters specific to the exchange API endpoint
175
- * @param {string} [params.name] the name of the method to call, 'trade' or 'aggTrade', default is 'trade'
176
- * @returns {object[]} a list of [trade structures]{@link https://docs.ccxt.com/?id=public-trades}
177
- */
178
- async watchTradesForSymbols(symbols, since = undefined, limit = undefined, params = {}) {
179
- await this.loadMarkets();
180
- symbols = this.marketSymbols(symbols, undefined, false, true, true);
181
- const marketIds = [];
182
- const messageHashes = [];
183
- if (symbols !== undefined) {
184
- for (let i = 0; i < symbols.length; i++) {
185
- const market = this.market(symbols[i]);
186
- marketIds.push(market['id']);
187
- messageHashes.push('trades:' + market['id']);
188
- }
189
- }
190
- const channel = 'trades:' + marketIds.join(',');
191
- params = this.extend(params, {
192
- 'ch': channel,
193
- });
194
- const trades = await this.watchPublicMultiple(messageHashes, params);
195
- if (this.newUpdates) {
196
- const first = this.safeValue(trades, 0);
197
- const tradeSymbol = this.safeString(first, 'symbol');
198
- limit = trades.getLimit(tradeSymbol, limit);
199
- }
200
- return this.filterBySinceLimit(trades, since, limit, 'timestamp', true);
201
- }
202
- handleTrades(client, message) {
203
- //
204
- // {
205
- // "m": "trades",
206
- // "symbol": "BTC/USDT",
207
- // "data": [
208
- // {
209
- // "p": "40744.28",
210
- // "q": "0.00150",
211
- // "ts": 1647514330758,
212
- // "bm": true,
213
- // "seqnum": 72057633465800320
214
- // }
215
- // ]
216
- // }
217
- //
218
- const marketId = this.safeString(message, 'symbol');
219
- const symbol = this.safeSymbol(marketId);
220
- const channel = this.safeString(message, 'm');
221
- const messageHash = channel + ':' + marketId;
222
- const market = this.market(symbol);
223
- let rawData = this.safeValue(message, 'data');
224
- if (rawData === undefined) {
225
- rawData = [];
226
- }
227
- const trades = this.parseTrades(rawData, market);
228
- let tradesArray = this.safeValue(this.trades, symbol);
229
- if (tradesArray === undefined) {
230
- const limit = this.safeInteger(this.options, 'tradesLimit', 1000);
231
- tradesArray = new Cache.ArrayCache(limit);
232
- }
233
- for (let i = 0; i < trades.length; i++) {
234
- tradesArray.append(trades[i]);
235
- }
236
- this.trades[symbol] = tradesArray;
237
- client.resolve(tradesArray, messageHash);
238
- }
239
- /**
240
- * @method
241
- * @name ascendex#watchOrderBook
242
- * @description watches information on open orders with bid (buy) and ask (sell) prices, volumes and other data
243
- * @see https://ascendex.github.io/ascendex-pro-api/#channel-level-2-order-book-updates
244
- * @param {string} symbol unified symbol of the market to fetch the order book for
245
- * @param {int} [limit] the maximum amount of order book entries to return
246
- * @param {object} [params] extra parameters specific to the exchange API endpoint
247
- * @returns {object} A dictionary of [order book structures]{@link https://docs.ccxt.com/?id=order-book-structure}
248
- */
249
- async watchOrderBook(symbol, limit = undefined, params = {}) {
250
- await this.loadMarkets();
251
- const market = this.market(symbol);
252
- const channel = 'depth' + ':' + market['id'];
253
- params = this.extend(params, {
254
- 'ch': channel,
255
- });
256
- const orderbook = await this.watchPublic(channel, params);
257
- return orderbook.limit();
258
- }
259
- async watchOrderBookSnapshot(symbol, limit = undefined, params = {}) {
260
- await this.loadMarkets();
261
- const market = this.market(symbol);
262
- const action = 'depth-snapshot';
263
- const channel = action + ':' + market['id'];
264
- params = this.extend(params, {
265
- 'action': action,
266
- 'args': {
267
- 'symbol': market['id'],
268
- },
269
- 'op': 'req',
270
- });
271
- const orderbook = await this.watchPublic(channel, params);
272
- return orderbook.limit();
273
- }
274
- async fetchOrderBookSnapshotCustom(symbol, limit = undefined, params = {}) {
275
- const restOrderBook = await this.fetchRestOrderBookSafe(symbol, limit, params);
276
- if (!(symbol in this.orderbooks)) {
277
- this.orderbooks[symbol] = this.orderBook();
278
- }
279
- const orderbook = this.orderbooks[symbol];
280
- orderbook.reset(restOrderBook);
281
- return orderbook;
282
- }
283
- handleOrderBookSnapshot(client, message) {
284
- //
285
- // {
286
- // "m": "depth",
287
- // "symbol": "BTC/USDT",
288
- // "data": {
289
- // "ts": 1647520500149,
290
- // "seqnum": 28590487626,
291
- // "asks": [
292
- // [Array], [Array], [Array],
293
- // [Array], [Array], [Array],
294
- // ],
295
- // "bids": [
296
- // [Array], [Array], [Array],
297
- // [Array], [Array], [Array],
298
- // ]
299
- // }
300
- // }
301
- //
302
- const marketId = this.safeString(message, 'symbol');
303
- const symbol = this.safeSymbol(marketId);
304
- const channel = this.safeString(message, 'm');
305
- const messageHash = channel + ':' + symbol;
306
- const orderbook = this.orderbooks[symbol];
307
- const data = this.safeValue(message, 'data');
308
- const snapshot = this.parseOrderBook(data, symbol);
309
- snapshot['nonce'] = this.safeInteger(data, 'seqnum');
310
- orderbook.reset(snapshot);
311
- // unroll the accumulated deltas
312
- const messages = orderbook.cache;
313
- for (let i = 0; i < messages.length; i++) {
314
- const messageItem = messages[i];
315
- this.handleOrderBookMessage(client, messageItem, orderbook);
316
- }
317
- this.orderbooks[symbol] = orderbook;
318
- client.resolve(orderbook, messageHash);
319
- }
320
- handleOrderBook(client, message) {
321
- //
322
- // {
323
- // "m": "depth",
324
- // "symbol": "BTC/USDT",
325
- // "data": {
326
- // "ts": 1647515136144,
327
- // "seqnum": 28590470736,
328
- // "asks": [ [Array], [Array] ],
329
- // "bids": [ [Array], [Array], [Array], [Array], [Array], [Array] ]
330
- // }
331
- // }
332
- //
333
- const channel = this.safeString(message, 'm');
334
- const marketId = this.safeString(message, 'symbol');
335
- const symbol = this.safeSymbol(marketId);
336
- const messageHash = channel + ':' + marketId;
337
- if (!(symbol in this.orderbooks)) {
338
- this.orderbooks[symbol] = this.orderBook({});
339
- }
340
- const orderbook = this.orderbooks[symbol];
341
- if (orderbook['nonce'] === undefined) {
342
- orderbook.cache.push(message);
343
- }
344
- else {
345
- this.handleOrderBookMessage(client, message, orderbook);
346
- client.resolve(orderbook, messageHash);
347
- }
348
- }
349
- handleDelta(bookside, delta) {
350
- //
351
- // ["40990.47","0.01619"],
352
- //
353
- const price = this.safeFloat(delta, 0);
354
- const amount = this.safeFloat(delta, 1);
355
- bookside.store(price, amount);
356
- }
357
- handleDeltas(bookside, deltas) {
358
- for (let i = 0; i < deltas.length; i++) {
359
- this.handleDelta(bookside, deltas[i]);
360
- }
361
- }
362
- handleOrderBookMessage(client, message, orderbook) {
363
- //
364
- // {
365
- // "m":"depth",
366
- // "symbol":"BTC/USDT",
367
- // "data":{
368
- // "ts":1647527417715,
369
- // "seqnum":28590257013,
370
- // "asks":[
371
- // ["40990.47","0.01619"],
372
- // ["41021.21","0"],
373
- // ["41031.59","0.06096"]
374
- // ],
375
- // "bids":[
376
- // ["40990.46","0.76114"],
377
- // ["40985.18","0"]
378
- // ]
379
- // }
380
- // }
381
- //
382
- const data = this.safeValue(message, 'data', {});
383
- const seqNum = this.safeInteger(data, 'seqnum');
384
- if (seqNum > orderbook['nonce']) {
385
- const asks = this.safeValue(data, 'asks', []);
386
- const bids = this.safeValue(data, 'bids', []);
387
- this.handleDeltas(orderbook['asks'], asks);
388
- this.handleDeltas(orderbook['bids'], bids);
389
- orderbook['nonce'] = seqNum;
390
- const timestamp = this.safeInteger(data, 'ts');
391
- orderbook['timestamp'] = timestamp;
392
- orderbook['datetime'] = this.iso8601(timestamp);
393
- }
394
- return orderbook;
395
- }
396
- /**
397
- * @method
398
- * @name ascendex#watchBalance
399
- * @description watch balance and get the amount of funds available for trading or funds locked in orders
400
- * @see https://ascendex.github.io/ascendex-pro-api/#channel-order-and-balance
401
- * @param {object} [params] extra parameters specific to the exchange API endpoint
402
- * @returns {object} a [balance structure]{@link https://docs.ccxt.com/?id=balance-structure}
403
- */
404
- async watchBalance(params = {}) {
405
- await this.loadMarkets();
406
- const [type, query] = this.handleMarketTypeAndParams('watchBalance', undefined, params);
407
- let channel = undefined;
408
- let messageHash = undefined;
409
- if ((type === 'spot') || (type === 'margin')) {
410
- const accountCategories = this.safeValue(this.options, 'accountCategories', {});
411
- let accountCategory = this.safeString(accountCategories, type, 'cash'); // cash, margin,
412
- accountCategory = accountCategory.toUpperCase();
413
- channel = 'order:' + accountCategory; // order and balance share the same channel
414
- messageHash = 'balance:' + type;
415
- }
416
- else {
417
- channel = 'futures-account-update';
418
- messageHash = 'balance:swap';
419
- }
420
- return await this.watchPrivate(channel, messageHash, query);
421
- }
422
- handleBalance(client, message) {
423
- //
424
- // cash account
425
- //
426
- // {
427
- // "m": "balance",
428
- // "accountId": "cshQtyfq8XLAA9kcf19h8bXHbAwwoqEo",
429
- // "ac": "CASH",
430
- // "data": {
431
- // "a" : "USDT",
432
- // "sn": 8159798,
433
- // "tb": "600",
434
- // "ab": "600"
435
- // }
436
- // }
437
- //
438
- // margin account
439
- //
440
- // {
441
- // "m": "balance",
442
- // "accountId": "marOxpKJV83dxTRx0Eyxpa0gxc4Txt0P",
443
- // "ac": "MARGIN",
444
- // "data": {
445
- // "a" : "USDT",
446
- // "sn" : 8159802,
447
- // "tb" : "400", // total Balance
448
- // "ab" : "400", // available balance
449
- // "brw": "0", // borrowws
450
- // "int": "0" // interest
451
- // }
452
- // }
453
- //
454
- // futures
455
- // {
456
- // "m" : "futures-account-update", // message
457
- // "e" : "ExecutionReport", // event type
458
- // "t" : 1612508562129, // time
459
- // "acc" : "futures-account-id", // account ID
460
- // "at" : "FUTURES", // account type
461
- // "sn" : 23128, // sequence number,
462
- // "id" : "r177710001cbU3813942147C5kbFGOan",
463
- // "col": [
464
- // {
465
- // "a": "USDT", // asset code
466
- // "b": "1000000", // balance
467
- // "f": "1" // discount factor
468
- // }
469
- // ],
470
- // (...)
471
- //
472
- const channel = this.safeString(message, 'm');
473
- let result = undefined;
474
- let type = undefined;
475
- if ((channel === 'order') || (channel === 'futures-order')) {
476
- const data = this.safeValue(message, 'data');
477
- const marketId = this.safeString(data, 's');
478
- const market = this.safeMarket(marketId);
479
- const baseAccount = this.account();
480
- baseAccount['free'] = this.safeString(data, 'bab');
481
- baseAccount['total'] = this.safeString(data, 'btb');
482
- const quoteAccount = this.account();
483
- quoteAccount['free'] = this.safeString(data, 'qab');
484
- quoteAccount['total'] = this.safeString(data, 'qtb');
485
- if (market['contract']) {
486
- type = 'swap';
487
- result = this.safeValue(this.balance, type, {});
488
- }
489
- else {
490
- type = market['type'];
491
- result = this.safeValue(this.balance, type, {});
492
- }
493
- result[market['base']] = baseAccount;
494
- result[market['quote']] = quoteAccount;
495
- }
496
- else {
497
- const accountType = this.safeStringLower2(message, 'ac', 'at');
498
- const categoriesAccounts = this.safeValue(this.options, 'categoriesAccount');
499
- type = this.safeString(categoriesAccounts, accountType, 'spot');
500
- result = this.safeValue(this.balance, type, {});
501
- const data = this.safeValue(message, 'data');
502
- let balances = undefined;
503
- if (data === undefined) {
504
- balances = this.safeValue(message, 'col');
505
- }
506
- else {
507
- balances = [data];
508
- }
509
- for (let i = 0; i < balances.length; i++) {
510
- const balance = balances[i];
511
- const code = this.safeCurrencyCode(this.safeString(balance, 'a'));
512
- const account = this.account();
513
- account['free'] = this.safeString(balance, 'ab');
514
- account['total'] = this.safeString2(balance, 'tb', 'b');
515
- result[code] = account;
516
- }
517
- }
518
- const messageHash = 'balance' + ':' + type;
519
- client.resolve(this.safeBalance(result), messageHash);
520
- }
521
- /**
522
- * @method
523
- * @name ascendex#watchOrders
524
- * @see https://ascendex.github.io/ascendex-pro-api/#channel-order-and-balance
525
- * @description watches information on multiple orders made by the user
526
- * @param {string} symbol unified market symbol of the market orders were made in
527
- * @param {int} [since] the earliest time in ms to fetch orders for
528
- * @param {int} [limit] the maximum number of order structures to retrieve
529
- * @param {object} [params] extra parameters specific to the exchange API endpoint
530
- * @returns {object[]} a list of [order structures]{@link https://docs.ccxt.com/?id=order-structure}
531
- */
532
- async watchOrders(symbol = undefined, since = undefined, limit = undefined, params = {}) {
533
- await this.loadMarkets();
534
- let market = undefined;
535
- if (symbol !== undefined) {
536
- market = this.market(symbol);
537
- symbol = market['symbol'];
538
- }
539
- const [type, query] = this.handleMarketTypeAndParams('watchOrders', market, params);
540
- let messageHash = undefined;
541
- let channel = undefined;
542
- if (type !== 'spot' && type !== 'margin') {
543
- channel = 'futures-order';
544
- messageHash = 'order:FUTURES';
545
- }
546
- else {
547
- const accountCategories = this.safeValue(this.options, 'accountCategories', {});
548
- let accountCategory = this.safeString(accountCategories, type, 'cash'); // cash, margin
549
- accountCategory = accountCategory.toUpperCase();
550
- messageHash = 'order' + ':' + accountCategory;
551
- channel = messageHash;
552
- }
553
- if (symbol !== undefined) {
554
- messageHash = messageHash + ':' + symbol;
555
- }
556
- const orders = await this.watchPrivate(channel, messageHash, query);
557
- if (this.newUpdates) {
558
- limit = orders.getLimit(symbol, limit);
559
- }
560
- return this.filterBySymbolSinceLimit(orders, symbol, since, limit, true);
561
- }
562
- handleOrder(client, message) {
563
- //
564
- // spot order
565
- // {
566
- // "m": "order",
567
- // "accountId": "cshF5SlR9ukAXoDOuXbND4dVpBMw9gzH",
568
- // "ac": "CASH",
569
- // "data": {
570
- // "sn": 19399016185,
571
- // "orderId": "r17f9d7983faU7223046196CMlrj3bfC",
572
- // "s": "LTC/USDT",
573
- // "ot": "Limit",
574
- // "t": 1647614461160,
575
- // "p": "50",
576
- // "q": "0.1",
577
- // "sd": "Buy",
578
- // "st": "New",
579
- // "ap": "0",
580
- // "cfq": "0",
581
- // "sp": '',
582
- // "err": '',
583
- // "btb": "0",
584
- // "bab": "0",
585
- // "qtb": "8",
586
- // "qab": "2.995",
587
- // "cf": "0",
588
- // "fa": "USDT",
589
- // "ei": "NULL_VAL"
590
- // }
591
- // }
592
- //
593
- // futures order
594
- // {
595
- // "m": "futures-order",
596
- // "sn": 19399927636,
597
- // "e": "ExecutionReport",
598
- // "a": "futF5SlR9ukAXoDOuXbND4dVpBMw9gzH", // account id
599
- // "ac": "FUTURES",
600
- // "t": 1647622515434, // last execution time
601
- // (...)
602
- // }
603
- //
604
- const accountType = this.safeString(message, 'ac');
605
- const messageHash = 'order:' + accountType;
606
- const data = this.safeValue(message, 'data', message);
607
- const order = this.parseWsOrder(data);
608
- if (this.orders === undefined) {
609
- const limit = this.safeInteger(this.options, 'ordersLimit', 1000);
610
- this.orders = new Cache.ArrayCacheBySymbolById(limit);
611
- }
612
- const orders = this.orders;
613
- orders.append(order);
614
- const symbolMessageHash = messageHash + ':' + order['symbol'];
615
- client.resolve(orders, symbolMessageHash);
616
- client.resolve(orders, messageHash);
617
- }
618
- parseWsOrder(order, market = undefined) {
619
- //
620
- // spot order
621
- // {
622
- // "sn": 19399016185, //sequence number
623
- // "orderId": "r17f9d7983faU7223046196CMlrj3bfC",
624
- // "s": "LTC/USDT",
625
- // "ot": "Limit", // order type
626
- // "t": 1647614461160, // last execution timestamp
627
- // "p": "50", // price
628
- // "q": "0.1", // quantity
629
- // "sd": "Buy", // side
630
- // "st": "New", // status
631
- // "ap": "0", // average fill price
632
- // "cfq": "0", // cumulated fill quantity
633
- // "sp": '', // stop price
634
- // "err": '',
635
- // "btb": "0", // base asset total balance
636
- // "bab": "0", // base asset available balance
637
- // "qtb": "8", // quote asset total balance
638
- // "qab": "2.995", // quote asset available balance
639
- // "cf": "0", // cumulated commission
640
- // "fa": "USDT", // fee asset
641
- // "ei": "NULL_VAL"
642
- // }
643
- //
644
- // futures order
645
- // {
646
- // "m": "futures-order",
647
- // "sn": 19399927636,
648
- // "e": "ExecutionReport",
649
- // "a": "futF5SlR9ukAXoDOuXbND4dVpBMw9gzH", // account id
650
- // "ac": "FUTURES",
651
- // "t": 1647622515434, // last execution time
652
- // "ct": 1647622515413, // order creation time
653
- // "orderId": "r17f9df469b1U7223046196Okf5Kbmd",
654
- // "sd": "Buy", // side
655
- // "ot": "Limit", // order type
656
- // "ei": "NULL_VAL",
657
- // "q": "1", // quantity
658
- // "p": "50", //price
659
- // "sp": "0", // stopPrice
660
- // "spb": '', // stopTrigger
661
- // "s": "LTC-PERP", // symbol
662
- // "st": "New", // state
663
- // "err": '',
664
- // "lp": "0", // last filled price
665
- // "lq": "0", // last filled quantity (base asset)
666
- // "ap": "0", // average filled price
667
- // "cfq": "0", // cummulative filled quantity (base asset)
668
- // "f": "0", // commission fee of the current execution
669
- // "cf": "0", // cumulative commission fee
670
- // "fa": "USDT", // fee asset
671
- // "psl": "0",
672
- // "pslt": "market",
673
- // "ptp": "0",
674
- // "ptpt": "market"
675
- // }
676
- //
677
- const status = this.parseOrderStatus(this.safeString(order, 'st'));
678
- const marketId = this.safeString(order, 's');
679
- const timestamp = this.safeInteger(order, 't');
680
- const symbol = this.safeSymbol(marketId, market, '/');
681
- const lastTradeTimestamp = this.safeInteger(order, 't');
682
- const price = this.safeString(order, 'p');
683
- const amount = this.safeString(order, 'q');
684
- const average = this.safeString(order, 'ap');
685
- const filled = this.safeString(order, 'cfq');
686
- const id = this.safeString(order, 'orderId');
687
- const type = this.safeStringLower(order, 'ot');
688
- const side = this.safeStringLower(order, 'sd');
689
- const feeCost = this.safeNumber(order, 'cf');
690
- let fee = undefined;
691
- if (feeCost !== undefined) {
692
- const feeCurrencyId = this.safeString(order, 'fa');
693
- const feeCurrencyCode = this.safeCurrencyCode(feeCurrencyId);
694
- fee = {
695
- 'cost': feeCost,
696
- 'currency': feeCurrencyCode,
697
- };
698
- }
699
- const stopPrice = this.parseNumber(this.omitZero(this.safeString(order, 'sp')));
700
- return this.safeOrder({
701
- 'info': order,
702
- 'id': id,
703
- 'clientOrderId': undefined,
704
- 'timestamp': timestamp,
705
- 'datetime': this.iso8601(timestamp),
706
- 'lastTradeTimestamp': lastTradeTimestamp,
707
- 'symbol': symbol,
708
- 'type': type,
709
- 'timeInForce': undefined,
710
- 'postOnly': undefined,
711
- 'side': side,
712
- 'price': price,
713
- 'stopPrice': stopPrice,
714
- 'triggerPrice': stopPrice,
715
- 'amount': amount,
716
- 'cost': undefined,
717
- 'average': average,
718
- 'filled': filled,
719
- 'remaining': undefined,
720
- 'status': status,
721
- 'fee': fee,
722
- 'trades': undefined,
723
- }, market);
724
- }
725
- handleErrorMessage(client, message) {
726
- //
727
- // {
728
- // "m": "disconnected",
729
- // "code": 100005,
730
- // "reason": "INVALID_WS_REQUEST_DATA",
731
- // "info": "Session is disconnected due to missing pong message from the client"
732
- // }
733
- //
734
- const errorCode = this.safeInteger(message, 'code');
735
- try {
736
- if (errorCode !== undefined) {
737
- const feedback = this.id + ' ' + this.json(message);
738
- this.throwExactlyMatchedException(this.exceptions['exact'], errorCode, feedback);
739
- const messageString = this.safeValue(message, 'message');
740
- if (messageString !== undefined) {
741
- this.throwBroadlyMatchedException(this.exceptions['broad'], messageString, feedback);
742
- }
743
- }
744
- return false;
745
- }
746
- catch (e) {
747
- if (e instanceof errors.AuthenticationError) {
748
- const messageHash = 'authenticated';
749
- client.reject(e, messageHash);
750
- if (messageHash in client.subscriptions) {
751
- delete client.subscriptions[messageHash];
752
- }
753
- }
754
- else {
755
- client.reject(e);
756
- }
757
- return true;
758
- }
759
- }
760
- handleAuthenticate(client, message) {
761
- //
762
- // { m: "auth", id: "1647605234", code: 0 }
763
- //
764
- const messageHash = 'authenticated';
765
- client.resolve(message, messageHash);
766
- }
767
- handleMessage(client, message) {
768
- if (this.handleErrorMessage(client, message)) {
769
- return;
770
- }
771
- //
772
- // { m: "ping", hp: 3 }
773
- //
774
- // { m: "sub", ch: "bar:BTC/USDT", code: 0 }
775
- //
776
- // { m: 'sub', id: "1647515701", ch: "depth:BTC/USDT", code: 0 }
777
- //
778
- // { m: "connected", type: "unauth" }
779
- //
780
- // { m: "auth", id: "1647605234", code: 0 }
781
- //
782
- // order or balance sub
783
- // {
784
- // "m": "sub",
785
- // "id": "1647605952",
786
- // "ch": "order:cshF5SlR9ukAXoDOuXbND4dVpBMw9gzH", or futures-order
787
- // "code": 0
788
- // }
789
- //
790
- // ohlcv
791
- // {
792
- // "m": "bar",
793
- // "s": "BTC/USDT",
794
- // "data": {
795
- // "i": "1",
796
- // "ts": 1647510060000,
797
- // "o": "40813.93",
798
- // "c": "40804.57",
799
- // "h": "40814.21",
800
- // "l": "40804.56",
801
- // "v": "0.01537"
802
- // }
803
- // }
804
- //
805
- // trades
806
- //
807
- // {
808
- // "m": "trades",
809
- // "symbol": "BTC/USDT",
810
- // "data": [
811
- // {
812
- // "p": "40762.26",
813
- // "q": "0.01500",
814
- // "ts": 1647514306759,
815
- // "bm": true,
816
- // "seqnum": 72057633465795180
817
- // }
818
- // ]
819
- // }
820
- //
821
- // orderbook deltas
822
- //
823
- // {
824
- // "m":"depth",
825
- // "symbol":"BTC/USDT",
826
- // "data":{
827
- // "ts":1647527417715,
828
- // "seqnum":28590257013,
829
- // "asks":[
830
- // ["40990.47","0.01619"],
831
- // ["41021.21","0"],
832
- // ["41031.59","0.06096"]
833
- // ],
834
- // "bids":[
835
- // ["40990.46","0.76114"],
836
- // ["40985.18","0"]
837
- // ]
838
- // }
839
- // }
840
- //
841
- // orderbook snapshot
842
- // {
843
- // "m": "depth-snapshot",
844
- // "symbol": "BTC/USDT",
845
- // "data": {
846
- // "ts": 1647525938513,
847
- // "seqnum": 28590504772,
848
- // "asks": [
849
- // [Array], [Array], [Array], [Array], [Array], [Array], [Array],
850
- // [Array], [Array], [Array], [Array], [Array], [Array], [Array],
851
- // [Array], [Array], [Array], [Array], [Array], [Array], [Array],
852
- // (...)
853
- // ]
854
- // }
855
- //
856
- // spot order update
857
- // {
858
- // "m": "order",
859
- // "accountId": "cshQtyfq8XLAA9kcf19h8bXHbAwwoqDo",
860
- // "ac": "CASH",
861
- // "data": {
862
- // "s": "BTC/USDT",
863
- // "sn": 8159711,
864
- // "sd": "Buy",
865
- // "ap": "0",
866
- // "bab": "2006.5974027",
867
- // "btb": "2006.5974027",
868
- // "cf": "0",
869
- // "cfq": "0",
870
- // (...)
871
- // }
872
- // }
873
- // future order update
874
- // {
875
- // "m": "futures-order",
876
- // "sn": 19404258063,
877
- // "e": "ExecutionReport",
878
- // "a": "futF5SlR9ukAXoDOuXbND4dVpBMw9gzH",
879
- // "ac": "FUTURES",
880
- // "t": 1647681792543,
881
- // "ct": 1647622515413,
882
- // "orderId": "r17f9df469b1U7223046196Okf5KbmdL",
883
- // (...)
884
- // "ptpt": "None"
885
- // }
886
- //
887
- // balance update cash
888
- // {
889
- // "m": "balance",
890
- // "accountId": "cshQtyfq8XLAA9kcf19h8bXHbAwwoqDo",
891
- // "ac": "CASH",
892
- // "data": {
893
- // "a" : "USDT",
894
- // "sn": 8159798,
895
- // "tb": "600",
896
- // "ab": "600"
897
- // }
898
- // }
899
- //
900
- // balance update margin
901
- // {
902
- // "m": "balance",
903
- // "accountId": "marOxpKJV83dxTRx0Eyxpa0gxc4Txt0P",
904
- // "ac": "MARGIN",
905
- // "data": {
906
- // "a" : "USDT",
907
- // "sn" : 8159802,
908
- // "tb" : "400",
909
- // "ab" : "400",
910
- // "brw": "0",
911
- // "int": "0"
912
- // }
913
- // }
914
- //
915
- const subject = this.safeString(message, 'm');
916
- const methods = {
917
- 'ping': this.handlePing,
918
- 'auth': this.handleAuthenticate,
919
- 'sub': this.handleSubscriptionStatus,
920
- 'depth': this.handleOrderBook,
921
- 'depth-snapshot': this.handleOrderBookSnapshot,
922
- 'trades': this.handleTrades,
923
- 'bar': this.handleOHLCV,
924
- 'balance': this.handleBalance,
925
- 'futures-account-update': this.handleBalance,
926
- };
927
- const method = this.safeValue(methods, subject);
928
- if (method !== undefined) {
929
- method.call(this, client, message);
930
- }
931
- if ((subject === 'order') || (subject === 'futures-order')) {
932
- // this.handleOrder (client, message);
933
- // balance updates may be in the order structure
934
- // they may also be standalone balance updates related to account transfers
935
- this.handleOrder(client, message);
936
- if (subject === 'order') {
937
- this.handleBalance(client, message);
938
- }
939
- }
940
- }
941
- handleSubscriptionStatus(client, message) {
942
- //
943
- // { m: "sub", ch: "bar:BTC/USDT", code: 0 }
944
- //
945
- // { m: 'sub', id: "1647515701", ch: "depth:BTC/USDT", code: 0 }
946
- //
947
- const channel = this.safeString(message, 'ch', '');
948
- if (channel.indexOf('depth') > -1 && !(channel.indexOf('depth-snapshot') > -1)) {
949
- this.handleOrderBookSubscription(client, message);
950
- }
951
- return message;
952
- }
953
- handleOrderBookSubscription(client, message) {
954
- const channel = this.safeString(message, 'ch');
955
- const parts = channel.split(':');
956
- const marketId = parts[1];
957
- const market = this.safeMarket(marketId);
958
- const symbol = market['symbol'];
959
- if (symbol in this.orderbooks) {
960
- delete this.orderbooks[symbol];
961
- }
962
- this.orderbooks[symbol] = this.orderBook({});
963
- if (this.options['defaultType'] === 'swap' || market['contract']) {
964
- this.spawn(this.fetchOrderBookSnapshotCustom, symbol);
965
- }
966
- else {
967
- this.spawn(this.watchOrderBookSnapshot, symbol);
968
- }
969
- }
970
- async pong(client, message) {
971
- //
972
- // { m: "ping", hp: 3 }
973
- //
974
- try {
975
- await client.send({ 'op': 'pong', 'hp': this.safeInteger(message, 'hp') });
976
- }
977
- catch (e) {
978
- const error = new errors.NetworkError(this.id + ' handlePing failed with error ' + this.exceptionMessage(e));
979
- client.reset(error);
980
- }
981
- }
982
- handlePing(client, message) {
983
- this.spawn(this.pong, client, message);
984
- }
985
- async authenticate(url, params = {}) {
986
- this.checkRequiredCredentials();
987
- const messageHash = 'authenticated';
988
- const client = this.client(url);
989
- let future = this.safeValue(client.subscriptions, messageHash);
990
- if (future === undefined) {
991
- const timestamp = this.milliseconds().toString();
992
- const urlParts = url.split('/');
993
- const partsLength = urlParts.length;
994
- const path = this.safeString(urlParts, partsLength - 1);
995
- const version = this.safeString(urlParts, partsLength - 2);
996
- const auth = timestamp + '+' + version + '/' + path;
997
- const secret = this.base64ToBinary(this.secret);
998
- const signature = this.hmac(this.encode(auth), secret, sha2_js.sha256, 'base64');
999
- const request = {
1000
- 'op': 'auth',
1001
- 'id': this.nonce().toString(),
1002
- 't': timestamp,
1003
- 'key': this.apiKey,
1004
- 'sig': signature,
1005
- };
1006
- future = await this.watch(url, messageHash, this.extend(request, params), messageHash);
1007
- client.subscriptions[messageHash] = future;
1008
- }
1009
- return future;
1010
- }
1011
- }
1012
-
1013
- exports["default"] = ascendex;