AutoTrader icon indicating copy to clipboard operation
AutoTrader copied to clipboard

Telegram support for alerts to buy and signal

Open rahulmr opened this issue 2 years ago • 4 comments

Is your feature request related to a problem? Please describe. Email notifications are bit complicated to manage and Telegram is used worldwide

Describe the solution you'd like Along with Email, is it possible to send signals to Telegram?

Describe alternatives you've considered Need to implement forwarding of email signals to Telegram channel or coding for the same.

Additional context It will be great is Telegram Channel support is implemented. Adv:

  1. One can send Buy Sell signals along with SL and TARGET and even Quantity based on predefined risk.
  2. Not supported brokers can be handled using Telegram. Code is already there to read Telegram messages from channel suing python and trades can be taken using python.

rahulmr avatar Dec 15 '21 10:12 rahulmr

@rahulmr You could add that yourself quite easily, e.g. by

import telebot # or similar for linux ... bot = telebot.TeleBot(token=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx') # botname, chatId chatId = 12345678

.... in code example ... bot.send_message(text='{} LONG ENTRY SIGNAL: price={}'.format( instrument.symbol, price), chat_id=chatId)

Polypod avatar Apr 04 '22 18:04 Polypod

@rahulmr You could add that yourself quite easily, e.g. by

import telebot # or similar for linux ... bot = telebot.TeleBot(token=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx') # botname, chatId chatId = 12345678

.... in code example ... bot.send_message(text='{} LONG ENTRY SIGNAL: price={}'.format( instrument.symbol, price), chat_id=chatId)

Yes, I am aware of telebot and even a simple get request can be used to post messages to telegram, just wanted to inform the owner that this can be a good feature. @kieran-mackle can implement it in a better way. That was my thought behind opening this issue. If possible, can you suggest where this telebot code must be added?

rahulmr avatar Apr 04 '22 20:04 rahulmr

Thanks for bringing this to my attention, it is definitely a good feature to have. If I was to add this (which I may get around to soon), I would create a telegram module under autotrader.comms, mimicking similar functionality as the email module. The main functionality I would include is a template to send signals, orders and trades from autobot.py, as well as a method for users to send custom messages from their strategy, by importing the telegram comms module. Admittedly I haven't used telegram, but the snippet above from @Polypod looks like it would be a relatively straightforward and worthwhile addition.

kieran-mackle avatar Apr 09 '22 00:04 kieran-mackle

@kieran-mackle it is even simpler without using any extra python package, check below code.


import requests
from urllib.parse import urlencode, quote_plus


def telegram_bot_sendtext(message):
    bot_token = config.bot_token
    bot_chatID = '-100'+config.chatID_or_channel_id
    data = {
        'text': message,
        'chat_id': bot_chatID,
        'parse_mode': 'MARKDOWN'
    }
    encodedData = urlencode(data, quote_via=quote_plus)

    url = 'https://api.telegram.org/bot' + bot_token + '/sendMessage?' + encodedData
    response = requests.get(url)
    return response.json()

Might be helpful.

rahulmr avatar Apr 09 '22 21:04 rahulmr