-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathhandler.py
100 lines (86 loc) · 3.55 KB
/
handler.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import config as config
from telegram import Bot
from discord_webhook import DiscordWebhook
import tweepy
import smtplib, ssl
from email.mime.text import MIMEText
##
import time
from time import sleep
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC1
from selenium.webdriver.common.by import By
telegram = config.send_telegram_alerts
discord = config.send_discord_alerts
twitter = config.send_twitter_alerts
email = config.send_email_alerts
if telegram:
tg_bot = Bot(token=config.tg_token)
if twitter:
tw_auth = tweepy.OAuthHandler(config.tw_ckey, config.tw_csecret)
tw_auth.set_access_token(config.tw_atoken, config.tw_asecret)
tw_api = tweepy.API(tw_auth)
def send_buy_order(data):
if telegram:
tg_bot.sendMessage(config.channel, data)
get_trading_view_graph()
print('Alert has been sent to Telegram.')
else:
print('INFO: Telegram alerts are disabled.')
if discord:
discord_alert = DiscordWebhook(url=config.discord_webhook, content=data)
response = discord_alert.execute()
print('Alert has been sent to Discord.')
else:
print('INFO: Discord alerts are disabled.')
if twitter:
tw_api.update_status(status=data)
print('Alert has been sent to Twitter.')
else:
print('INFO: Twitter 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:
tg_bot.sendMessage(config.channel, data)
print('Alert has been sent to Telegram.')
else:
print('INFO: Telegram alerts are disabled.')
if discord:
discord_alert = DiscordWebhook(url=config.discord_webhook, content=data)
response = discord_alert.execute()
print('Alert has been sent to Discord.')
else:
print('INFO: Discord alerts are disabled.')
if twitter:
tw_api.update_status(status=data)
print('Alert has been sent to Twitter.')
else:
print('INFO: Twitter 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.')