fix: treat 404 on Alpaca positions endpoint as empty result

Alpaca returns 404 when you don't hold a position in a ticker.
The ingestion worker was logging this as an error and incrementing
the failure count. Now returns an empty items list instead, since
'no position' is a valid state, not an error.
This commit is contained in:
Celes Renata
2026-04-16 01:33:35 +00:00
parent 00ea917fc0
commit 88c9f50371
+13
View File
@@ -364,6 +364,19 @@ class AlpacaBrokerAdapter(BrokerDataAdapter):
)
except httpx.HTTPStatusError as e:
elapsed_ms = (time.monotonic() - t0) * 1000
# 404 on positions endpoint means no position held — not an error
if e.response is not None and e.response.status_code == 404 and endpoint == "positions":
return AdapterResult(
source_type="broker",
ticker=ticker,
items=[],
raw_payload=b"[]",
content_hash=hashlib.sha256(b"[]").hexdigest(),
fetched_at=datetime.now(timezone.utc),
http_status=404,
response_time_ms=round(elapsed_ms, 1),
metadata={"provider": "alpaca", "mode": self._mode.value, "endpoint": endpoint},
)
logger.error("Alpaca HTTP error for %s: %s", ticker, e)
return self._error_result(
ticker, str(e), elapsed_ms,