-
Notifications
You must be signed in to change notification settings - Fork 2
refactor: dedup B3 quote guard and push anbima emissor into the source #31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,26 @@ | ||||||||||||||||||||||||||||||||||||||||||||
| """Shared B3 live-quote helpers for the REST and MCP layers. | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| ``yfinance`` is imported lazily so the rest of the API keeps working without | ||||||||||||||||||||||||||||||||||||||||||||
| the optional ``[b3]`` extra installed. Both ``routers/b3.py`` and ``mcp_app.py`` | ||||||||||||||||||||||||||||||||||||||||||||
| resolve the quotes module through here, so the install hint lives in one place. | ||||||||||||||||||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| from __future__ import annotations | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| from typing import Any | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| from fastapi import HTTPException | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| MAX_TICKERS = 20 | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| def resolve_quotes() -> Any: | ||||||||||||||||||||||||||||||||||||||||||||
| """Return the yfinance-backed quotes module, or raise 503 if the extra is missing.""" | ||||||||||||||||||||||||||||||||||||||||||||
| try: | ||||||||||||||||||||||||||||||||||||||||||||
| from findata.sources.b3 import quotes | ||||||||||||||||||||||||||||||||||||||||||||
| except ImportError as exc: # pragma: no cover - only without the [b3] extra | ||||||||||||||||||||||||||||||||||||||||||||
| raise HTTPException( | ||||||||||||||||||||||||||||||||||||||||||||
| status_code=503, | ||||||||||||||||||||||||||||||||||||||||||||
| detail="B3 live quotes need the optional extra: pip install 'openfindata[b3]'", | ||||||||||||||||||||||||||||||||||||||||||||
| ) from exc | ||||||||||||||||||||||||||||||||||||||||||||
| return quotes | ||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+17
to
+26
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The To fix this, explicitly attempt to import
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
The missing-
[b3]path no longer turns into the shared 503 response.findata.sources.b3.quotesnow defers theyfinanceimport to_import_yfinance()insrc/findata/sources/b3/quotes.py:70-77, sofrom findata.sources.b3 import quotessucceeds even when the extra is absent. In that case this helper returns normally, and the later quote call raisesRuntimeError, which the REST/MCP callers currently translate into 404/500 instead of the advertised 503 install hint.Possible fix
📝 Committable suggestion
🤖 Prompt for AI Agents