Added option to whitelist words

- Easily add whitelisted words in config.py
- Better error handling
pull/8/head
sixBit 2020-07-12 09:48:57 +02:00
rodzic f2a5f5c5ec
commit b35a293a65
3 zmienionych plików z 30 dodań i 24 usunięć

Wyświetl plik

@ -8,7 +8,6 @@
<br /><a href="https://github.com/sixBit/TradingView-Webhook-Bot/stargazers"><img src="https://img.shields.io/github/stars/sixbit/TradingView-Webhook-Bot?style=social" alt="GitHub stars"></a>
<a href="https://github.com/sixBit/TradingView-Webhook-Bot/network/members"><img src="https://img.shields.io/github/forks/sixbit/TradingView-Webhook-Bot?style=social" alt="GitHub forks"></a>
<a href="https://github.com/sixBit/TradingView-Webhook-Bot/watchers"><img src="https://img.shields.io/github/watchers/sixbit/TradingView-Webhook-Bot?style=social" alt="GitHub watchers"></a>
<br /><a href="https://conversations.im/j/codehub@room.sixbit.io"><img src="https://inverse.chat/badge.svg?room=codehub@room.sixbit.io" alt="Join XMPP Server"></a>
</p>
<p align="center">
@ -24,7 +23,8 @@
</p>
## About
The **TradingView Webhook Bot** ⚙️ listens to [TradingView](https://tradingview.com) alerts via [webhooks](https://www.tradingview.com/support/solutions/43000529348-i-want-to-know-more-about-webhooks/) using [flask](https://flask.palletsprojects.com/en/1.1.x/). All alerts can be instantly sent to Telegram, Discord, Twitter and/or Email.
The **TradingView Webhook Bot** ⚙️ listens to [TradingView](https://tradingview.com) alerts via [webhooks](https://www.tradingview.com/support/solutions/43000529348-i-want-to-know-more-about-webhooks/) using [flask](https://flask.palletsprojects.com/en/1.1.x/).
All alerts can be instantly sent to Telegram, Discord, Twitter and/or Email.
## Features
- Telegram Support using the [Python Telegram](https://github.com/python-telegram-bot/python-telegram-bot) libary
@ -32,7 +32,7 @@ The **TradingView Webhook Bot** ⚙️ listens to [TradingView](https://tradingv
- Twitter Support using the [tweepy](https://github.com/tweepy/tweepy) libary
- Email Support using [smtplib](https://docs.python.org/3/library/smtplib.html)
- Alert channels can be enabled or disabled in [`config.py`](https://github.com/sixBit/TradingView-Webhook-Bot/blob/master/config.py)
- Differentiate between Buy and Sell alerts
- Whitelisted words can be easily added in [`config.py`](https://github.com/sixBit/TradingView-Webhook-Bot/blob/master/config.py)
- TradingView `{{close}}`, `{{exchange}}` etc. variables support. Read more [here](https://www.tradingview.com/blog/en/introducing-variables-in-alerts-14880/)
> 💡 Got a feature idea? Open an [issue](https://github.com/sixBit/Telegram-Webhook-Bot/issues/new) and I might implement it.

Wyświetl plik

@ -5,8 +5,10 @@
# ----------------------------------------------- #
# Alert message in TradingView (ex. https://i.imgur.com/RFkuf1d.png)
Buy_Alert = 'Buy Alert!'
Sell_Alert = 'Sell Alert!'
# !! Case insensitive !!
whitelisted = [
'buy alert', 'sell alert'
]
# Telegram Settings
send_telegram_alerts = False
@ -30,7 +32,7 @@ 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
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
main.py
Wyświetl plik

@ -5,27 +5,31 @@
# ----------------------------------------------- #
import config
from flask import Flask, request, abort
import time
from flask import Flask, request
from handler import *
timestamp = time.strftime("%Y-%m-%d %X")
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_alert(data)
return '', 200
elif config.Sell_Alert in data:
print('Alert Received:', data)
send_alert(data)
return '', 200
try:
if request.method == 'POST':
data = request.get_data(as_text=True)
for whitelisted in config.whitelisted:
if whitelisted.lower() in data.lower():
print('[✓]', timestamp, 'Alert Received & Sent!\n>', data)
send_alert(data)
return 'Sent alert', 200
else:
print('[✗]', timestamp, 'Alert Received & Refused!\n>', data)
return 'Refused alert', 400
else:
abort(400)
else:
abort(400)
return 'Refused alert', 400
except Exception as e:
print('[✘]', timestamp, 'Error:\n>', e)
return 'Error', 400
if __name__ == '__main__':
from waitress import serve