MCPcopy
hub / github.com/fabston/TradingView-Webhook-Bot / webhook

Function webhook

main.py:21–40  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

19
20@app.route("/webhook", methods=["POST"])
21def webhook():
22 whitelisted_ips = ['52.89.214.238', '34.212.75.30', '54.218.53.128', '52.32.178.7']
23 client_ip = request.headers.get('X-Forwarded-For', request.remote_addr)
24 if client_ip not in whitelisted_ips:
25 return jsonify({'message': 'Unauthorized'}), 401
26 try:
27 if request.method == "POST":
28 data = request.get_json()
29 if data["key"] == config.sec_key:
30 print(get_timestamp(), "Alert Received & Sent!")
31 send_alert(data)
32 return jsonify({'message': 'Webhook received successfully'}), 200
33
34 else:
35 print("[X]", get_timestamp(), "Alert Received & Refused! (Wrong Key)")
36 return jsonify({'message': 'Unauthorized'}), 401
37
38 except Exception as e:
39 print("[X]", get_timestamp(), "Error:\n>", e)
40 return jsonify({'message': 'Error'}), 400
41
42
43if __name__ == "__main__":

Callers

nothing calls this directly

Calls 2

send_alertFunction · 0.90
get_timestampFunction · 0.85

Tested by

no test coverage detected