Upload 3 files
Browse files
README.md
CHANGED
|
@@ -7,8 +7,6 @@ app_file: app.py
|
|
| 7 |
Set these Space variables:
|
| 8 |
|
| 9 |
- `RECEIVER_URL=https://YOUR-NETLIFY-SITE.netlify.app/api/signal`
|
| 10 |
-
- `SIGNAL_TOKEN=the_same_random_token_as_netlify`
|
| 11 |
-
|
| 12 |
The Space exposes the Gradio API function `tick`; Netlify's scheduled
|
| 13 |
function calls it once per minute. It uses Delta public candles and sends only
|
| 14 |
paper signal events.
|
|
|
|
| 7 |
Set these Space variables:
|
| 8 |
|
| 9 |
- `RECEIVER_URL=https://YOUR-NETLIFY-SITE.netlify.app/api/signal`
|
|
|
|
|
|
|
| 10 |
The Space exposes the Gradio API function `tick`; Netlify's scheduled
|
| 11 |
function calls it once per minute. It uses Delta public candles and sends only
|
| 12 |
paper signal events.
|
app.py
CHANGED
|
@@ -4,8 +4,7 @@ import requests, pandas as pd
|
|
| 4 |
import gradio as gr
|
| 5 |
DELTA = os.getenv("DELTA_URL", "https://api.india.delta.exchange")
|
| 6 |
SYMBOL = os.getenv("SYMBOL", "BTCUSD")
|
| 7 |
-
RECEIVER_URL = os.environ.get("RECEIVER_URL", "")
|
| 8 |
-
TOKEN = os.environ.get("SIGNAL_TOKEN", "")
|
| 9 |
last_signal = None
|
| 10 |
|
| 11 |
def candles(limit=240):
|
|
@@ -41,8 +40,12 @@ def tick():
|
|
| 41 |
if event and event["signal_time"] != (last_signal or {}).get("signal_time"):
|
| 42 |
last_signal = event
|
| 43 |
if RECEIVER_URL:
|
| 44 |
-
|
| 45 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
return {"ok":True,"event":event,"sent":bool(event and RECEIVER_URL)}
|
| 47 |
|
| 48 |
with gr.Blocks() as demo:
|
|
|
|
| 4 |
import gradio as gr
|
| 5 |
DELTA = os.getenv("DELTA_URL", "https://api.india.delta.exchange")
|
| 6 |
SYMBOL = os.getenv("SYMBOL", "BTCUSD")
|
| 7 |
+
RECEIVER_URL = os.environ.get("RECEIVER_URL", "").rstrip("/")
|
|
|
|
| 8 |
last_signal = None
|
| 9 |
|
| 10 |
def candles(limit=240):
|
|
|
|
| 40 |
if event and event["signal_time"] != (last_signal or {}).get("signal_time"):
|
| 41 |
last_signal = event
|
| 42 |
if RECEIVER_URL:
|
| 43 |
+
try:
|
| 44 |
+
response = requests.post(RECEIVER_URL, json=event, timeout=15)
|
| 45 |
+
response.raise_for_status()
|
| 46 |
+
except requests.RequestException as exc:
|
| 47 |
+
return {"ok":False, "event":event, "sent":False,
|
| 48 |
+
"receiver_url":RECEIVER_URL, "error":str(exc)}
|
| 49 |
return {"ok":True,"event":event,"sent":bool(event and RECEIVER_URL)}
|
| 50 |
|
| 51 |
with gr.Blocks() as demo:
|