ccxt 4.5.38 → 4.5.40

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 (117) hide show
  1. package/README.md +5 -7
  2. package/dist/ccxt.browser.min.js +3 -3
  3. package/dist/cjs/ccxt.js +1 -6
  4. package/dist/cjs/src/base/Exchange.js +62 -5
  5. package/dist/cjs/src/binance.js +151 -2
  6. package/dist/cjs/src/bingx.js +137 -120
  7. package/dist/cjs/src/bitget.js +47 -1
  8. package/dist/cjs/src/bitmart.js +23 -8
  9. package/dist/cjs/src/bitmex.js +416 -0
  10. package/dist/cjs/src/bitstamp.js +264 -43
  11. package/dist/cjs/src/bitvavo.js +10 -0
  12. package/dist/cjs/src/blofin.js +85 -0
  13. package/dist/cjs/src/btcmarkets.js +1 -1
  14. package/dist/cjs/src/bybit.js +135 -0
  15. package/dist/cjs/src/coinspot.js +77 -7
  16. package/dist/cjs/src/delta.js +367 -0
  17. package/dist/cjs/src/htx.js +265 -2
  18. package/dist/cjs/src/hyperliquid.js +37 -8
  19. package/dist/cjs/src/krakenfutures.js +4 -0
  20. package/dist/cjs/src/kucoinfutures.js +121 -0
  21. package/dist/cjs/src/mexc.js +9 -1
  22. package/dist/cjs/src/phemex.js +359 -0
  23. package/dist/cjs/src/poloniex.js +5 -0
  24. package/dist/cjs/src/pro/binance.js +111 -26
  25. package/dist/cjs/src/pro/bingx.js +33 -33
  26. package/dist/cjs/src/pro/bitget.js +48 -90
  27. package/dist/cjs/src/pro/bitmart.js +68 -0
  28. package/dist/cjs/src/pro/blofin.js +52 -1
  29. package/dist/cjs/src/pro/bybit.js +2 -2
  30. package/dist/cjs/src/pro/coinbaseinternational.js +5 -2
  31. package/dist/cjs/src/pro/mexc.js +72 -0
  32. package/dist/cjs/src/pro/okx.js +8 -5
  33. package/dist/cjs/src/pro/paradex.js +137 -0
  34. package/dist/cjs/src/pro/woo.js +43 -0
  35. package/dist/cjs/src/tokocrypto.js +23 -0
  36. package/dist/cjs/src/toobit.js +20 -0
  37. package/dist/cjs/src/whitebit.js +11 -10
  38. package/dist/cjs/src/woo.js +103 -3
  39. package/js/ccxt.d.ts +3 -9
  40. package/js/ccxt.js +2 -6
  41. package/js/src/abstract/binance.d.ts +5 -0
  42. package/js/src/abstract/binancecoinm.d.ts +5 -0
  43. package/js/src/abstract/binanceus.d.ts +5 -0
  44. package/js/src/abstract/binanceusdm.d.ts +5 -0
  45. package/js/src/abstract/bitget.d.ts +47 -1
  46. package/js/src/abstract/bitstamp.d.ts +1 -1
  47. package/js/src/abstract/bitvavo.d.ts +10 -0
  48. package/js/src/abstract/coinspot.d.ts +45 -0
  49. package/js/src/base/Exchange.d.ts +11 -8
  50. package/js/src/base/Exchange.js +65 -5
  51. package/js/src/base/types.d.ts +9 -0
  52. package/js/src/binance.d.ts +26 -1
  53. package/js/src/binance.js +151 -2
  54. package/js/src/bingx.d.ts +113 -108
  55. package/js/src/bingx.js +137 -120
  56. package/js/src/bitget.js +47 -1
  57. package/js/src/bitmart.js +23 -8
  58. package/js/src/bitmex.d.ts +50 -1
  59. package/js/src/bitmex.js +416 -0
  60. package/js/src/bitstamp.d.ts +52 -1
  61. package/js/src/bitstamp.js +264 -43
  62. package/js/src/bitvavo.js +10 -0
  63. package/js/src/blofin.d.ts +12 -1
  64. package/js/src/blofin.js +85 -0
  65. package/js/src/btcmarkets.js +1 -1
  66. package/js/src/bybit.d.ts +12 -1
  67. package/js/src/bybit.js +135 -0
  68. package/js/src/coinspot.js +77 -7
  69. package/js/src/delta.d.ts +12 -1
  70. package/js/src/delta.js +367 -0
  71. package/js/src/htx.d.ts +15 -1
  72. package/js/src/htx.js +265 -2
  73. package/js/src/hyperliquid.js +37 -8
  74. package/js/src/krakenfutures.js +4 -0
  75. package/js/src/kucoinfutures.d.ts +12 -1
  76. package/js/src/kucoinfutures.js +121 -0
  77. package/js/src/mexc.js +9 -1
  78. package/js/src/phemex.d.ts +16 -1
  79. package/js/src/phemex.js +359 -0
  80. package/js/src/poloniex.js +5 -0
  81. package/js/src/pro/binance.d.ts +13 -0
  82. package/js/src/pro/binance.js +111 -26
  83. package/js/src/pro/bingx.d.ts +33 -33
  84. package/js/src/pro/bingx.js +33 -33
  85. package/js/src/pro/bitget.d.ts +6 -6
  86. package/js/src/pro/bitget.js +48 -90
  87. package/js/src/pro/bitmart.d.ts +22 -1
  88. package/js/src/pro/bitmart.js +69 -1
  89. package/js/src/pro/blofin.d.ts +12 -1
  90. package/js/src/pro/blofin.js +52 -1
  91. package/js/src/pro/bybit.d.ts +1 -1
  92. package/js/src/pro/bybit.js +2 -2
  93. package/js/src/pro/coinbaseinternational.d.ts +2 -2
  94. package/js/src/pro/coinbaseinternational.js +6 -3
  95. package/js/src/pro/mexc.d.ts +22 -1
  96. package/js/src/pro/mexc.js +72 -0
  97. package/js/src/pro/okx.d.ts +4 -4
  98. package/js/src/pro/okx.js +8 -5
  99. package/js/src/pro/paradex.d.ts +23 -1
  100. package/js/src/pro/paradex.js +137 -0
  101. package/js/src/pro/woo.d.ts +12 -1
  102. package/js/src/pro/woo.js +43 -0
  103. package/js/src/tokocrypto.js +23 -0
  104. package/js/src/toobit.js +20 -0
  105. package/js/src/whitebit.js +8 -8
  106. package/js/src/woo.d.ts +12 -1
  107. package/js/src/woo.js +103 -3
  108. package/package.json +1 -1
  109. package/dist/cjs/src/abstract/probit.js +0 -11
  110. package/dist/cjs/src/pro/probit.js +0 -594
  111. package/dist/cjs/src/probit.js +0 -1936
  112. package/js/src/abstract/probit.d.ts +0 -26
  113. package/js/src/abstract/probit.js +0 -11
  114. package/js/src/pro/probit.d.ts +0 -91
  115. package/js/src/pro/probit.js +0 -593
  116. package/js/src/probit.d.ts +0 -283
  117. package/js/src/probit.js +0 -1935
