2018-03-19 23:02:24 +01:00
|
|
|
'use strict'
|
2018-01-19 18:33:27 +01:00
|
|
|
|
2018-03-20 14:39:30 +01:00
|
|
|
const axios = require('axios')
|
|
|
|
|
2018-03-20 13:50:51 +01:00
|
|
|
async function getGasPrice () {
|
2018-03-20 14:39:30 +01:00
|
|
|
const response = await axios.get('https://ethgasstation.info/json/ethgasAPI.json')
|
|
|
|
const gasPriceWei = Math.trunc(parseFloat(response.data.safeLowWait) * Math.pow(10, 10))
|
|
|
|
return gasPriceWei
|
2018-03-19 22:37:38 +01:00
|
|
|
}
|
2018-01-19 18:33:27 +01:00
|
|
|
|
2018-03-20 13:50:51 +01:00
|
|
|
async function getTokenPrice (token) {
|
2018-03-20 09:55:07 +01:00
|
|
|
if (token === 'STT') {
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
2018-03-19 23:02:24 +01:00
|
|
|
const currency = 'USD'
|
2018-03-20 14:39:30 +01:00
|
|
|
const response = await axios.get(`https://min-api.cryptocompare.com/data/price?fsym=${token}&tsyms=${currency}`)
|
|
|
|
const tokenPrice = parseFloat(response.data[currency])
|
|
|
|
return tokenPrice
|
2018-01-19 18:33:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = {
|
2018-03-19 23:02:24 +01:00
|
|
|
getGasPrice: getGasPrice,
|
|
|
|
getTokenPrice: getTokenPrice
|
2018-01-19 18:33:27 +01:00
|
|
|
}
|