Ejemplo n.º 1
0
def get_price_investpy(sname, sticker, stype, scountry):
    if stype == "Stock":
        try:
            df = investpy.get_stock_recent_data(sname, scountry)
        except RuntimeError:
            try:
                df = investpy.get_stock_recent_data(sticker, scountry)
            except RuntimeError:
                raise MethodNotWorkingError
    elif stype == "Fund":
        try:
            df = investpy.get_fund_recent_data(sname, scountry)
        except RuntimeError:
            try:
                df = investpy.get_fund_recent_data(sticker, scountry)
            except RuntimeError:
                raise MethodNotWorkingError
    elif stype == "ETF":
        try:
            df = investpy.get_etf_recent_data(sname, scountry)
        except RuntimeError:
            try:
                df = investpy.get_etf_recent_data(sticker, scountry)
            except RuntimeError:
                raise MethodNotWorkingError
    elif stype == "Crypto":
        try:
            df = investpy.get_crypto_recent_data(sname)
        except RuntimeError:
            try:
                df = investpy.get_crypto_recent_data(sticker)
            except RuntimeError:
                raise MethodNotWorkingError
    else:
        raise MethodNotWorkingError

    return df.iloc[-1]['Close']
Ejemplo n.º 2
0
def test_investpy_cryptos():
    """
    This function checks that crypto currencies data retrieval functions listed in investpy work properly.
    """
    
    investpy.get_cryptos()
    investpy.get_cryptos_list()

    params = [
        {
            'columns': None,
            'as_json': False
        },
        {
            'columns': ['name', 'symbol', 'currency'],
            'as_json': False
        },
        {
            'columns': None,
            'as_json': True
        },    
    ]

    for param in params:
        investpy.get_cryptos_dict(columns=param['columns'],
                                  as_json=param['as_json'])

    params = [
        {
            'as_json': True,
            'order': 'ascending',
        },
        {
            'as_json': False,
            'order': 'ascending',
        },
        {
            'as_json': True,
            'order': 'descending',
        },
        {
            'as_json': False,
            'order': 'descending',
        },
    ]

    for param in params:
        investpy.get_crypto_recent_data(crypto='bitcoin',
                                        as_json=param['as_json'],
                                        order=param['order'],
                                        interval='Daily')

        investpy.get_crypto_historical_data(crypto='bitcoin',
                                            from_date='01/01/1990',
                                            to_date='01/01/2019',
                                            as_json=param['as_json'],
                                            order=param['order'],
                                            interval='Daily')

    params = [
        {
            'crypto': 'bitcoin',
            'as_json': False
        },
        {
            'crypto': 'bitcoin',
            'as_json': True
        }
    ]

    for param in params:
        investpy.get_crypto_information(crypto=param['crypto'], as_json=param['as_json'])
    
    params = [
        {
            'as_json': False,
            'n_results': 10
        },
        {
            'as_json': True,
            'n_results': 10
        },
        {
            'as_json': False,
            'n_results': 110
        },
        {
            'as_json': True,
            'n_results': 110
        },
        {
            'as_json': False,
            'n_results': None
        },
        {
            'as_json': True,
            'n_results': None
        },
    ]

    for param in params:
        investpy.get_cryptos_overview(as_json=param['as_json'], n_results=param['n_results'])

    investpy.search_cryptos(by='name', value='bitcoin')