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:
Yaojia Wang
2026-03-19 23:15:00 +01:00
parent 37c46e76ae
commit 0f7341b158
12 changed files with 184 additions and 204 deletions

View File

@@ -6,12 +6,10 @@ from typing import Any
import yfinance as yf
from openbb import obb
from obb_utils import to_list, first_or_empty
from obb_utils import to_list, first_or_empty, days_ago, PROVIDER
logger = logging.getLogger(__name__)
PROVIDER = "yfinance"
async def get_quote(symbol: str) -> dict[str, Any]:
result = await asyncio.to_thread(
@@ -21,7 +19,7 @@ async def get_quote(symbol: str) -> dict[str, Any]:
async def get_historical(symbol: str, days: int = 365) -> list[dict[str, Any]]:
start = (datetime.now(tz=timezone.utc) - timedelta(days=days)).strftime("%Y-%m-%d")
start = days_ago(days)
result = await asyncio.to_thread(
obb.equity.price.historical,
symbol,