def base(): """Show base.html.""" c = CurrencyRates() x = c.get_rates("USD") res = {item: "{0:.2f}".format(round(x[item], 2)) for item in x} session["rates"] = res b = BtcConverter() bit = {} bit["bitcoin_usd"] = round(b.get_latest_price("USD"), 2) bit["bitcoin_eur"] = round(b.get_latest_price("EUR"), 2) bit["bitcoin_gbp"] = round(b.get_latest_price("GBP"), 2) cc = CurrencyCodes() bit["name_usd"] = cc.get_currency_name("USD") bit["name_eur"] = cc.get_currency_name("EUR") bit["name_gbp"] = cc.get_currency_name("GBP") bit["symbol"] = b.get_symbol() bit["symbol_eur"] = cc.get_symbol("EUR") bit["symbol_gbp"] = cc.get_symbol("GBP") session["bit"] = bit return render_template("base.html", rates=res, bit=bit)
def pullData(): t = '{:%H:%M:%S}'.format(datetime.datetime.now() + datetime.timedelta(hours=1)) #t = time.strftime("%H:%M:%S") print("Starting at number: " + str(datetime.datetime.utcnow())) # Using forex to get latest data: https://media.readthedocs.org/pdf/forex-python/latest/forex-python.pdf c = CurrencyRates() b = BtcConverter() rates = c.get_rates(config.LOCAL_CURR_CODE) pop = False # Adapted from: https://stackoverflow.com/questions/30071886/how-to-get-current-time-in-python-and-break-up-into-year-month-day-hour-minu chart_data['labels'].append(t) # If 20 dates are already currently in the list - pop. if len(chart_data['labels']) >= 20: chart_data['labels'].pop(0) pop = True # Loop through array of datasets to append or append and pop. if chart_data['datasets']: for i, code in enumerate(config.CURR_CODES): if code == 'BTC': price = round(b.get_latest_price(config.LOCAL_CURR_CODE), 2) rate = round(b.convert_to_btc(1, config.LOCAL_CURR_CODE), 5) else: price = round(c.get_rate(code, config.LOCAL_CURR_CODE), 2) rate = round(rates[chart_data['datasets'][i]['label']], 5) chart_data['datasets'][i]['data'].append(price) latest_currencies['currencies'][i]['data'] = rate if pop: chart_data['datasets'][i]['data'].pop(0) else: co = CurrencyCodes() # Prepare data objects and pull first prices. for i, code in enumerate(config.CURR_CODES): if code == 'BTC': symbol = b.get_symbol() name = 'Bitcoin' price = round(b.get_latest_price(config.LOCAL_CURR_CODE), 2) rate = round(b.convert_to_btc(1, config.LOCAL_CURR_CODE), 5) else: name = co.get_currency_name(code) symbol = co.get_symbol(code) price = round(c.get_rate(code, config.LOCAL_CURR_CODE), 2) rate = round(rates[code], 5) chart_data['datasets'].append({ 'label': code, 'backgroundColor': config.CURR_COLORS[i], 'data': [price] }) latest_currencies['currencies'].append({ 'code': code, 'name': name, 'symbol': symbol, 'data': rate }) r.set(config.REDIS_CHAN_LIST, latest_currencies) r.set(config.REDIS_CHAN_GRAPH, chart_data) print("Finishing at number: " + str(datetime.datetime.utcnow()))
#Get the data amount = float(input('Enter the Amount you want to Convert: ')) from_currency = input('From : ').upper() to_currency = input('To : ').upper() print('\n' + from_currency + " To " + to_currency, amount) print('The current conversion rate for {} to {} is {}'.format(from_currency, to_currency, c.get_rate(from_currency, to_currency))) #Get conversion rate from USD to INR result = c.convert(from_currency, to_currency, amount) #Convert the amount print('Latest Conversion: ',result) #Get conversion rate as of 2021-01-01 print('\nThe conversion rate from {} to {} as per 1st Jan 2021 is {}'.format(from_currency, to_currency, c.get_rate(from_currency, to_currency, date_obj))) print('The conversion as per 1st Jan 2021: ', c.convert(from_currency, to_currency, amount, date_obj)) b = BtcConverter() print('\n\nBitcoin Symbol: ', b.get_symbol()) # get_btc_symbol() print('Bitcoin Latest Price in USD : ', b.get_latest_price('USD')) #Get latest Bitcoin price. print('Convert 10 Million USD to Bitcoin', b.convert_to_btc(10000000, 'USD')) #Convert Amount to Bitcoins based on latest exchange price. print('The Equivalent of 10.99 Bitcoin in USD: ',b.convert_btc_to_cur(10.99, 'USD')) #Convert Bitcoins to valid currency amount based on lates price print('\nBitcoin price as per 1st Jan 2021: ',b.get_previous_price('USD', date_obj)) #Get price of Bitcoin based on prevois date print('The conversion of 10 Million Dollars to Bitcoin as of 1st Jan 2021',b.convert_to_btc_on(10000000, 'USD', date_obj)) #Convert Amount to bitcoins based on previous date prices print('The conversion of 10.99 Bitcoin in USD as of 1st Jan 2021: ',b.convert_btc_to_cur_on(10.99, 'USD', date_obj)) #Convert Bitcoins to valid currency amount based on previous date price start_date = datetime.datetime(2021, 2, 1, 19, 39, 36, 815417) end_date = datetime.datetime(2021, 2, 7, 19, 39, 36, 815417) print('\nBitcoin rates over the week in USD: ',b.get_previous_price_list('USD', start_date, end_date)) #Get list of prices list for given date range d = CurrencyCodes() print('\nUS Dollar Symbol:', d.get_symbol('USD')) #Get currency symbol using currency code print(d.get_currency_name('USD')) #Get Currency Name using currency code
from forex_python.bitcoin import BtcConverter from forex_python.converter import CurrencyCodes b = BtcConverter() c = CurrencyCodes() # print(b.get_latest_price("INR")) #quantity,currency (input) --> output price quantity = float(input("Enter the quantity of Bitcoin you wanna Buy : ")) currency = input("Currency you wanna pay : ") currency_symbol = c.get_symbol(currency) bitcoin_symbol = b.get_symbol() price = b.convert_btc_to_cur(quantity,currency) print(f"{quantity}{bitcoin_symbol} : {currency_symbol}{price}")