Python Forum
Creating a TG crypto Bot_ problem when trying to with bot.polling
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Creating a TG crypto Bot_ problem when trying to with bot.polling
#1
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.
Reply
#2
Anyone ?!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  SHA256 ImportError when using Crypto.Hash in crypto.py andrewk 1 495 Feb-17-2025, 02:06 PM
Last Post: DeaD_EyE
  how to manage crypto trading flooding data from exchange servers Mikeardy 0 1,793 Dec-26-2021, 08:31 PM
Last Post: Mikeardy
  How to listen to clipboard content change without polling the clipboard continuously? edgelord 0 3,312 Nov-27-2020, 06:07 AM
Last Post: edgelord
  Problem creating an archive trojantrojan 3 2,930 May-10-2020, 01:32 AM
Last Post: trojantrojan
  Problem with using Crypto library reks2004 2 3,317 Mar-27-2020, 05:38 AM
Last Post: buran
  Python crypto byte plaintext to hexint Mangaz90 2 3,666 Feb-21-2020, 07:42 PM
Last Post: Mangaz90
  mouse 0.7.0 - mouse polling hate 125-1000hz penahuse 1 3,239 Dec-06-2019, 09:51 PM
Last Post: Larz60+
  Problem in creating a vector termo 11 5,660 Oct-10-2019, 03:09 PM
Last Post: stullis
  Create file archive that contains crypto hash ED209 1 2,710 May-29-2019, 03:05 AM
Last Post: heiner55
  crypto import issue saisankalpj 2 9,705 Dec-20-2018, 06:08 AM
Last Post: saisankalpj

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020