def convert_to_btc(self, amount, currency):
        """
        Convert X amount to Bit Coins
        """
        if isinstance(amount, Decimal):
            use_decimal = True
        else:
            use_decimal = self._force_decimal

        url = 'https://api.coindesk.com/v1/bpi/currentprice/{}.json'.format(currency)
        response = requests.get(url)
        if response.status_code == 200:
            data = response.json()
            price = data.get('bpi').get(currency, {}).get('rate_float', None)
            if price:
                if use_decimal:
                    price = Decimal(price)
                try:
                    converted_btc = amount/price
                    return converted_btc
                except TypeError:
                    raise DecimalFloatMismatchError("convert_to_btc requires amount parameter is of type Decimal when force_decimal=True")
        raise RatesNotAvailableError("BitCoin Rates Source Not Ready For Given date")
def convert_to_btc ( self , amount , currency ) : if isinstance ( amount , Decimal ) : use_decimal = True else : use_decimal = self . _force_decimal url = 'https://api.coindesk.com/v1/bpi/currentprice/{}.json' . format ( currency ) response = requests . get ( url ) if response . status_code == 200 : data = response . json ( ) price = data . get ( 'bpi' ) . get ( currency , { } ) . get ( 'rate_float' , None ) if price : if use_decimal : price = Decimal ( price ) try : converted_btc = amount / price return converted_btc except TypeError : raise DecimalFloatMismatchError ( "convert_to_btc requires amount parameter is of type Decimal when force_decimal=True" ) raise RatesNotAvailableError ( "BitCoin Rates Source Not Ready For Given date" )
Convert X amount to Bit Coins