ccxt-ir 4.9.14 → 4.9.15

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.
@@ -0,0 +1,334 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var tehran_exchange$1 = require('./abstract/tehran_exchange.js');
6
+
7
+ // ----------------------------------------------------------------------------
8
+ // ---------------------------------------------------------------------------
9
+ /**
10
+ * @class tehran_exchange
11
+ * @augments Exchange
12
+ * @description Set rateLimit to 1000 if fully verified
13
+ */
14
+ class tehran_exchange extends tehran_exchange$1["default"] {
15
+ describe() {
16
+ return this.deepExtend(super.describe(), {
17
+ 'id': 'tehran_exchange',
18
+ 'name': 'Tehran Exchange',
19
+ 'countries': ['IR'],
20
+ 'rateLimit': 1000,
21
+ 'version': '1',
22
+ 'certified': false,
23
+ 'pro': false,
24
+ 'has': {
25
+ 'CORS': undefined,
26
+ 'spot': true,
27
+ 'margin': false,
28
+ 'swap': false,
29
+ 'future': false,
30
+ 'option': false,
31
+ 'addMargin': false,
32
+ 'cancelAllOrders': false,
33
+ 'cancelOrder': false,
34
+ 'cancelOrders': false,
35
+ 'createDepositAddress': false,
36
+ 'createOrder': false,
37
+ 'createStopLimitOrder': false,
38
+ 'createStopMarketOrder': false,
39
+ 'createStopOrder': false,
40
+ 'editOrder': false,
41
+ 'fetchBalance': false,
42
+ 'fetchBorrowInterest': false,
43
+ 'fetchBorrowRateHistories': false,
44
+ 'fetchBorrowRateHistory': false,
45
+ 'fetchClosedOrders': false,
46
+ 'fetchCrossBorrowRate': false,
47
+ 'fetchCrossBorrowRates': false,
48
+ 'fetchCurrencies': false,
49
+ 'fetchDepositAddress': false,
50
+ 'fetchDeposits': false,
51
+ 'fetchFundingHistory': false,
52
+ 'fetchFundingRate': false,
53
+ 'fetchFundingRateHistory': false,
54
+ 'fetchFundingRates': false,
55
+ 'fetchIndexOHLCV': false,
56
+ 'fetchIsolatedBorrowRate': false,
57
+ 'fetchIsolatedBorrowRates': false,
58
+ 'fetchL2OrderBook': false,
59
+ 'fetchLedger': false,
60
+ 'fetchLedgerEntry': false,
61
+ 'fetchLeverageTiers': false,
62
+ 'fetchMarkets': true,
63
+ 'fetchMarkOHLCV': false,
64
+ 'fetchMyTrades': false,
65
+ 'fetchOHLCV': false,
66
+ 'fetchOpenInterestHistory': false,
67
+ 'fetchOpenOrders': false,
68
+ 'fetchOrder': false,
69
+ 'fetchOrderBook': false,
70
+ 'fetchOrders': false,
71
+ 'fetchOrderTrades': 'emulated',
72
+ 'fetchPositions': false,
73
+ 'fetchPremiumIndexOHLCV': false,
74
+ 'fetchTicker': true,
75
+ 'fetchTickers': true,
76
+ 'fetchTime': false,
77
+ 'fetchTrades': false,
78
+ 'fetchTradingFee': false,
79
+ 'fetchTradingFees': false,
80
+ 'fetchWithdrawals': false,
81
+ 'setLeverage': false,
82
+ 'setMarginMode': false,
83
+ 'transfer': false,
84
+ 'withdraw': false,
85
+ },
86
+ 'comment': 'This comment is optional',
87
+ 'urls': {
88
+ 'logo': 'https://cdn.arz.digital/cr-odin/img/exchanges/tehran_exchange/64x64.png',
89
+ 'api': {
90
+ 'public': 'https://otc-api.tehran.exchange',
91
+ },
92
+ 'www': 'https://tehran.exchange',
93
+ 'doc': [
94
+ 'https://tehran.exchange',
95
+ ],
96
+ },
97
+ 'api': {
98
+ 'public': {
99
+ 'get': {
100
+ 'otc/v1/market/pair': 1,
101
+ 'otc/v1/market/order/pair/price': 1,
102
+ },
103
+ },
104
+ },
105
+ 'fees': {
106
+ 'trading': {
107
+ 'tierBased': false,
108
+ 'percentage': true,
109
+ 'maker': this.parseNumber('0.0025'),
110
+ 'taker': this.parseNumber('0.0025'),
111
+ },
112
+ },
113
+ });
114
+ }
115
+ async fetchMarkets(params = {}) {
116
+ /**
117
+ * @method
118
+ * @name tehran_exchange#fetchMarkets
119
+ * @description retrieves data on all markets for tehran_exchange
120
+ * @see https://otc-api.tehran.exchange/otc/v1/market/pair
121
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
122
+ * @returns {object[]} an array of objects representing market data
123
+ */
124
+ const response = await this.publicGetOtcV1MarketPair(params);
125
+ const data = this.safeDict(response, 'data', {});
126
+ const pairs = this.safeList(data, 'pairs', []);
127
+ const result = [];
128
+ for (let i = 0; i < pairs.length; i++) {
129
+ const market = this.parseMarket(pairs[i]);
130
+ result.push(market);
131
+ }
132
+ return result;
133
+ }
134
+ parseMarket(market) {
135
+ // {
136
+ // "id": 6054,
137
+ // "pair": "HBAR_USDT",
138
+ // "status": "TRADABLE",
139
+ // "tradable": true,
140
+ // "fiatOrder": false,
141
+ // "quoteName": "Tether",
142
+ // "baseName": "Hedera",
143
+ // "quoteNameFa": "تتر",
144
+ // "baseNameFa": "هدرا هش گراف ",
145
+ // "quoteImageUrl": "https://s3-dev.tehranex.com/asset/coin_icon/64/usdt.png",
146
+ // "baseImageUrl": "https://s3-dev.tehranex.com/asset/coin_icon/64/hbar.png",
147
+ // "quoteSymbol": "USDT",
148
+ // "baseSymbol": "HBAR",
149
+ // "amountPrecision": 2,
150
+ // "feePercentage": 0.25,
151
+ // "providerFeePercentage": 0.05,
152
+ // "maxQuoteAmount": 600000,
153
+ // "minBaseAmount": 0.01,
154
+ // "minQuoteAmount": 1,
155
+ // "pricePrecision": 5,
156
+ // "baseVirtualCurrencyId": 989,
157
+ // "quoteVirtualCurrencyId": 1
158
+ // }
159
+ const id = this.safeString(market, 'pair');
160
+ const baseId = this.safeString(market, 'baseSymbol');
161
+ const quoteId = this.safeString(market, 'quoteSymbol');
162
+ const base = this.safeCurrencyCode(baseId);
163
+ const quote = this.safeCurrencyCode(quoteId);
164
+ const status = this.safeString(market, 'status');
165
+ const tradable = this.safeBool(market, 'tradable', false);
166
+ const active = (status === 'TRADABLE') && tradable;
167
+ const amountPrecision = this.safeInteger(market, 'amountPrecision');
168
+ const pricePrecision = this.safeInteger(market, 'pricePrecision');
169
+ const minBaseAmount = this.safeString(market, 'minBaseAmount');
170
+ const minQuoteAmount = this.safeString(market, 'minQuoteAmount');
171
+ const maxQuoteAmount = this.safeString(market, 'maxQuoteAmount');
172
+ return {
173
+ 'id': id,
174
+ 'symbol': base + '/' + quote,
175
+ 'base': base,
176
+ 'quote': quote,
177
+ 'settle': undefined,
178
+ 'baseId': baseId,
179
+ 'quoteId': quoteId,
180
+ 'settleId': undefined,
181
+ 'type': 'spot',
182
+ 'spot': true,
183
+ 'margin': false,
184
+ 'swap': false,
185
+ 'future': false,
186
+ 'option': false,
187
+ 'active': active,
188
+ 'contract': false,
189
+ 'linear': undefined,
190
+ 'inverse': undefined,
191
+ 'contractSize': undefined,
192
+ 'expiry': undefined,
193
+ 'expiryDatetime': undefined,
194
+ 'strike': undefined,
195
+ 'optionType': undefined,
196
+ 'precision': {
197
+ 'amount': amountPrecision,
198
+ 'price': pricePrecision,
199
+ },
200
+ 'limits': {
201
+ 'leverage': {
202
+ 'min': undefined,
203
+ 'max': undefined,
204
+ },
205
+ 'amount': {
206
+ 'min': this.parseNumber(minBaseAmount),
207
+ 'max': undefined,
208
+ },
209
+ 'price': {
210
+ 'min': undefined,
211
+ 'max': undefined,
212
+ },
213
+ 'cost': {
214
+ 'min': this.parseNumber(minQuoteAmount),
215
+ 'max': this.parseNumber(maxQuoteAmount),
216
+ },
217
+ },
218
+ 'created': undefined,
219
+ 'info': market,
220
+ };
221
+ }
222
+ async fetchTickers(symbols = undefined, params = {}) {
223
+ /**
224
+ * @method
225
+ * @name tehran_exchange#fetchTickers
226
+ * @description fetches price tickers for multiple markets, statistical information calculated over the past 24 hours for each market
227
+ * @see https://otc-api.tehran.exchange/otc/v1/market/pair
228
+ * @see https://otc-api.tehran.exchange/otc/v1/market/order/pair/price
229
+ * @param {string[]|undefined} symbols unified symbols of the markets to fetch the ticker for, all market tickers are returned if not assigned
230
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
231
+ * @returns {object} a dictionary of [ticker structures]{@link https://docs.ccxt.com/#/?id=ticker-structure}
232
+ */
233
+ await this.loadMarkets();
234
+ if (symbols !== undefined) {
235
+ symbols = this.marketSymbols(symbols);
236
+ }
237
+ const response = await this.publicGetOtcV1MarketPair(params);
238
+ const data = this.safeDict(response, 'data', {});
239
+ const pairs = this.safeList(data, 'pairs', []);
240
+ // filter symbols from pairs
241
+ const filteredPairs = [];
242
+ for (let i = 0; i < pairs.length; i++) {
243
+ const pair = pairs[i];
244
+ const pairId = this.safeString(pair, 'pair');
245
+ const symbol = this.safeSymbol(pairId);
246
+ if (symbols.includes(symbol)) {
247
+ filteredPairs.push(pair);
248
+ }
249
+ }
250
+ const result = {};
251
+ for (let i = 0; i < filteredPairs.length; i++) {
252
+ const pairData = filteredPairs[i];
253
+ const pairId = this.safeString(pairData, 'pair');
254
+ // Fetch BUY price
255
+ const request = {
256
+ 'pair': pairId,
257
+ 'side': 'BUY',
258
+ 'basedOn': 'BASE',
259
+ 'amount': 1,
260
+ };
261
+ const priceResponse = await this.publicGetOtcV1MarketOrderPairPrice(request);
262
+ const priceData = this.safeDict(priceResponse, 'data', {});
263
+ const price = this.safeFloat(priceData, 'price', 0);
264
+ pairData['price'] = price;
265
+ const ticker = this.parseTicker(pairData);
266
+ const symbol = ticker['symbol'];
267
+ result[symbol] = ticker;
268
+ }
269
+ return this.filterByArrayTickers(result, 'symbol', symbols);
270
+ }
271
+ async fetchTicker(symbol, params = {}) {
272
+ /**
273
+ * @method
274
+ * @name tehran_exchange#fetchTicker
275
+ * @description fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market
276
+ * @see https://otc-api.tehran.exchange/otc/v1/market/pair
277
+ * @param {string} symbol unified symbol of the market to fetch the ticker for
278
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
279
+ * @returns {object} a [ticker structure]{@link https://docs.ccxt.com/#/?id=ticker-structure}
280
+ */
281
+ const ticker = await this.fetchTickers([symbol]);
282
+ return ticker[this.safeSymbol(symbol)];
283
+ }
284
+ parseTicker(ticker, market = undefined) {
285
+ // {
286
+ // "id": 6054,
287
+ // "pair": "HBAR_USDT",
288
+ // "status": "TRADABLE",
289
+ // "tradable": true,
290
+ // "baseSymbol": "HBAR",
291
+ // "quoteSymbol": "USDT",
292
+ // ...
293
+ // "price": 12345,
294
+ // }
295
+ const marketType = 'spot';
296
+ const baseSymbol = this.safeString(ticker, 'baseSymbol');
297
+ const quoteSymbol = this.safeString(ticker, 'quoteSymbol');
298
+ const marketId = baseSymbol + '/' + quoteSymbol;
299
+ const symbol = this.safeSymbol(marketId, market, undefined, marketType);
300
+ const price = this.safeFloat(ticker, 'price');
301
+ return this.safeTicker({
302
+ 'symbol': symbol,
303
+ 'timestamp': undefined,
304
+ 'datetime': undefined,
305
+ 'high': undefined,
306
+ 'low': undefined,
307
+ 'bid': price,
308
+ 'bidVolume': undefined,
309
+ 'ask': price,
310
+ 'askVolume': undefined,
311
+ 'open': undefined,
312
+ 'close': price,
313
+ 'last': price,
314
+ 'previousClose': undefined,
315
+ 'change': undefined,
316
+ 'percentage': undefined,
317
+ 'average': undefined,
318
+ 'baseVolume': undefined,
319
+ 'quoteVolume': undefined,
320
+ 'info': ticker,
321
+ }, market);
322
+ }
323
+ sign(path, api = 'public', method = 'GET', params = {}, headers = undefined, body = undefined) {
324
+ const query = this.omit(params, this.extractParams(path));
325
+ let url = this.urls['api']['public'] + '/' + path;
326
+ if (Object.keys(query).length) {
327
+ url += '?' + this.urlencode(query);
328
+ }
329
+ headers = { 'Content-Type': 'application/json' };
330
+ return { 'url': url, 'method': method, 'body': body, 'headers': headers };
331
+ }
332
+ }
333
+
334
+ exports["default"] = tehran_exchange;