def get_current_price(crypto, fiat, services=None, convert_to=None, helper_prices=None, **modes):
    """
    High level function for getting current exchange rate for a cryptocurrency.
    If the fiat value is not explicitly defined, it will try the wildcard service.
    if that does not work, it tries converting to an intermediate cryptocurrency
    if available.
    """
    fiat = fiat.lower()
    args = {'crypto': crypto, 'fiat': fiat, 'convert_to': convert_to}

    if not services:
        services = get_optimal_services(crypto, 'current_price')

    if fiat in services:
        # first, try service with explicit fiat support
        try_services = services[fiat]
        result = _try_price_fetch(try_services, args, modes)
        if not isinstance(result, Exception):
            return result

    if '*' in services:
        # then try wildcard service
        try_services = services['*']
        result = _try_price_fetch(try_services, args, modes)
        if not isinstance(result, Exception):
            return result

    def _do_composite_price_fetch(crypto, convert_crypto, fiat, helpers, modes):
        before = modes.get('report_services', False)
        modes['report_services'] = True
        services1, converted_price = get_current_price(crypto, convert_crypto, **modes)
        if not helpers or convert_crypto not in helpers[fiat]:
            services2, fiat_price = get_current_price(convert_crypto, fiat, **modes)
        else:
            services2, fiat_price = helpers[fiat][convert_crypto]

        modes['report_services'] = before

        if modes.get('report_services', False):
            #print("composit service:", crypto, fiat, services1, services2)
            serv = CompositeService(services1, services2, convert_crypto)
            return [serv], converted_price * fiat_price
        else:
            return converted_price * fiat_price

    all_composite_cryptos = ['btc', 'ltc', 'doge', 'uno']
    if crypto in all_composite_cryptos: all_composite_cryptos.remove(crypto)
    for composite_attempt in all_composite_cryptos:
        if composite_attempt in services and services[composite_attempt]:
            result = _do_composite_price_fetch(
                crypto, composite_attempt, fiat, helper_prices, modes
            )
            if not isinstance(result, Exception):
                return result

    raise result
def get_current_price ( crypto , fiat , services = None , convert_to = None , helper_prices = None , ** modes ) : fiat = fiat . lower ( ) args = { 'crypto' : crypto , 'fiat' : fiat , 'convert_to' : convert_to } if not services : services = get_optimal_services ( crypto , 'current_price' ) if fiat in services : try_services = services [ fiat ] result = _try_price_fetch ( try_services , args , modes ) if not isinstance ( result , Exception ) : return result if '*' in services : try_services = services [ '*' ] result = _try_price_fetch ( try_services , args , modes ) if not isinstance ( result , Exception ) : return result def _do_composite_price_fetch ( crypto , convert_crypto , fiat , helpers , modes ) : before = modes . get ( 'report_services' , False ) modes [ 'report_services' ] = True services1 , converted_price = get_current_price ( crypto , convert_crypto , ** modes ) if not helpers or convert_crypto not in helpers [ fiat ] : services2 , fiat_price = get_current_price ( convert_crypto , fiat , ** modes ) else : services2 , fiat_price = helpers [ fiat ] [ convert_crypto ] modes [ 'report_services' ] = before if modes . get ( 'report_services' , False ) : serv = CompositeService ( services1 , services2 , convert_crypto ) return [ serv ] , converted_price * fiat_price else : return converted_price * fiat_price all_composite_cryptos = [ 'btc' , 'ltc' , 'doge' , 'uno' ] if crypto in all_composite_cryptos : all_composite_cryptos . remove ( crypto ) for composite_attempt in all_composite_cryptos : if composite_attempt in services and services [ composite_attempt ] : result = _do_composite_price_fetch ( crypto , composite_attempt , fiat , helper_prices , modes ) if not isinstance ( result , Exception ) : return result raise result
High level function for getting current exchange rate for a cryptocurrency.
    If the fiat value is not explicitly defined, it will try the wildcard service.
    if that does not work, it tries converting to an intermediate cryptocurrency
    if available.