0% found this document useful (0 votes)
13 views1 page

Main Py

This document outlines a Python script that utilizes the Telegram API to create a bot that detects forex trading signals in messages. It uses regular expressions to identify 'BUY' or 'SELL' signals and sends them to a specified Telegram group while logging them to a file. The script initializes a Telegram client and bot, listens for new messages, and processes them accordingly.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views1 page

Main Py

This document outlines a Python script that utilizes the Telegram API to create a bot that detects forex trading signals in messages. It uses regular expressions to identify 'BUY' or 'SELL' signals and sends them to a specified Telegram group while logging them to a file. The script initializes a Telegram client and bot, listens for new messages, and processes them accordingly.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

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 = re.compile(r'(BUY|SELL)\s+[A-Z]{3}/[A-Z]{3}.*TP|SL',
re.IGNORECASE)

# --- LISTEN TO MESSAGES ---


@client.on(events.NewMessage(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:
file.write(message + '\n')

# --- START BOT ---


print("Bot is running and watching for signals...")
client.start()
client.run_until_disconnected()

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy