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:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user