Skip to content
This repository has been archived by the owner on Jul 18, 2024. It is now read-only.

Commit

Permalink
Merge pull request #14 from Adamant-im/chore/addSourceKRW
Browse files Browse the repository at this point in the history
Add one more source with KRW
  • Loading branch information
confleux authored Nov 25, 2022
2 parents b7c934c + cf12346 commit 42fd998
Show file tree
Hide file tree
Showing 8 changed files with 6,747 additions and 24 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
node_modules/
logs/
.vscode/
.idea/
config.test
config.test2
package-lock.json
tests.js
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
ADAMANT InfoServices is a crypto and fiat currency rates service provider. It collects rates from MOEX, Currency-Api, Coinmarketcap, CryptoCompare and Coingecko and calculates cross-rates, and provides information via API.
ADAMANT InfoServices is a crypto and fiat currency rates service provider. It collects rates from MOEX, Currency-Api, ExchangeRate, Coinmarketcap, CryptoCompare and Coingecko and calculates cross-rates, and provides information via API.

Features:

- Collects rates from MOEX for fiat tickers
- Collects rates from Currency-Api for fiat tickers
- Collects rates from ExchangeRate (Currency-Api2) for fiat tickers
- Collects rates from Coinmarketcap for crypto tickers
- Collects rates from CryptoCompare for crypto tickers
- Collects rates from Coingecko for crypto tickers
Expand All @@ -21,8 +22,8 @@ Features:

## Requirements

