ccxt-ir 4.9.14 → 4.9.16

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.
package/js/src/toobit.js CHANGED
@@ -4,388 +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
- },
119
- },
120
- },
121
- 'fees': {
122
- 'trading': {
123
- 'tierBased': false,
124
- 'percentage': true,
125
- 'maker': this.parseNumber('0.001'),
126
- 'taker': this.parseNumber('0.001'),
127
- },
128
- },
129
- });
130
- }
131
- async fetchMarkets(params = {}) {
132
- /**
133
- * @method
134
- * @name toobit#fetchMarkets
135
- * @description retrieves data on all markets for toobit
136
- * @see https://apidocs.toobit.io/#tickers
137
- * @param {object} [params] extra parameters specific to the exchange API endpoint
138
- * @returns {object[]} an array of objects representing market data
139
- */
140
- const response = await this.publicGetQuoteV1Ticker24hr();
141
- const result = [];
142
- for (let i = 0; i < response.length; i++) {
143
- const volume = this.safeFloat(response[i], 'v');
144
- const symbol = this.safeValue(response[i], 's');
145
- if (volume === 0 || symbol === 'TESTA1S3TESTX8Z9') {
146
- continue;
147
- }
148
- const market = this.parseMarket(response[i]);
149
- result.push(market);
150
- }
151
- return result;
152
- }
153
- parseMarket(market) {
154
- // {
155
- // t: 1757164008834,
156
- // s: "BTCUSDT",
157
- // c: "110895.06",
158
- // h: "113310.01",
159
- // l: "110219.01",
160
- // o: "112951.99",
161
- // v: "3893.406649",
162
- // qv: "433374169.27969515",
163
- // pc: "-2056.93",
164
- // pcp: "-0.0182"
165
- // }
166
- const symbol = this.safeValue(market, 's');
167
- let baseId = symbol;
168
- let quoteId = undefined;
169
- if (symbol.endsWith('USDT')) {
170
- baseId = symbol.slice(0, -4);
171
- quoteId = 'USDT';
172
- }
173
- else if (symbol.endsWith('USDC')) {
174
- baseId = symbol.slice(0, -4);
175
- quoteId = 'USDC';
176
- }
177
- const id = symbol;
178
- const base = this.safeCurrencyCode(baseId);
179
- const quote = this.safeCurrencyCode(quoteId);
180
- baseId = baseId.toLowerCase();
181
- quoteId = quoteId.toLowerCase();
182
- return {
183
- 'id': id,
184
- 'symbol': base + '/' + quote,
185
- 'base': base,
186
- 'quote': quote,
187
- 'settle': undefined,
188
- 'baseId': baseId,
189
- 'quoteId': quoteId,
190
- 'settleId': undefined,
191
- 'type': 'spot',
192
- 'spot': true,
193
- 'margin': false,
194
- 'swap': false,
195
- 'future': false,
196
- 'option': false,
197
- 'active': true,
198
- 'contract': false,
199
- 'linear': undefined,
200
- 'inverse': undefined,
201
- 'contractSize': undefined,
202
- 'expiry': undefined,
203
- 'expiryDatetime': undefined,
204
- 'strike': undefined,
205
- 'optionType': undefined,
206
- 'precision': {
207
- 'amount': undefined,
208
- 'price': undefined,
209
- },
210
- 'limits': {
211
- 'leverage': {
212
- 'min': undefined,
213
- 'max': undefined,
214
- },
215
- 'amount': {
216
- 'min': undefined,
217
- 'max': undefined,
218
- },
219
- 'price': {
220
- 'min': undefined,
221
- 'max': undefined,
222
- },
223
- 'cost': {
224
- 'min': undefined,
225
- 'max': undefined,
226
- },
227
- },
228
- 'created': undefined,
229
- 'info': market,
230
- };
231
- }
232
- async fetchTickers(symbols = undefined, params = {}) {
233
- /**
234
- * @method
235
- * @name toobit#fetchTickers
236
- * @description fetches price tickers for multiple markets, statistical information calculated over the past 24 hours for each market
237
- * @see https://apidocs.toobit.io/#tickers
238
- * @param {string[]|undefined} symbols unified symbols of the markets to fetch the ticker for, all market tickers are returned if not assigned
239
- * @param {object} [params] extra parameters specific to the exchange API endpoint
240
- * @returns {object} a dictionary of [ticker structures]{@link https://docs.ccxt.com/#/?id=ticker-structure}
241
- */
242
- await this.loadMarkets();
243
- if (symbols !== undefined) {
244
- symbols = this.marketSymbols(symbols);
245
- }
246
- const response = await this.publicGetQuoteV1Ticker24hr();
247
- const result = {};
248
- for (let i = 0; i < response.length; i++) {
249
- const volume = this.safeFloat(response[i], 'v');
250
- if (volume === 0) {
251
- continue;
252
- }
253
- const ticker = this.parseTicker(response[i]);
254
- const symbol = ticker['symbol'];
255
- result[symbol] = ticker;
256
- }
257
- return this.filterByArrayTickers(result, 'symbol', symbols);
258
- }
259
- async fetchTicker(symbol, params = {}) {
260
- /**
261
- * @method
262
- * @name toobit#fetchTicker
263
- * @description fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market
264
- * @see https://apidocs.toobit.io/#ticker
265
- * @param {string} symbol unified symbol of the market to fetch the ticker for
266
- * @param {object} [params] extra parameters specific to the exchange API endpoint
267
- * @returns {object} a [ticker structure]{@link https://docs.ccxt.com/#/?id=ticker-structure}
268
- */
269
- await this.loadMarkets();
270
- const market = this.market(symbol);
271
- const request = {
272
- 'symbol': market['id'],
273
- };
274
- const response = await this.publicGetQuoteV1Ticker24hr(request);
275
- const ticker = this.parseTicker(response[0]);
276
- return ticker;
277
- }
278
- parseTicker(ticker, market = undefined) {
279
- // {
280
- // t: 1757164008834,
281
- // s: "BTCUSDT",
282
- // c: "110895.06",
283
- // h: "113310.01",
284
- // l: "110219.01",
285
- // o: "112951.99",
286
- // v: "3893.406649",
287
- // qv: "433374169.27969515",
288
- // pc: "-2056.93",
289
- // pcp: "-0.0182"
290
- // }
291
- const marketType = 'spot';
292
- let symbol = this.safeValue(ticker, 's');
293
- const marketId = symbol;
294
- symbol = this.safeSymbol(marketId, market, undefined, marketType);
295
- const high = this.safeFloat(ticker, 'h');
296
- const low = this.safeFloat(ticker, 'l');
297
- const open = this.safeFloat(ticker, 'o');
298
- const close = this.safeFloat(ticker, 'c');
299
- const last = this.safeFloat(ticker, 'c');
300
- const change = this.safeFloat(ticker, 'pcp');
301
- const priceChange = this.safeFloat(ticker, 'pc');
302
- const baseVolume = this.safeFloat(ticker, 'v');
303
- const quoteVolume = this.safeFloat(ticker, 'qv');
304
- const datetime = this.safeString(ticker, 't');
305
- const bid = this.safeFloat(ticker, 'b', 0);
306
- const ask = this.safeFloat(ticker, 'a', 0);
307
- return this.safeTicker({
308
- 'symbol': symbol,
309
- 'timestamp': datetime,
310
- 'datetime': this.parse8601(datetime),
311
- 'high': high,
312
- 'low': low,
313
- 'bid': bid,
314
- 'bidVolume': undefined,
315
- 'ask': ask,
316
- 'askVolume': undefined,
317
- 'vwap': undefined,
318
- 'open': open,
319
- 'close': close,
320
- 'last': last,
321
- 'previousClose': undefined,
322
- 'change': priceChange,
323
- 'percentage': change,
324
- 'average': undefined,
325
- 'baseVolume': baseVolume,
326
- 'quoteVolume': quoteVolume,
327
- 'info': ticker,
328
- }, market);
329
- }
330
- async fetchOHLCV(symbol, timeframe = '1h', since = undefined, limit = undefined, params = {}) {
331
- /**
332
- * @method
333
- * @name toobit#fetchOHLCV
334
- * @description fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market
335
- * @see https://apidocs.toobit.io/#chart
336
- * @param {string} symbol unified symbol of the market to fetch OHLCV data for
337
- * @param {string} timeframe the length of time each candle represents
338
- * @param {int} [since] timestamp in ms of the earliest candle to fetch
339
- * @param {int} [limit] the maximum amount of candles to fetch
340
- * @param {object} [params] extra parameters specific to the exchange API endpoint
341
- * @returns {int[][]} A list of candles ordered as timestamp, open, high, low, close, volume
342
- */
343
- await this.loadMarkets();
344
- const market = this.market(symbol);
345
- const endTime = Date.now();
346
- const request = {
347
- 'symbol': market['id'],
348
- 'from': (endTime - (24 * 60 * 60 * 1000)),
349
- 'to': endTime,
350
- 'interval': this.safeString(this.timeframes, timeframe, timeframe),
351
- };
352
- if (since !== undefined) {
353
- request['from'] = since;
354
- }
355
- if (timeframe !== undefined) {
356
- request['interval'] = this.safeString(this.timeframes, timeframe, timeframe);
357
- }
358
- const response = await this.publicGetQuoteV1Klines(request);
359
- const ohlcvs = [];
360
- for (let i = 0; i < response.length; i++) {
361
- const candle = response[i];
362
- const ts = this.safeTimestamp(candle, 0);
363
- const open = this.safeFloat(candle, 1);
364
- const high = this.safeFloat(candle, 2);
365
- const low = this.safeFloat(candle, 3);
366
- const close = this.safeFloat(candle, 4);
367
- const volume = this.safeFloat(candle, 5);
368
- ohlcvs.push([
369
- ts,
370
- open,
371
- high,
372
- low,
373
- close,
374
- volume,
375
- ]);
376
- }
377
- return this.parseOHLCVs(ohlcvs, market, timeframe, since, limit);
378
- }
379
- sign(path, api = 'public', method = 'GET', params = {}, headers = undefined, body = undefined) {
380
- const query = this.omit(params, this.extractParams(path));
381
- let url = this.urls['api']['public'] + '/' + path;
382
- if (path === 'quote/v1/ticker/24hr') {
383
- url = url + '?' + this.urlencode(query);
384
- }
385
- if (path === 'quote/v1/klines') {
386
- url = url + '?' + this.urlencode(query);
387
- }
388
- headers = { 'Content-Type': 'application/json' };
389
- return { 'url': url, 'method': method, 'body': body, 'headers': headers };
390
- }
391
- }
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.safeNumber(filter, 'tickSize');
214
+ }
215
+ else if (filterType === 'LOT_SIZE') {
216
+ minQty = this.safeNumber(filter, 'minQty');
217
+ maxQty = this.safeNumber(filter, 'maxQty');
218
+ stepSize = this.safeNumber(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
+ }