ccxt 4.4.73 → 4.4.75

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 (89) hide show
  1. package/README.md +4 -4
  2. package/dist/ccxt.browser.min.js +2 -2
  3. package/dist/cjs/ccxt.js +1 -11
  4. package/dist/cjs/src/ace.js +9 -6
  5. package/dist/cjs/src/alpaca.js +3 -0
  6. package/dist/cjs/src/ascendex.js +6 -0
  7. package/dist/cjs/src/base/Exchange.js +36 -14
  8. package/dist/cjs/src/bequant.js +1 -0
  9. package/dist/cjs/src/binanceusdm.js +1 -1
  10. package/dist/cjs/src/bit2c.js +30 -4
  11. package/dist/cjs/src/bitbank.js +32 -0
  12. package/dist/cjs/src/bitbns.js +1 -1
  13. package/dist/cjs/src/bitflyer.js +1 -0
  14. package/dist/cjs/src/bithumb.js +34 -0
  15. package/dist/cjs/src/bitmart.js +74 -7
  16. package/dist/cjs/src/bitopro.js +37 -0
  17. package/dist/cjs/src/blofin.js +1 -1
  18. package/dist/cjs/src/bybit.js +14 -1
  19. package/dist/cjs/src/coinlist.js +87 -11
  20. package/dist/cjs/src/deribit.js +29 -1
  21. package/dist/cjs/src/gate.js +12 -7
  22. package/dist/cjs/src/hitbtc.js +7 -1
  23. package/dist/cjs/src/okx.js +29 -25
  24. package/dist/cjs/src/pro/ascendex.js +1 -1
  25. package/dist/cjs/src/pro/bingx.js +10 -1
  26. package/dist/cjs/src/pro/bitget.js +10 -1
  27. package/dist/cjs/src/pro/bitmart.js +10 -1
  28. package/dist/cjs/src/pro/bitopro.js +5 -4
  29. package/dist/cjs/src/pro/onetrading.js +7 -7
  30. package/js/ccxt.d.ts +2 -14
  31. package/js/ccxt.js +2 -10
  32. package/js/src/abstract/bitmart.d.ts +2 -0
  33. package/js/src/abstract/coinlist.d.ts +3 -0
  34. package/js/src/ace.js +9 -6
  35. package/js/src/alpaca.js +3 -0
  36. package/js/src/ascendex.js +6 -0
  37. package/js/src/base/Exchange.d.ts +1 -0
  38. package/js/src/base/Exchange.js +36 -14
  39. package/js/src/bequant.js +1 -0
  40. package/js/src/binanceusdm.js +1 -1
  41. package/js/src/bit2c.js +30 -4
  42. package/js/src/bitbank.js +32 -0
  43. package/js/src/bitbns.js +1 -1
  44. package/js/src/bitflyer.js +1 -0
  45. package/js/src/bithumb.js +34 -0
  46. package/js/src/bitmart.d.ts +24 -0
  47. package/js/src/bitmart.js +74 -7
  48. package/js/src/bitopro.js +37 -0
  49. package/js/src/blofin.js +1 -1
  50. package/js/src/bybit.js +14 -1
  51. package/js/src/coinlist.js +87 -11
  52. package/js/src/deribit.js +29 -1
  53. package/js/src/gate.js +12 -7
  54. package/js/src/hitbtc.js +7 -1
  55. package/js/src/okx.js +29 -25
  56. package/js/src/pro/ascendex.js +1 -1
  57. package/js/src/pro/bingx.js +10 -1
  58. package/js/src/pro/bitget.js +10 -1
  59. package/js/src/pro/bitmart.js +10 -1
  60. package/js/src/pro/bitopro.js +5 -4
  61. package/js/src/pro/onetrading.d.ts +7 -7
  62. package/js/src/pro/onetrading.js +7 -7
  63. package/package.json +1 -1
  64. package/js/src/abstract/bitcoincom.d.ts +0 -118
  65. package/js/src/abstract/bitcoincom.js +0 -11
  66. package/js/src/abstract/bitfinex1.d.ts +0 -72
  67. package/js/src/abstract/bitfinex1.js +0 -11
  68. package/js/src/abstract/bitpanda.d.ts +0 -26
  69. package/js/src/abstract/bitpanda.js +0 -11
  70. package/js/src/abstract/poloniexfutures.d.ts +0 -51
  71. package/js/src/abstract/poloniexfutures.js +0 -11
  72. package/js/src/abstract/wazirx.d.ts +0 -33
  73. package/js/src/abstract/wazirx.js +0 -11
  74. package/js/src/bitcoincom.d.ts +0 -4
  75. package/js/src/bitcoincom.js +0 -18
  76. package/js/src/bitpanda.d.ts +0 -4
  77. package/js/src/bitpanda.js +0 -17
  78. package/js/src/poloniexfutures.d.ts +0 -321
  79. package/js/src/poloniexfutures.js +0 -1941
  80. package/js/src/pro/bitcoincom.d.ts +0 -4
  81. package/js/src/pro/bitcoincom.js +0 -34
  82. package/js/src/pro/bitpanda.d.ts +0 -4
  83. package/js/src/pro/bitpanda.js +0 -17
  84. package/js/src/pro/poloniexfutures.d.ts +0 -108
  85. package/js/src/pro/poloniexfutures.js +0 -1042
  86. package/js/src/pro/wazirx.d.ts +0 -102
  87. package/js/src/pro/wazirx.js +0 -784
  88. package/js/src/static_dependencies/starknet/utils/json.d.ts +0 -24
  89. package/js/src/static_dependencies/starknet/utils/json.js +0 -43