@@ -1,593 +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 probitRest from '../probit.js';
9
- import { NotSupported, ExchangeError } from '../base/errors.js';
10
- import { ArrayCache, ArrayCacheBySymbolById } from '../base/ws/Cache.js';
11
- // ---------------------------------------------------------------------------
12
- export default class probit extends probitRest {
13
- describe() {
14
- return this.deepExtend(super.describe(), {
15
- 'has': {
16
- 'ws': true,
17
- 'watchBalance': true,
18
- 'watchTicker': true,
19
- 'watchTickers': false,
20
- 'watchTrades': true,
21
- 'watchTradesForSymbols': false,
22
- 'watchMyTrades': true,
23
- 'watchOrders': true,
24
- 'watchOrderBook': true,
25
- 'watchOHLCV': false,
26
- },
27
- 'urls': {
28
- 'api': {
29
- 'ws': 'wss://api.probit.com/api/exchange/v1/ws',
30
- },
31
- 'test': {
32
- 'ws': 'wss://demo-api.probit.com/api/exchange/v1/ws',
33
- },
34
- },
35
- 'options': {
36
- 'watchOrderBook': {
37
- 'filter': 'order_books_l2',
38
- 'interval': 100, // or 500
39
- },
40
- },
41
- 'streaming': {},
42
- });
43
- }
44
- /**
45
- * @method
46
- * @name probit#watchBalance
47
- * @description watch balance and get the amount of funds available for trading or funds locked in orders
48
- * @see https://docs-en.probit.com/reference/balance-1
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.authenticate(params);
54
- const messageHash = 'balance';
55
- return await this.subscribePrivate(messageHash, 'balance', params);
56
- }
57
- handleBalance(client, message) {
58
- //
59
- // {
60
- // "channel": "balance",
61
- // "reset": false,
62
- // "data": {
63
- // "USDT": {
64
- // "available": "15",
65
- // "total": "15"
66
- // }
67
- // }
68
- // }
69
- //
70
- const messageHash = 'balance';
71
- this.parseWSBalance(message);
72
- client.resolve(this.balance, messageHash);
73
- }
74
- parseWSBalance(message) {
75
- //
76
- // {
77
- // "channel": "balance",
78
- // "reset": false,
79
- // "data": {
80
- // "USDT": {
81
- // "available": "15",
82
- // "total": "15"
83
- // }
84
- // }
85
- // }
86
- //
87
- const reset = this.safeBool(message, 'reset', false);
88
- const data = this.safeValue(message, 'data', {});
89
- const currencyIds = Object.keys(data);
90
- if (reset) {
91
- this.balance = {};
92
- }
93
- for (let i = 0; i < currencyIds.length; i++) {
94
- const currencyId = currencyIds[i];
95
- const entry = data[currencyId];
96
- const code = this.safeCurrencyCode(currencyId);
97
- const account = this.account();
98
- account['free'] = this.safeString(entry, 'available');
99
- account['total'] = this.safeString(entry, 'total');
100
- this.balance[code] = account;
101
- }
102
- this.balance = this.safeBalance(this.balance);
103
- }
104
- /**
105
- * @method
106
- * @name probit#watchTicker
107
- * @description watches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market
108
- * @see https://docs-en.probit.com/reference/marketdata
109
- * @param {string} symbol unified symbol of the market to fetch the ticker for
110
- * @param {object} [params] extra parameters specific to the exchange API endpoint
111
- * @param {int} [params.interval] Unit time to synchronize market information (ms). Available units: 100, 500
112
- * @returns {object} a [ticker structure]{@link https://docs.ccxt.com/?id=ticker-structure}
113
- */
114
- async watchTicker(symbol, params = {}) {
115
- const channel = 'ticker';
116
- return await this.subscribePublic('watchTicker', symbol, 'ticker', channel, params);
117
- }
118
- handleTicker(client, message) {
119
- //
120
- // {
121
- // "channel": "marketdata",
122
- // "market_id": "BTC-USDT",
123
- // "status": "ok",
124
- // "lag": 0,
125
- // "ticker": {
126
- // "time": "2022-07-21T14:18:04.000Z",
127
- // "last": "22591.3",
128
- // "low": "22500.1",
129
- // "high": "39790.7",
130
- // "change": "-1224",
131
- // "base_volume": "1002.32005445",
132
- // "quote_volume": "23304489.385351021"
133
- // },
134
- // "reset": true
135
- // }
136
- //
137
- const marketId = this.safeString(message, 'market_id');
138
- const symbol = this.safeSymbol(marketId);
139
- const ticker = this.safeValue(message, 'ticker', {});
140
- const market = this.safeMarket(marketId);
141
- const parsedTicker = this.parseTicker(ticker, market);
142
- const messageHash = 'ticker:' + symbol;
143
- this.tickers[symbol] = parsedTicker;
144
- client.resolve(parsedTicker, messageHash);
145
- }
146
- /**
147
- * @method
148
- * @name probit#watchTrades
149
- * @description get the list of most recent trades for a particular symbol
150
- * @see https://docs-en.probit.com/reference/trade_history
151
- * @param {string} symbol unified symbol of the market to fetch trades for
152
- * @param {int} [since] timestamp in ms of the earliest trade to fetch
153
- * @param {int} [limit] the maximum amount of trades to fetch
154
- * @param {object} [params] extra parameters specific to the exchange API endpoint
155
- * @param {int} [params.interval] Unit time to synchronize market information (ms). Available units: 100, 500
156
- * @returns {object[]} a list of [trade structures]{@link https://docs.ccxt.com/?id=public-trades}
157
- */
158
- async watchTrades(symbol, since = undefined, limit = undefined, params = {}) {
159
- const channel = 'recent_trades';
160
- symbol = this.safeSymbol(symbol);
161
- const trades = await this.subscribePublic('watchTrades', symbol, 'trades', channel, params);
162
- if (this.newUpdates) {
163
- limit = trades.getLimit(symbol, limit);
164
- }
165
- return this.filterBySymbolSinceLimit(trades, symbol, since, limit, true);
166
- }
167
- handleTrades(client, message) {
168
- //
169
- // {
170
- // "channel": "marketdata",
171
- // "market_id": "BTC-USDT",
172
- // "status": "ok",
173
- // "lag": 0,
174
- // "recent_trades": [
175
- // {
176
- // "id": "BTC-USDT:8010233",
177
- // "price": "22701.4",
178
- // "quantity": "0.011011",
179
- // "time": "2022-07-21T13:40:40.983Z",
180
- // "side": "buy",
181
- // "tick_direction": "up"
182
- // }
183
- // ...
184
- // ]
185
- // "reset": true
186
- // }
187
- //
188
- const marketId = this.safeString(message, 'market_id');
189
- const symbol = this.safeSymbol(marketId);
190
- const market = this.safeMarket(marketId);
191
- const trades = this.safeValue(message, 'recent_trades', []);
192
- if (this.safeBool(message, 'reset', false)) {
193
- return; // see comment in handleMessage
194
- }
195
- const messageHash = 'trades:' + symbol;
196
- let stored = this.safeValue(this.trades, symbol);
197
- if (stored === undefined) {
198
- const limit = this.safeInteger(this.options, 'tradesLimit', 1000);
199
- stored = new ArrayCache(limit);
200
- this.trades[symbol] = stored;
201
- }
202
- for (let i = 0; i < trades.length; i++) {
203
- const trade = trades[i];
204
- const parsed = this.parseTrade(trade, market);
205
- stored.append(parsed);
206
- }
207
- this.trades[symbol] = stored;
208
- client.resolve(this.trades[symbol], messageHash);
209
- }
210
- /**
211
- * @method
212
- * @name probit#watchMyTrades
213
- * @description get the list of trades associated with the user
214
- * @see https://docs-en.probit.com/reference/trade_history
215
- * @param {string} symbol unified symbol of the market to fetch trades for
216
- * @param {int} [since] timestamp in ms of the earliest trade to fetch
217
- * @param {int} [limit] the maximum amount of trades to fetch
218
- * @param {object} [params] extra parameters specific to the exchange API endpoint
219
- * @returns {object[]} a list of [trade structures]{@link https://docs.ccxt.com/?id=public-trades}
220
- */
221
- async watchMyTrades(symbol = undefined, since = undefined, limit = undefined, params = {}) {
222
- await this.loadMarkets();
223
- await this.authenticate(params);
224
- let messageHash = 'trades';
225
- if (symbol !== undefined) {
226
- symbol = this.safeSymbol(symbol);
227
- messageHash = messageHash + ':' + symbol;
228
- }
229
- const trades = await this.subscribePrivate(messageHash, 'trade_history', params);
230
- if (this.newUpdates) {
231
- limit = trades.getLimit(symbol, limit);
232
- }
233
- return this.filterBySymbolSinceLimit(trades, symbol, since, limit, true);
234
- }
235
- handleMyTrades(client, message) {
236
- //
237
- // {
238
- // "channel": "trade_history",
239
- // "reset": false,
240
- // "data": [{
241
- // "id": "BTC-USDT:8010722",
242
- // "order_id": "4124999207",
243
- // "side": "buy",
244
- // "fee_amount": "0.0134999868096",
245
- // "fee_currency_id": "USDT",
246
- // "status": "settled",
247
- // "price": "23136.7",
248
- // "quantity": "0.00032416",
249
- // "cost": "7.499992672",
250
- // "time": "2022-07-21T17:09:33.056Z",
251
- // "market_id": "BTC-USDT"
252
- // }]
253
- // }
254
- //
255
- const rawTrades = this.safeValue(message, 'data', []);
256
- const length = rawTrades.length;
257
- if (length === 0) {
258
- return;
259
- }
260
- if (this.safeBool(message, 'reset', false)) {
261
- return; // see comment in handleMessage
262
- }
263
- const messageHash = 'trades';
264
- let stored = this.myTrades;
265
- if (stored === undefined) {
266
- const limit = this.safeInteger(this.options, 'tradesLimit', 1000);
267
- stored = new ArrayCacheBySymbolById(limit);
268
- this.myTrades = stored;
269
- }
270
- const trades = this.parseTrades(rawTrades);
271
- const tradeSymbols = {};
272
- for (let j = 0; j < trades.length; j++) {
273
- const trade = trades[j];
274
- // don't include 'executed' state, because it's just blanket state of the trade, emited before actual trade event
275
- if (this.safeString(trade['info'], 'status') === 'executed') {
276
- continue;
277
- }
278
- tradeSymbols[trade['symbol']] = true;
279
- stored.append(trade);
280
- }
281
- const unique = Object.keys(tradeSymbols);
282
- const uniqueLength = unique.length;
283
- if (uniqueLength === 0) {
284
- return;
285
- }
286
- for (let i = 0; i < unique.length; i++) {
287
- const symbol = unique[i];
288
- const symbolSpecificMessageHash = messageHash + ':' + symbol;
289
- client.resolve(stored, symbolSpecificMessageHash);
290
- }
291
- client.resolve(stored, messageHash);
292
- }
293
- /**
294
- * @method
295
- * @name probit#watchOrders
296
- * @description watches information on an order made by the user
297
- * @see https://docs-en.probit.com/reference/open_order
298
- * @param {string} symbol unified symbol of the market the order was made in
299
- * @param {int} [since] timestamp in ms of the earliest order to watch
300
- * @param {int} [limit] the maximum amount of orders to watch
301
- * @param {object} [params] extra parameters specific to the exchange API endpoint
302
- * @param {string} [params.channel] choose what channel to use. Can open_order or order_history.
303
- * @returns {object} An [order structure]{@link https://docs.ccxt.com/?id=order-structure}
304
- */
305
- async watchOrders(symbol = undefined, since = undefined, limit = undefined, params = {}) {
306
- await this.authenticate(params);
307
- let messageHash = 'orders';
308
- if (symbol !== undefined) {
309
- symbol = this.safeSymbol(symbol);
310
- messageHash = messageHash + ':' + symbol;
311
- }
312
- const orders = await this.subscribePrivate(messageHash, 'open_order', params);
313
- if (this.newUpdates) {
314
- limit = orders.getLimit(symbol, limit);
315
- }
316
- return this.filterBySymbolSinceLimit(orders, symbol, since, limit, true);
317
- }
318
- handleOrders(client, message) {
319
- //
320
- // {
321
- // "channel": "order_history",
322
- // "reset": true,
323
- // "data": [{
324
- // "id": "4124999207",
325
- // "user_id": "633dc56a-621b-4680-8a4e-85a823499b6d",
326
- // "market_id": "BTC-USDT",
327
- // "type": "market",
328
- // "side": "buy",
329
- // "limit_price": "0",
330
- // "time_in_force": "ioc",
331
- // "filled_cost": "7.499992672",
332
- // "filled_quantity": "0.00032416",
333
- // "open_quantity": "0",
334
- // "status": "filled",
335
- // "time": "2022-07-21T17:09:33.056Z",
336
- // "client_order_id": '',
337
- // "cost": "7.5"
338
- // },
339
- // ...
340
- // ]
341
- // }
342
- //
343
- const rawOrders = this.safeValue(message, 'data', []);
344
- const length = rawOrders.length;
345
- if (length === 0) {
346
- return;
347
- }
348
- const messageHash = 'orders';
349
- const reset = this.safeBool(message, 'reset', false);
350
- let stored = this.orders;
351
- if (stored === undefined || reset) {
352
- const limit = this.safeInteger(this.options, 'ordersLimit', 1000);
353
- stored = new ArrayCacheBySymbolById(limit);
354
- this.orders = stored;
355
- }
356
- const orderSymbols = {};
357
- for (let i = 0; i < rawOrders.length; i++) {
358
- const rawOrder = rawOrders[i];
359
- const order = this.parseOrder(rawOrder);
360
- orderSymbols[order['symbol']] = true;
361
- stored.append(order);
362
- }
363
- const unique = Object.keys(orderSymbols);
364
- for (let i = 0; i < unique.length; i++) {
365
- const symbol = unique[i];
366
- const symbolSpecificMessageHash = messageHash + ':' + symbol;
367
- client.resolve(stored, symbolSpecificMessageHash);
368
- }
369
- client.resolve(stored, messageHash);
370
- }
371
- /**
372
- * @method
373
- * @name probit#watchOrderBook
374
- * @description watches information on open orders with bid (buy) and ask (sell) prices, volumes and other data
375
- * @see https://docs-en.probit.com/reference/marketdata
376
- * @param {string} symbol unified symbol of the market to fetch the order book for
377
- * @param {int} [limit] the maximum amount of order book entries to return
378
- * @param {object} [params] extra parameters specific to the exchange API endpoint
379
- * @returns {object} A dictionary of [order book structures]{@link https://docs.ccxt.com/?id=order-book-structure} indexed by market symbols
380
- */
381
- async watchOrderBook(symbol, limit = undefined, params = {}) {
382
- let channel = undefined;
383
- [channel, params] = this.handleOptionAndParams(params, 'watchOrderBook', 'filter', 'order_books');
384
- const orderbook = await this.subscribePublic('watchOrderBook', symbol, 'orderbook', channel, params);
385
- return orderbook.limit();
386
- }
387
- async subscribePrivate(messageHash, channel, params) {
388
- const url = this.urls['api']['ws'];
389
- const subscribe = {
390
- 'type': 'subscribe',
391
- 'channel': channel,
392
- };
393
- const request = this.extend(subscribe, params);
394
- const subscribeHash = messageHash;
395
- return await this.watch(url, messageHash, request, subscribeHash);
396
- }
397
- async subscribePublic(methodName, symbol, dataType, filter, params = {}) {
398
- await this.loadMarkets();
399
- const market = this.market(symbol);
400
- symbol = market['symbol'];
401
- const url = this.urls['api']['ws'];
402
- const client = this.client(url);
403
- const subscribeHash = 'marketdata:' + symbol;
404
- const messageHash = dataType + ':' + symbol;
405
- let filters = {};
406
- if (subscribeHash in client.subscriptions) {
407
- // already subscribed
408
- filters = client.subscriptions[subscribeHash];
409
- if (!(filter in filters)) {
410
- // resubscribe
411
- delete client.subscriptions[subscribeHash];
412
- }
413
- }
414
- filters[filter] = true;
415
- const keys = Object.keys(filters);
416
- let interval = undefined;
417
- [interval, params] = this.handleOptionAndParams(params, methodName, 'interval', 100);
418
- let request = {
419
- 'type': 'subscribe',
420
- 'channel': 'marketdata',
421
- 'market_id': market['id'],
422
- 'filter': keys,
423
- 'interval': interval,
424
- };
425
- request = this.extend(request, params);
426
- return await this.watch(url, messageHash, request, subscribeHash, filters);
427
- }
428
- handleOrderBook(client, message, orderBook) {
429
- //
430
- // {
431
- // "channel": "marketdata",
432
- // "market_id": "BTC-USDT",
433
- // "status": "ok",
434
- // "lag": 0,
435
- // "order_books": [
436
- // { side: "buy", price: '1420.7', quantity: "0.057" },
437
- // ...
438
- // ],
439
- // "reset": true
440
- // }
441
- //
442
- const marketId = this.safeString(message, 'market_id');
443
- const symbol = this.safeSymbol(marketId);
444
- const dataBySide = this.groupBy(orderBook, 'side');
445
- const messageHash = 'orderbook:' + symbol;
446
- // let orderbook = this.safeValue (this.orderbooks, symbol);
447
- if (!(symbol in this.orderbooks)) {
448
- this.orderbooks[symbol] = this.orderBook({});
449
- }
450
- const orderbook = this.orderbooks[symbol];
451
- const reset = this.safeBool(message, 'reset', false);
452
- if (reset) {
453
- const snapshot = this.parseOrderBook(dataBySide, symbol, undefined, 'buy', 'sell', 'price', 'quantity');
454
- orderbook.reset(snapshot);
455
- }
456
- else {
457
- this.handleDelta(orderbook, dataBySide);
458
- }
459
- client.resolve(orderbook, messageHash);
460
- }
461
- handleBidAsks(bookSide, bidAsks) {
462
- for (let i = 0; i < bidAsks.length; i++) {
463
- const bidAsk = bidAsks[i];
464
- const parsed = this.parseBidAsk(bidAsk, 'price', 'quantity');
465
- bookSide.storeArray(parsed);
466
- }
467
- }
468
- handleDelta(orderbook, delta) {
469
- const storedBids = orderbook['bids'];
470
- const storedAsks = orderbook['asks'];
471
- const asks = this.safeValue(delta, 'sell', []);
472
- const bids = this.safeValue(delta, 'buy', []);
473
- this.handleBidAsks(storedBids, bids);
474
- this.handleBidAsks(storedAsks, asks);
475
- }
476
- handleErrorMessage(client, message) {
477
- //
478
- // {
479
- // "errorCode": "INVALID_ARGUMENT",
480
- // "message": '',
481
- // "details": {
482
- // "interval": "invalid"
483
- // }
484
- // }
485
- //
486
- const code = this.safeString(message, 'errorCode');
487
- const errMessage = this.safeString(message, 'message', '');
488
- const details = this.safeValue(message, 'details');
489
- const feedback = this.id + ' ' + code + ' ' + errMessage + ' ' + this.json(details);
490
- if ('exact' in this.exceptions) {
491
- this.throwExactlyMatchedException(this.exceptions['exact'], code, feedback);
492
- }
493
- if ('broad' in this.exceptions) {
494
- this.throwBroadlyMatchedException(this.exceptions['broad'], errMessage, feedback);
495
- }
496
- throw new ExchangeError(feedback);
497
- }
498
- handleAuthenticate(client, message) {
499
- //
500
- // { type: "authorization", result: "ok" }
501
- //
502
- const result = this.safeString(message, 'result');
503
- const future = client.subscriptions['authenticated'];
504
- if (result === 'ok') {
505
- const messageHash = 'authenticated';
506
- client.resolve(message, messageHash);
507
- }
508
- else {
509
- future.reject(message);
510
- delete client.subscriptions['authenticated'];
511
- }
512
- }
513
- handleMarketData(client, message) {
514
- const ticker = this.safeValue(message, 'ticker');
515
- if (ticker !== undefined) {
516
- this.handleTicker(client, message);
517
- }
518
- const trades = this.safeValue(message, 'recent_trades', []);
519
- const tradesLength = trades.length;
520
- if (tradesLength) {
521
- this.handleTrades(client, message);
522
- }
523
- const orderBook = this.safeValueN(message, ['order_books', 'order_books_l1', 'order_books_l2', 'order_books_l3', 'order_books_l4'], []);
524
- const orderBookLength = orderBook.length;
525
- if (orderBookLength) {
526
- this.handleOrderBook(client, message, orderBook);
527
- }
528
- }
529
- handleMessage(client, message) {
530
- //
531
- // {
532
- // "errorCode": "INVALID_ARGUMENT",
533
- // "message": '',
534
- // "details": {
535
- // "interval": "invalid"
536
- // }
537
- // }
538
- //
539
- // Note about 'reset' field
540
- // 'reset': true field - it happens once after initial subscription, which just returns old items by the moment of subscription (like "fetchMyTrades" does)
541
- //
542
- const errorCode = this.safeString(message, 'errorCode');
543
- if (errorCode !== undefined) {
544
- this.handleErrorMessage(client, message);
545
- return;
546
- }
547
- const type = this.safeString(message, 'type');
548
- if (type === 'authorization') {
549
- this.handleAuthenticate(client, message);
550
- return;
551
- }
552
- const handlers = {
553
- 'marketdata': this.handleMarketData,
554
- 'balance': this.handleBalance,
555
- 'trade_history': this.handleMyTrades,
556
- 'open_order': this.handleOrders,
557
- 'order_history': this.handleOrders,
558
- };
559
- const channel = this.safeString(message, 'channel');
560
- const handler = this.safeValue(handlers, channel);
561
- if (handler !== undefined) {
562
- handler.call(this, client, message);
563
- return;
564
- }
565
- const error = new NotSupported(this.id + ' handleMessage: unknown message: ' + this.json(message));
566
- client.reject(error);
567
- }
568
- async authenticate(params = {}) {
569
- const url = this.urls['api']['ws'];
570
- const client = this.client(url);
571
- const messageHash = 'authenticated';
572
- const expires = this.safeInteger(this.options, 'expires', 0);
573
- let future = this.safeValue(client.subscriptions, messageHash);
574
- if ((future === undefined) || (this.milliseconds() > expires)) {
575
- const response = await this.signIn();
576
- //
577
- // {
578
- // "access_token": "0ttDv/2hTTn3bLi8GP1gKaneiEQ6+0hOBenPrxNQt2s=",
579
- // "token_type": "bearer",
580
- // "expires_in": 900
581
- // }
582
- //
583
- const accessToken = this.safeString(response, 'access_token');
584
- const request = {
585
- 'type': 'authorization',
586
- 'token': accessToken,
587
- };
588
- future = await this.watch(url, messageHash, this.extend(request, params), messageHash);
589
- client.subscriptions[messageHash] = future;
590
- }
591
- return future;
592
- }
593
- }