price token telegram bot on python

Viewed 156

I've a question about crypto price in my telegram bot with coinmarketcap API

the bot works fine, but the price has too many zeros on telegram: coin=[7.68321846e-06]$ and real price is 0.00000768$

How I can modify this one? Thanks in advance!

# global variables
api_key = '-----'
bot_token = '----'
chat_id = '-----'
market_symbol = 'coin'
currency_iso = 'USD'
time_interval = 5 * 60 # in seconds
def get_coin_price():
    url = 'https://pro-api.coinmarketcap.com/v1/cryptocurrency/quotes/latest'
    query = '?symbol=' + market_symbol + '&convert=' + currency_iso
    headers = {
        'Accepts': 'application/json',
        'X-CMC_PRO_API_KEY': api_key
    }


    # make a request to the coinmarketcap api
    response = requests.get(url + query, headers=headers)
    response_json = response.json()

# extract the coin price from the json data
    coin_price = response_json['data'][market_symbol]

    return coin_price['quote'][currency_iso]['price']
# fn to send_message through telegram
def send_message(chat_id, msg):
    url = f"https://api.telegram.org/bot{bot_token}/sendMessage?chat_id={chat_id}&text=coin={msg}$"
0 Answers
Related