/ bot / prices.js
prices.js
 1  'use strict'
 2  
 3  const axios = require('axios')
 4  
 5  async function getGasPrice () {
 6    const response = await axios.get('https://ethgasstation.info/json/ethgasAPI.json')
 7    const gasPriceWei = Math.trunc(parseFloat(response.data.safeLowWait) * Math.pow(10, 10))
 8    return gasPriceWei
 9  }
10  
11  async function getTokenPrice (token) {
12    if (token === 'STT') {
13      return 1
14    }
15  
16    const currency = 'USD'
17    const response = await axios.get(`https://min-api.cryptocompare.com/data/price?fsym=${token}&tsyms=${currency}`)
18    const tokenPrice = parseFloat(response.data[currency])
19    return tokenPrice
20  }
21  
22  module.exports = {
23    getGasPrice: getGasPrice,
24    getTokenPrice: getTokenPrice
25  }