In our current times staying on top of the latest signals can be challenging. Especially if the screeners are not automated to provide the most up-to-date information on the latest signals. That's why tying a screener to telegram can make one aware of a lot of opportunities. It can notify you when a new signal is found (and we all get the dopamine hit when a new notification arrives on our smartphones). You can also share this screener with people for fun (and of course profit).
To be able to follow along you
- know you way around Python
- have a Telegram account
- have a screener, that outputs a
string
when it finds a new signal
Although there are many excellent solutions to sending your signals over to telegram I preffer to use pyTelegramBotAPI
- you just need a token and you are off to the races.
import telebot
bot = telebot.TeleBot("TOKEN", parse_mode=None)
In order to get your telegram token you need to go through a couple of steps:
- Open Telegram and find @botfarther
- [Optional] To see all available commands type
/help
- To create a new bot just write
/newbot
- Go through the prompts from botfather
- At the end it will give you your API key.
- Login with a browser version of telegram: https://web.telegram.org/
- Click on your channel.
- At the end of your current url after the
#
should be your channel id. It always starts with a minus.
import telebot
def run_screener() -> str:
'''
This is where you would develop your screener.
It is important to note - you should return a string.
'''
return "I generated a new signal!"
TOKEN = "<YOUR-TOKEN-HERE>"
CHANNEL = "<YOUR-CHANNEL-ID-HERE>"
tb = telebot.TeleBot(TOKEN, parse_mode=None)
msg = run_screener()
tb.send_message(CHANNEL, msg)
However do note that this bot is only sending messages to a telegram channel and does not respond to any messages, targeted at it. But for our use case, this is plenty.
As shown above, to send a single message its quite simple. A way to automate it is to host that script and run it on a schedule using crontab
- good article on it.
Another way to automate it, within python is to use a libary to automate this process. I used schedule.
Something to take into an account is that you need to wrap all of your code into a single function. A simple refactor you could do is shown below.
import telebot
TOKEN = "<YOUR-TOKEN-HERE>"
CHANNEL = "<YOUR-CHANNEL-ID-HERE>"
tb = telebot.TeleBot(TOKEN, parse_mode=None)
def run_screener() -> str:
'''
This is where you would develop your screener.
It is important to note - you should return a string.
'''
return "I generated a new signal!"
def send_telegram_signals() -> None:
msg = run_screener()
tb.send_message(CHANNEL, msg)
Lets assume you want to send a message every hour, exactly at 00.
import schedule
schedule.every().hour.at("00").do(send_telegram_signals)
Easy enough.
import telebot
import schedule
TOKEN = "<YOUR-TOKEN-HERE>"
CHANNEL = "<YOUR-CHANNEL-ID-HERE>"
tb = telebot.TeleBot(TOKEN, parse_mode=None)
def run_screener() -> str:
'''
This is where you would develop your screener.
It is important to note - you should return a string.
'''
return "I generated a new signal!"
def send_telegram_signals() -> None:
msg = run_screener()
tb.send_message(CHANNEL, msg)
if __name__ == '__main__':
schedule.every().hour.at("00").do(send_telegram_signals)
In this article I showcased how easy it is to send your screener notifications and signals over to telegram and run it on a schedule. That's all there is to it.
If you have any questions, suggestions or thoughts, always feel free to share them with me! And if you like to see more how-tos on deploying your screeners and strategies, make sure to follow me and receive the most recent updates.