python-telegram-bot / python-telegram-bot

We have made you a wrapper you can't refuse
https://python-telegram-bot.org
GNU General Public License v3.0
26.21k stars 5.32k forks source link

Telegram bot not responding #3859

Closed layalihamam closed 1 year ago

layalihamam commented 1 year ago

Issue I am facing

I wrote a python binance bot that is connected to a telegram bot I sent on telegram group a signal and the bot read it send it to my code and get the values and open with it orders and position in binance the binance code is working cause i already checked it before connecting it to my telegram i created "main.py" that provide the connection to the telegram bot and when i run it and send a signal nothing happen it's as i don't send anything anyone can help me resolve this issue? will add the code from my main.py of course the api and hash will be deleted here so i don't share sensitive information

Traceback to the issue

No response

Related part of your code

from classes import Bot
from threading import Thread
from telethon import TelegramClient, events

# Telegram client setup
TGRAM_API_ID = "12345678"
TGRAM_API_HASH = "asdfgh1234567890987654df"
TGRAM_CHAT_ID = -xxxxxxxx
TGRAM_BOT_TOKEN = "yyyyyyyy:AAAAAAAAAAAAAAA"

telegram_client = TelegramClient('anon', int(TGRAM_API_ID), TGRAM_API_HASH)

@telegram_client.on(events.NewMessage(chats=TGRAM_CHAT_ID))
async def handle_signal(event):
    msg = event.message.text.split('\n')  # Split the message into lines
    params = {}  # Initialize an empty dictionary to store the parsed parameters
    for line in msg:
        key, value = line.split(' - ')  # Split each line into key and value
        params[key] = value  # Store the key-value pair in the params dictionary

    bot_instance = Bot(
        symbol=params['symbol'],
        volume=float(params['volume']),
        no_of_decimals=3,  # Assuming this is a constant
        no_of_cycles=50,  # Assuming this is a constant
        initial_deviation=-0.05,  # Assuming this is a constant
        step=1.2,  # Assuming this is a constant
        no_of_safty_orders=7,  # Assuming this is a constant
        volume_multiplier=float(params['volume_multiplier']),
        direction=params['direction'],
        tp=float(params['tp']),
        sl=float(params['sl'])
    )

    # Run the bot in a separate thread
    t = Thread(target=bot_instance.run)
    t.start()

# Start the Telegram client
with telegram_client:
    telegram_client.run_until_disconnected()

Operating System

python

Version of Python, python-telegram-bot & dependencies

python 3.11 
python-telegram-bot 20.4
python-binance 1.0.19
layalihamam commented 1 year ago

thank you

for anyone having the same issue and seeing this , i changed @telegram_client.on(events.NewMessage(chats=TGRAM_CHAT_ID)) to: @telegram_client.on(events.NewMessage())