Python Forum
Creating a TG crypto Bot_ problem when trying to with bot.polling - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Creating a TG crypto Bot_ problem when trying to with bot.polling (/thread-37023.html)



Creating a TG crypto Bot_ problem when trying to with bot.polling - p1ner0 - Apr-24-2022

Hi there, I have a problem, I have made a telegram bot, which gets input from telgegram(namely the crypto coin name) and then using the CoinGecko API, it sends the price of that coin on telegram, here is my code:

import environs
from pycoingecko import CoinGeckoAPI
from telebot import TeleBot

env = environs.Env()
env.read_env('.env')

BOT_TOKEN = env('API_KEY')

bot = TeleBot(token=BOT_TOKEN)
coin_client = CoinGeckoAPI()


### print(coin_client.get_price(ids="bone-shibaswap", vs_currencies='usd')['bone-shibaswap']['usd'])


@bot.message_handler(content_types=['text'])
def crypto_price_message_handler(message):
    crypto_id = message.text
    price = coin_client.get_price(ids=crypto_id, vs_currencies='usd')[crypto_id]['usd']

    bot.send_message(chat_id=message.chat.id, text=f"Price of {crypto_id}: {price}$")


bot.polling(none_stop=True, )
I tried bot.infinity_polling() :(

What I want to achieve is that, for ex. if in the TG bot, I enter bitcoin, it replies me with price, but I want the price to autopost constanstly as the price changes.
Again the data of the prices is from Coingecko API.

So far so good, If anyone could help me with the issue I would really apreaciate it.

Best regards.


RE: Creating a TG crypto Bot_ problem when trying to with bot.polling - p1ner0 - Apr-27-2022

Anyone ?!