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