kopia lustrzana https://github.com/fabston/TradingView-Webhook-Bot
simplified handler.py
rodzic
353c136fb7
commit
f2a5f5c5ec
|
@ -9,12 +9,12 @@ 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)
|
||||
send_telegram_alerts = False
|
||||
tg_token = '' # Bot token. Get it from @Botfather
|
||||
channel = 0 # Channel ID (ex. -1001487568087)
|
||||
|
||||
# Discord Settings
|
||||
send_discord_alerts = True
|
||||
send_discord_alerts = False
|
||||
discord_webhook = '' # Discord Webhook URL (https://support.discordapp.com/hc/de/articles/228383668-Webhooks-verwenden)
|
||||
|
||||
#Twitter Settings
|
||||
|
|
72
handler.py
72
handler.py
|
@ -4,7 +4,7 @@
|
|||
# File Name : handler.py #
|
||||
# ----------------------------------------------- #
|
||||
|
||||
import config as config
|
||||
import config
|
||||
from telegram import Bot
|
||||
from discord_webhook import DiscordWebhook
|
||||
import tweepy
|
||||
|
@ -24,62 +24,44 @@ if twitter:
|
|||
tw_auth.set_access_token(config.tw_atoken, config.tw_asecret)
|
||||
tw_api = tweepy.API(tw_auth)
|
||||
|
||||
def send_buy_order(data):
|
||||
def send_alert(data):
|
||||
if telegram:
|
||||
tg_bot.sendMessage(config.channel, data)
|
||||
try:
|
||||
tg_bot.sendMessage(config.channel, data)
|
||||
except Exception as e:
|
||||
print(e)
|
||||
else:
|
||||
pass
|
||||
|
||||
if discord:
|
||||
discord_alert = DiscordWebhook(url=config.discord_webhook, content=data)
|
||||
response = discord_alert.execute()
|
||||
try:
|
||||
discord_alert = DiscordWebhook(url=config.discord_webhook, content=data)
|
||||
response = discord_alert.execute()
|
||||
except Exception as e:
|
||||
print(e)
|
||||
else:
|
||||
pass
|
||||
|
||||
if twitter:
|
||||
tw_api.update_status(status=data)
|
||||
try:
|
||||
tw_api.update_status(status=data)
|
||||
except Exception as e:
|
||||
print(e)
|
||||
else:
|
||||
pass
|
||||
|
||||
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()
|
||||
else:
|
||||
pass
|
||||
|
||||
def send_sell_order(data):
|
||||
if telegram:
|
||||
tg_bot.sendMessage(config.channel, data)
|
||||
else:
|
||||
pass
|
||||
|
||||
if discord:
|
||||
discord_alert = DiscordWebhook(url=config.discord_webhook, content=data)
|
||||
response = discord_alert.execute()
|
||||
else:
|
||||
pass
|
||||
|
||||
if twitter:
|
||||
tw_api.update_status(status=data)
|
||||
else:
|
||||
pass
|
||||
|
||||
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()
|
||||
try:
|
||||
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()
|
||||
except Exception as e:
|
||||
print(e)
|
||||
else:
|
||||
pass
|
8
main.py
8
main.py
|
@ -4,9 +4,9 @@
|
|||
# File Name : main.py #
|
||||
# ----------------------------------------------- #
|
||||
|
||||
import config as config
|
||||
import config
|
||||
from flask import Flask, request, abort
|
||||
from handler import send_buy_order, send_sell_order
|
||||
from handler import *
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
|
@ -16,11 +16,11 @@ def webhook():
|
|||
data = request.get_data(as_text=True)
|
||||
if config.Buy_Alert in data:
|
||||
print('Alert Received:', data)
|
||||
send_buy_order(data)
|
||||
send_alert(data)
|
||||
return '', 200
|
||||
elif config.Sell_Alert in data:
|
||||
print('Alert Received:', data)
|
||||
send_sell_order(data)
|
||||
send_alert(data)
|
||||
return '', 200
|
||||
else:
|
||||
abort(400)
|
||||
|
|
Ładowanie…
Reference in New Issue