ccxt-ir 4.18.1 → 4.19.0
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/README.md +4 -4
- package/dist/ccxt.browser.min.js +3 -3
- package/dist/cjs/ccxt.js +4 -1
- package/dist/cjs/package.json +1 -1
- package/dist/cjs/src/daric.js +1 -1
- package/dist/cjs/src/digikalagold.js +2 -2
- package/dist/cjs/src/melligold.js +5 -2
- package/dist/cjs/src/zarniv.js +2 -2
- package/dist/cjs/src/zarpin.js +185 -0
- package/js/ccxt.d.ts +5 -2
- package/js/ccxt.js +4 -2
- package/js/src/abstract/zarpin.d.ts +8 -0
- package/js/src/abstract/zarpin.js +11 -0
- package/js/src/daric.js +1 -1
- package/js/src/digikalagold.js +2 -2
- package/js/src/melligold.js +5 -2
- package/js/src/zarniv.js +2 -2
- package/js/src/zarpin.d.ts +21 -0
- package/js/src/zarpin.js +184 -0
- package/js/test.js +19 -53
- package/package.json +1 -1
package/js/src/zarpin.js
ADDED
|
@@ -0,0 +1,184 @@
|
|
|
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 Exchange from './base/Exchange.js';
|
|
9
|
+
// ---------------------------------------------------------------------------
|
|
10
|
+
/**
|
|
11
|
+
* @class zarpin
|
|
12
|
+
* @augments Exchange
|
|
13
|
+
*/
|
|
14
|
+
export default class zarpin extends Exchange {
|
|
15
|
+
describe() {
|
|
16
|
+
return this.deepExtend(super.describe(), {
|
|
17
|
+
'id': 'zarpin',
|
|
18
|
+
'name': 'Zarpin',
|
|
19
|
+
'countries': ['IR'],
|
|
20
|
+
'rateLimit': 1000,
|
|
21
|
+
'version': 'v1',
|
|
22
|
+
'certified': false,
|
|
23
|
+
'pro': false,
|
|
24
|
+
'has': {
|
|
25
|
+
'CORS': undefined,
|
|
26
|
+
'spot': false,
|
|
27
|
+
'margin': false,
|
|
28
|
+
'swap': false,
|
|
29
|
+
'future': false,
|
|
30
|
+
'option': false,
|
|
31
|
+
'fetchMarkets': true,
|
|
32
|
+
'fetchTicker': true,
|
|
33
|
+
'fetchTickers': true,
|
|
34
|
+
'otc': true,
|
|
35
|
+
},
|
|
36
|
+
'options': {
|
|
37
|
+
'defaultType': 'otc',
|
|
38
|
+
},
|
|
39
|
+
'urls': {
|
|
40
|
+
'api': {
|
|
41
|
+
'public': 'https://api-khazaneh.zarpin.com',
|
|
42
|
+
},
|
|
43
|
+
'www': 'https://zarpin.com',
|
|
44
|
+
'doc': 'https://api-khazaneh.zarpin.com/v1/prc/prices',
|
|
45
|
+
},
|
|
46
|
+
'api': {
|
|
47
|
+
'public': {
|
|
48
|
+
'get': {
|
|
49
|
+
'v1/prc/prices': 1,
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
async fetchMarkets(params = {}) {
|
|
56
|
+
const response = await this.publicGetV1PrcPrices(params);
|
|
57
|
+
return this.parseMarkets(response);
|
|
58
|
+
}
|
|
59
|
+
parseMarkets(response) {
|
|
60
|
+
let prices = [];
|
|
61
|
+
if (Array.isArray(response)) {
|
|
62
|
+
prices = response;
|
|
63
|
+
}
|
|
64
|
+
const result = [];
|
|
65
|
+
for (let i = 0; i < prices.length; i++) {
|
|
66
|
+
const price = prices[i];
|
|
67
|
+
const code = this.safeString(price, 'code');
|
|
68
|
+
if (code === 'GOLD_IRT' || code === 'SILVER_IRT') {
|
|
69
|
+
result.push(this.parseMarket(price));
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return result;
|
|
73
|
+
}
|
|
74
|
+
parseMarket(market) {
|
|
75
|
+
const code = this.safeString(market, 'code');
|
|
76
|
+
let base = 'XAG-1G';
|
|
77
|
+
if (code === 'GOLD_IRT') {
|
|
78
|
+
base = 'XAU18';
|
|
79
|
+
}
|
|
80
|
+
const quote = 'IRT';
|
|
81
|
+
return {
|
|
82
|
+
'id': code,
|
|
83
|
+
'symbol': base + '/' + quote,
|
|
84
|
+
'base': base,
|
|
85
|
+
'quote': quote,
|
|
86
|
+
'settle': undefined,
|
|
87
|
+
'baseId': code,
|
|
88
|
+
'quoteId': quote,
|
|
89
|
+
'settleId': undefined,
|
|
90
|
+
'type': 'otc',
|
|
91
|
+
'spot': false,
|
|
92
|
+
'margin': false,
|
|
93
|
+
'swap': false,
|
|
94
|
+
'future': false,
|
|
95
|
+
'option': false,
|
|
96
|
+
'active': this.safeNumber(market, 'price') !== undefined,
|
|
97
|
+
'contract': false,
|
|
98
|
+
'linear': undefined,
|
|
99
|
+
'inverse': undefined,
|
|
100
|
+
'contractSize': undefined,
|
|
101
|
+
'expiry': undefined,
|
|
102
|
+
'expiryDatetime': undefined,
|
|
103
|
+
'strike': undefined,
|
|
104
|
+
'optionType': undefined,
|
|
105
|
+
'precision': {
|
|
106
|
+
'amount': undefined,
|
|
107
|
+
'price': undefined,
|
|
108
|
+
},
|
|
109
|
+
'limits': {
|
|
110
|
+
'leverage': { 'min': undefined, 'max': undefined },
|
|
111
|
+
'amount': { 'min': undefined, 'max': undefined },
|
|
112
|
+
'price': { 'min': undefined, 'max': undefined },
|
|
113
|
+
'cost': { 'min': undefined, 'max': undefined },
|
|
114
|
+
},
|
|
115
|
+
'created': undefined,
|
|
116
|
+
'info': market,
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
async fetchTicker(symbol, params = {}) {
|
|
120
|
+
await this.loadMarkets();
|
|
121
|
+
const market = this.market(symbol);
|
|
122
|
+
const response = await this.publicGetV1PrcPrices(params);
|
|
123
|
+
return this.parseTicker(response, market);
|
|
124
|
+
}
|
|
125
|
+
async fetchTickers(symbols = undefined, params = {}) {
|
|
126
|
+
await this.loadMarkets();
|
|
127
|
+
if (symbols !== undefined) {
|
|
128
|
+
symbols = this.marketSymbols(symbols);
|
|
129
|
+
}
|
|
130
|
+
const response = await this.publicGetV1PrcPrices(params);
|
|
131
|
+
const markets = this.parseMarkets(response);
|
|
132
|
+
const result = {};
|
|
133
|
+
for (let i = 0; i < markets.length; i++) {
|
|
134
|
+
const ticker = this.parseTicker(response, markets[i]);
|
|
135
|
+
result[ticker['symbol']] = ticker;
|
|
136
|
+
}
|
|
137
|
+
return this.filterByArrayTickers(result, 'symbol', symbols);
|
|
138
|
+
}
|
|
139
|
+
parseTicker(response, market = undefined) {
|
|
140
|
+
let prices = [];
|
|
141
|
+
if (Array.isArray(response)) {
|
|
142
|
+
prices = response;
|
|
143
|
+
}
|
|
144
|
+
let price = {};
|
|
145
|
+
for (let i = 0; i < prices.length; i++) {
|
|
146
|
+
const entry = prices[i];
|
|
147
|
+
if (this.safeString(entry, 'code') === market['baseId']) {
|
|
148
|
+
price = entry;
|
|
149
|
+
break;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
return this.safeTicker({
|
|
153
|
+
'symbol': market['symbol'],
|
|
154
|
+
'timestamp': undefined,
|
|
155
|
+
'datetime': undefined,
|
|
156
|
+
'high': this.safeNumber(price, 'max_24h_price'),
|
|
157
|
+
'low': this.safeNumber(price, 'min_24h_price'),
|
|
158
|
+
'bid': this.safeNumber(price, 'price'),
|
|
159
|
+
'bidVolume': undefined,
|
|
160
|
+
'ask': this.safeNumber(price, 'price'),
|
|
161
|
+
'askVolume': undefined,
|
|
162
|
+
'vwap': undefined,
|
|
163
|
+
'open': this.safeNumber(price, 'price_at_in_last_24h'),
|
|
164
|
+
'close': this.safeNumber(price, 'price'),
|
|
165
|
+
'last': this.safeNumber(price, 'price'),
|
|
166
|
+
'previousClose': this.safeNumber(price, 'price_at_in_last_24h'),
|
|
167
|
+
'change': undefined,
|
|
168
|
+
'percentage': this.safeNumber(price, 'price_change_24h'),
|
|
169
|
+
'average': undefined,
|
|
170
|
+
'baseVolume': undefined,
|
|
171
|
+
'quoteVolume': undefined,
|
|
172
|
+
'info': price,
|
|
173
|
+
}, market);
|
|
174
|
+
}
|
|
175
|
+
sign(path, api = 'public', method = 'GET', params = {}, headers = undefined, body = undefined) {
|
|
176
|
+
let url = this.urls['api'][api] + '/' + this.implodeParams(path, params);
|
|
177
|
+
const query = this.omit(params, this.extractParams(path));
|
|
178
|
+
if (Object.keys(query).length) {
|
|
179
|
+
url += '?' + this.urlencode(query);
|
|
180
|
+
}
|
|
181
|
+
headers = { 'Accept': 'application/json' };
|
|
182
|
+
return { 'url': url, 'method': method, 'body': body, 'headers': headers };
|
|
183
|
+
}
|
|
184
|
+
}
|
package/js/test.js
CHANGED
|
@@ -4,64 +4,30 @@
|
|
|
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
|
-
import
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
{ id: 'talasea', create: () => new talasea({ enableRateLimit: true, timeout: 30000 }) },
|
|
14
|
-
{ id: 'melligold', create: () => new melligold({ enableRateLimit: true, timeout: 30000 }) },
|
|
15
|
-
{ id: 'technogold', create: () => new technogold({ enableRateLimit: true, timeout: 30000 }) },
|
|
16
|
-
{ id: 'wallgold', create: () => new wallgold({ enableRateLimit: true, timeout: 30000 }) },
|
|
17
|
-
{ id: 'milligold', create: () => new milligold({ enableRateLimit: true, timeout: 30000 }) },
|
|
18
|
-
];
|
|
19
|
-
async function testExchange(id, create) {
|
|
20
|
-
const exchange = create();
|
|
7
|
+
import zarpin from './src/zarpin.js';
|
|
8
|
+
async function main() {
|
|
9
|
+
const exchange = new zarpin({
|
|
10
|
+
'enableRateLimit': true,
|
|
11
|
+
'timeout': 20000,
|
|
12
|
+
});
|
|
21
13
|
try {
|
|
22
|
-
const
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
const symbol = symbols[0];
|
|
28
|
-
const ticker = await exchange.fetchTicker(symbol, { 'type': 'otc' });
|
|
29
|
-
const tickers = await exchange.fetchTickers(symbols, { 'type': 'otc' });
|
|
30
|
-
if (ticker['symbol'] !== symbol) {
|
|
31
|
-
throw new Error(`fetchTicker returned ${ticker['symbol']} instead of ${symbol}`);
|
|
14
|
+
const tickers = await exchange.fetchTickers();
|
|
15
|
+
const gold = tickers['XAU18/IRT'];
|
|
16
|
+
const silver = tickers['XAG-1G/IRT'];
|
|
17
|
+
if (gold === undefined || gold.last === undefined) {
|
|
18
|
+
throw new Error('XAU18/IRT has no valid last price');
|
|
32
19
|
}
|
|
33
|
-
if (
|
|
34
|
-
throw new Error(
|
|
20
|
+
if (silver === undefined || silver.last === undefined) {
|
|
21
|
+
throw new Error('XAG-1G/IRT has no valid last price');
|
|
35
22
|
}
|
|
36
|
-
console.log(
|
|
37
|
-
|
|
38
|
-
ticker: {
|
|
39
|
-
symbol: ticker['symbol'],
|
|
40
|
-
bid: ticker['bid'],
|
|
41
|
-
ask: ticker['ask'],
|
|
42
|
-
last: ticker['last'],
|
|
43
|
-
timestamp: ticker['timestamp'],
|
|
44
|
-
},
|
|
45
|
-
});
|
|
23
|
+
console.log('Zarpin gold last price: ' + gold.last + ' IRT');
|
|
24
|
+
console.log('Zarpin silver last price: ' + silver.last + ' IRT');
|
|
46
25
|
}
|
|
47
26
|
finally {
|
|
48
27
|
await exchange.close();
|
|
49
28
|
}
|
|
50
29
|
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
try {
|
|
56
|
-
await testExchange(exchange.id, exchange.create);
|
|
57
|
-
}
|
|
58
|
-
catch (error) {
|
|
59
|
-
failed = true;
|
|
60
|
-
console.error(`${exchange.id} test failed:`, error);
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
if (failed) {
|
|
64
|
-
process.exitCode = 1;
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
void main();
|
|
30
|
+
main().catch((error) => {
|
|
31
|
+
console.error('Zarpin ticker test failed:', error);
|
|
32
|
+
process.exitCode = 1;
|
|
33
|
+
});
|
package/package.json
CHANGED