}L iddlmZmZddlZddlmZmZmZddl Z ddl m Z m Z ddl mZddlmZe dZGd d eZy) )ABCabstractmethodN)DictListOptional) _QUERY1_URL_ _SENTINEL_)YfData)Tickerz /v1/financecFeZdZdZdefdefdZedefdZedefdZ edefdZ ede fd Z ede fd Zedeej"fd Zedee eeffd Zde fd ZddZde fdZdeej"fdZeddZddZy)Domainz Abstract base class representing a domain entity in financial data, with key attributes and methods for fetching and parsing data. Derived classes must implement the `_fetch_and_parse()` method. Nkeyc||_||_t||_|tur7t j dtd|jj|d|_ d|_ d|_ d|_ d|_ y)a Initializes the Domain object with a key, session, and proxy. Args: key (str): Unique key identifying the domain entity. session (Optional[requests.Session]): Session object for HTTP requests. Defaults to None. )sessionz=Set proxy via new config function: yf.set_config(proxy=proxy)r) stacklevelN)_keyrr _datar warningswarnDeprecationWarning _set_proxy_name_symbol _overview_top_companies_research_reports)selfrrproxys \/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/yfinance/domain/domain.py__init__zDomain.__init__sp  #G4  " MMY[mz{ | JJ ! !% ($( &* )-7;AEreturnc|jS)z Retrieves the key of the domain entity. Returns: str: The unique key of the domain entity. )rrs r rz Domain.key'syyr"cP|j|j|jS)z| Retrieves the name of the domain entity. Returns: str: The name of the domain entity. )_ensure_fetchedrr%s r namez Domain.name1s  TZZ(zzr"cP|j|j|jS)z Retrieves the symbol of the domain entity. Returns: str: The symbol representing the domain entity. )r'rr%s r symbolz Domain.symbol<s  T\\*||r"cb|j|jt|jS)z Retrieves a Ticker object based on the domain entity's symbol. Returns: Ticker: A Ticker object associated with the domain entity. )r'rr r%s r tickerz Domain.tickerGs% T\\*dll##r"cP|j|j|jS)z Retrieves the overview information of the domain entity. Returns: Dict: A dictionary containing an overview of the domain entity. )r'rr%s r overviewzDomain.overviewRs  T^^,~~r"cP|j|j|jS)z Retrieves the top companies within the domain entity. Returns: pandas.DataFrame: A DataFrame containing the top companies in the domain. )r'rr%s r top_companieszDomain.top_companies]s$ T001"""r"cP|j|j|jS)z Retrieves research reports related to the domain entity. Returns: List[Dict[str, str]]: A list of research reports, where each report is a dictionary with metadata. )r'rr%s r research_reportszDomain.research_reportshs$ T334%%%r"cNddddd}|jj||}|S)z Fetches data from the given query URL. Args: query_url (str): The URL used for the data query. Returns: Dict: The JSON response data from the request. truezen-USUS) formatted withReturnslangregion)params)r get_raw_json)r query_url params_dictresults r _fetchz Domain._fetchss1%+67^bc ((;(G r"c |jd|_|jd|_|j|jdi|_|j |jdi|_|jd|_y)z Parses and assigns common data fields such as name, symbol, overview, and top companies. Args: data (Dict): The raw data received from the API. r(r*r. topCompaniesresearchReportsN)getrr_parse_overviewr_parse_top_companiesrr)rdatas r _parse_and_assign_commonzDomain._parse_and_assign_commonsrXXf% xx) --dhhz2.FG"77QS8TU!%*;!<r"c V|jdd|jdijdd|jdd|jdd|jdd|jdijdd|jd ijddd S) z Parses the overview data for the domain entity. Args: overview (Dict): The raw overview data. Returns: Dict: A dictionary containing parsed overview information. companiesCountN marketCaprawmessageBoardId descriptionindustriesCount marketWeight employeeCount)companies_count market_capmessage_board_idrMindustries_count market_weightemployee_count)rC)rr.s r rDzDomain._parse_overviews (||, E%\\."=AA%N&ll?B?CCE4P  r"c &gd}|Dcgc]U}|jd|jd|jd|jdijddfW}}|sytj||jdScc}w) a) Parses the top companies data and converts it into a pandas DataFrame. Args: top_companies (Dict): The raw top companies data. Returns: Optional[pandas.DataFrame]: A DataFrame containing top company data, or None if no data is available. )r*r(ratingz market weightr*r(rXrOrKN)columns)rC_pd DataFrame set_index)rr0top_companies_columnctop_companies_valuess r rEzDomain._parse_top_companiess MTa bOP"#x !f !h !nR 8 < _fetch_and_parse() needs to be implemented by children classes)NotImplementedErrorr%s r _fetch_and_parsezDomain._fetch_and_parses ""bccr"c*||jyy)z Ensures that the given attribute is fetched by calling `_fetch_and_parse()` if the attribute is None. Args: attribute: The attribute to check and potentially fetch. N)rb)r attributes r r'zDomain._ensure_fetcheds    ! ! # r")r#N)__name__ __module__ __qualname____doc__r strr!propertyrr(r*r r,rr.rrZr[r0rr2r?rGrDrErrbr'r"r rr s> *.ZFCF*Sc$$$$#x 6##&$tCH~"6&& 4  = 4 (eXcmm5Le*dd$r"r)abcrrpandasrZtypingrrrrconstr r rFr r,r _QUERY_URL_rrkr"r rqs7#'',k* {$S{$r"