@@ -1,784 +0,0 @@
1
- // ----------------------------------------------------------------------------
2
-
3
- // PLEASE DO NOT EDIT THIS FILE, IT IS GENERATED AND WILL BE OVERWRITTEN:
4
- // https://github.com/ccxt/ccxt/blob/master/CONTRIBUTING.md#how-to-contribute-code
5
- // EDIT THE CORRESPONDENT .ts FILE INSTEAD
6
-
7
- // ---------------------------------------------------------------------------
8
- import wazirxRest from '../wazirx.js';
9
- import { NotSupported, ExchangeError } from '../base/errors.js';
10
- import { ArrayCacheBySymbolById, ArrayCacheByTimestamp, ArrayCache } from '../base/ws/Cache.js';
11
- // ---------------------------------------------------------------------------
12
- export default class wazirx extends wazirxRest {
13
- describe() {
14
- return this.deepExtend(super.describe(), {
15
- 'has': {
16
- 'ws': true,
17
- 'watchBalance': true,
18
- 'watchTicker': true,
19
- 'watchTickers': true,
20
- 'watchTrades': true,
21
- 'watchTradesForSymbols': false,
22
- 'watchMyTrades': true,
23
- 'watchOrders': true,
24
- 'watchOrderBook': true,
25
- 'watchOHLCV': true,
26
- },
27
- 'urls': {
28
- 'api': {
29
- 'ws': 'wss://stream.wazirx.com/stream',
30
- },
31
- },
32
- 'options': {},
33
- 'streaming': {},
34
- 'exceptions': {},
35
- 'api': {
36
- 'private': {
37
- 'post': {
38
- 'create_auth_token': 1,
39
- },
40
- },
41
- },
42
- });
43
- }
44
- /**
45
- * @method
46
- * @name wazirx#watchBalance
47
- * @description watch balance and get the amount of funds available for trading or funds locked in orders
48
- * @see https://docs.wazirx.com/#account-update
49
- * @param {object} [params] extra parameters specific to the exchange API endpoint
50
- * @returns {object} a [balance structure]{@link https://docs.ccxt.com/#/?id=balance-structure}
51
- */
52
- async watchBalance(params = {}) {
53
- await this.loadMarkets();
54
- const token = await this.authenticate(params);
55
- const messageHash = 'balance';
56
- const url = this.urls['api']['ws'];
57
- const subscribe = {
58
- 'event': 'subscribe',
59
- 'streams': ['outboundAccountPosition'],
60
- 'auth_key': token,
61
- };
62
- const request = this.deepExtend(subscribe, params);
63
- return await this.watch(url, messageHash, request, messageHash);
64
- }
65
- handleBalance(client, message) {
66
- //
67
- // {
68
- // "data":
69
- // {
70
- // "B": [
71
- // {
72
- // "a":"wrx",
73
- // "b":"2043856.426455209",
74
- // "l":"3001318.98"
75
- // }
76
- // ],
77
- // "E":1631683058909
78
- // },
79
- // "stream":"outboundAccountPosition"
80
- // }
81
- //
82
- const data = this.safeValue(message, 'data', {});
83
- const balances = this.safeValue(data, 'B', []);
84
- const timestamp = this.safeInteger(data, 'E');
85
- this.balance['info'] = balances;
86
- this.balance['timestamp'] = timestamp;
87
- this.balance['datetime'] = this.iso8601(timestamp);
88
- for (let i = 0; i < balances.length; i++) {
89
- const balance = balances[i];
90
- const currencyId = this.safeString(balance, 'a');
91
- const code = this.safeCurrencyCode(currencyId);
92
- const available = this.safeString(balance, 'b');
93
- const locked = this.safeString(balance, 'l');
94
- const account = this.account();
95
- account['free'] = available;
96
- account['used'] = locked;
97
- this.balance[code] = account;
98
- }
99
- this.balance = this.safeBalance(this.balance);
100
- const messageHash = 'balance';
101
- client.resolve(this.balance, messageHash);
102
- }
103
- parseWsTrade(trade, market = undefined) {
104
- //
105
- // trade
106
- // {
107
- // "E": 1631681323000, Event time
108
- // "S": "buy", Side
109
- // "a": 26946138, Buyer order ID
110
- // "b": 26946169, Seller order ID
111
- // "m": true, Is buyer maker?
112
- // "p": "7.0", Price
113
- // "q": "15.0", Quantity
114
- // "s": "btcinr", Symbol
115
- // "t": 17376030 Trade ID
116
- // }
117
- // ownTrade
118
- // {
119
- // "E": 1631683058000,
120
- // "S": "ask",
121
- // "U": "inr",
122
- // "a": 114144050,
123
- // "b": 114144121,
124
- // "f": "0.2",
125
- // "m": true,
126
- // "o": 26946170,
127
- // "p": "5.0",
128
- // "q": "20.0",
129
- // "s": "btcinr",
130
- // "t": 17376032,
131
- // "w": "100.0"
132
- // }
133
- //
134
- const timestamp = this.safeInteger(trade, 'E');
135
- const marketId = this.safeString(trade, 's');
136
- market = this.safeMarket(marketId, market);
137
- const feeCost = this.safeString(trade, 'f');
138
- const feeCurrencyId = this.safeString(trade, 'U');
139
- const isMaker = this.safeValue(trade, 'm') === true;
140
- let fee = undefined;
141
- if (feeCost !== undefined) {
142
- fee = {
143
- 'cost': feeCost,
144
- 'currency': this.safeCurrencyCode(feeCurrencyId),
145
- 'rate': undefined,
146
- };
147
- }
148
- return this.safeTrade({
149
- 'id': this.safeString(trade, 't'),
150
- 'info': trade,
151
- 'timestamp': timestamp,
152
- 'datetime': this.iso8601(timestamp),
153
- 'symbol': market['symbol'],
154
- 'order': this.safeStringN(trade, ['o']),
155
- 'type': undefined,
156
- 'side': this.safeString(trade, 'S'),
157
- 'takerOrMaker': isMaker ? 'maker' : 'taker',
158
- 'price': this.safeString(trade, 'p'),
159
- 'amount': this.safeString(trade, 'q'),
160
- 'cost': undefined,
161
- 'fee': fee,
162
- }, market);
163
- }
164
- /**
165
- * @method
166
- * @name wazirx#watchTicker
167
- * @description watches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market
168
- * @see https://docs.wazirx.com/#all-market-tickers-stream
169
- * @param {string} symbol unified symbol of the market to fetch the ticker for
170
- * @param {object} [params] extra parameters specific to the exchange API endpoint
171
- * @returns {object} a [ticker structure]{@link https://docs.ccxt.com/#/?id=ticker-structure}
172
- */
173
- async watchTicker(symbol, params = {}) {
174
- await this.loadMarkets();
175
- const market = this.market(symbol);
176
- const url = this.urls['api']['ws'];
177
- const messageHash = 'ticker:' + market['symbol'];
178
- const subscribeHash = 'tickers';
179
- const stream = '!' + 'ticker@arr';
180
- const subscribe = {
181
- 'event': 'subscribe',
182
- 'streams': [stream],
183
- };
184
- const request = this.deepExtend(subscribe, params);
185
- return await this.watch(url, messageHash, request, subscribeHash);
186
- }
187
- /**
188
- * @method
189
- * @name wazirx#watchTickers
190
- * @description watches a price ticker, a statistical calculation with the information calculated over the past 24 hours for all markets of a specific list
191
- * @see https://docs.wazirx.com/#all-market-tickers-stream
192
- * @param {string[]} symbols unified symbol of the market to fetch the ticker for
193
- * @param {object} [params] extra parameters specific to the exchange API endpoint
194
- * @returns {object} a [ticker structure]{@link https://docs.ccxt.com/#/?id=ticker-structure}
195
- */
196
- async watchTickers(symbols = undefined, params = {}) {
197
- await this.loadMarkets();
198
- symbols = this.marketSymbols(symbols);
199
- const url = this.urls['api']['ws'];
200
- const messageHash = 'tickers';
201
- const stream = '!' + 'ticker@arr';
202
- const subscribe = {
203
- 'event': 'subscribe',
204
- 'streams': [stream],
205
- };
206
- const request = this.deepExtend(subscribe, params);
207
- const tickers = await this.watch(url, messageHash, request, messageHash);
208
- return this.filterByArray(tickers, 'symbol', symbols, false);
209
- }
210
- handleTicker(client, message) {
211
- //
212
- // {
213
- // "data":
214
- // [
215
- // {
216
- // "E":1631625534000, // Event time
217
- // "T":"SPOT", // Type
218
- // "U":"wrx", // Quote unit
219
- // "a":"0.0", // Best sell price
220
- // "b":"0.0", // Best buy price
221
- // "c":"5.0", // Last price
222
- // "h":"5.0", // High price
223
- // "l":"5.0", // Low price
224
- // "o":"5.0", // Open price
225
- // "q":"0.0", // Quantity
226
- // "s":"btcwrx", // Symbol
227
- // "u":"btc" // Base unit
228
- // }
229
- // ],
230
- // "stream":"!ticker@arr"
231
- // }
232
- //
233
- const data = this.safeValue(message, 'data', []);
234
- for (let i = 0; i < data.length; i++) {
235
- const ticker = data[i];
236
- const parsedTicker = this.parseWSTicker(ticker);
237
- const symbol = parsedTicker['symbol'];
238
- this.tickers[symbol] = parsedTicker;
239
- const messageHash = 'ticker:' + symbol;
240
- client.resolve(parsedTicker, messageHash);
241
- }
242
- client.resolve(this.tickers, 'tickers');
243
- }
244
- parseWSTicker(ticker, market = undefined) {
245
- //
246
- // {
247
- // "E":1631625534000, // Event time
248
- // "T":"SPOT", // Type
249
- // "U":"wrx", // Quote unit
250
- // "a":"0.0", // Best sell price
251
- // "b":"0.0", // Best buy price
252
- // "c":"5.0", // Last price
253
- // "h":"5.0", // High price
254
- // "l":"5.0", // Low price
255
- // "o":"5.0", // Open price
256
- // "q":"0.0", // Quantity
257
- // "s":"btcwrx", // Symbol
258
- // "u":"btc" // Base unit
259
- // }
260
- //
261
- const marketId = this.safeString(ticker, 's');
262
- const timestamp = this.safeInteger(ticker, 'E');
263
- return this.safeTicker({
264
- 'symbol': this.safeSymbol(marketId, market),
265
- 'timestamp': timestamp,
266
- 'datetime': this.iso8601(timestamp),
267
- 'high': this.safeString(ticker, 'h'),
268
- 'low': this.safeString(ticker, 'l'),
269
- 'bid': this.safeNumber(ticker, 'b'),
270
- 'bidVolume': undefined,
271
- 'ask': this.safeNumber(ticker, 'a'),
272
- 'askVolume': undefined,
273
- 'vwap': undefined,
274
- 'open': this.safeString(ticker, 'o'),
275
- 'close': undefined,
276
- 'last': this.safeString(ticker, 'l'),
277
- 'previousClose': undefined,
278
- 'change': undefined,
279
- 'percentage': undefined,
280
- 'average': undefined,
281
- 'baseVolume': undefined,
282
- 'quoteVolume': this.safeString(ticker, 'q'),
283
- 'info': ticker,
284
- }, market);
285
- }
286
- /**
287
- * @method
288
- * @name wazirx#watchTrades
289
- * @description get the list of most recent trades for a particular symbol
290
- * @see https://docs.wazirx.com/#trade-streams
291
- * @param {string} symbol unified symbol of the market to fetch trades for
292
- * @param {int} [since] timestamp in ms of the earliest trade to fetch
293
- * @param {int} [limit] the maximum amount of trades to fetch
294
- * @param {object} [params] extra parameters specific to the exchange API endpoint
295
- * @returns {object[]} a list of [trade structures]{@link https://docs.ccxt.com/#/?id=public-trades}
296
- */
297
- async watchTrades(symbol, since = undefined, limit = undefined, params = {}) {
298
- await this.loadMarkets();
299
- const market = this.market(symbol);
300
- symbol = market['symbol'];
301
- const messageHash = market['id'] + '@trades';
302
- const url = this.urls['api']['ws'];
303
- const message = {
304
- 'event': 'subscribe',
305
- 'streams': [messageHash],
306
- };
307
- const request = this.extend(message, params);
308
- const trades = await this.watch(url, messageHash, request, messageHash);
309
- if (this.newUpdates) {
310
- limit = trades.getLimit(symbol, limit);
311
- }
312
- return this.filterBySinceLimit(trades, since, limit, 'timestamp', true);
313
- }
314
- handleTrades(client, message) {
315
- //
316
- // {
317
- // "data": {
318
- // "trades": [{
319
- // "E": 1631681323000, Event time
320
- // "S": "buy", Side
321
- // "a": 26946138, Buyer order ID
322
- // "b": 26946169, Seller order ID
323
- // "m": true, Is buyer maker?
324
- // "p": "7.0", Price
325
- // "q": "15.0", Quantity
326
- // "s": "btcinr", Symbol
327
- // "t": 17376030 Trade ID
328
- // }]
329
- // },
330
- // "stream": "btcinr@trades"
331
- // }
332
- //
333
- const data = this.safeValue(message, 'data', {});
334
- const rawTrades = this.safeValue(data, 'trades', []);
335
- const messageHash = this.safeString(message, 'stream');
336
- const split = messageHash.split('@');
337
- const marketId = this.safeString(split, 0);
338
- const market = this.safeMarket(marketId);
339
- const symbol = this.safeSymbol(marketId, market);
340
- let trades = this.safeValue(this.trades, symbol);
341
- if (trades === undefined) {
342
- const limit = this.safeInteger(this.options, 'tradesLimit', 1000);
343
- trades = new ArrayCache(limit);
344
- this.trades[symbol] = trades;
345
- }
346
- for (let i = 0; i < rawTrades.length; i++) {
347
- const parsedTrade = this.parseWsTrade(rawTrades[i], market);
348
- trades.append(parsedTrade);
349
- }
350
- client.resolve(trades, messageHash);
351
- }
352
- /**
353
- * @method
354
- * @name wazirx#watchMyTrades
355
- * @description watch trades by user
356
- * @see https://docs.wazirx.com/#trade-update
357
- * @param {string} symbol unified symbol of the market to fetch trades for
358
- * @param {int} [since] timestamp in ms of the earliest trade to fetch
359
- * @param {int} [limit] the maximum amount of trades to fetch
360
- * @param {object} [params] extra parameters specific to the exchange API endpoint
361
- * @returns {object[]} a list of [trade structures]{@link https://docs.ccxt.com/#/?id=public-trades}
362
- */
363
- async watchMyTrades(symbol = undefined, since = undefined, limit = undefined, params = {}) {
364
- await this.loadMarkets();
365
- const token = await this.authenticate(params);
366
- if (symbol !== undefined) {
367
- const market = this.market(symbol);
368
- symbol = market['symbol'];
369
- }
370
- const url = this.urls['api']['ws'];
371
- const messageHash = 'myTrades';
372
- const message = {
373
- 'event': 'subscribe',
374
- 'streams': ['ownTrade'],
375
- 'auth_key': token,
376
- };
377
- const request = this.deepExtend(message, params);
378
- const trades = await this.watch(url, messageHash, request, messageHash);
379
- if (this.newUpdates) {
380
- limit = trades.getLimit(symbol, limit);
381
- }
382
- return this.filterBySymbolSinceLimit(trades, symbol, since, limit, true);
383
- }
384
- /**
385
- * @method
386
- * @name wazirx#watchOHLCV
387
- * @description watches historical candlestick data containing the open, high, low, and close price, and the volume of a market
388
- * @see https://docs.wazirx.com/#kline-candlestick-stream
389
- * @param {string} symbol unified symbol of the market to fetch OHLCV data for
390
- * @param {string} timeframe the length of time each candle represents
391
- * @param {int} [since] timestamp in ms of the earliest candle to fetch
392
- * @param {int} [limit] the maximum amount of candles to fetch
393
- * @param {object} [params] extra parameters specific to the exchange API endpoint
394
- * @returns {int[][]} A list of candles ordered as timestamp, open, high, low, close, volume
395
- */
396
- async watchOHLCV(symbol, timeframe = '1m', since = undefined, limit = undefined, params = {}) {
397
- await this.loadMarkets();
398
- const market = this.market(symbol);
399
- symbol = market['symbol'];
400
- const url = this.urls['api']['ws'];
401
- const messageHash = 'ohlcv:' + symbol + ':' + timeframe;
402
- const stream = market['id'] + '@kline_' + timeframe;
403
- const message = {
404
- 'event': 'subscribe',
405
- 'streams': [stream],
406
- };
407
- const request = this.deepExtend(message, params);
408
- const ohlcv = await this.watch(url, messageHash, request, messageHash);
409
- if (this.newUpdates) {
410
- limit = ohlcv.getLimit(symbol, limit);
411
- }
412
- return this.filterBySinceLimit(ohlcv, since, limit, 0, true);
413
- }
414
- handleOHLCV(client, message) {
415
- //
416
- // {
417
- // "data": {
418
- // "E":1631683058904, Event time
419
- // "s": "btcinr", Symbol
420
- // "t": 1638747660000, Kline start time
421
- // "T": 1638747719999, Kline close time
422
- // "i": "1m", Interval
423
- // "o": "0.0010", Open price
424
- // "c": "0.0020", Close price
425
- // "h": "0.0025", High price
426
- // "l": "0.0015", Low price
427
- // "v": "1000", Base asset volume
428
- // },
429
- // "stream": "btcinr@kline_1m"
430
- // }
431
- //
432
- const data = this.safeValue(message, 'data', {});
433
- const marketId = this.safeString(data, 's');
434
- const market = this.safeMarket(marketId);
435
- const symbol = this.safeSymbol(marketId, market);
436
- const timeframe = this.safeString(data, 'i');
437
- this.ohlcvs[symbol] = this.safeValue(this.ohlcvs, symbol, {});
438
- let stored = this.safeValue(this.ohlcvs[symbol], timeframe);
439
- if (stored === undefined) {
440
- const limit = this.safeInteger(this.options, 'OHLCVLimit', 1000);
441
- stored = new ArrayCacheByTimestamp(limit);
442
- this.ohlcvs[symbol][timeframe] = stored;
443
- }
444
- const parsed = this.parseWsOHLCV(data, market);
445
- stored.append(parsed);
446
- const messageHash = 'ohlcv:' + symbol + ':' + timeframe;
447
- client.resolve(stored, messageHash);
448
- }
449
- parseWsOHLCV(ohlcv, market = undefined) {
450
- //
451
- // {
452
- // "E":1631683058904, Event time
453
- // "s": "btcinr", Symbol
454
- // "t": 1638747660000, Kline start time
455
- // "T": 1638747719999, Kline close time
456
- // "i": "1m", Interval
457
- // "o": "0.0010", Open price
458
- // "c": "0.0020", Close price
459
- // "h": "0.0025", High price
460
- // "l": "0.0015", Low price
461
- // "v": "1000", Base asset volume
462
- // }
463
- //
464
- return [
465
- this.safeInteger(ohlcv, 't'),
466
- this.safeNumber(ohlcv, 'o'),
467
- this.safeNumber(ohlcv, 'c'),
468
- this.safeNumber(ohlcv, 'h'),
469
- this.safeNumber(ohlcv, 'l'),
470
- this.safeNumber(ohlcv, 'v'),
471
- ];
472
- }
473
- /**
474
- * @method
475
- * @name wazirx#watchOrderBook
476
- * @description watches information on open orders with bid (buy) and ask (sell) prices, volumes and other data
477
- * @see https://docs.wazirx.com/#depth-stream
478
- * @param {string} symbol unified symbol of the market to fetch the order book for
479
- * @param {int} [limit] the maximum amount of order book entries to return
480
- * @param {object} [params] extra parameters specific to the exchange API endpoint
481
- * @returns {object} A dictionary of [order book structures]{@link https://docs.ccxt.com/#/?id=order-book-structure} indexed by market symbols
482
- */
483
- async watchOrderBook(symbol, limit = undefined, params = {}) {
484
- await this.loadMarkets();
485
- const market = this.market(symbol);
486
- symbol = market['symbol'];
487
- const url = this.urls['api']['ws'];
488
- const messageHash = 'orderbook:' + symbol;
489
- const stream = market['id'] + '@depth';
490
- const subscribe = {
491
- 'event': 'subscribe',
492
- 'streams': [stream],
493
- };
494
- const request = this.deepExtend(subscribe, params);
495
- const orderbook = await this.watch(url, messageHash, request, messageHash);
496
- return orderbook.limit();
497
- }
498
- handleDelta(bookside, delta) {
499
- const bidAsk = this.parseBidAsk(delta, 0, 1);
500
- bookside.storeArray(bidAsk);
501
- }
502
- handleDeltas(bookside, deltas) {
503
- for (let i = 0; i < deltas.length; i++) {
504
- this.handleDelta(bookside, deltas[i]);
505
- }
506
- }
507
- handleOrderBook(client, message) {
508
- //
509
- // {
510
- // "data": {
511
- // "E": 1659475095000,
512
- // "a": [
513
- // ["23051.0", "1.30141"],
514
- // ],
515
- // "b": [
516
- // ["22910.0", "1.30944"],
517
- // ],
518
- // "s": "btcusdt"
519
- // },
520
- // "stream": "btcusdt@depth"
521
- // }
522
- //
523
- const data = this.safeValue(message, 'data', {});
524
- const timestamp = this.safeInteger(data, 'E');
525
- const marketId = this.safeString(data, 's');
526
- const market = this.safeMarket(marketId);
527
- const symbol = market['symbol'];
528
- const messageHash = 'orderbook:' + symbol;
529
- // const currentOrderBook = this.safeValue (this.orderbooks, symbol);
530
- if (!(symbol in this.orderbooks)) {
531
- const snapshot = this.parseOrderBook(data, symbol, timestamp, 'b', 'a');
532
- this.orderbooks[symbol] = this.orderBook(snapshot);
533
- }
534
- else {
535
- const orderbook = this.orderbooks[symbol];
536
- const asks = this.safeList(data, 'a', []);
537
- const bids = this.safeList(data, 'b', []);
538
- this.handleDeltas(orderbook['asks'], asks);
539
- this.handleDeltas(orderbook['bids'], bids);
540
- orderbook['nonce'] = timestamp;
541
- orderbook['timestamp'] = timestamp;
542
- orderbook['datetime'] = this.iso8601(timestamp);
543
- this.orderbooks[symbol] = orderbook;
544
- }
545
- client.resolve(this.orderbooks[symbol], messageHash);
546
- }
547
- async watchOrders(symbol = undefined, since = undefined, limit = undefined, params = {}) {
548
- await this.loadMarkets();
549
- if (symbol !== undefined) {
550
- const market = this.market(symbol);
551
- symbol = market['symbol'];
552
- }
553
- const token = await this.authenticate(params);
554
- const messageHash = 'orders';
555
- const message = {
556
- 'event': 'subscribe',
557
- 'streams': ['orderUpdate'],
558
- 'auth_key': token,
559
- };
560
- const url = this.urls['api']['ws'];
561
- const request = this.deepExtend(message, params);
562
- const orders = await this.watch(url, messageHash, request, messageHash, request);
563
- if (this.newUpdates) {
564
- limit = orders.getLimit(symbol, limit);
565
- }
566
- return this.filterBySymbolSinceLimit(orders, symbol, since, limit, true);
567
- }
568
- handleOrder(client, message) {
569
- //
570
- // {
571
- // "data": {
572
- // "E": 1631683058904,
573
- // "O": 1631683058000,
574
- // "S": "ask",
575
- // "V": "70.0",
576
- // "X": "wait",
577
- // "i": 26946170,
578
- // "m": true,
579
- // "o": "sell",
580
- // "p": "5.0",
581
- // "q": "70.0",
582
- // "s": "wrxinr",
583
- // "v": "0.0"
584
- // },
585
- // "stream": "orderUpdate"
586
- // }
587
- //
588
- const order = this.safeValue(message, 'data', {});
589
- const parsedOrder = this.parseWsOrder(order);
590
- if (this.orders === undefined) {
591
- const limit = this.safeInteger(this.options, 'ordersLimit', 1000);
592
- this.orders = new ArrayCacheBySymbolById(limit);
593
- }
594
- const orders = this.orders;
595
- orders.append(parsedOrder);
596
- let messageHash = 'orders';
597
- client.resolve(this.orders, messageHash);
598
- messageHash += ':' + parsedOrder['symbol'];
599
- client.resolve(this.orders, messageHash);
600
- }
601
- parseWsOrder(order, market = undefined) {
602
- //
603
- // {
604
- // "E": 1631683058904,
605
- // "O": 1631683058000,
606
- // "S": "ask",
607
- // "V": "70.0",
608
- // "X": "wait",
609
- // "i": 26946170,
610
- // "m": true,
611
- // "o": "sell",
612
- // "p": "5.0",
613
- // "q": "70.0",
614
- // "s": "wrxinr",
615
- // "v": "0.0"
616
- // }
617
- //
618
- const timestamp = this.safeInteger(order, 'O');
619
- const marketId = this.safeString(order, 's');
620
- const status = this.safeString(order, 'X');
621
- market = this.safeMarket(marketId);
622
- return this.safeOrder({
623
- 'info': order,
624
- 'id': this.safeString(order, 'i'),
625
- 'clientOrderId': this.safeString(order, 'c'),
626
- 'datetime': this.iso8601(timestamp),
627
- 'timestamp': timestamp,
628
- 'lastTradeTimestamp': undefined,
629
- 'symbol': market['symbol'],
630
- 'type': this.safeValue(order, 'm') ? 'limit' : 'market',
631
- 'timeInForce': undefined,
632
- 'postOnly': undefined,
633
- 'side': this.safeString(order, 'o'),
634
- 'price': this.safeString(order, 'p'),
635
- 'stopPrice': undefined,
636
- 'triggerPrice': undefined,
637
- 'amount': this.safeString(order, 'V'),
638
- 'filled': undefined,
639
- 'remaining': this.safeString(order, 'q'),
640
- 'cost': undefined,
641
- 'average': this.safeString(order, 'v'),
642
- 'status': this.parseOrderStatus(status),
643
- 'fee': undefined,
644
- 'trades': undefined,
645
- }, market);
646
- }
647
- handleMyTrades(client, message) {
648
- //
649
- // {
650
- // "data": {
651
- // "E": 1631683058000,
652
- // "S": "ask",
653
- // "U": "usdt",
654
- // "a": 114144050,
655
- // "b": 114144121,
656
- // "f": "0.2",
657
- // "ga": "0.0",
658
- // "gc": "usdt",
659
- // "m": true,
660
- // "o": 26946170,
661
- // "p": "5.0",
662
- // "q": "20.0",
663
- // "s": "btcusdt",
664
- // "t": 17376032,
665
- // "w": "100.0"
666
- // },
667
- // "stream": "ownTrade"
668
- // }
669
- //
670
- const trade = this.safeValue(message, 'data', {});
671
- const messageHash = 'myTrades';
672
- let myTrades = undefined;
673
- if (this.myTrades === undefined) {
674
- const limit = this.safeInteger(this.options, 'tradesLimit', 1000);
675
- myTrades = new ArrayCacheBySymbolById(limit);
676
- this.myTrades = myTrades;
677
- }
678
- else {
679
- myTrades = this.myTrades;
680
- }
681
- const parsedTrade = this.parseWsTrade(trade);
682
- myTrades.append(parsedTrade);
683
- client.resolve(myTrades, messageHash);
684
- }
685
- handleConnected(client, message) {
686
- //
687
- // {
688
- // "data": {
689
- // "timeout_duration": 1800
690
- // },
691
- // "event": "connected"
692
- // }
693
- //
694
- return message;
695
- }
696
- handleSubscribed(client, message) {
697
- //
698
- // {
699
- // "data": {
700
- // "streams": ["!ticker@arr"]
701
- // },
702
- // "event": "subscribed",
703
- // "id": 0
704
- // }
705
- //
706
- return message;
707
- }
708
- handleError(client, message) {
709
- //
710
- // {
711
- // "data": {
712
- // "code": 400,
713
- // "message": "Invalid request: streams must be an array"
714
- // },
715
- // "event": "error",
716
- // "id": 0
717
- // }
718
- //
719
- // {
720
- // "message": "HeartBeat message not received, closing the connection",
721
- // "status": "error"
722
- // }
723
- //
724
- throw new ExchangeError(this.id + ' ' + this.json(message));
725
- }
726
- handleMessage(client, message) {
727
- const status = this.safeString(message, 'status');
728
- if (status === 'error') {
729
- this.handleError(client, message);
730
- return;
731
- }
732
- const event = this.safeString(message, 'event');
733
- const eventHandlers = {
734
- 'error': this.handleError,
735
- 'connected': this.handleConnected,
736
- 'subscribed': this.handleSubscribed,
737
- };
738
- const eventHandler = this.safeValue(eventHandlers, event);
739
- if (eventHandler !== undefined) {
740
- eventHandler.call(this, client, message);
741
- return;
742
- }
743
- const stream = this.safeString(message, 'stream', '');
744
- const streamHandlers = {
745
- 'ticker@arr': this.handleTicker,
746
- '@depth': this.handleOrderBook,
747
- '@kline': this.handleOHLCV,
748
- '@trades': this.handleTrades,
749
- 'outboundAccountPosition': this.handleBalance,
750
- 'orderUpdate': this.handleOrder,
751
- 'ownTrade': this.handleMyTrades,
752
- };
753
- const streams = Object.keys(streamHandlers);
754
- for (let i = 0; i < streams.length; i++) {
755
- const streamContains = stream.indexOf(streams[i]) > -1;
756
- if (streamContains) {
757
- const handler = streamHandlers[streams[i]];
758
- handler.call(this, client, message);
759
- return;
760
- }
761
- }
762
- throw new NotSupported(this.id + ' this message type is not supported yet. Message: ' + this.json(message));
763
- }
764
- async authenticate(params = {}) {
765
- const url = this.urls['api']['ws'];
766
- const client = this.client(url);
767
- const messageHash = 'authenticated';
768
- const now = this.milliseconds();
769
- let subscription = this.safeValue(client.subscriptions, messageHash);
770
- const expires = this.safeInteger(subscription, 'expires');
771
- if (subscription === undefined || now > expires) {
772
- subscription = await this.privatePostCreateAuthToken();
773
- subscription['expires'] = now + this.safeInteger(subscription, 'timeout_duration') * 1000;
774
- //
775
- // {
776
- // "auth_key": "Xx***dM",
777
- // "timeout_duration": 900
778
- // }
779
- //
780
- client.subscriptions[messageHash] = subscription;
781
- }
782
- return this.safeString(subscription, 'auth_key');
783
- }
784
- }