- Ubuntu 18 / 20 (we didn't test with others)
- NodeJS v12+
- Ubuntu 18+ (we didn't test with others)
- NodeJS v16+
- MongoDB ([installation instructions](https://docs.mongodb.com/manual/tutorial/install-mongodb-on-ubuntu/))

## Setup
Expand Down
34 changes: 25 additions & 9 deletions app.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const Moex = require('./helpers/getMoex');
const CurrencyApi = require('./helpers/getCurrencyApi');
const CurrencyApi1 = require('./helpers/getCurrencyApi1');
const CurrencyApi2 = require('./helpers/getCurrencyApi2');
const Cmc = require('./helpers/getCmc');
const Cc = require('./helpers/getCc');
const Cg = require('./helpers/getCg');
Expand All @@ -20,9 +21,9 @@ function refresh() {
fetchedAll = true;
tickers = {};

CurrencyApi((data) => {
CurrencyApi1((data) => {
if (data) {
tickersInfo = mergeData({}, data, 'Null', 'CurrencyApi');
tickersInfo = mergeData({}, data, 'Null', 'CurrencyApi1');
if (tickersInfo.isAlert) {
notify(`Error: rates from different sources significantly differs: ${tickersInfo.alertString}. InfoService will provide previous rates; historical rates wouldn't be saved.`, 'error');
fetchedAll = false;
Expand All @@ -31,12 +32,27 @@ function refresh() {
}
} else {
fetchedAll = false;
notify(`Error: Unable to get data from CurrencyApi. InfoService will provide previous rates; historical rates wouldn't be saved.`, 'error');
notify(`Error: Unable to get data from CurrencyApi1. InfoService will provide previous rates; historical rates wouldn't be saved.`, 'error');
}

CurrencyApi2((data) => {
if (data) {
tickersInfo = mergeData({}, data, 'CurrencyApi1', 'CurrencyApi2');
if (tickersInfo.isAlert) {
notify(`Error: rates from different sources significantly differs: ${tickersInfo.alertString}. InfoService will provide previous rates; historical rates wouldn't be saved.`, 'error');
fetchedAll = false;
} else {
tickers = tickersInfo.merged;
}
} else {
fetchedAll = false;
notify(`Error: Unable to get data from CurrencyApi2. InfoService will provide previous rates; historical rates wouldn't be saved.`, 'error');
}
});

Cmc('USD', (data) => {
if (data) {
tickersInfo = mergeData(tickers, data, 'CurrencyApi', 'Cmc');
tickersInfo = mergeData(tickers, data, 'CurrencyApi1+CurrencyApi2', 'Cmc');
if (tickersInfo.isAlert) {
notify(`Error: rates from different sources significantly differs: ${tickersInfo.alertString}. InfoService will provide previous rates; historical rates wouldn't be saved.`, 'error');
fetchedAll = false;
Expand All @@ -50,7 +66,7 @@ function refresh() {

Moex((data) => {
if (data) {
tickersInfo = mergeData(tickers, data, 'CurrencyApi+Cmc', 'Moex');
tickersInfo = mergeData(tickers, data, 'CurrencyApi1+CurrencyApi2+Cmc', 'Moex');
if (tickersInfo.isAlert) {
notify(`Error: rates from different sources significantly differs: ${tickersInfo.alertString}. InfoService will provide previous rates; historical rates wouldn't be saved.`, 'error');
fetchedAll = false;
Expand All @@ -64,7 +80,7 @@ function refresh() {

Cc('USD', (data) => {
if (data) {
tickersInfo = mergeData(tickers, data, 'CurrencyApi+Cmc+Moex', 'Cc');
tickersInfo = mergeData(tickers, data, 'CurrencyApi1+CurrencyApi2+Cmc+Moex', 'Cc');
if (tickersInfo.isAlert) {
notify(`Error: rates from different sources significantly differs: ${tickersInfo.alertString}. InfoService will provide previous rates; historical rates wouldn't be saved.`, 'error');
fetchedAll = false;
Expand All @@ -78,7 +94,7 @@ function refresh() {

Cg('USD', (data) => {
if (data) {
tickersInfo = mergeData(tickers, data, 'CurrencyApi+Cmc+Moex+Cc', 'Cg');
tickersInfo = mergeData(tickers, data, 'CurrencyApi1+CurrencyApi2+Cmc+Moex+Cc', 'Cg');
if (tickersInfo.isAlert) {
notify(`Error: rates from different sources significantly differs: ${tickersInfo.alertString}. InfoService will provide previous rates; historical rates wouldn't be saved.`, 'error');
fetchedAll = false;
Expand All @@ -104,7 +120,7 @@ function refresh() {
}); // Cryptocompare
}); // Moex
}); // Coinmarketcap
}); // CurrencyApi
}); // CurrencyApi1

} // refresh

Expand Down
2 changes: 1 addition & 1 deletion config.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"crypto_cg": [],
"crypto_cg_coinids": ["bitcoin", "ethereum", "dash", "lisk", "dogecoin", "tether", "litecoin", "adamant-messenger",
"binancecoin", "ethereum-classic", "usd-coin", "true-usd", "stableusd", "resfinex-token"],
"baseCoins": ["USD", "RUB", "EUR", "CNY", "JPY", "BTC", "ETH"],
"baseCoins": ["USD", "RUB", "EUR", "CNY", "JPY", "BTC", "ETH", "KRW"],
"fiat": {
"USD/RUB": "USDRUB_TOM",
"EUR/RUB": "EURRUB_TOM",
Expand Down
2 changes: 1 addition & 1 deletion helpers/getCurrencyApi.js → helpers/getCurrencyApi1.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ module.exports = (cb) => {
rates[currency.toUpperCase() + '/USD'] = +(1 / +rate).toFixed(8);
}
});
log.log(`Cryptocurrency-Api rates updated successfully`);
log.log(`Currency-Api1 rates updated successfully`);
cb(rates);
} catch (e) {
notify(`Unable to process data ${JSON.stringify(response.data)} from request to ${url}. Error: ${e}`, 'error');
Expand Down
38 changes: 38 additions & 0 deletions helpers/getCurrencyApi2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
const axios = require('axios');
const config = require('./configReader');
const log = require('./log');
const notify = require('./notify');

// https://github.com/Formicka/exchangerate.host
const url = 'https://api.exchangerate.host/latest?base=USD';
// This service doesn't include crypto except Bitcoin
// Also, it sometimes provides chicken digits, like 47k usd for Bitcoin instead of 16k, and 73 rub/usd instead of 60
// Good we have built-in check system
const skipCoins = ['USD', 'ETH'];

module.exports = (cb) => {

axios.get(url)
.then(function(response) {
try {
const rates = {};
const data = response.data.rates;
config.baseCoins.forEach((currency) => {
const rate = data[currency.toUpperCase()];
if (!skipCoins.includes(currency) && rate) {
rates['USD/' + currency.toUpperCase()] = +rate.toFixed(8);
rates[currency.toUpperCase() + '/USD'] = +(1 / +rate).toFixed(8);
}
});
log.log(`Currency-Api2 rates updated successfully`);
cb(rates);
} catch (e) {
notify(`Unable to process data ${JSON.stringify(response.data)} from request to ${url}. Error: ${e}`, 'error');
cb(false);
}
})
.catch(function(error) {
notify(`Request to ${url} failed with ${error.response?.status} status code, ${error.toString()}${error.response?.data ? '. Message: ' + JSON.stringify(error.response.data) : ''}.`, 'error');
cb(false);
});
};
Loading

0 comments on commit 42fd998

Please sign in to comment.