Yahoo
yahoo ¶
__all__ = ['YahooClient', 'YahooRecord'] module-attribute ¶
YahooClient(timeout: float = 30.0, requestlog: bool = False) ¶
Yahoo Finance HTTP client.
Source code in src/equities_classifier/clients/yahoo/client.py
def __init__(
self,
timeout: float = 30.0,
requestlog: bool = False,
) -> None:
"""Initialize Yahoo Finance client."""
_client: httpx.Client | None
self._client = httpx.Client(
base_url=self._BASE_URL,
timeout=timeout,
follow_redirects=True,
event_hooks={"request": [log_request], "response": [log_response]} if requestlog else None,
)
__enter__() -> Self ¶
__exit__(*_: object) -> None ¶
read_provider_profile_data(source_identifiers: Sequence[SecurityIdentifier], raise_error: bool = False) -> list[YahooRecord] ¶
Read profile data for identifiers from Yahoo Finance.
Source code in src/equities_classifier/clients/yahoo/client.py
def read_provider_profile_data(
self,
source_identifiers: Sequence[SecurityIdentifier],
raise_error: bool = False,
) -> list[YahooRecord]:
"""Read profile data for identifiers from Yahoo Finance."""
records: list[YahooRecord] = []
for source_identifier in source_identifiers:
if not self.supports_identifier_type(source_identifier.type):
ClientHelperErrorHandler.invalid_security_type(DataSourceID.YAHOO, source_identifier)
continue
response_data = self._execute_search_request(source_identifier)
search_results = self._parse_search_results(source_identifier, response_data, raise_error)
if search_results is None or len(search_results) == 0:
continue
record = self._parse_record(source_identifier, search_results[0])
# check for duplicates
if record:
duplicate = False
for existing_record in records:
if record.name == existing_record.name:
duplicate = True
for identifier in record.identifiers:
if not existing_record.has_identifier(identifier.type):
existing_record.identifiers.append(identifier)
if not duplicate:
records.append(record)
return records
supports_identifier_type(identifier_type: SecurityIdentifierType) -> bool classmethod ¶
Check if identifier type is supported.
YahooRecord(name: str | None = None, ticker: str | None = None, ticker_yahoo: str | None = None, exchange: str | None = None, exch_disp: str | None = None, sector: str | None = None, industry: str | None = None, *, identifiers: SecurityIdentifierList = SecurityIdentifierList()) dataclass ¶
Internal representation of a Yahoo Finance classification record.