I would like to read messages from a Telegram channel (which are essential forex signals) and place the orders in MT4 windows application. For now, I have made a python script which listens to the channels and stores messages in a database. I can also parse the messages for necessary values like TP,SL etc. Now, that I have those signals, how can I place them?
I read in others answers about ZeroMQ and Python binding but I don’t need to do any analysis or strategy building, I just want to place an order. I saw a video in which he placed a csv file in the MQL4/Files folder and the order was placed but I am not sure how the csv was formatted.
This is my python code for reading telegram messages if anyone needs it. Thanks in advance
import configparser
import json
from telethon import TelegramClient, events
from telethon.errors import SessionPasswordNeededError
from telethon.tl.functions.channels import GetParticipantsRequest
from telethon.tl.types import ChannelParticipantsSearch
from telethon.tl.types import PeerChannel
from telethon.tl.functions.messages import (GetHistoryRequest)
my_channel = "<channel_url>"
# Reading Configs
config = configparser.ConfigParser()
config.read("config.ini")
# Setting configuration values
api_id = config['Telegram']['api_id']
api_hash = config['Telegram']['api_hash']
api_hash = str(api_hash)
phone = config['Telegram']['phone']
username = config['Telegram']['username']
client = TelegramClient(username, api_id, api_hash)
# async def main():
# me = await client.get_me()
# print(me.stringify())
# async for message in client.iter_messages('Hanil02'):
# print(message.id, message.text)
# with client:
# client.loop.run_until_complete(main())
@client.on(events.NewMessage)
async def my_event_handler(event):
chat = await event.get_chat()
sender = await event.get_sender()
chat_id = event.chat_id
sender_id = event.sender.id
text = event.raw_text
# print(sender.id)
if sender_id == 1386059246:
print(event.raw_text)
client.start()
client.run_until_disconnected()
2
Answers
the code posted by Nematillo Ochilov is a piece of art!
i have replaced:
has to be