Hello Everyone,
In this video, we will try to go through revised implementation of Tradingview-Telegram-Bot which can be used to send alert messages from tradingview to telegram along with current chart snapshot.
🎲 Base
Initial version of the same idea are as below:
🎲 Prerequisite
Before proceeding with the current video, please watch the first video - which covers lots of basic things such as
- Creating Telegram Bot using botfather and capturing required information such as TOKEN and CHANNEL
- Basic usage of replit - a cloud based hosting service which lets us define our webhooks with little to no cost.
- Postman - tool which is required to test the webhooks created
- Other information such as keeping the bot alive via cronjob, using the webhooks in tradingview alert widget etc.
🎲 Setup
- Clone/fork replit repo
- Set mandatory environment variables CHANNEL and TOKEN
- Set optional environment variables username/password or sessionid
- Run the bot and start using webhooks
🎲 Usage
Webhook URL will be of the format.
https://Tradingview-Telegram-Bot.[YOUR_REPL_ACCOUNT].repl.co/webhook?[...query_parameters]
🎲 Important Query parameters
- jsonRequest - can be set as true/false. Default is false. If set to true, the payload should be a standard json. Output to telegram will be sent in tabular format. If not set or if set to false, output to telegram will be clear text.
- tblfmt - table format to be used when jsonRequest is set to true. Default is plain. The values are exactly same as the ones required for tabulate package.
- chart - Send the chart id if required to send chart snapshot along with alert message. For this to work - chart needs to be either a shared chart or environment variables for tvusername and tvpassword should be set to the user who has access to given chart.
- ticker - Chart ticker. You no longer need to use different chart for different tickers. You can have a common chart and pass ticker to it so that chart will automatically switch to given ticker before taking screenshot
- delivery - Taking chart snapshot takes time. This also delays the delivery of alert message. To avoid this, we can use this option - delivery=asap so that alert message will be sent as soon as possible and chart is sent later. If this parameter is not set, then both the messages will be delivered together.
🎲 Repository URLs
Tradingview-Telegram-Bot-Github
Tradingview-Telegram-Bot-Replit
when i send text webhook
[I] Chart : None
[I] Ticker : NONE
[I] Payload:
b'TEST MESSAGE'
--->Sending message to telegram
[X] Telegram Error:
> reject_bytes is on and 'TEST MESSAGE' is bytes
somehow i fixed this error with this code
import os
from telegram import Bot
def sendMessage(data):
tg_bot = Bot(token=os.environ['TOKEN'])
channel = os.environ['CHANNEL']
try:
print('--->Sending message to telegram')
tg_bot.sendMessage(
channel,
data,
parse_mode="MARKDOWN",
)
return True
except KeyError:
print('--->Key error - sending error to telegram')
tg_bot.sendMessage(
channel,
data,
parse_mode="MARKDOWN",
)
except Exception as e:
print("[X] Telegram Error:\n>", e)
return False
But it is also not sending image screenshot and giving following error
172.31.196.1 - - [10/Jul/2023 22:30:48] "POST /webhook?jsonRequest=true&tblfmt=fancy_grid&chart=xXna1Emw&ticker=AAPL&delivery=asap HTTP/1.1" 200 -
Exception in thread Thread-3:
Traceback (most recent call last):
File "/home/runner/ttstradingsignalswebhookbot/venv/lib/python3.8/site-packages/selenium/webdriver/common/service.py", line 71, in start
self.process = subprocess.Popen(cmd, env=self.env,
File "/nix/store/2vm88xw7513h9pyjyafw32cps51b0ia1-python3-3.8.12/lib/python3.8/subprocess.py", line 858, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "/nix/store/2vm88xw7513h9pyjyafw32cps51b0ia1-python3-3.8.12/lib/python3.8/subprocess.py", line 1704, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'chromedriver'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/nix/store/2vm88xw7513h9pyjyafw32cps51b0ia1-python3-3.8.12/lib/python3.8/threading.py", line 932, in _bootstrap_inner
self.run()
File "/nix/store/2vm88xw7513h9pyjyafw32cps51b0ia1-python3-3.8.12/lib/python3.8/threading.py", line 870, in run
self._target(*self._args, **self._kwargs)
File "/home/runner/ttstradingsignalswebhookbot/captureutil.py", line 62, in send_chart
driver = setup()
File "/home/runner/ttstradingsignalswebhookbot/captureutil.py", line 25, in setup
driver = webdriver.Chrome(options=chrome_options,
File "/home/runner/ttstradingsignalswebhookbot/venv/lib/python3.8/site-packages/selenium/webdriver/chrome/webdriver.py", line 70, in __init__
super(WebDriver, self).__init__(DesiredCapabilities.CHROME['browserName'], "goog",
File "/home/runner/ttstradingsignalswebhookbot/venv/lib/python3.8/site-packages/selenium/webdriver/chromium/webdriver.py", line 90, in __init__
self.s