ccxt 4.2.28 → 4.2.30

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 (158) hide show
  1. package/CONTRIBUTING.md +4 -1
  2. package/README.md +6 -6
  3. package/dist/ccxt.browser.js +1865 -558
  4. package/dist/ccxt.browser.min.js +7 -7
  5. package/dist/cjs/ccxt.js +3 -1
  6. package/dist/cjs/src/ascendex.js +5 -5
  7. package/dist/cjs/src/base/Exchange.js +114 -21
  8. package/dist/cjs/src/base/errors.js +3 -3
  9. package/dist/cjs/src/base/functions/type.js +12 -0
  10. package/dist/cjs/src/bigone.js +2 -2
  11. package/dist/cjs/src/binance.js +896 -217
  12. package/dist/cjs/src/bingx.js +1 -1
  13. package/dist/cjs/src/bitfinex.js +1 -1
  14. package/dist/cjs/src/bitfinex2.js +52 -62
  15. package/dist/cjs/src/bitget.js +8 -4
  16. package/dist/cjs/src/bitmart.js +3 -3
  17. package/dist/cjs/src/bitmex.js +9 -6
  18. package/dist/cjs/src/bitrue.js +1 -1
  19. package/dist/cjs/src/bitso.js +1 -1
  20. package/dist/cjs/src/bitteam.js +2 -2
  21. package/dist/cjs/src/btcalpha.js +1 -1
  22. package/dist/cjs/src/bybit.js +28 -12
  23. package/dist/cjs/src/coinbase.js +12 -5
  24. package/dist/cjs/src/coincheck.js +1 -1
  25. package/dist/cjs/src/coinex.js +2 -2
  26. package/dist/cjs/src/coinlist.js +1 -1
  27. package/dist/cjs/src/coinmate.js +1 -1
  28. package/dist/cjs/src/coinmetro.js +12 -6
  29. package/dist/cjs/src/coinsph.js +1 -1
  30. package/dist/cjs/src/cryptocom.js +3 -3
  31. package/dist/cjs/src/digifinex.js +6 -4
  32. package/dist/cjs/src/exmo.js +2 -2
  33. package/dist/cjs/src/gate.js +5 -5
  34. package/dist/cjs/src/gemini.js +3 -3
  35. package/dist/cjs/src/hitbtc.js +14 -20
  36. package/dist/cjs/src/hollaex.js +2 -2
  37. package/dist/cjs/src/htx.js +5 -5
  38. package/dist/cjs/src/huobijp.js +1 -1
  39. package/dist/cjs/src/krakenfutures.js +1 -1
  40. package/dist/cjs/src/kucoin.js +17 -17
  41. package/dist/cjs/src/kucoinfutures.js +3 -3
  42. package/dist/cjs/src/lbank.js +1 -1
  43. package/dist/cjs/src/mexc.js +7 -7
  44. package/dist/cjs/src/novadax.js +1 -1
  45. package/dist/cjs/src/okcoin.js +2 -2
  46. package/dist/cjs/src/okx.js +24 -10
  47. package/dist/cjs/src/p2b.js +1 -0
  48. package/dist/cjs/src/phemex.js +3 -3
  49. package/dist/cjs/src/poloniexfutures.js +3 -3
  50. package/dist/cjs/src/pro/alpaca.js +1 -1
  51. package/dist/cjs/src/pro/binance.js +4 -4
  52. package/dist/cjs/src/pro/bitget.js +1 -1
  53. package/dist/cjs/src/pro/bitmart.js +1 -1
  54. package/dist/cjs/src/pro/bitmex.js +49 -6
  55. package/dist/cjs/src/pro/bitvavo.js +1 -1
  56. package/dist/cjs/src/pro/bybit.js +2 -2
  57. package/dist/cjs/src/pro/cex.js +2 -2
  58. package/dist/cjs/src/pro/coinbase.js +1 -1
  59. package/dist/cjs/src/pro/independentreserve.js +1 -1
  60. package/dist/cjs/src/pro/okx.js +1 -1
  61. package/dist/cjs/src/pro/onetrading.js +2 -2
  62. package/dist/cjs/src/pro/p2b.js +432 -0
  63. package/dist/cjs/src/pro/probit.js +5 -5
  64. package/dist/cjs/src/pro/whitebit.js +1 -1
  65. package/dist/cjs/src/probit.js +1 -1
  66. package/dist/cjs/src/timex.js +1 -1
  67. package/dist/cjs/src/tokocrypto.js +3 -3
  68. package/dist/cjs/src/wavesexchange.js +2 -2
  69. package/dist/cjs/src/whitebit.js +2 -2
  70. package/dist/cjs/src/woo.js +3 -3
  71. package/dist/cjs/src/yobit.js +1 -1
  72. package/dist/cjs/src/zaif.js +1 -1
  73. package/dist/cjs/src/zonda.js +3 -3
  74. package/js/ccxt.d.ts +4 -1
  75. package/js/ccxt.js +3 -1
  76. package/js/src/abstract/bybit.d.ts +2 -2
  77. package/js/src/abstract/okx.d.ts +1 -0
  78. package/js/src/ascendex.js +5 -5
  79. package/js/src/base/Exchange.d.ts +10 -1
  80. package/js/src/base/Exchange.js +114 -21
  81. package/js/src/base/errorHierarchy.d.ts +7 -6
  82. package/js/src/base/errorHierarchy.js +7 -6
  83. package/js/src/base/errors.d.ts +3 -3
  84. package/js/src/base/errors.js +3 -3
  85. package/js/src/base/functions/type.js +12 -0
  86. package/js/src/bigone.js +2 -2
  87. package/js/src/binance.d.ts +1 -0
  88. package/js/src/binance.js +897 -218
  89. package/js/src/bingx.js +1 -1
  90. package/js/src/bitfinex.js +1 -1
  91. package/js/src/bitfinex2.js +52 -62
  92. package/js/src/bitget.js +8 -4
  93. package/js/src/bitmart.js +3 -3
  94. package/js/src/bitmex.js +9 -6
  95. package/js/src/bitrue.js +1 -1
  96. package/js/src/bitso.d.ts +1 -1
  97. package/js/src/bitso.js +1 -1
  98. package/js/src/bitteam.js +2 -2
  99. package/js/src/btcalpha.js +1 -1
  100. package/js/src/bybit.js +28 -12
  101. package/js/src/coinbase.js +12 -5
  102. package/js/src/coincheck.js +1 -1
  103. package/js/src/coinex.js +2 -2
  104. package/js/src/coinlist.js +1 -1
  105. package/js/src/coinmate.js +1 -1
  106. package/js/src/coinmetro.d.ts +1 -1
  107. package/js/src/coinmetro.js +12 -6
  108. package/js/src/coinsph.js +1 -1
  109. package/js/src/cryptocom.js +3 -3
  110. package/js/src/digifinex.js +6 -4
  111. package/js/src/exmo.js +2 -2
  112. package/js/src/gate.js +5 -5
  113. package/js/src/gemini.d.ts +1 -1
  114. package/js/src/gemini.js +3 -3
  115. package/js/src/hitbtc.js +14 -20
  116. package/js/src/hollaex.js +2 -2
  117. package/js/src/htx.js +5 -5
  118. package/js/src/huobijp.js +1 -1
  119. package/js/src/krakenfutures.js +1 -1
  120. package/js/src/kucoin.js +17 -17
  121. package/js/src/kucoinfutures.js +3 -3
  122. package/js/src/lbank.js +1 -1
  123. package/js/src/mexc.js +7 -7
  124. package/js/src/novadax.js +1 -1
  125. package/js/src/okcoin.js +2 -2
  126. package/js/src/okx.js +24 -10
  127. package/js/src/p2b.js +1 -0
  128. package/js/src/phemex.js +3 -3
  129. package/js/src/poloniexfutures.js +3 -3
  130. package/js/src/pro/alpaca.js +1 -1
  131. package/js/src/pro/binance.js +4 -4
  132. package/js/src/pro/bitget.js +1 -1
  133. package/js/src/pro/bitmart.js +1 -1
  134. package/js/src/pro/bitmex.d.ts +2 -1
  135. package/js/src/pro/bitmex.js +49 -6
  136. package/js/src/pro/bitvavo.js +1 -1
  137. package/js/src/pro/bybit.js +2 -2
  138. package/js/src/pro/cex.js +2 -2
  139. package/js/src/pro/coinbase.js +2 -2
  140. package/js/src/pro/independentreserve.js +1 -1
  141. package/js/src/pro/okx.js +1 -1
  142. package/js/src/pro/onetrading.js +2 -2
  143. package/js/src/pro/p2b.d.ts +23 -0
  144. package/js/src/pro/p2b.js +433 -0
  145. package/js/src/pro/probit.js +5 -5
  146. package/js/src/pro/whitebit.js +1 -1
  147. package/js/src/probit.js +1 -1
  148. package/js/src/timex.js +1 -1
  149. package/js/src/tokocrypto.js +3 -3
  150. package/js/src/wavesexchange.js +2 -2
  151. package/js/src/whitebit.js +2 -2
  152. package/js/src/woo.js +3 -3
  153. package/js/src/yobit.js +1 -1
  154. package/js/src/zaif.js +1 -1
  155. package/js/src/zonda.d.ts +1 -1
  156. package/js/src/zonda.js +3 -3
  157. package/package.json +1 -1
  158. package/skip-tests.json +3 -10
