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:
@@ -9,6 +9,7 @@ from route_utils import safe, validate_symbol
|
||||
import alphavantage_service
|
||||
import finnhub_service
|
||||
import openbb_service
|
||||
import reddit_service
|
||||
|
||||
import logging
|
||||
|
||||
@@ -35,7 +36,7 @@ async def stock_sentiment(symbol: str = Path(..., min_length=1, max_length=20)):
|
||||
av_data, finnhub_data, reddit_data, upgrades_data, recs_data = await asyncio.gather(
|
||||
alphavantage_service.get_news_sentiment(symbol, limit=20),
|
||||
finnhub_service.get_sentiment_summary(symbol),
|
||||
finnhub_service.get_reddit_sentiment(symbol),
|
||||
reddit_service.get_reddit_sentiment(symbol),
|
||||
openbb_service.get_upgrades_downgrades(symbol, limit=10),
|
||||
finnhub_service.get_recommendation_trends(symbol),
|
||||
return_exceptions=True,
|
||||
@@ -211,7 +212,7 @@ async def stock_reddit_sentiment(
|
||||
):
|
||||
"""Reddit sentiment: mentions, upvotes, rank on WSB/stocks/investing (free, no key)."""
|
||||
symbol = validate_symbol(symbol)
|
||||
data = await finnhub_service.get_reddit_sentiment(symbol)
|
||||
data = await reddit_service.get_reddit_sentiment(symbol)
|
||||
return ApiResponse(data=data)
|
||||
|
||||
|
||||
@@ -219,5 +220,5 @@ async def stock_reddit_sentiment(
|
||||
@safe
|
||||
async def reddit_trending():
|
||||
"""Top 25 trending stocks on Reddit (WSB, r/stocks, r/investing). Free, no key."""
|
||||
data = await finnhub_service.get_reddit_trending()
|
||||
data = await reddit_service.get_reddit_trending()
|
||||
return ApiResponse(data=data)
|
||||
|
||||
Reference in New Issue
Block a user