Add files via upload

Initial release
pull/1/head
fabcx 2020-04-21 16:29:00 +02:00 zatwierdzone przez GitHub
rodzic f46e0a8367
commit fb0d8260ee
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
4 zmienionych plików z 78 dodań i 0 usunięć

12
config.py 100644
Wyświetl plik

@ -0,0 +1,12 @@
# Alert message in TradingView ex. https://i.imgur.com/QpAP3wp.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
# Discord Settings
send_discord_alerts = True
discord_webhook = '' # Discord Webhook URL (https://support.discordapp.com/hc/de/articles/228383668-Webhooks-verwenden)

34
handler.py 100644
Wyświetl plik

@ -0,0 +1,34 @@
import config as config
from telegram import Bot
from discord_webhook import DiscordWebhook
tg_bot = Bot(token=config.tg_token)
telegram = config.send_telegram_alerts
discord = config.send_discord_alerts
def send_buy_order(data):
if telegram:
tg_bot.sendMessage(config.channel, config.Buy_Alert)
print('Alert has been sent to Telegram.')
else:
print('INFO: Telegram alerts are disabled.')
if discord:
discord_alert = DiscordWebhook(url=config.discord_webhook, content=config.Buy_Alert)
response = discord_alert.execute()
print('Alert has been sent to Discord.')
else:
print('INFO: Discord alerts are disabled.')
def send_sell_order(data):
if telegram:
tg_bot.sendMessage(config.channel, config.Sell_Alert)
print('Alert has been sent to Telegram.')
else:
print('INFO: Telegram alerts are disabled.')
if discord:
discord_alert = DiscordWebhook(url=config.discord_webhook, content=config.Sell_Alert)
response = discord_alert.execute()
print('Alert has been sent to Discord.')
else:
print('INFO: Discord alerts are disabled.')

26
main.py 100644
Wyświetl plik

@ -0,0 +1,26 @@
import config as config
from flask import Flask, request, abort
from handler import send_buy_order, send_sell_order
app = Flask(__name__)
@app.route('/webhook', methods=['POST'])
def webhook():
if request.method == 'POST':
data = request.get_data(as_text=True)
if config.Buy_Alert in data:
print('Alert Received:', data)
send_buy_order(data)
return '', 200
elif config.Sell_Alert in data:
print('Alert Received:', data)
send_sell_order(data)
return '', 200
else:
abort(400)
else:
abort(400)
if __name__ == '__main__':
from waitress import serve
serve(app, host='0.0.0.0', port=80)

6
requirements.txt 100644
Wyświetl plik

@ -0,0 +1,6 @@
flask
waitress
python-telegram-bot
discord-webhook