This repository has been archived by the owner on Jul 18, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from Adamant-im/chore/addSourceKRW
Add one more source with KRW
- Loading branch information
Showing
8 changed files
with
6,747 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}; |
Oops, something went wrong.