-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathwebhook.py
More file actions
33 lines (26 loc) · 841 Bytes
/
webhook.py
File metadata and controls
33 lines (26 loc) · 841 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
from actions import send_order, parse_webhook
from auth import get_token
from flask import Flask, request, abort
# Create Flask object called app.
app = Flask(__name__)
# Create root to easily let us know its on/working.
@app.route('/')
def root():
return 'online'
@app.route('/webhook', methods=['POST'])
def webhook():
if request.method == 'POST':
# Parse the string data from tradingview into a python dict
data = parse_webhook(request.get_data(as_text=True))
# Check that the key is correct
if get_token() == data['key']:
print(' [Alert Received] ')
print('POST Received:', data)
send_order(data)
return '', 200
else:
abort(403)
else:
abort(400)
if __name__ == '__main__':
app.run(host='0.0.0.0', port=80)