@@ -0,0 +1,433 @@
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 p2bRest from '../p2b.js';
9
+ import { BadRequest, ExchangeError } from '../base/errors.js';
10
+ import { ArrayCache, ArrayCacheByTimestamp } from '../base/ws/Cache.js';
11
+ // ---------------------------------------------------------------------------
12
+ export default class p2b extends p2bRest {
13
+ describe() {
14
+ return this.deepExtend(super.describe(), {
15
+ 'has': {
16
+ 'ws': true,
17
+ 'cancelAllOrdersWs': false,
18
+ 'cancelOrdersWs': false,
19
+ 'cancelOrderWs': false,
20
+ 'createOrderWs': false,
21
+ 'editOrderWs': false,
22
+ 'fetchBalanceWs': false,
23
+ 'fetchOpenOrdersWs': false,
24
+ 'fetchOrderWs': false,
25
+ 'fetchTradesWs': false,
26
+ 'watchBalance': false,
27
+ 'watchMyTrades': false,
28
+ 'watchOHLCV': true,
29
+ 'watchOrderBook': true,
30
+ 'watchOrders': false,
31
+ // 'watchStatus': true,
32
+ 'watchTicker': true,
33
+ 'watchTickers': false,
34
+ 'watchTrades': true,
35
+ },
36
+ 'urls': {
37
+ 'api': {
38
+ 'ws': 'wss://apiws.p2pb2b.com/',
39
+ },
40
+ },
41
+ 'options': {
42
+ 'OHLCVLimit': 1000,
43
+ 'tradesLimit': 1000,
44
+ 'timeframes': {
45
+ '15m': 900,
46
+ '30m': 1800,
47
+ '1h': 3600,
48
+ '1d': 86400,
49
+ },
50
+ 'watchTicker': {
51
+ 'name': 'state', // or 'price'
52
+ },
53
+ 'watchTickers': {
54
+ 'name': 'state', // or 'price'
55
+ },
56
+ },
57
+ 'streaming': {
58
+ 'ping': this.ping,
59
+ },
60
+ });
61
+ }
62
+ async subscribe(name, messageHash, request, params = {}) {
63
+ /**
64
+ * @ignore
65
+ * @method
66
+ * @description Connects to a websocket channel
67
+ * @param {string} name name of the channel
68
+ * @param {string} messageHash string to look up in handler
69
+ * @param {string[]|float[]} request endpoint parameters
70
+ * @param {object} [params] extra parameters specific to the p2b api
71
+ * @returns {object} data from the websocket stream
72
+ */
73
+ const url = this.urls['api']['ws'];
74
+ const subscribe = {
75
+ 'method': name,
76
+ 'params': request,
77
+ 'id': this.milliseconds(),
78
+ };
79
+ const query = this.extend(subscribe, params);
80
+ return await this.watch(url, messageHash, query, messageHash);
81
+ }
82
+ async watchOHLCV(symbol, timeframe = '15m', since = undefined, limit = undefined, params = {}) {
83
+ /**
84
+ * @method
85
+ * @name p2b#watchOHLCV
86
+ * @description watches historical candlestick data containing the open, high, low, and close price, and the volume of a market. Can only subscribe to one timeframe at a time for each symbol
87
+ * @see https://github.com/P2B-team/P2B-WSS-Public/blob/main/wss_documentation.md#kline-candlestick
88
+ * @param {string} symbol unified symbol of the market to fetch OHLCV data for
89
+ * @param {string} timeframe 15m, 30m, 1h or 1d
90
+ * @param {int} [since] timestamp in ms of the earliest candle to fetch
91
+ * @param {int} [limit] the maximum amount of candles to fetch
92
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
93
+ * @returns {int[][]} A list of candles ordered as timestamp, open, high, low, close, volume
94
+ */
95
+ await this.loadMarkets();
96
+ const timeframes = this.safeValue(this.options, 'timeframes', {});
97
+ const channel = this.safeInteger(timeframes, timeframe);
98
+ if (channel === undefined) {
99
+ throw new BadRequest(this.id + ' watchOHLCV cannot take a timeframe of ' + timeframe);
100
+ }
101
+ const market = this.market(symbol);
102
+ const request = [
103
+ market['id'],
104
+ channel,
105
+ ];
106
+ const messageHash = 'kline::' + market['symbol'];
107
+ const ohlcv = await this.subscribe('kline.subscribe', messageHash, request, params);
108
+ if (this.newUpdates) {
109
+ limit = ohlcv.getLimit(symbol, limit);
110
+ }
111
+ return this.filterBySinceLimit(ohlcv, since, limit, 0, true);
112
+ }
113
+ async watchTicker(symbol, params = {}) {
114
+ /**
115
+ * @method
116
+ * @name p2b#watchTicker
117
+ * @description watches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market
118
+ * @see https://github.com/P2B-team/P2B-WSS-Public/blob/main/wss_documentation.md#last-price
119
+ * @see https://github.com/P2B-team/P2B-WSS-Public/blob/main/wss_documentation.md#market-status
120
+ * @param {string} symbol unified symbol of the market to fetch the ticker for
121
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
122
+ * @param {object} [params.method] 'state' (default) or 'price'
123
+ * @returns {object} a [ticker structure]{@link https://docs.ccxt.com/#/?id=ticker-structure}
124
+ */
125
+ await this.loadMarkets();
126
+ const watchTickerOptions = this.safeValue(this.options, 'watchTicker');
127
+ let name = this.safeString(watchTickerOptions, 'name', 'state'); // or price
128
+ [name, params] = this.handleOptionAndParams(params, 'method', 'name', name);
129
+ const market = this.market(symbol);
130
+ const request = [
131
+ market['id'],
132
+ ];
133
+ const messageHash = name + '::' + market['symbol'];
134
+ return await this.subscribe(name + '.subscribe', messageHash, request, params);
135
+ }
136
+ async watchTrades(symbol, since = undefined, limit = undefined, params = {}) {
137
+ /**
138
+ * @method
139
+ * @name p2b#watchTrades
140
+ * @description get the list of most recent trades for a particular symbol
141
+ * @see https://github.com/P2B-team/P2B-WSS-Public/blob/main/wss_documentation.md#deals
142
+ * @param {string} symbol unified symbol of the market to fetch trades for
143
+ * @param {int} [since] timestamp in ms of the earliest trade to fetch
144
+ * @param {int} [limit] the maximum amount of trades to fetch
145
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
146
+ * @returns {object[]} a list of [trade structures]{@link https://docs.ccxt.com/#/?id=public-trades}
147
+ */
148
+ await this.loadMarkets();
149
+ const market = this.market(symbol);
150
+ const request = [
151
+ market['id'],
152
+ ];
153
+ const messageHash = 'deals::' + market['symbol'];
154
+ const trades = await this.subscribe('deals.subscribe', messageHash, request, params);
155
+ if (this.newUpdates) {
156
+ limit = trades.getLimit(symbol, limit);
157
+ }
158
+ return this.filterBySinceLimit(trades, since, limit, 'timestamp', true);
159
+ }
160
+ async watchOrderBook(symbol, limit = undefined, params = {}) {
161
+ /**
162
+ * @method
163
+ * @name p2b#watchOrderBook
164
+ * @description watches information on open orders with bid (buy) and ask (sell) prices, volumes and other data
165
+ * @see https://github.com/P2B-team/P2B-WSS-Public/blob/main/wss_documentation.md#depth-of-market
166
+ * @param {string} symbol unified symbol of the market to fetch the order book for
167
+ * @param {int} [limit] 1-100, default=100
168
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
169
+ * @param {float} [params.interval] 0, 0.00000001, 0.0000001, 0.000001, 0.00001, 0.0001, 0.001, 0.01, 0.1, interval of precision for order, default=0.001
170
+ * @returns {object} A dictionary of [order book structures]{@link https://docs.ccxt.com/#/?id=order-book-structure} indexed by market symbols
171
+ */
172
+ await this.loadMarkets();
173
+ const market = this.market(symbol);
174
+ const name = 'depth.subscribe';
175
+ const messageHash = 'orderbook::' + market['symbol'];
176
+ const interval = this.safeString(params, 'interval', '0.001');
177
+ if (limit === undefined) {
178
+ limit = 100;
179
+ }
180
+ const request = [
181
+ market['id'],
182
+ limit,
183
+ interval,
184
+ ];
185
+ const orderbook = await this.subscribe(name, messageHash, request, params);
186
+ return orderbook.limit();
187
+ }
188
+ handleOHLCV(client, message) {
189
+ //
190
+ // {
191
+ // "method": "kline.update",
192
+ // "params": [
193
+ // [
194
+ // 1657648800, // Kline start time
195
+ // "0.054146", // Kline open price
196
+ // "0.053938", // Kline close price (current price)
197
+ // "0.054146", // Kline high price
198
+ // "0.053911", // Kline low price
199
+ // "596.4674", // Volume for stock currency
200
+ // "32.2298758767", // Volume for money currency
201
+ // "ETH_BTC" // Market
202
+ // ]
203
+ // ],
204
+ // "id": null
205
+ // }
206
+ //
207
+ let data = this.safeList(message, 'params');
208
+ data = this.safeList(data, 0);
209
+ const method = this.safeString(message, 'method');
210
+ const splitMethod = method.split('.');
211
+ const channel = this.safeString(splitMethod, 0);
212
+ const marketId = this.safeString(data, 7);
213
+ const market = this.safeMarket(marketId);
214
+ const timeframes = this.safeDict(this.options, 'timeframes', {});
215
+ const timeframe = this.findTimeframe(channel, timeframes);
216
+ const symbol = this.safeString(market, 'symbol');
217
+ const messageHash = channel + '::' + symbol;
218
+ const parsed = this.parseOHLCV(data, market);
219
+ this.ohlcvs[symbol] = this.safeValue(this.ohlcvs, symbol, {});
220
+ let stored = this.safeValue(this.ohlcvs[symbol], timeframe);
221
+ if (symbol !== undefined) {
222
+ if (stored === undefined) {
223
+ const limit = this.safeInteger(this.options, 'OHLCVLimit', 1000);
224
+ stored = new ArrayCacheByTimestamp(limit);
225
+ this.ohlcvs[symbol][timeframe] = stored;
226
+ }
227
+ stored.append(parsed);
228
+ client.resolve(stored, messageHash);
229
+ }
230
+ return message;
231
+ }
232
+ handleTrade(client, message) {
233
+ //
234
+ // {
235
+ // "method": "deals.update",
236
+ // "params": [
237
+ // "ETH_BTC",
238
+ // [
239
+ // {
240
+ // "id": 4503032979, // Order_id
241
+ // "amount": "0.103",
242
+ // "type": "sell", // Side
243
+ // "time": 1657661950.8487639, // Creation time
244
+ // "price": "0.05361"
245
+ // },
246
+ // ...
247
+ // ]
248
+ // ],
249
+ // "id": null
250
+ // }
251
+ //
252
+ const data = this.safeList(message, 'params', []);
253
+ const trades = this.safeList(data, 1);
254
+ const marketId = this.safeString(data, 0);
255
+ const market = this.safeMarket(marketId);
256
+ const symbol = this.safeString(market, 'symbol');
257
+ let tradesArray = this.safeValue(this.trades, symbol);
258
+ if (tradesArray === undefined) {
259
+ const tradesLimit = this.safeInteger(this.options, 'tradesLimit', 1000);
260
+ tradesArray = new ArrayCache(tradesLimit);
261
+ this.trades[symbol] = tradesArray;
262
+ }
263
+ for (let i = 0; i < trades.length; i++) {
264
+ const item = trades[i];
265
+ const trade = this.parseTrade(item, market);
266
+ tradesArray.append(trade);
267
+ }
268
+ const messageHash = 'deals::' + symbol;
269
+ client.resolve(tradesArray, messageHash);
270
+ return message;
271
+ }
272
+ handleTicker(client, message) {
273
+ //
274
+ // state
275
+ //
276
+ // {
277
+ // "method": "state.update",
278
+ // "params": [
279
+ // "ETH_BTC",
280
+ // {
281
+ // "high": "0.055774", // High price for the last 24h
282
+ // "close": "0.053679", // Close price for the last 24h
283
+ // "low": "0.053462", // Low price for the last 24h
284
+ // "period": 86400, // Period 24h
285
+ // "last": "0.053679", // Last price for the last 24h
286
+ // "volume": "38463.6132", // Stock volume for the last 24h
287
+ // "open": "0.055682", // Open price for the last 24h
288
+ // "deal": "2091.0038055314" // Money volume for the last 24h
289
+ // }
290
+ // ],
291
+ // "id": null
292
+ // }
293
+ //
294
+ // price
295
+ //
296
+ // {
297
+ // "method": "price.update",
298
+ // "params": [
299
+ // "ETH_BTC", // market
300
+ // "0.053836" // last price
301
+ // ],
302
+ // "id": null
303
+ // }
304
+ //
305
+ const data = this.safeList(message, 'params', []);
306
+ const marketId = this.safeString(data, 0);
307
+ const market = this.safeMarket(marketId);
308
+ const method = this.safeString(message, 'method');
309
+ const splitMethod = method.split('.');
310
+ const messageHashStart = this.safeString(splitMethod, 0);
311
+ const tickerData = this.safeDict(data, 1);
312
+ let ticker = undefined;
313
+ if (method === 'price.update') {
314
+ const lastPrice = this.safeString(data, 1);
315
+ ticker = this.safeTicker({
316
+ 'last': lastPrice,
317
+ 'close': lastPrice,
318
+ 'symbol': market['symbol'],
319
+ });
320
+ }
321
+ else {
322
+ ticker = this.parseTicker(tickerData, market);
323
+ }
324
+ const symbol = ticker['symbol'];
325
+ const messageHash = messageHashStart + '::' + symbol;
326
+ client.resolve(ticker, messageHash);
327
+ return message;
328
+ }
329
+ handleOrderBook(client, message) {
330
+ //
331
+ // {
332
+ // "method": "depth.update",
333
+ // "params": [
334
+ // false, // true - all records, false - new records
335
+ // {
336
+ // "asks": [ // side
337
+ // [
338
+ // "19509.81", // price
339
+ // "0.277" // amount
340
+ // ]
341
+ // ]
342
+ // },
343
+ // "BTC_USDT"
344
+ // ],
345
+ // "id": null
346
+ // }
347
+ //
348
+ const params = this.safeList(message, 'params', []);
349
+ const data = this.safeDict(params, 1);
350
+ const asks = this.safeList(data, 'asks');
351
+ const bids = this.safeList(data, 'bids');
352
+ const marketId = this.safeString(params, 2);
353
+ const market = this.safeMarket(marketId);
354
+ const symbol = market['symbol'];
355
+ const messageHash = 'orderbook::' + market['symbol'];
356
+ const subscription = this.safeValue(client.subscriptions, messageHash, {});
357
+ const limit = this.safeInteger(subscription, 'limit');
358
+ let orderbook = this.safeValue(this.orderbooks, symbol);
359
+ if (orderbook === undefined) {
360
+ this.orderbooks[symbol] = this.orderBook({}, limit);
361
+ orderbook = this.orderbooks[symbol];
362
+ }
363
+ if (bids !== undefined) {
364
+ for (let i = 0; i < bids.length; i++) {
365
+ const bid = this.safeValue(bids, i);
366
+ const price = this.safeNumber(bid, 0);
367
+ const amount = this.safeNumber(bid, 1);
368
+ orderbook['bids'].store(price, amount);
369
+ }
370
+ }
371
+ if (asks !== undefined) {
372
+ for (let i = 0; i < asks.length; i++) {
373
+ const ask = this.safeValue(asks, i);
374
+ const price = this.safeNumber(ask, 0);
375
+ const amount = this.safeNumber(ask, 1);
376
+ orderbook['asks'].store(price, amount);
377
+ }
378
+ }
379
+ orderbook['symbol'] = symbol;
380
+ client.resolve(orderbook, messageHash);
381
+ }
382
+ handleMessage(client, message) {
383
+ if (this.handleErrorMessage(client, message)) {
384
+ return;
385
+ }
386
+ const result = this.safeString(message, 'result');
387
+ if (result === 'pong') {
388
+ this.handlePong(client, message);
389
+ return;
390
+ }
391
+ const method = this.safeString(message, 'method');
392
+ const methods = {
393
+ 'depth.update': this.handleOrderBook,
394
+ 'price.update': this.handleTicker,
395
+ 'kline.update': this.handleOHLCV,
396
+ 'state.update': this.handleTicker,
397
+ 'deals.update': this.handleTrade,
398
+ };
399
+ const endpoint = this.safeValue(methods, method);
400
+ if (endpoint !== undefined) {
401
+ return endpoint.call(this, client, message);
402
+ }
403
+ }
404
+ handleErrorMessage(client, message) {
405
+ const error = this.safeString(message, 'error');
406
+ if (error !== undefined) {
407
+ throw new ExchangeError(this.id + ' error: ' + this.json(error));
408
+ }
409
+ return false;
410
+ }
411
+ ping(client) {
412
+ /**
413
+ * @see https://github.com/P2B-team/P2B-WSS-Public/blob/main/wss_documentation.md#ping
414
+ * @param client
415
+ */
416
+ return {
417
+ 'method': 'server.ping',
418
+ 'params': [],
419
+ 'id': this.milliseconds(),
420
+ };
421
+ }
422
+ handlePong(client, message) {
423
+ //
424
+ // {
425
+ // error: null,
426
+ // result: 'pong',
427
+ // id: 1706539608030
428
+ // }
429
+ //
430
+ client.lastPong = this.safeInteger(message, 'id');
431
+ return message;
432
+ }
433
+ }
@@ -100,7 +100,7 @@ export default class probit extends probitRest {
100
100
  // }
101
101
  // }
102
102
  //
103
- const reset = this.safeValue(message, 'reset', false);
103
+ const reset = this.safeBool(message, 'reset', false);
104
104
  const data = this.safeValue(message, 'data', {});
105
105
  const currencyIds = Object.keys(data);
106
106
  if (reset) {
@@ -206,7 +206,7 @@ export default class probit extends probitRest {
206
206
  const symbol = this.safeSymbol(marketId);
207
207
  const market = this.safeMarket(marketId);
208
208
  const trades = this.safeValue(message, 'recent_trades', []);
209
- const reset = this.safeValue(message, 'reset', false);
209
+ const reset = this.safeBool(message, 'reset', false);
210
210
  const messageHash = 'trades:' + symbol;
211
211
  let stored = this.safeValue(this.trades, symbol);
212
212
  if (stored === undefined || reset) {
@@ -279,7 +279,7 @@ export default class probit extends probitRest {
279
279
  if (length === 0) {
280
280
  return;
281
281
  }
282
- const reset = this.safeValue(message, 'reset', false);
282
+ const reset = this.safeBool(message, 'reset', false);
283
283
  const messageHash = 'myTrades';
284
284
  let stored = this.myTrades;
285
285
  if ((stored === undefined) || reset) {
@@ -367,7 +367,7 @@ export default class probit extends probitRest {
367
367
  return;
368
368
  }
369
369
  const messageHash = 'orders';
370
- const reset = this.safeValue(message, 'reset', false);
370
+ const reset = this.safeBool(message, 'reset', false);
371
371
  let stored = this.orders;
372
372
  if (stored === undefined || reset) {
373
373
  const limit = this.safeInteger(this.options, 'ordersLimit', 1000);
@@ -459,7 +459,7 @@ export default class probit extends probitRest {
459
459
  storedOrderBook = this.orderBook({});
460
460
  this.orderbooks[symbol] = storedOrderBook;
461
461
  }
462
- const reset = this.safeValue(message, 'reset', false);
462
+ const reset = this.safeBool(message, 'reset', false);
463
463
  if (reset) {
464
464
  const snapshot = this.parseOrderBook(dataBySide, symbol, undefined, 'buy', 'sell', 'price', 'quantity');
465
465
  storedOrderBook.reset(snapshot);
@@ -741,7 +741,7 @@ export default class whitebit extends whitebitRest {
741
741
  let hasSymbolSubscription = true;
742
742
  const market = this.market(symbol);
743
743
  const marketId = market['id'];
744
- const isSubscribed = this.safeValue(subscription, marketId, false);
744
+ const isSubscribed = this.safeBool(subscription, marketId, false);
745
745
  if (!isSubscribed) {
746
746
  subscription[marketId] = true;
747
747
  hasSymbolSubscription = false;
package/js/src/probit.js CHANGED
@@ -287,7 +287,7 @@ export default class probit extends Exchange {
287
287
  const quoteId = this.safeString(market, 'quote_currency_id');
288
288
  const base = this.safeCurrencyCode(baseId);
289
289
  const quote = this.safeCurrencyCode(quoteId);
290
- const closed = this.safeValue(market, 'closed', false);
290
+ const closed = this.safeBool(market, 'closed', false);
291
291
  const takerFeeRate = this.safeString(market, 'taker_fee_rate');
292
292
  const taker = Precise.stringDiv(takerFeeRate, '100');
293
293
  const makerFeeRate = this.safeString(market, 'maker_fee_rate');
package/js/src/timex.js CHANGED
@@ -724,7 +724,7 @@ export default class timex extends Exchange {
724
724
  const market = this.market(symbol);
725
725
  const uppercaseSide = side.toUpperCase();
726
726
  let uppercaseType = type.toUpperCase();
727
- const postOnly = this.safeValue(params, 'postOnly', false);
727
+ const postOnly = this.safeBool(params, 'postOnly', false);
728
728
  if (postOnly) {
729
729
  uppercaseType = 'POST_ONLY';
730
730
  params = this.omit(params, ['postOnly']);
@@ -692,7 +692,7 @@ export default class tokocrypto extends Exchange {
692
692
  break;
693
693
  }
694
694
  }
695
- const isMarginTradingAllowed = this.safeValue(market, 'isMarginTradingAllowed', false);
695
+ const isMarginTradingAllowed = this.safeBool(market, 'isMarginTradingAllowed', false);
696
696
  const entry = {
697
697
  'id': id,
698
698
  'lowercaseId': lowercaseId,
@@ -1591,7 +1591,7 @@ export default class tokocrypto extends Exchange {
1591
1591
  await this.loadMarkets();
1592
1592
  const market = this.market(symbol);
1593
1593
  const clientOrderId = this.safeString2(params, 'clientOrderId', 'clientId');
1594
- const postOnly = this.safeValue(params, 'postOnly', false);
1594
+ const postOnly = this.safeBool(params, 'postOnly', false);
1595
1595
  // only supported for spot/margin api
1596
1596
  if (postOnly) {
1597
1597
  type = 'LIMIT_MAKER';
@@ -2465,7 +2465,7 @@ export default class tokocrypto extends Exchange {
2465
2465
  }
2466
2466
  // check success value for wapi endpoints
2467
2467
  // response in format {'msg': 'The coin does not exist.', 'success': true/false}
2468
- const success = this.safeValue(response, 'success', true);
2468
+ const success = this.safeBool(response, 'success', true);
2469
2469
  if (!success) {
2470
2470
  const messageInner = this.safeString(response, 'msg');
2471
2471
  let parsedMessage = undefined;
@@ -398,7 +398,7 @@ export default class wavesexchange extends Exchange {
398
398
  // "matcherFee":"4077612"
399
399
  // }
400
400
  // }
401
- const isDiscountFee = this.safeValue(params, 'isDiscountFee', false);
401
+ const isDiscountFee = this.safeBool(params, 'isDiscountFee', false);
402
402
  let mode = undefined;
403
403
  if (isDiscountFee) {
404
404
  mode = this.safeValue(response, 'discount');
@@ -2415,7 +2415,7 @@ export default class wavesexchange extends Exchange {
2415
2415
  }
2416
2416
  handleErrors(code, reason, url, method, headers, body, response, requestHeaders, requestBody) {
2417
2417
  const errorCode = this.safeString(response, 'error');
2418
- const success = this.safeValue(response, 'success', true);
2418
+ const success = this.safeBool(response, 'success', true);
2419
2419
  const Exception = this.safeValue(this.exceptions, errorCode);
2420
2420
  if (Exception !== undefined) {
2421
2421
  const messageInner = this.safeString(response, 'message');
@@ -425,8 +425,8 @@ export default class whitebit extends Exchange {
425
425
  const currency = response[id];
426
426
  // breaks down in Python due to utf8 encoding issues on the exchange side
427
427
  // const name = this.safeString (currency, 'name');
428
- const canDeposit = this.safeValue(currency, 'can_deposit', true);
429
- const canWithdraw = this.safeValue(currency, 'can_withdraw', true);
428
+ const canDeposit = this.safeBool(currency, 'can_deposit', true);
429
+ const canWithdraw = this.safeBool(currency, 'can_withdraw', true);
430
430
  const active = canDeposit && canWithdraw;
431
431
  const code = this.safeCurrencyCode(id);
432
432
  result[code] = {
package/js/src/woo.js CHANGED
@@ -1136,7 +1136,7 @@ export default class woo extends Exchange {
1136
1136
  * @param {boolean} [params.stop] whether the order is a stop/algo order
1137
1137
  * @returns {object} An [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
1138
1138
  */
1139
- const stop = this.safeValue(params, 'stop', false);
1139
+ const stop = this.safeBool(params, 'stop', false);
1140
1140
  params = this.omit(params, 'stop');
1141
1141
  if (!stop && (symbol === undefined)) {
1142
1142
  throw new ArgumentsRequired(this.id + ' cancelOrder() requires a symbol argument');
@@ -1304,7 +1304,7 @@ export default class woo extends Exchange {
1304
1304
  const request = {};
1305
1305
  let market = undefined;
1306
1306
  const stop = this.safeValue(params, 'stop');
1307
- const trailing = this.safeValue(params, 'trailing', false);
1307
+ const trailing = this.safeBool(params, 'trailing', false);
1308
1308
  params = this.omit(params, ['stop', 'trailing']);
1309
1309
  if (symbol !== undefined) {
1310
1310
  market = this.market(symbol);
@@ -2086,7 +2086,7 @@ export default class woo extends Exchange {
2086
2086
  //
2087
2087
  const transfer = this.parseTransfer(response, currency);
2088
2088
  const transferOptions = this.safeValue(this.options, 'transfer', {});
2089
- const fillResponseFromRequest = this.safeValue(transferOptions, 'fillResponseFromRequest', true);
2089
+ const fillResponseFromRequest = this.safeBool(transferOptions, 'fillResponseFromRequest', true);
2090
2090
  if (fillResponseFromRequest) {
2091
2091
  transfer['amount'] = amount;
2092
2092
  transfer['fromAccount'] = fromAccount;
package/js/src/yobit.js CHANGED
@@ -1291,7 +1291,7 @@ export default class yobit extends Exchange {
1291
1291
  //
1292
1292
  // To cover points 1, 2, 3 and 4 combined this handler should work like this:
1293
1293
  //
1294
- let success = this.safeValue(response, 'success', false);
1294
+ let success = this.safeBool(response, 'success', false);
1295
1295
  if (typeof success === 'string') {
1296
1296
  if ((success === 'true') || (success === '1')) {
1297
1297
  success = true;
package/js/src/zaif.js CHANGED
@@ -728,7 +728,7 @@ export default class zaif extends Exchange {
728
728
  this.throwBroadlyMatchedException(this.exceptions['broad'], error, feedback);
729
729
  throw new ExchangeError(feedback); // unknown message
730
730
  }
731
- const success = this.safeValue(response, 'success', true);
731
+ const success = this.safeBool(response, 'success', true);
732
732
  if (!success) {
733
733
  throw new ExchangeError(feedback);
734
734
  }
package/js/src/zonda.d.ts CHANGED
@@ -42,7 +42,7 @@ export default class zonda extends Exchange {
42
42
  fetchTrades(symbol: string, since?: Int, limit?: Int, params?: {}): Promise<Trade[]>;
43
43
  createOrder(symbol: string, type: OrderType, side: OrderSide, amount: any, price?: any, params?: {}): Promise<Order>;
44
44
  cancelOrder(id: string, symbol?: Str, params?: {}): Promise<any>;
45
- isFiat(currency: any): any;
45
+ isFiat(currency: any): boolean;
46
46
  parseDepositAddress(depositAddress: any, currency?: Currency): {
47
47
  currency: string;
48
48
  address: string;
package/js/src/zonda.js CHANGED
@@ -1439,7 +1439,7 @@ export default class zonda extends Exchange {
1439
1439
  // }
1440
1440
  //
1441
1441
  const id = this.safeString2(response, 'offerId', 'stopOfferId');
1442
- const completed = this.safeValue(response, 'completed', false);
1442
+ const completed = this.safeBool(response, 'completed', false);
1443
1443
  const status = completed ? 'closed' : 'open';
1444
1444
  const transactions = this.safeValue(response, 'transactions');
1445
1445
  return this.safeOrder({
@@ -1501,7 +1501,7 @@ export default class zonda extends Exchange {
1501
1501
  'EUR': true,
1502
1502
  'PLN': true,
1503
1503
  };
1504
- return this.safeValue(fiatCurrencies, currency, false);
1504
+ return this.safeBool(fiatCurrencies, currency, false);
1505
1505
  }
1506
1506
  parseDepositAddress(depositAddress, currency = undefined) {
1507
1507
  //
@@ -1638,7 +1638,7 @@ export default class zonda extends Exchange {
1638
1638
  //
1639
1639
  const transfer = this.parseTransfer(response, currency);
1640
1640
  const transferOptions = this.safeValue(this.options, 'transfer', {});
1641
- const fillResponseFromRequest = this.safeValue(transferOptions, 'fillResponseFromRequest', true);
1641
+ const fillResponseFromRequest = this.safeBool(transferOptions, 'fillResponseFromRequest', true);
1642
1642
  if (fillResponseFromRequest) {
1643
1643
  transfer['amount'] = amount;
1644
1644
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ccxt",
3
- "version": "4.2.28",
3
+ "version": "4.2.30",
4
4
  "description": "A JavaScript / TypeScript / Python / C# / PHP cryptocurrency trading library with support for 100+ exchanges",
5
5
  "unpkg": "dist/ccxt.browser.js",
6
6
  "type": "module",