ccxt-ir 4.9.19 → 4.9.23

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 (111) hide show
  1. package/README.md +3 -3
  2. package/dist/ccxt.browser.min.js +2 -2
  3. package/dist/cjs/ccxt.js +4 -1
  4. package/dist/cjs/src/abantether.js +344 -344
  5. package/dist/cjs/src/abstract/bitbarg.js +1 -1
  6. package/dist/cjs/src/abstract/bitunix.js +1 -1
  7. package/dist/cjs/src/abstract/bydfi.js +1 -1
  8. package/dist/cjs/src/abstract/cafearz.js +1 -1
  9. package/dist/cjs/src/abstract/hamtapay.js +1 -1
  10. package/dist/cjs/src/abstract/iranexchange.js +11 -0
  11. package/dist/cjs/src/abstract/kifpoolme.js +1 -1
  12. package/dist/cjs/src/abstract/mazdax.js +1 -1
  13. package/dist/cjs/src/abstract/pingi.js +1 -1
  14. package/dist/cjs/src/abstract/pooleno.js +1 -1
  15. package/dist/cjs/src/abstract/tehran_exchange.js +1 -1
  16. package/dist/cjs/src/afratether.js +347 -347
  17. package/dist/cjs/src/arzplus.js +572 -572
  18. package/dist/cjs/src/bitbarg.js +303 -303
  19. package/dist/cjs/src/bitunix.js +317 -317
  20. package/dist/cjs/src/bydfi.js +425 -425
  21. package/dist/cjs/src/cafearz.js +337 -337
  22. package/dist/cjs/src/hamtapay.js +294 -294
  23. package/dist/cjs/src/iranexchange.js +398 -0
  24. package/dist/cjs/src/kcex.js +326 -326
  25. package/dist/cjs/src/kifpoolme.js +401 -401
  26. package/dist/cjs/src/mazdax.js +525 -525
  27. package/dist/cjs/src/ompfinex.js +501 -501
  28. package/dist/cjs/src/pingi.js +437 -437
  29. package/dist/cjs/src/pooleno.js +338 -338
  30. package/dist/cjs/src/sarmayex.js +367 -367
  31. package/dist/cjs/src/tehran_exchange.js +324 -324
  32. package/dist/cjs/src/tetherland.js +358 -358
  33. package/dist/cjs/src/toobit.js +436 -436
  34. package/dist/cjs/src/twox.js +362 -362
  35. package/dist/cjs/src/xt.js +5171 -5171
  36. package/js/ccxt.d.ts +5 -2
  37. package/js/ccxt.js +4 -2
  38. package/js/src/abantether.js +347 -347
  39. package/js/src/abstract/abantether.d.ts +8 -8
  40. package/js/src/abstract/arzplus.d.ts +11 -11
  41. package/js/src/abstract/bitbarg.d.ts +8 -8
  42. package/js/src/abstract/bitbarg.js +5 -5
  43. package/js/src/abstract/bitunix.d.ts +9 -9
  44. package/js/src/abstract/bitunix.js +5 -5
  45. package/js/src/abstract/bydfi.d.ts +11 -11
  46. package/js/src/abstract/bydfi.js +5 -5
  47. package/js/src/abstract/cafearz.d.ts +8 -8
  48. package/js/src/abstract/cafearz.js +5 -5
  49. package/js/src/abstract/hamtapay.d.ts +9 -9
  50. package/js/src/abstract/hamtapay.js +5 -5
  51. package/js/src/abstract/iranexchange.d.ts +9 -0
  52. package/js/src/abstract/iranexchange.js +11 -0
  53. package/js/src/abstract/kcex.d.ts +10 -10
  54. package/js/src/abstract/kifpoolme.d.ts +9 -9
  55. package/js/src/abstract/kifpoolme.js +5 -5
  56. package/js/src/abstract/mazdax.d.ts +11 -11
  57. package/js/src/abstract/mazdax.js +5 -5
  58. package/js/src/abstract/pingi.d.ts +9 -9
  59. package/js/src/abstract/pingi.js +5 -5
  60. package/js/src/abstract/pooleno.d.ts +8 -8
  61. package/js/src/abstract/pooleno.js +5 -5
  62. package/js/src/abstract/tehran_exchange.d.ts +9 -9
  63. package/js/src/abstract/tehran_exchange.js +5 -5
  64. package/js/src/abstract/toobit.d.ts +10 -10
  65. package/js/src/afratether.js +350 -350
  66. package/js/src/arzplus.d.ts +26 -26
  67. package/js/src/arzplus.js +575 -575
  68. package/js/src/base/Exchange.d.ts +2 -2
  69. package/js/src/base/types.d.ts +586 -586
  70. package/js/src/bitbarg.d.ts +21 -21
  71. package/js/src/bitbarg.js +306 -306
  72. package/js/src/bitunix.d.ts +21 -21
  73. package/js/src/bitunix.js +320 -320
  74. package/js/src/bydfi.d.ts +23 -23
  75. package/js/src/bydfi.js +428 -428
  76. package/js/src/cafearz.d.ts +21 -21
  77. package/js/src/cafearz.js +340 -340
  78. package/js/src/coinbaseexchange.d.ts +1 -1
  79. package/js/src/hamtapay.d.ts +21 -21
  80. package/js/src/hamtapay.js +297 -297
  81. package/js/src/iranexchange.d.ts +21 -0
  82. package/js/src/iranexchange.js +397 -0
  83. package/js/src/kcex.d.ts +21 -21
  84. package/js/src/kcex.js +329 -329
  85. package/js/src/kifpoolme.d.ts +23 -23
  86. package/js/src/kifpoolme.js +404 -404
  87. package/js/src/mazdax.d.ts +23 -23
  88. package/js/src/mazdax.js +528 -528
  89. package/js/src/ompfinex.js +504 -504
  90. package/js/src/pingi.d.ts +22 -22
  91. package/js/src/pingi.js +440 -440
  92. package/js/src/pooleno.d.ts +21 -21
  93. package/js/src/pooleno.js +341 -341
  94. package/js/src/protobuf/mexc/compiled.d.cts +0 -6
  95. package/js/src/sarmayex.js +370 -370
  96. package/js/src/static_dependencies/fflake/browser.d.ts +5 -5
  97. package/js/src/static_dependencies/jsencrypt/lib/asn1js/asn1.d.ts +51 -51
  98. package/js/src/static_dependencies/jsencrypt/lib/jsbn/jsbn.d.ts +101 -101
  99. package/js/src/static_dependencies/qs/formats.d.cts +0 -6
  100. package/js/src/static_dependencies/qs/index.d.cts +0 -6
  101. package/js/src/static_dependencies/qs/parse.d.cts +0 -6
  102. package/js/src/static_dependencies/qs/stringify.d.cts +0 -6
  103. package/js/src/static_dependencies/qs/utils.d.cts +0 -6
  104. package/js/src/static_dependencies/starknet/utils/calldata/parser/index.d.ts +5 -5
  105. package/js/src/tehran_exchange.d.ts +21 -21
  106. package/js/src/tehran_exchange.js +327 -327
  107. package/js/src/tetherland.js +361 -361
  108. package/js/src/toobit.js +439 -439
  109. package/js/src/twox.js +365 -365
  110. package/js/src/xt.js +5178 -5178
  111. package/package.json +1 -1
