-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathindex.js
72 lines (66 loc) · 1.67 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
const ccxt = require("ccxt");
const pairs = [
"XRP/USD",
"DGB/USD",
"BCH/USD",
"ETH/USD",
"ALGO/USD",
"DOGE/USD",
"ADA/USD",
"BTC/USD",
"LTC/USD",
"XLM/USD",
"FIL/USD",
"SGB/USD",
];
const exchange_list = [
// "binance",
// // "binanceus",
// "bitfinex",
// "gemini",
"huobi",
// "bitstamp",
// "coinbasepro",
// "kraken",
// "gateio",
// "bittrex"
]
let exchanges = [];
const loadMarkets = async() => {
for (source of exchange_list) {
if (source == "kraken") {
exchanges[source] = new ccxt[source]({
apiKey: 'rK80EGv3jaBOI5pHIqvR5qESsngWGzi8LIagWLftyFVh6pHxNobyPdYJ',
secret: 'hjj6d42ZmeuNO6dZdNg5PaoSaZ7aFJZU7X4DlZvfcJ1ZZWQV0VyVA3mzCanksyoTjTROT0cwh3Em8fqmKI2gAw==',
});
}
else exchanges[source] = new ccxt[source]({ enableRateLimit: true });
await exchanges[source].loadMarkets();
console.log("--------- ", source, " ------------");
}
console.log(" *** All finished ***");
}
let prices = [];
const getPrices = async(source) => {
console.log(`Getting prices from *${source}*...`);
let ex = exchanges[source];
for (pair of pairs) {
const name = pair.slice(0, -4);
if (ex.currencies.hasOwnProperty(name)) {
if (source == "huobi" || source == "binance") pair += "T";
try {
const price = await ex.fetchTicker(pair);
console.log(source, " => ", name, ": ", price.last);
if (!prices[name]) prices[name] = [];
prices[name].push({source : price});
} catch (e) {}
}
else console.log(source, " => ", name, ": XXX");
}
}
(async() => {
await loadMarkets();
for await (source of exchange_list) {
await getPrices(source);
}
})();