Getting signals from telegram channel and placing them in MT4 using Python

旧城冷巷雨未停 提交于 2021-01-25 07:09:51

问题


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()

来源:https://stackoverflow.com/questions/61552973/getting-signals-from-telegram-channel-and-placing-them-in-mt4-using-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!