Spaces:
Running
Running
Upload app.py with huggingface_hub
Browse files
app.py
CHANGED
|
@@ -61,10 +61,22 @@ async def target():
|
|
| 61 |
async def nav():
|
| 62 |
try:
|
| 63 |
hist = await run_in_threadpool(alpaca.nav_history)
|
| 64 |
-
|
| 65 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 66 |
spy = await run_in_threadpool(alpaca.spy_series, start)
|
| 67 |
-
return {"fund":
|
| 68 |
except alpaca.AlpacaError as e:
|
| 69 |
raise HTTPException(503, str(e))
|
| 70 |
|
|
|
|
| 61 |
async def nav():
|
| 62 |
try:
|
| 63 |
hist = await run_in_threadpool(alpaca.nav_history)
|
| 64 |
+
pts = list(hist["points"])
|
| 65 |
+
# Alpaca's portfolio/history posts a daily point that lags the LIVE equity (so the chart
|
| 66 |
+
# would end on yesterday's close while the Day% KPI already shows today's move). Append a
|
| 67 |
+
# current-equity point so the line matches the live KPIs.
|
| 68 |
+
try:
|
| 69 |
+
acct = await run_in_threadpool(alpaca.account)
|
| 70 |
+
eq = acct.get("equity")
|
| 71 |
+
if eq and (not pts or abs(eq - pts[-1]["equity"]) > 0.01):
|
| 72 |
+
import time as _t
|
| 73 |
+
pts.append({"t": int(_t.time()), "equity": float(eq)})
|
| 74 |
+
except Exception:
|
| 75 |
+
pass
|
| 76 |
+
start = (datetime.fromtimestamp(pts[0]["t"], timezone.utc).strftime("%Y-%m-%d")
|
| 77 |
+
if pts else "2024-01-01")
|
| 78 |
spy = await run_in_threadpool(alpaca.spy_series, start)
|
| 79 |
+
return {"fund": pts, "base_value": hist["base_value"], "spy": spy}
|
| 80 |
except alpaca.AlpacaError as e:
|
| 81 |
raise HTTPException(503, str(e))
|
| 82 |
|