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!'
|
Sell_Alert = 'Sell Alert!'
|
||||||
|
|
||||||
# Telegram Settings
|
# Telegram Settings
|
||||||
send_telegram_alerts = True
|
send_telegram_alerts = False
|
||||||
tg_token = '' # Bot token. Get it from @Botfather
|
tg_token = '' # Bot token. Get it from @Botfather
|
||||||
channel = # Channel ID (ex. -1001487568087)
|
channel = 0 # Channel ID (ex. -1001487568087)
|
||||||
|
|
||||||
# Discord Settings
|
# 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)
|
discord_webhook = '' # Discord Webhook URL (https://support.discordapp.com/hc/de/articles/228383668-Webhooks-verwenden)
|
||||||
|
|
||||||
#Twitter Settings
|
#Twitter Settings
|
||||||
|
|
46
handler.py
46
handler.py
|
@ -4,7 +4,7 @@
|
||||||
# File Name : handler.py #
|
# File Name : handler.py #
|
||||||
# ----------------------------------------------- #
|
# ----------------------------------------------- #
|
||||||
|
|
||||||
import config as config
|
import config
|
||||||
from telegram import Bot
|
from telegram import Bot
|
||||||
from discord_webhook import DiscordWebhook
|
from discord_webhook import DiscordWebhook
|
||||||
import tweepy
|
import tweepy
|
||||||
|
@ -24,54 +24,34 @@ if twitter:
|
||||||
tw_auth.set_access_token(config.tw_atoken, config.tw_asecret)
|
tw_auth.set_access_token(config.tw_atoken, config.tw_asecret)
|
||||||
tw_api = tweepy.API(tw_auth)
|
tw_api = tweepy.API(tw_auth)
|
||||||
|
|
||||||
def send_buy_order(data):
|
def send_alert(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()
|
|
||||||
else:
|
|
||||||
pass
|
|
||||||
|
|
||||||
def send_sell_order(data):
|
|
||||||
if telegram:
|
if telegram:
|
||||||
|
try:
|
||||||
tg_bot.sendMessage(config.channel, data)
|
tg_bot.sendMessage(config.channel, data)
|
||||||
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
else:
|
else:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
if discord:
|
if discord:
|
||||||
|
try:
|
||||||
discord_alert = DiscordWebhook(url=config.discord_webhook, content=data)
|
discord_alert = DiscordWebhook(url=config.discord_webhook, content=data)
|
||||||
response = discord_alert.execute()
|
response = discord_alert.execute()
|
||||||
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
else:
|
else:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
if twitter:
|
if twitter:
|
||||||
|
try:
|
||||||
tw_api.update_status(status=data)
|
tw_api.update_status(status=data)
|
||||||
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
else:
|
else:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
if email:
|
if email:
|
||||||
|
try:
|
||||||
email_msg = MIMEText(data)
|
email_msg = MIMEText(data)
|
||||||
email_msg['Subject'] = config.email_subject
|
email_msg['Subject'] = config.email_subject
|
||||||
email_msg['From'] = config.email_sender
|
email_msg['From'] = config.email_sender
|
||||||
|
@ -81,5 +61,7 @@ def send_sell_order(data):
|
||||||
server.login(config.email_user, config.email_password)
|
server.login(config.email_user, config.email_password)
|
||||||
server.sendmail(config.email_sender, config.email_receivers, email_msg.as_string())
|
server.sendmail(config.email_sender, config.email_receivers, email_msg.as_string())
|
||||||
server.quit()
|
server.quit()
|
||||||
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
else:
|
else:
|
||||||
pass
|
pass
|
8
main.py
8
main.py
|
@ -4,9 +4,9 @@
|
||||||
# File Name : main.py #
|
# File Name : main.py #
|
||||||
# ----------------------------------------------- #
|
# ----------------------------------------------- #
|
||||||
|
|
||||||
import config as config
|
import config
|
||||||
from flask import Flask, request, abort
|
from flask import Flask, request, abort
|
||||||
from handler import send_buy_order, send_sell_order
|
from handler import *
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
|
|
||||||
|
@ -16,11 +16,11 @@ def webhook():
|
||||||
data = request.get_data(as_text=True)
|
data = request.get_data(as_text=True)
|
||||||
if config.Buy_Alert in data:
|
if config.Buy_Alert in data:
|
||||||
print('Alert Received:', data)
|
print('Alert Received:', data)
|
||||||
send_buy_order(data)
|
send_alert(data)
|
||||||
return '', 200
|
return '', 200
|
||||||
elif config.Sell_Alert in data:
|
elif config.Sell_Alert in data:
|
||||||
print('Alert Received:', data)
|
print('Alert Received:', data)
|
||||||
send_sell_order(data)
|
send_alert(data)
|
||||||
return '', 200
|
return '', 200
|
||||||
else:
|
else:
|
||||||
abort(400)
|
abort(400)
|
||||||
|
|
Ładowanie…
Reference in New Issue