Implemented Slack Support

pull/78/head
vzns 2021-02-05 18:27:05 +01:00
rodzic 127ed28bbf
commit 7868203264
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 7DF2CD11394B933C
4 zmienionych plików z 29 dodań i 4 usunięć

Wyświetl plik

@ -32,6 +32,7 @@ I am running my own TradingView Webhook Service. No setup and hosting required.
## Features
- Telegram Support using the [Python Telegram](https://github.com/python-telegram-bot/python-telegram-bot) libary
- Discord Support using [webhooks](https://support.discord.com/hc/de/articles/228383668-Webhooks-verwenden)
- Slack Support using [webhooks](https://api.slack.com/messaging/webhooks)
- 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/vsnz/TradingView-Webhook-Bot/blob/master/config.py)
@ -49,10 +50,16 @@ I am running my own TradingView Webhook Service. No setup and hosting required.
1. Edit and update [`config.py`](https://github.com/vsnz/TradingView-Webhook-Bot/blob/master/config.py)
1. Setup TradingView alerts. An example alert message would be:
```json
{"key": "9T2q394M92", "telegram": "-1001277977502", "discord": "789842341870960670/BFeBBrCt-w2Z9RJ2wlH6TWUjM5bJuC29aJaJ5OQv9sE6zCKY_AlOxxFwRURkgEl852s3", "msg": "Long #{{ticker}} at `{{close}}`"}
{
"key": "9T2q394M92",
"telegram": "-1001277977502",
"discord": "789842341870960670/BFeBBrCt-w2Z9RJ2wlH6TWUjM5bJuC29aJaJ5OQv9sE6zCKY_AlOxxFwRURkgEl852s3",
"slack": "T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX",
"msg": "Long *#{{ticker}}* at `{{close}}`"
}
```
- `key` is mandatory! It has to match with `sec_key` in [`config.py`](https://github.com/vsnz/TradingView-Webhook-Bot/blob/master/config.py). It's an extra security measurement to ensure nobody else is executing your alerts
- `telegram` and `discord` is optional. If it is not set it will fall back to the config.py settings
- `telegram`, `discord`, `slack` is optional. If it is not set it will fall back to the config.py settings
- `msg` can be anything. Markdown for [Telegram](https://core.telegram.org/api/entities) and [Discord](https://support.discord.com/hc/en-us/articles/210298617-Markdown-Text-101-Chat-Formatting-Bold-Italic-Underline-) is supported as well
- TradingViews variables like `{{close}}`, `{{exchange}}` etc. work too. More can be found [here](https://www.tradingview.com/blog/en/introducing-variables-in-alerts-14880/)
- Your webhook url would be `http://<YOUR-IP>/webhook`

Wyświetl plik

@ -5,7 +5,9 @@
# ----------------------------------------------- #
# TradingView Example Alert Message:
# {"key": "9T2q394M92", "telegram": "-1001298977502", "discord": "789842349670960670/BFeBBrCt-w2Z9RJ2wlH6TWUjM5bJuC29aJaJ5OQv9sE6zCKY_AlOxxFwRURkgEl852s3","msg": "Long #{{ticker}} at `{{close}}`"}
# {
# "key":"9T2q394M92", "telegram":"-1001298977502", "discord":"789842349670960670/BFeBBrCt-w2Z9RJ2wlH6TWUjM5bJuC29aJaJ5OQv9sE6zCKY_AlOxxFwRURkgEl852s3", "msg":"Long #{{ticker}} at `{{close}}`"
# }
sec_key = '' # Can be anything. Has to match with "key" in your TradingView alert message
@ -18,6 +20,10 @@ channel = 0 # Channel ID (ex. -1001487568087)
send_discord_alerts = False
discord_webhook = '' # Discord Webhook URL (https://support.discordapp.com/hc/de/articles/228383668-Webhooks-verwenden)
# Slack Settings
send_slack_alerts = False
slack_webhook = '' # Slack Webhook URL (https://api.slack.com/messaging/webhooks)
#Twitter Settings
send_twitter_alerts = False
tw_ckey = ''

Wyświetl plik

@ -7,6 +7,7 @@
import config
from telegram import Bot
from discord_webhook import DiscordWebhook, DiscordEmbed
from slack_webhook import Slack
import tweepy
import smtplib, ssl
from email.mime.text import MIMEText
@ -34,7 +35,17 @@ def send_alert(data):
response = webhook.execute()
except Exception as e:
print('[X] Discord Error:\n>', e)
if config.send_slack_alerts:
try:
slack = Slack(url='https://hooks.slack.com/services/' + data['slack'])
slack.post(text=data['msg'])
except KeyError:
slack = Slack(url='https://hooks.slack.com/services/' + config.slack_webhook)
slack.post(text=data['msg'])
except Exception as e:
print('[X] Slack Error:\n>', e)
if config.send_twitter_alerts:
tw_auth = tweepy.OAuthHandler(config.tw_ckey, config.tw_csecret)
tw_auth.set_access_token(config.tw_atoken, config.tw_asecret)

Wyświetl plik

@ -2,4 +2,5 @@ flask
waitress
python-telegram-bot
discord-webhook
slack-webhook
tweepy