from telegram import Bot
from telethon import TelegramClient, events
import re
# --- CONFIGURATION ---
api_id = 12345678 # Replace with your actual Telegram API ID
api_hash = 'your_api_hash_here' # Replace with your API hash
bot_token = 'your_bot_token_here' # Replace with your bot token
chat_id = -1001234567890 # Replace with your group's chat ID (starts with -100)
# --- INIT TELEGRAM BOT & CLIENT ---
bot = Bot(token=bot_token)
client = TelegramClient('session_name', api_id, api_hash)
# --- REGEX FOR FOREX SIGNAL DETECTION ---
signal_pattern = [Link](r'(BUY|SELL)\s+[A-Z]{3}/[A-Z]{3}.*TP|SL',
[Link])
# --- LISTEN TO MESSAGES ---
@[Link]([Link](chats=chat_id))
async def handler(event):
message = event.raw_text
if signal_pattern.search(message):
print("Signal detected:", message)
# Send signal to Telegram group
bot.send_message(chat_id=chat_id, text=f"**Signal detected:**\n{message}",
parse_mode='Markdown')
# Save signal to a file
with open('signals_log.txt', 'a') as file:
[Link](message + '\n')
# --- START BOT ---
print("Bot is running and watching for signals...")
[Link]()
client.run_until_disconnected()