§
    ¦ìNgô  ã                   óf   — d Z ddlZddlmZmZmZ ddlZddlmZ ddl	m
Z
 dZ G d„ de
¦  «        ZdS )	zp
Util that calls several of financial datasets stock market REST APIs.
Docs: https://docs.financialdatasets.ai/
é    N)ÚAnyÚListÚOptional)Úget_from_dict_or_env)Ú	BaseModelz!https://api.financialdatasets.ai/c            	       ó  ‡ — e Zd ZU dZdZee         ed<   defˆ fd„Z	e
defd„¦   «         Zded	ed
ee         dee         fd„Zded	ed
ee         dee         fd„Zded	ed
ee         dee         fd„Zdedededefd„Zˆ xZS )ÚFinancialDatasetsAPIWrapperz#Wrapper for financial datasets API.NÚfinancial_datasets_api_keyÚdatac                 óf   •—  t          ¦   «         j        di |¤Ž t          |dd¦  «        | _        d S )Nr
   ÚFINANCIAL_DATASETS_API_KEY© )ÚsuperÚ__init__r   r
   )Úselfr   Ú	__class__s     €úl/var/www/html/ai-engine/env/lib/python3.11/site-packages/langchain_community/utilities/financial_datasets.pyr   z$FinancialDatasetsAPIWrapper.__init__   sA   ø€ Ø‰ŒÔÐ Ð ˜4Ð Ð Ð Ý*>ØÐ.Ð0Lñ+
ô +
ˆÔ'Ð'Ð'ó    Úreturnc                 ó<   — | j         €t          d¦  «        ‚| j         S )Na#  API key is required for the FinancialDatasetsAPIWrapper. Please provide the API key by either:
1. Manually specifying it when initializing the wrapper: FinancialDatasetsAPIWrapper(financial_datasets_api_key='your_api_key')
2. Setting it as an environment variable: FINANCIAL_DATASETS_API_KEY)r
   Ú
ValueError)r   s    r   Ú_api_keyz$FinancialDatasetsAPIWrapper._api_key   s.   € àÔ*Ð2ÝðWñô ð ð Ô.Ð.r   ÚtickerÚperiodÚlimitc                 óÀ   — t           › d|› d|› d|r|nd› }d| j        i}t          j        ||¬¦  «        }|                     ¦   «         }|                     dd¦  «        S )	av  
        Get the income statements for a stock `ticker` over a `period` of time.

        :param ticker: the stock ticker
        :param period: the period of time to get the balance sheets for.
            Possible values are: annual, quarterly, ttm.
        :param limit: the number of results to return, default is 10
        :return: a list of income statements
        z%financials/income-statements/?ticker=ú&period=ú&limit=é
   ú	X-API-KEY©ÚheadersÚincome_statementsN©ÚFINANCIAL_DATASETS_BASE_URLr   ÚrequestsÚgetÚjson©r   r   r   r   Úurlr"   Úresponser   s           r   Úget_income_statementsz1FinancialDatasetsAPIWrapper.get_income_statements'   sŽ   € õ  +ð /ð /Øð/ð /àð/ð /ð  %Ð,ee¨"ð/ð /ð 	ð  ¤Ð.ˆõ ”< ¨WÐ5Ñ5Ô5ˆØ}Š}‰ŒˆàxŠxÐ+¨TÑ2Ô2Ð2r   c                 óÀ   — t           › d|› d|› d|r|nd› }d| j        i}t          j        ||¬¦  «        }|                     ¦   «         }|                     dd¦  «        S )	ap  
        Get the balance sheets for a stock `ticker` over a `period` of time.

        :param ticker: the stock ticker
        :param period: the period of time to get the balance sheets for.
            Possible values are: annual, quarterly, ttm.
        :param limit: the number of results to return, default is 10
        :return: a list of balance sheets
        z"financials/balance-sheets/?ticker=r   r   r   r    r!   Úbalance_sheetsNr$   r)   s           r   Úget_balance_sheetsz.FinancialDatasetsAPIWrapper.get_balance_sheetsF   sŽ   € õ  +ð /ð /Øð/ð /àð/ð /ð  %Ð,ee¨"ð/ð /ð 	ð  ¤Ð.ˆõ ”< ¨WÐ5Ñ5Ô5ˆØ}Š}‰ŒˆàxŠxÐ(¨$Ñ/Ô/Ð/r   c                 óÀ   — t           › d|› d|› d|r|nd› }d| j        i}t          j        ||¬¦  «        }|                     ¦   «         }|                     dd¦  «        S )	a|  
        Get the cash flow statements for a stock `ticker` over a `period` of time.

        :param ticker: the stock ticker
        :param period: the period of time to get the balance sheets for.
            Possible values are: annual, quarterly, ttm.
        :param limit: the number of results to return, default is 10
        :return: a list of cash flow statements
        z(financials/cash-flow-statements/?ticker=r   r   r   r    r!   Úcash_flow_statementsNr$   r)   s           r   Úget_cash_flow_statementsz4FinancialDatasetsAPIWrapper.get_cash_flow_statementse   sŽ   € õ" +ð /ð /Øð/ð /àð/ð /ð  %Ð,ee¨"ð/ð /ð 	ð  ¤Ð.ˆõ ”< ¨WÐ5Ñ5Ô5ˆØ}Š}‰ŒˆàxŠxÐ.°Ñ5Ô5Ð5r   ÚmodeÚkwargsc                 óJ  — |dk    rU|                      dd¦  «        }|                      dd¦  «        }t          j        |                      |||¦  «        ¦  «        S |dk    rU|                      dd¦  «        }|                      dd¦  «        }t          j        |                      |||¦  «        ¦  «        S |dk    rU|                      dd¦  «        }|                      dd¦  «        }t          j        |                      |||¦  «        ¦  «        S t          d|› d	¦  «        ‚)
