refactor: address architect review findings (6 items)
R1: Extend @safe to catch ValueError->400, simplify routes_backtest
(eliminated 4 copies of duplicated try/except)
R2: Consolidate PROVIDER constant into obb_utils.py (single source)
R3: Add days_ago() helper to obb_utils.py, replace 8+ duplications
R4: Extract Reddit/ApeWisdom into reddit_service.py from finnhub_service
R5: Fix missing top-level import asyncio in finnhub_service
R6: (deferred - sentiment logic extraction is a larger change)
All 561 tests passing.
This commit is contained in:
@@ -66,11 +66,16 @@ def first_or_empty(result: Any) -> dict[str, Any]:
|
||||
return items[0] if items else {}
|
||||
|
||||
|
||||
def days_ago(days: int) -> str:
|
||||
"""Return a YYYY-MM-DD date string for N days ago (UTC)."""
|
||||
return (datetime.now(tz=timezone.utc) - timedelta(days=days)).strftime("%Y-%m-%d")
|
||||
|
||||
|
||||
async def fetch_historical(
|
||||
symbol: str, days: int = 365, provider: str = PROVIDER,
|
||||
) -> Any | None:
|
||||
"""Fetch historical price data, returning the OBBject result or None."""
|
||||
start = (datetime.now(tz=timezone.utc) - timedelta(days=days)).strftime("%Y-%m-%d")
|
||||
start = days_ago(days)
|
||||
try:
|
||||
result = await asyncio.to_thread(
|
||||
obb.equity.price.historical, symbol, start_date=start, provider=provider,
|
||||
|
||||
Reference in New Issue
Block a user