package/js/src/toobit.js CHANGED
@@ -4,442 +4,442 @@
4
4
  // https://github.com/ccxt/ccxt/blob/master/CONTRIBUTING.md#how-to-contribute-code
5
5
  // EDIT THE CORRESPONDENT .ts FILE INSTEAD
6
6
 
7
- // ---------------------------------------------------------------------------
8
- import Exchange from './abstract/toobit.js';
9
- // ---------------------------------------------------------------------------
10
- /**
11
- * @class toobit
12
- * @augments Exchange
13
- * @description Set rateLimit to 1000 if fully verified
14
- */
15
- export default class toobit extends Exchange {
16
- describe() {
17
- return this.deepExtend(super.describe(), {
18
- 'id': 'toobit',
19
- 'name': 'Toobit',
20
- 'countries': ['KY'],
21
- 'rateLimit': 1000,
22
- 'version': '1',
23
- 'certified': false,
24
- 'pro': false,
25
- 'has': {
26
- 'CORS': undefined,
27
- 'spot': true,
28
- 'margin': false,
29
- 'swap': true,
30
- 'future': false,
31
- 'option': false,
32
- 'addMargin': false,
33
- 'cancelAllOrders': false,
34
- 'cancelOrder': false,
35
- 'cancelOrders': false,
36
- 'createDepositAddress': false,
37
- 'createOrder': false,
38
- 'createStopLimitOrder': false,
39
- 'createStopMarketOrder': false,
40
- 'createStopOrder': false,
41
- 'editOrder': false,
42
- 'fetchBalance': false,
43
- 'fetchBorrowInterest': false,
44
- 'fetchBorrowRateHistories': false,
45
- 'fetchBorrowRateHistory': false,
46
- 'fetchClosedOrders': false,
47
- 'fetchCrossBorrowRate': false,
48
- 'fetchCrossBorrowRates': false,
49
- 'fetchCurrencies': false,
50
- 'fetchDepositAddress': false,
51
- 'fetchDeposits': false,
52
- 'fetchFundingHistory': false,
53
- 'fetchFundingRate': false,
54
- 'fetchFundingRateHistory': false,
55
- 'fetchFundingRates': false,
56
- 'fetchIndexOHLCV': false,
57
- 'fetchIsolatedBorrowRate': false,
58
- 'fetchIsolatedBorrowRates': false,
59
- 'fetchL2OrderBook': false,
60
- 'fetchLedger': false,
61
- 'fetchLedgerEntry': false,
62
- 'fetchLeverageTiers': false,
63
- 'fetchMarkets': true,
64
- 'fetchMarkOHLCV': false,
65
- 'fetchMyTrades': false,
66
- 'fetchOHLCV': true,
67
- 'fetchOpenInterestHistory': false,
68
- 'fetchOpenOrders': false,
69
- 'fetchOrder': false,
70
- 'fetchOrderBook': true,
71
- 'fetchOrders': false,
72
- 'fetchOrderTrades': 'emulated',
73
- 'fetchPositions': false,
74
- 'fetchPremiumIndexOHLCV': false,
75
- 'fetchTicker': true,
76
- 'fetchTickers': true,
77
- 'fetchTime': false,
78
- 'fetchTrades': false,
79
- 'fetchTradingFee': false,
80
- 'fetchTradingFees': false,
81
- 'fetchWithdrawals': false,
82
- 'setLeverage': false,
83
- 'setMarginMode': false,
84
- 'transfer': false,
85
- 'withdraw': false,
86
- },
87
- 'comment': 'This comment is optional',
88
- 'urls': {
89
- 'logo': 'https://toobit-docs.github.io/apidocs/spot/v1/en/images/logo.svg',
90
- 'api': {
91
- 'public': 'https://api.toobit.com',
92
- },
93
- 'www': 'https://www.toobit.com/',
94
- 'doc': [
95
- 'https://toobit-docs.github.io/apidocs/spot/v1/en/#change-log',
96
- ],
97
- },
98
- 'timeframes': {
99
- '1m': '1m',
100
- '3m': '3m',
101
- '5m': '5m',
102
- '15m': '15m',
103
- '30m': '30m',
104
- '1h': '1h',
105
- '2h': '2h',
106
- '4h': '4h',
107
- '6h': '6h',
108
- '12h': '12h',
109
- '1d': '1d',
110
- '1w': '1w',
111
- '1M': '1M',
112
- },
113
- 'api': {
114
- 'public': {
115
- 'get': {
116
- 'quote/v1/ticker/24hr': 1,
117
- 'quote/v1/klines': 1,
118
- '/api/v1/exchangeInfo': 1,
119
- },
120
- },
121
- },
122
- 'fees': {
123
- 'trading': {
124
- 'tierBased': false,
125
- 'percentage': true,
126
- 'maker': this.parseNumber('0.001'),
127
- 'taker': this.parseNumber('0.001'),
128
- },
129
- },
130
- });
131
- }
132
- async fetchMarkets(params = {}) {
133
- /**
134
- * @method
135
- * @name toobit#fetchMarkets
136
- * @description retrieves data on all markets for toobit
137
- * @see https://api.toobit.com/api/v1/exchangeInfo
138
- * @param {object} [params] extra parameters specific to the exchange API endpoint
139
- * @returns {object[]} an array of objects representing market data
140
- */
141
- const response = await this.publicGetApiV1ExchangeInfo();
142
- const symbols = this.safeValue(response, 'symbols', []);
143
- const result = [];
144
- for (let i = 0; i < symbols.length; i++) {
145
- const symbolData = symbols[i];
146
- const status = this.safeValue(symbolData, 'status');
147
- const symbol = this.safeValue(symbolData, 'symbol');
148
- if (status !== 'TRADING' || symbol === 'TESTA1S3TESTX8Z9') {
149
- continue;
150
- }
151
- const market = this.parseMarket(symbolData);
152
- result.push(market);
153
- }
154
- return result;
155
- }
156
- parseMarket(market) {
157
- // {
158
- // "filters": [
159
- // {
160
- // "minPrice": "0.01",
161
- // "maxPrice": "10000000.00000000",
162
- // "tickSize": "0.01",
163
- // "filterType": "PRICE_FILTER"
164
- // },
165
- // {
166
- // "minQty": "0.0001",
167
- // "maxQty": "4000",
168
- // "stepSize": "0.0001",
169
- // "filterType": "LOT_SIZE"
170
- // },
171
- // {
172
- // "minNotional": "5",
173
- // "filterType": "MIN_NOTIONAL"
174
- // }
175
- // ],
176
- // "exchangeId": "301",
177
- // "symbol": "ETHUSDT",
178
- // "symbolName": "ETHUSDT",
179
- // "status": "TRADING",
180
- // "baseAsset": "ETH",
181
- // "baseAssetName": "ETH",
182
- // "baseAssetPrecision": "0.0001",
183
- // "quoteAsset": "USDT",
184
- // "quoteAssetName": "USDT",
185
- // "quotePrecision": "0.01",
186
- // "icebergAllowed": false,
187
- // "isAggregate": false,
188
- // "allowMargin": true
189
- // }
190
- const symbol = this.safeValue(market, 'symbol');
191
- const baseAsset = this.safeValue(market, 'baseAsset');
192
- const quoteAsset = this.safeValue(market, 'quoteAsset');
193
- const baseAssetPrecision = this.safeValue(market, 'baseAssetPrecision');
194
- const quotePrecision = this.safeValue(market, 'quotePrecision');
195
- const allowMargin = this.safeValue(market, 'allowMargin', false);
196
- const filters = this.safeValue(market, 'filters', []);
197
- // Parse filters to extract limits and precision
198
- let minPrice = undefined;
199
- let maxPrice = undefined;
200
- let tickSize = undefined;
201
- let minQty = undefined;
202
- let maxQty = undefined;
203
- let stepSize = undefined;
204
- let minNotional = undefined;
205
- let minAmount = undefined;
206
- let maxAmount = undefined;
207
- for (let i = 0; i < filters.length; i++) {
208
- const filter = filters[i];
209
- const filterType = this.safeValue(filter, 'filterType');
210
- if (filterType === 'PRICE_FILTER') {
211
- minPrice = this.safeNumber(filter, 'minPrice');
212
- maxPrice = this.safeNumber(filter, 'maxPrice');
213
- tickSize = this.safeString(filter, 'tickSize');
214
- }
215
- else if (filterType === 'LOT_SIZE') {
216
- minQty = this.safeNumber(filter, 'minQty');
217
- maxQty = this.safeNumber(filter, 'maxQty');
218
- stepSize = this.safeString(filter, 'stepSize');
219
- }
220
- else if (filterType === 'MIN_NOTIONAL') {
221
- minNotional = this.safeNumber(filter, 'minNotional');
222
- }
223
- else if (filterType === 'TRADE_AMOUNT') {
224
- minAmount = this.safeNumber(filter, 'minAmount');
225
- maxAmount = this.safeNumber(filter, 'maxAmount');
226
- }
227
- }
228
- const id = symbol;
229
- const base = this.safeCurrencyCode(baseAsset);
230
- const quote = this.safeCurrencyCode(quoteAsset);
231
- const baseId = baseAsset.toLowerCase();
232
- const quoteId = quoteAsset.toLowerCase();
233
- // Calculate precision from step sizes and precision strings
234
- const amountPrecision = stepSize ? this.precisionFromString(stepSize.toString()) : this.precisionFromString(baseAssetPrecision);
235
- const pricePrecision = tickSize ? this.precisionFromString(tickSize.toString()) : this.precisionFromString(quotePrecision);
236
- return {
237
- 'id': id,
238
- 'symbol': base + '/' + quote,
239
- 'base': base,
240
- 'quote': quote,
241
- 'settle': undefined,
242
- 'baseId': baseId,
243
- 'quoteId': quoteId,
244
- 'settleId': undefined,
245
- 'type': 'spot',
246
- 'spot': true,
247
- 'margin': allowMargin,
248
- 'swap': false,
249
- 'future': false,
250
- 'option': false,
251
- 'active': true,
252
- 'contract': false,
253
- 'linear': undefined,
254
- 'inverse': undefined,
255
- 'contractSize': undefined,
256
- 'expiry': undefined,
257
- 'expiryDatetime': undefined,
258
- 'strike': undefined,
259
- 'optionType': undefined,
260
- 'precision': {
261
- 'amount': amountPrecision,
262
- 'price': pricePrecision,
263
- },
264
- 'limits': {
265
- 'leverage': {
266
- 'min': undefined,
267
- 'max': undefined,
268
- },
269
- 'amount': {
270
- 'min': minQty,
271
- 'max': maxQty,
272
- },
273
- 'price': {
274
- 'min': minPrice,
275
- 'max': maxPrice,
276
- },
277
- 'cost': {
278
- 'min': minNotional || minAmount,
279
- 'max': maxAmount,
280
- },
281
- },
282
- 'created': undefined,
283
- 'info': market,
284
- };
285
- }
286
- async fetchTickers(symbols = undefined, params = {}) {
287
- /**
288
- * @method
289
- * @name toobit#fetchTickers
290
- * @description fetches price tickers for multiple markets, statistical information calculated over the past 24 hours for each market
291
- * @see https://toobit-docs.github.io/apidocs/spot/v1/en/#tickers
292
- * @param {string[]|undefined} symbols unified symbols of the markets to fetch the ticker for, all market tickers are returned if not assigned
293
- * @param {object} [params] extra parameters specific to the exchange API endpoint
294
- * @returns {object} a dictionary of [ticker structures]{@link https://docs.ccxt.com/#/?id=ticker-structure}
295
- */
296
- await this.loadMarkets();
297
- if (symbols !== undefined) {
298
- symbols = this.marketSymbols(symbols);
299
- }
300
- const response = await this.publicGetQuoteV1Ticker24hr();
301
- const result = {};
302
- for (let i = 0; i < response.length; i++) {
303
- const volume = this.safeFloat(response[i], 'v');
304
- if (volume === 0) {
305
- continue;
306
- }
307
- const ticker = this.parseTicker(response[i]);
308
- const symbol = ticker['symbol'];
309
- result[symbol] = ticker;
310
- }
311
- return this.filterByArrayTickers(result, 'symbol', symbols);
312
- }
313
- async fetchTicker(symbol, params = {}) {
314
- /**
315
- * @method
316
- * @name toobit#fetchTicker
317
- * @description fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market
318
- * @see https://toobit-docs.github.io/apidocs/spot/v1/en/#ticker
319
- * @param {string} symbol unified symbol of the market to fetch the ticker for
320
- * @param {object} [params] extra parameters specific to the exchange API endpoint
321
- * @returns {object} a [ticker structure]{@link https://docs.ccxt.com/#/?id=ticker-structure}
322
- */
323
- await this.loadMarkets();
324
- const market = this.market(symbol);
325
- const request = {
326
- 'symbol': market['id'],
327
- };
328
- const response = await this.publicGetQuoteV1Ticker24hr(request);
329
- const ticker = this.parseTicker(response[0]);
330
- return ticker;
331
- }
332
- parseTicker(ticker, market = undefined) {
333
- // {
334
- // t: 1757164008834,
335
- // s: "BTCUSDT",
336
- // c: "110895.06",
337
- // h: "113310.01",
338
- // l: "110219.01",
339
- // o: "112951.99",
340
- // v: "3893.406649",
341
- // qv: "433374169.27969515",
342
- // pc: "-2056.93",
343
- // pcp: "-0.0182"
344
- // }
345
- const marketType = 'spot';
346
- let symbol = this.safeValue(ticker, 's');
347
- const marketId = symbol;
348
- symbol = this.safeSymbol(marketId, market, undefined, marketType);
349
- const high = this.safeFloat(ticker, 'h');
350
- const low = this.safeFloat(ticker, 'l');
351
- const open = this.safeFloat(ticker, 'o');
352
- const close = this.safeFloat(ticker, 'c');
353
- const last = this.safeFloat(ticker, 'c');
354
- const change = this.safeFloat(ticker, 'pcp');
355
- const priceChange = this.safeFloat(ticker, 'pc');
356
- const baseVolume = this.safeFloat(ticker, 'v');
357
- const quoteVolume = this.safeFloat(ticker, 'qv');
358
- const datetime = this.safeString(ticker, 't');
359
- const bid = this.safeFloat(ticker, 'b', 0);
360
- const ask = this.safeFloat(ticker, 'a', 0);
361
- return this.safeTicker({
362
- 'symbol': symbol,
363
- 'timestamp': datetime,
364
- 'datetime': this.parse8601(datetime),
365
- 'high': high,
366
- 'low': low,
367
- 'bid': bid,
368
- 'bidVolume': undefined,
369
- 'ask': ask,
370
- 'askVolume': undefined,
371
- 'vwap': undefined,
372
- 'open': open,
373
- 'close': close,
374
- 'last': last,
375
- 'previousClose': undefined,
376
- 'change': priceChange,
377
- 'percentage': change,
378
- 'average': undefined,
379
- 'baseVolume': baseVolume,
380
- 'quoteVolume': quoteVolume,
381
- 'info': ticker,
382
- }, market);
383
- }
384
- async fetchOHLCV(symbol, timeframe = '1h', since = undefined, limit = undefined, params = {}) {
385
- /**
386
- * @method
387
- * @name toobit#fetchOHLCV
388
- * @description fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market
389
- * @see https://toobit-docs.github.io/apidocs/spot/v1/en/#chart
390
- * @param {string} symbol unified symbol of the market to fetch OHLCV data for
391
- * @param {string} timeframe the length of time each candle represents
392
- * @param {int} [since] timestamp in ms of the earliest candle to fetch
393
- * @param {int} [limit] the maximum amount of candles to fetch
394
- * @param {object} [params] extra parameters specific to the exchange API endpoint
395
- * @returns {int[][]} A list of candles ordered as timestamp, open, high, low, close, volume
396
- */
397
- await this.loadMarkets();
398
- const market = this.market(symbol);
399
- const endTime = Date.now();
400
- const request = {
401
- 'symbol': market['id'],
402
- 'from': (endTime - (24 * 60 * 60 * 1000)),
403
- 'to': endTime,
404
- 'interval': this.safeString(this.timeframes, timeframe, timeframe),
405
- };
406
- if (since !== undefined) {
407
- request['from'] = since;
408
- }
409
- if (timeframe !== undefined) {
410
- request['interval'] = this.safeString(this.timeframes, timeframe, timeframe);
411
- }
412
- const response = await this.publicGetQuoteV1Klines(request);
413
- const ohlcvs = [];
414
- for (let i = 0; i < response.length; i++) {
415
- const candle = response[i];
416
- const ts = this.safeTimestamp(candle, 0);
417
- const open = this.safeFloat(candle, 1);
418
- const high = this.safeFloat(candle, 2);
419
- const low = this.safeFloat(candle, 3);
420
- const close = this.safeFloat(candle, 4);
421
- const volume = this.safeFloat(candle, 5);
422
- ohlcvs.push([
423
- ts,
424
- open,
425
- high,
426
- low,
427
- close,
428
- volume,
429
- ]);
430
- }
431
- return this.parseOHLCVs(ohlcvs, market, timeframe, since, limit);
432
- }
433
- sign(path, api = 'public', method = 'GET', params = {}, headers = undefined, body = undefined) {
434
- const query = this.omit(params, this.extractParams(path));
435
- let url = this.urls['api']['public'] + '/' + path;
436
- if (path === 'quote/v1/ticker/24hr') {
437
- url = url + '?' + this.urlencode(query);
438
- }
439
- if (path === 'quote/v1/klines') {
440
- url = url + '?' + this.urlencode(query);
441
- }
442
- headers = { 'Content-Type': 'application/json' };
443
- return { 'url': url, 'method': method, 'body': body, 'headers': headers };
444
- }
445
- }
7
+ // ---------------------------------------------------------------------------
8
+ import Exchange from './abstract/toobit.js';
9
+ // ---------------------------------------------------------------------------
10
+ /**
11
+ * @class toobit
12
+ * @augments Exchange
13
+ * @description Set rateLimit to 1000 if fully verified
14
+ */
15
+ export default class toobit extends Exchange {
16
+ describe() {
17
+ return this.deepExtend(super.describe(), {
18
+ 'id': 'toobit',
19
+ 'name': 'Toobit',
20
+ 'countries': ['KY'],
21
+ 'rateLimit': 1000,
22
+ 'version': '1',
23
+ 'certified': false,
24
+ 'pro': false,
25
+ 'has': {
26
+ 'CORS': undefined,
27
+ 'spot': true,
28
+ 'margin': false,
29
+ 'swap': true,
30
+ 'future': false,
31
+ 'option': false,
32
+ 'addMargin': false,
33
+ 'cancelAllOrders': false,
34
+ 'cancelOrder': false,
35
+ 'cancelOrders': false,
36
+ 'createDepositAddress': false,
37
+ 'createOrder': false,
38
+ 'createStopLimitOrder': false,
39
+ 'createStopMarketOrder': false,
40
+ 'createStopOrder': false,
41
+ 'editOrder': false,
42
+ 'fetchBalance': false,
43
+ 'fetchBorrowInterest': false,
44
+ 'fetchBorrowRateHistories': false,
45
+ 'fetchBorrowRateHistory': false,
46
+ 'fetchClosedOrders': false,
47
+ 'fetchCrossBorrowRate': false,
48
+ 'fetchCrossBorrowRates': false,
49
+ 'fetchCurrencies': false,
50
+ 'fetchDepositAddress': false,
51
+ 'fetchDeposits': false,
52
+ 'fetchFundingHistory': false,
53
+ 'fetchFundingRate': false,
54
+ 'fetchFundingRateHistory': false,
55
+ 'fetchFundingRates': false,
56
+ 'fetchIndexOHLCV': false,
57
+ 'fetchIsolatedBorrowRate': false,
58
+ 'fetchIsolatedBorrowRates': false,
59
+ 'fetchL2OrderBook': false,
60
+ 'fetchLedger': false,
61
+ 'fetchLedgerEntry': false,
62
+ 'fetchLeverageTiers': false,
63
+ 'fetchMarkets': true,
64
+ 'fetchMarkOHLCV': false,
65
+ 'fetchMyTrades': false,
66
+ 'fetchOHLCV': true,
67
+ 'fetchOpenInterestHistory': false,
68
+ 'fetchOpenOrders': false,
69
+ 'fetchOrder': false,
70
+ 'fetchOrderBook': true,
71
+ 'fetchOrders': false,
72
+ 'fetchOrderTrades': 'emulated',
73
+ 'fetchPositions': false,
74
+ 'fetchPremiumIndexOHLCV': false,
75
+ 'fetchTicker': true,
76
+ 'fetchTickers': true,
77
+ 'fetchTime': false,
78
+ 'fetchTrades': false,
79
+ 'fetchTradingFee': false,
80
+ 'fetchTradingFees': false,
81
+ 'fetchWithdrawals': false,
82
+ 'setLeverage': false,
83
+ 'setMarginMode': false,
84
+ 'transfer': false,
85
+ 'withdraw': false,
86
+ },
87
+ 'comment': 'This comment is optional',
88
+ 'urls': {
89
+ 'logo': 'https://toobit-docs.github.io/apidocs/spot/v1/en/images/logo.svg',
90
+ 'api': {
91
+ 'public': 'https://api.toobit.com',
92
+ },
93
+ 'www': 'https://www.toobit.com/',
94
+ 'doc': [
95
+ 'https://toobit-docs.github.io/apidocs/spot/v1/en/#change-log',
96
+ ],
97
+ },
98
+ 'timeframes': {
99
+ '1m': '1m',
100
+ '3m': '3m',
101
+ '5m': '5m',
102
+ '15m': '15m',
103
+ '30m': '30m',
104
+ '1h': '1h',
105
+ '2h': '2h',
106
+ '4h': '4h',
107
+ '6h': '6h',
108
+ '12h': '12h',
109
+ '1d': '1d',
110
+ '1w': '1w',
111
+ '1M': '1M',
112
+ },
113
+ 'api': {
114
+ 'public': {
115
+ 'get': {
116
+ 'quote/v1/ticker/24hr': 1,
117
+ 'quote/v1/klines': 1,
118
+ '/api/v1/exchangeInfo': 1,
119
+ },
120
+ },
121
+ },
122
+ 'fees': {
123
+ 'trading': {
124
+ 'tierBased': false,
125
+ 'percentage': true,
126
+ 'maker': this.parseNumber('0.001'),
127
+ 'taker': this.parseNumber('0.001'),
128
+ },
129
+ },
130
+ });
131
+ }
132
+ async fetchMarkets(params = {}) {
133
+ /**
134
+ * @method
135
+ * @name toobit#fetchMarkets
136
+ * @description retrieves data on all markets for toobit
137
+ * @see https://api.toobit.com/api/v1/exchangeInfo
138
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
139
+ * @returns {object[]} an array of objects representing market data
140
+ */
141
+ const response = await this.publicGetApiV1ExchangeInfo();
142
+ const symbols = this.safeValue(response, 'symbols', []);
143
+ const result = [];
144
+ for (let i = 0; i < symbols.length; i++) {
145
+ const symbolData = symbols[i];
146
+ const status = this.safeValue(symbolData, 'status');
147
+ const symbol = this.safeValue(symbolData, 'symbol');
148
+ if (status !== 'TRADING' || symbol === 'TESTA1S3TESTX8Z9') {
149
+ continue;
150
+ }
151
+ const market = this.parseMarket(symbolData);
152
+ result.push(market);
153
+ }
154
+ return result;
155
+ }
156
+ parseMarket(market) {
157
+ // {
158
+ // "filters": [
159
+ // {
160
+ // "minPrice": "0.01",
161
+ // "maxPrice": "10000000.00000000",
162
+ // "tickSize": "0.01",
163
+ // "filterType": "PRICE_FILTER"
164
+ // },
165
+ // {
166
+ // "minQty": "0.0001",
167
+ // "maxQty": "4000",
168
+ // "stepSize": "0.0001",
169
+ // "filterType": "LOT_SIZE"
170
+ // },
171
+ // {
172
+ // "minNotional": "5",
173
+ // "filterType": "MIN_NOTIONAL"
174
+ // }
175
+ // ],
176
+ // "exchangeId": "301",
177
+ // "symbol": "ETHUSDT",
178
+ // "symbolName": "ETHUSDT",
179
+ // "status": "TRADING",
180
+ // "baseAsset": "ETH",
181
+ // "baseAssetName": "ETH",
182
+ // "baseAssetPrecision": "0.0001",
183
+ // "quoteAsset": "USDT",
184
+ // "quoteAssetName": "USDT",
185
+ // "quotePrecision": "0.01",
186
+ // "icebergAllowed": false,
187
+ // "isAggregate": false,
188
+ // "allowMargin": true
189
+ // }
190
+ const symbol = this.safeValue(market, 'symbol');
191
+ const baseAsset = this.safeValue(market, 'baseAsset');
192
+ const quoteAsset = this.safeValue(market, 'quoteAsset');
193
+ const baseAssetPrecision = this.safeValue(market, 'baseAssetPrecision');
194
+ const quotePrecision = this.safeValue(market, 'quotePrecision');
195
+ const allowMargin = this.safeValue(market, 'allowMargin', false);
196
+ const filters = this.safeValue(market, 'filters', []);
197
+ // Parse filters to extract limits and precision
198
+ let minPrice = undefined;
199
+ let maxPrice = undefined;
200
+ let tickSize = undefined;
201
+ let minQty = undefined;
202
+ let maxQty = undefined;
203
+ let stepSize = undefined;
204
+ let minNotional = undefined;
205
+ let minAmount = undefined;
206
+ let maxAmount = undefined;
207
+ for (let i = 0; i < filters.length; i++) {
208
+ const filter = filters[i];
209
+ const filterType = this.safeValue(filter, 'filterType');
210
+ if (filterType === 'PRICE_FILTER') {
211
+ minPrice = this.safeNumber(filter, 'minPrice');
212
+ maxPrice = this.safeNumber(filter, 'maxPrice');
213
+ tickSize = this.safeString(filter, 'tickSize');
214
+ }
215
+ else if (filterType === 'LOT_SIZE') {
216
+ minQty = this.safeNumber(filter, 'minQty');
217
+ maxQty = this.safeNumber(filter, 'maxQty');
218
+ stepSize = this.safeString(filter, 'stepSize');
219
+ }
220
+ else if (filterType === 'MIN_NOTIONAL') {
221
+ minNotional = this.safeNumber(filter, 'minNotional');
222
+ }
223
+ else if (filterType === 'TRADE_AMOUNT') {
224
+ minAmount = this.safeNumber(filter, 'minAmount');
225
+ maxAmount = this.safeNumber(filter, 'maxAmount');
226
+ }
227
+ }
228
+ const id = symbol;
229
+ const base = this.safeCurrencyCode(baseAsset);
230
+ const quote = this.safeCurrencyCode(quoteAsset);
231
+ const baseId = baseAsset.toLowerCase();
232
+ const quoteId = quoteAsset.toLowerCase();
233
+ // Calculate precision from step sizes and precision strings
234
+ const amountPrecision = stepSize ? this.precisionFromString(stepSize.toString()) : this.precisionFromString(baseAssetPrecision);
235
+ const pricePrecision = tickSize ? this.precisionFromString(tickSize.toString()) : this.precisionFromString(quotePrecision);
236
+ return {
237
+ 'id': id,
238
+ 'symbol': base + '/' + quote,
239
+ 'base': base,
240
+ 'quote': quote,
241
+ 'settle': undefined,
242
+ 'baseId': baseId,
243
+ 'quoteId': quoteId,
244
+ 'settleId': undefined,
245
+ 'type': 'spot',
246
+ 'spot': true,
247
+ 'margin': allowMargin,
248
+ 'swap': false,
249
+ 'future': false,
250
+ 'option': false,
251
+ 'active': true,
252
+ 'contract': false,
253
+ 'linear': undefined,
254
+ 'inverse': undefined,
255
+ 'contractSize': undefined,
256
+ 'expiry': undefined,
257
+ 'expiryDatetime': undefined,
258
+ 'strike': undefined,
259
+ 'optionType': undefined,
260
+ 'precision': {
261
+ 'amount': amountPrecision,
262
+ 'price': pricePrecision,
263
+ },
264
+ 'limits': {
265
+ 'leverage': {
266
+ 'min': undefined,
267
+ 'max': undefined,
268
+ },
269
+ 'amount': {
270
+ 'min': minQty,
271
+ 'max': maxQty,
272
+ },
273
+ 'price': {
274
+ 'min': minPrice,
275
+ 'max': maxPrice,
276
+ },
277
+ 'cost': {
278
+ 'min': minNotional || minAmount,
279
+ 'max': maxAmount,
280
+ },
281
+ },
282
+ 'created': undefined,
283
+ 'info': market,
284
+ };
285
+ }
286
+ async fetchTickers(symbols = undefined, params = {}) {
287
+ /**
288
+ * @method
289
+ * @name toobit#fetchTickers
290
+ * @description fetches price tickers for multiple markets, statistical information calculated over the past 24 hours for each market
291
+ * @see https://toobit-docs.github.io/apidocs/spot/v1/en/#tickers
292
+ * @param {string[]|undefined} symbols unified symbols of the markets to fetch the ticker for, all market tickers are returned if not assigned
293
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
294
+ * @returns {object} a dictionary of [ticker structures]{@link https://docs.ccxt.com/#/?id=ticker-structure}
295
+ */
296
+ await this.loadMarkets();
297
+ if (symbols !== undefined) {
298
+ symbols = this.marketSymbols(symbols);
299
+ }
300
+ const response = await this.publicGetQuoteV1Ticker24hr();
301
+ const result = {};
302
+ for (let i = 0; i < response.length; i++) {
303
+ const volume = this.safeFloat(response[i], 'v');
304
+ if (volume === 0) {
305
+ continue;
306
+ }
307
+ const ticker = this.parseTicker(response[i]);
308
+ const symbol = ticker['symbol'];
309
+ result[symbol] = ticker;
310
+ }
311
+ return this.filterByArrayTickers(result, 'symbol', symbols);
312
+ }
313
+ async fetchTicker(symbol, params = {}) {
314
+ /**
315
+ * @method
316
+ * @name toobit#fetchTicker
317
+ * @description fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market
318
+ * @see https://toobit-docs.github.io/apidocs/spot/v1/en/#ticker
319
+ * @param {string} symbol unified symbol of the market to fetch the ticker for
320
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
321
+ * @returns {object} a [ticker structure]{@link https://docs.ccxt.com/#/?id=ticker-structure}
322
+ */
323
+ await this.loadMarkets();
324
+ const market = this.market(symbol);
325
+ const request = {
326
+ 'symbol': market['id'],
327
+ };
328
+ const response = await this.publicGetQuoteV1Ticker24hr(request);
329
+ const ticker = this.parseTicker(response[0]);
330
+ return ticker;
331
+ }
332
+ parseTicker(ticker, market = undefined) {
333
+ // {
334
+ // t: 1757164008834,
335
+ // s: "BTCUSDT",
336
+ // c: "110895.06",
337
+ // h: "113310.01",
338
+ // l: "110219.01",
339
+ // o: "112951.99",
340
+ // v: "3893.406649",
341
+ // qv: "433374169.27969515",
342
+ // pc: "-2056.93",
343
+ // pcp: "-0.0182"
344
+ // }
345
+ const marketType = 'spot';
346
+ let symbol = this.safeValue(ticker, 's');
347
+ const marketId = symbol;
348
+ symbol = this.safeSymbol(marketId, market, undefined, marketType);
349
+ const high = this.safeFloat(ticker, 'h');
350
+ const low = this.safeFloat(ticker, 'l');
351
+ const open = this.safeFloat(ticker, 'o');
352
+ const close = this.safeFloat(ticker, 'c');
353
+ const last = this.safeFloat(ticker, 'c');
354
+ const change = this.safeFloat(ticker, 'pcp');
355
+ const priceChange = this.safeFloat(ticker, 'pc');
356
+ const baseVolume = this.safeFloat(ticker, 'v');
357
+ const quoteVolume = this.safeFloat(ticker, 'qv');
358
+ const datetime = this.safeString(ticker, 't');
359
+ const bid = this.safeFloat(ticker, 'b', 0);
360
+ const ask = this.safeFloat(ticker, 'a', 0);
361
+ return this.safeTicker({
362
+ 'symbol': symbol,
363
+ 'timestamp': datetime,
364
+ 'datetime': this.parse8601(datetime),
365
+ 'high': high,
366
+ 'low': low,
367
+ 'bid': bid,
368
+ 'bidVolume': undefined,
369
+ 'ask': ask,
370
+ 'askVolume': undefined,
371
+ 'vwap': undefined,
372
+ 'open': open,
373
+ 'close': close,
374
+ 'last': last,
375
+ 'previousClose': undefined,
376
+ 'change': priceChange,
377
+ 'percentage': change,
378
+ 'average': undefined,
379
+ 'baseVolume': baseVolume,
380
+ 'quoteVolume': quoteVolume,
381
+ 'info': ticker,
382
+ }, market);
383
+ }
384
+ async fetchOHLCV(symbol, timeframe = '1h', since = undefined, limit = undefined, params = {}) {
385
+ /**
386
+ * @method
387
+ * @name toobit#fetchOHLCV
388
+ * @description fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market
389
+ * @see https://toobit-docs.github.io/apidocs/spot/v1/en/#chart
390
+ * @param {string} symbol unified symbol of the market to fetch OHLCV data for
391
+ * @param {string} timeframe the length of time each candle represents
392
+ * @param {int} [since] timestamp in ms of the earliest candle to fetch
393
+ * @param {int} [limit] the maximum amount of candles to fetch
394
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
395
+ * @returns {int[][]} A list of candles ordered as timestamp, open, high, low, close, volume
396
+ */
397
+ await this.loadMarkets();
398
+ const market = this.market(symbol);
399
+ const endTime = Date.now();
400
+ const request = {
401
+ 'symbol': market['id'],
402
+ 'from': (endTime - (24 * 60 * 60 * 1000)),
403
+ 'to': endTime,
404
+ 'interval': this.safeString(this.timeframes, timeframe, timeframe),
405
+ };
406
+ if (since !== undefined) {
407
+ request['from'] = since;
408
+ }
409
+ if (timeframe !== undefined) {
410
+ request['interval'] = this.safeString(this.timeframes, timeframe, timeframe);
411
+ }
412
+ const response = await this.publicGetQuoteV1Klines(request);
413
+ const ohlcvs = [];
414
+ for (let i = 0; i < response.length; i++) {
415
+ const candle = response[i];
416
+ const ts = this.safeTimestamp(candle, 0);
417
+ const open = this.safeFloat(candle, 1);
418
+ const high = this.safeFloat(candle, 2);
419
+ const low = this.safeFloat(candle, 3);
420
+ const close = this.safeFloat(candle, 4);
421
+ const volume = this.safeFloat(candle, 5);
422
+ ohlcvs.push([
423
+ ts,
424
+ open,
425
+ high,
426
+ low,
427
+ close,
428
+ volume,
429
+ ]);
430
+ }
431
+ return this.parseOHLCVs(ohlcvs, market, timeframe, since, limit);
432
+ }
433
+ sign(path, api = 'public', method = 'GET', params = {}, headers = undefined, body = undefined) {
434
+ const query = this.omit(params, this.extractParams(path));
435
+ let url = this.urls['api']['public'] + '/' + path;
436
+ if (path === 'quote/v1/ticker/24hr') {
437
+ url = url + '?' + this.urlencode(query);
438
+ }
439
+ if (path === 'quote/v1/klines') {
440
+ url = url + '?' + this.urlencode(query);
441
+ }
442
+ headers = { 'Content-Type': 'application/json' };
443
+ return { 'url': url, 'method': method, 'body': body, 'headers': headers };
444
+ }
445
+ }