Nr,   r   Úannualr   r   r/   r2   zInvalid mode z for financial datasets API.)r'   r(   Údumpsr,   r/   r2   r   )r   r3   r   r4   r   r   s         r   ÚrunzFinancialDatasetsAPIWrapper.run…   s  € ØÐ*Ò*Ð*Ø—Z’Z ¨(Ñ3Ô3ˆFØ—J’J˜w¨Ñ+Ô+ˆEÝ”:˜d×8Ò8¸ÀÈÑOÔOÑPÔPÐPØÐ)Ò)Ð)Ø—Z’Z ¨(Ñ3Ô3ˆFØ—J’J˜w¨Ñ+Ô+ˆEÝ”:˜d×5Ò5°f¸fÀeÑLÔLÑMÔMÐMØÐ/Ò/Ð/Ø—Z’Z ¨(Ñ3Ô3ˆFØ—J’J˜w¨Ñ+Ô+ˆEÝ”:˜d×;Ò;¸FÀFÈEÑRÔRÑSÔSÐSåÐO¨TÐOÐOÐOÑPÔPÐPr   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r
   r   ÚstrÚ__annotations__r   r   Úpropertyr   ÚintÚdictr,   r   r/   r2   r8   Ú__classcell__)r   s   @r   r	   r	      s‹  ø€ € € € € € Ø-Ð-à04Ð ¨¤Ð4Ð4Ñ4ð
˜sð 
ð 
ð 
ð 
ð 
ð 
ð ð	/˜#ð 	/ð 	/ð 	/ñ „Xð	/ð3àð3ð ð3ð ˜Œ}ð	3ð
 
$Œð3ð 3ð 3ð 3ð>0àð0ð ð0ð ˜Œ}ð	0ð
 
ˆdŒð0ð 0ð 0ð 0ð>6àð6ð ð6ð ˜Œ}ð	6ð
 
ˆdŒð6ð 6ð 6ð 6ð@Q˜ð Q Sð Q°Cð Q¸Cð Qð Qð Qð Qð Qð Qð Qð Qr   r	   )r<   r(   Útypingr   r   r   r&   Úlangchain_core.utilsr   Úpydanticr   r%   r	   r   r   r   ú<module>rF      s³   ððð ð
 €€€Ø &Ð &Ð &Ð &Ð &Ð &Ð &Ð &Ð &Ð &à €€€Ø 5Ð 5Ð 5Ð 5Ð 5Ð 5Ø Ð Ð Ð Ð Ð àAÐ ðCQð CQð CQð CQð CQ )ñ CQô CQð CQð CQð CQr   