Apr-24-2022, 04:30 AM
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:
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.
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.