
    fi                        d Z ddlZddlZ	 ddedededej        fd	Z	 d dededededej        f
dZ	 	 	 	 	 d!dedededededej        fdZd"dededej        fdZ		 	 	 	 d#dededededej        f
dZ
edk    r edd          Z ee            edd
d          Z ee            edd
ddd          Z ee            e	dd          Z ee            e
dddd          Z ee           dS dS )$u   
Date: 2023/7/24 18:30
Desc: currencybeacon 提供的外汇数据
该网站需要先注册后获取 API 使用
https://currencyscoop.com/
    NUSD basesymbolsapi_keyreturnc                 H   | ||d}d}t          j        ||          }t          j                            |                                d                   }t          j        |d                   |d<   |                    d           |                    dd	id
           |S )a  
    Latest data from currencyscoop.com
    https://currencyscoop.com/api-documentation
    :param base: The base currency you would like to use for your rates
    :type base: str
    :param symbols: A list of currencies you will like to see the rates for. You can refer to a list all supported currencies here
    :type symbols: str
    :param api_key: Account -> Account Details -> API KEY (use as password in external tools)
    :type api_key: str
    :return: Latest data of base currency
    :rtype: pandas.DataFrame
    )r   r   r   z'https://api.currencyscoop.com/v1/latestparamsresponsedateTinplaceindexcurrencycolumnsr   )	requestsgetpd	DataFrame	from_dictjsonto_datetimereset_indexrename)r   r   r   r   urlrtemp_dfs          D/usr/local/lib/python3.11/dist-packages/akshare/currency/currency.pycurrency_latestr!      s     w7CCF
3CS(((Al$$QVVXXj%9::GnWV_55GFO%%%NNGZ0$N???N    
2023-02-03r   c                 ^   | |||d}d}t          j        ||          }t          j                            |                                d                   }t          j        |d                   j        j        |d<   |	                    d           |
                    dd	id
           |S )aU  
    Latest data from currencyscoop.com
    https://currencyscoop.com/api-documentation
    :param base: The base currency you would like to use for your rates
    :type base: str
    :param date: Specific date, e.g., "2020-02-03"
    :type date: str
    :param symbols: A list of currencies you will like to see the rates for. You can refer to a list all supported currencies here
    :type symbols: str
    :param api_key: Account -> Account Details -> API KEY (use as password in external tools)
    :type api_key: str
    :return: Latest data of base currency
    :rtype: pandas.DataFrame
    )r   r   r   r   z+https://api.currencyscoop.com/v1/historicalr
   r   r   Tr   r   r   r   )r   r   r   r   r   r   r   dtr   r   r   )r   r   r   r   r   r   r   r   s           r    currency_historyr&   '   s    " DWQQF
7CS(((Al$$QVVXXj%9::GnWV_558=GFO%%%NNGZ0$N???Nr"   
2023-03-04
start_dateend_datec                 n   | ||||d}d}t          j        ||          }t          j                            |                                d                   }|j        }|                    d           |                    ddid	           t          j	        |d                   j
        j        |d<   |S )
a  
    Time-series data from currencyscoop.com
    P.S. need special authority
    https://currencyscoop.com/api-documentation
    :param base: The base currency you would like to use for your rates
    :type base: str
    :param start_date: Specific date, e.g., "2020-02-03"
    :type start_date: str
    :param end_date: Specific date, e.g., "2020-02-03"
    :type end_date: str
    :param symbols: A list of currencies you will like to see the rates for. You can refer to a list all supported currencies here
    :type symbols: str
    :param api_key: Account -> Account Details -> API KEY (use as password in external tools)
    :type api_key: str
    :return: Latest data of base currency
    :rtype: pandas.DataFrame
    )r   r   r(   r)   r   z+https://api.currencyscoop.com/v1/timeseriesr
   r   Tr   r   r   r   )r   r   r   r   r   r   Tr   r   r   r%   r   )	r   r(   r)   r   r   r   r   r   r   s	            r    currency_time_seriesr,   B   s    2   F 8CS(((Al$$QVVXXj%9::GiG%%%NNGV,dN;;;nWV_558=GFONr"   fiatc_typec                     | |d}d}t          j        ||          }|                                }t          j        |d                   }|S )ae  
    currencies data from currencyscoop.com
    https://currencyscoop.com/api-documentation
    :param c_type: now only "fiat" can return data
    :type c_type: str
    :param api_key: Account -> Account Details -> API KEY (use as password in external tools)
    :type api_key: str
    :return: Latest data of base currency
    :rtype: pandas.DataFrame
    )typer   z+https://api.currencyscoop.com/v1/currenciesr
   r   )r   r   r   r   r   )r.   r   r   r   r   	data_jsonr   s          r    currency_currenciesr2   k   sP     11F
7CS(((AIl9Z011GNr"   CNY10000toamountc                 @   | |||d}d}t          j        ||          }t          j        |                                d                   }t          j        |d         d          |d<   |                                }|                    d	           d
dg|_        |S )a  
    currencies data from currencyscoop.com
    https://currencyscoop.com/api-documentation
    :param base: The base currency you would like to use for your rates
    :type base: str
    :param to: The currency you would like to use for your rates
    :type to: str
    :param amount: The amount of base currency
    :type amount: str
    :param api_key: Account -> Account Details -> API KEY (use as password in external tools)
    :type api_key: str
    :return: Latest data of base currency
    :rtype: pandas.Series
    )fromr5   r6   r   z(https://api.currencyscoop.com/v1/convertr
   r   	timestamps)unitTr   itemvalue)	r   r   r   Seriesr   r   to_framer   r   )	r   r5   r6   r   r   r   r   temp_ser   s	            r    currency_convertrA   ~   s    * 	 F 5CS(((Ai,--G>'+*>SIIIGK  G%%%w'GONr"   __main__)r   r   )r   r   r   )r   r(   r)   r   r   )r.   r   )r   r5   r6   r   )r   r   r   )r   r#   r   r   )r   r#   r'   r   r   )r-   r   )r   r3   r4   r   )__doc__pandasr   r   strr   r!   r&   r,   r2   rA   __name__currency_latest_dfprintcurrency_history_dfcurrency_time_series_dfcurrency_currencies_dfcurrency_convert_se r"   r    <module>rN      s         :< 
 #36\   4 TV 
 :=MP\   8 " & &
&& & 	&
 & \& & & &R  s BL    ( 	! !
!! ! 	!
 \! ! ! !H z(eR@@@	E
**LRTUUU	E
22   
E
!"""00KKK	E
 !!!**uWb   
E
- r"   