kopia lustrzana https://github.com/fabston/TradingView-Webhook-Bot
Added email support
rodzic
1d6a278f87
commit
6b0e1d932a
|
@ -3,7 +3,7 @@
|
|||

|
||||

|
||||
|
||||
This bot listens to [TradingView](https://tradingview.com) alerts via webhooks and sends them instantly to Telegram and/or Discord.
|
||||
This bot listens to [TradingView](https://tradingview.com) alerts via webhooks and sends them instantly to Telegram, Discord and/or Email.
|
||||
|
||||
## Usage
|
||||
1. Clone this repository `git clone https://github.com/fabcx/TradingView-Webhook-Bot.git`
|
||||
|
|
15
config.py
15
config.py
|
@ -1,12 +1,23 @@
|
|||
# Alert message in TradingView ex. https://i.imgur.com/RFkuf1d.png
|
||||
# Alert message in TradingView (ex. https://i.imgur.com/RFkuf1d.png)
|
||||
Buy_Alert = 'Buy Alert!'
|
||||
Sell_Alert = 'Sell Alert!'
|
||||
|
||||
# Telegram Settings
|
||||
send_telegram_alerts = True
|
||||
tg_token = '' # Bot token. Get it from @Botfather
|
||||
channel = # Channel ID ex. -1001487568087
|
||||
channel = # Channel ID (ex. -1001487568087)
|
||||
|
||||
# Discord Settings
|
||||
send_discord_alerts = True
|
||||
discord_webhook = '' # Discord Webhook URL (https://support.discordapp.com/hc/de/articles/228383668-Webhooks-verwenden)
|
||||
|
||||
# Email Settings
|
||||
send_email_alerts = False
|
||||
email_sender = '' # Your email address
|
||||
email_receivers = ['', ''] # Receivers, can be multiple
|
||||
email_subject = 'Trade Alert!'
|
||||
|
||||
email_port = 465 # SMTP SSL Port (ex. 465)
|
||||
email_host = '' # SMTP host (ex. smtp.gmail.com)
|
||||
email_user = '' # SMTP Login credentials
|
||||
email_password = '' # SMTP Login credentials
|
34
handler.py
34
handler.py
|
@ -1,11 +1,15 @@
|
|||
import config as config
|
||||
from telegram import Bot
|
||||
from discord_webhook import DiscordWebhook
|
||||
|
||||
tg_bot = Bot(token=config.tg_token)
|
||||
import smtplib, ssl
|
||||
from email.mime.text import MIMEText
|
||||
|
||||
telegram = config.send_telegram_alerts
|
||||
discord = config.send_discord_alerts
|
||||
email = config.send_email_alerts
|
||||
|
||||
if telegram:
|
||||
tg_bot = Bot(token=config.tg_token)
|
||||
|
||||
def send_buy_order(data):
|
||||
if telegram:
|
||||
|
@ -19,6 +23,19 @@ def send_buy_order(data):
|
|||
print('Alert has been sent to Discord.')
|
||||
else:
|
||||
print('INFO: Discord alerts are disabled.')
|
||||
if email:
|
||||
email_msg = MIMEText(data)
|
||||
email_msg['Subject'] = config.email_subject
|
||||
email_msg['From'] = config.email_sender
|
||||
email_msg['To'] = config.email_sender
|
||||
context = ssl.create_default_context()
|
||||
with smtplib.SMTP_SSL(config.email_host, config.email_port, context=context) as server:
|
||||
server.login(config.email_user, config.email_password)
|
||||
server.sendmail(config.email_sender, config.email_receivers, email_msg.as_string())
|
||||
server.quit()
|
||||
print('Alert has been sent by email.')
|
||||
else:
|
||||
print('INFO: Email alerts are disabled.')
|
||||
|
||||
def send_sell_order(data):
|
||||
if telegram:
|
||||
|
@ -32,3 +49,16 @@ def send_sell_order(data):
|
|||
print('Alert has been sent to Discord.')
|
||||
else:
|
||||
print('INFO: Discord alerts are disabled.')
|
||||
if email:
|
||||
email_msg = MIMEText(data)
|
||||
email_msg['Subject'] = config.email_subject
|
||||
email_msg['From'] = config.email_sender
|
||||
email_msg['To'] = config.email_sender
|
||||
context = ssl.create_default_context()
|
||||
with smtplib.SMTP_SSL(config.email_host, config.email_port, context=context) as server:
|
||||
server.login(config.email_user, config.email_password)
|
||||
server.sendmail(config.email_sender, config.email_receivers, email_msg.as_string())
|
||||
server.quit()
|
||||
print('Alert has been sent by email.')
|
||||
else:
|
||||
print('INFO: Email alerts are disabled.')
|
Ładowanie…
Reference in New Issue