Wednesday, February 27, 2019

codingdirectional: Include the currency name into the forex application

Hello and welcome back to this new python forex application project. In the previous chapter, we have successfully retrieved the name and the id pair for all the conbase supported currencies, and in this chapter, we will use that information to add the currency name beside each currency id when we are comparing that currency to the USD. Below is the modify version of this program.

from coinbase.wallet.client import Client
import json
from tkinter import *
import tkinter.ttk as tk

win = Tk() # Create tk instance
win.title("Real CryptoGeek") # Add a title
win.resizable(0, 0) # Disable resizing the GUI
win.configure(background='white') # change background color

s = StringVar() # change text
currencyFrame = Frame(win) # create currency frame
currencyFrame.pack(side=TOP)
currency = Label(currencyFrame)
currency.pack()
text_widget = Text(currency, fg='white', background='black')
text_widget.pack()

s.set("Click the below button to find out the bitcoin exchange rate")
text_widget.insert(END, s.get())

buttonFrame = Frame(win) # create a button frame
buttonFrame.pack(side = BOTTOM, fill=X, pady = 6)

def get_exchange_rate():

    f = open("coin.txt", "r")
    api_key = f.readline()
    api_secret = f.readline()
    f.close()

    sell_buy = ''

    api_key = api_key.replace('\n', '')
    api_secret = api_secret.replace('\n', '')

    try:
        client = Client(api_key, api_secret)
        market_currencies_o = client.get_exchange_rates()
        market_currencies_s = json.dumps(market_currencies_o)
        exchange_rate = json.loads(market_currencies_s)
        supported_currency = client.get_currencies() # get all the available currencies
        exchange_rate_s = json.loads(json.dumps(supported_currency))

    except:
        print("An exception occurred")

    exchange_name_dict = dict()

    for key in exchange_rate_s['data']:
        id = key['id']
        name = key['name']
        obj_currency = {id:name}
        exchange_name_dict.update(obj_currency)

    count = 0
    found = False
    for key in exchange_rate['rates']:
        count += 1
        for e_key in exchange_name_dict:
            if(e_key == key):
                sell_buy += str(count) + ".) Pair : " + exchange_rate['currency'] + "/" + key + " (" + exchange_name_dict[e_key] + ") : " + \
                exchange_rate['rates'][key] + '\n'
                found = True
                break
        if(found == False):
            sell_buy += str(count) + ".) Pair : " + exchange_rate['currency'] + "/" + key + " : " + \
                exchange_rate['rates'][key] + '\n'
        else:
            found = False

    text_widget.delete('1.0', END) # clear all those previous text first
    s.set(sell_buy)
    text_widget.insert(INSERT, s.get())

action_vid = tk.Button(buttonFrame, text="Find", command=get_exchange_rate) # find out the exchange rate of bitcoin
action_vid.pack(fill=X)
win.mainloop()

By introducing the new exchange name dictionary to the above program, that program can now place the currency name next to the id of that currency if that name is inside the object returned by the coinbase API.

Like, share or follow me on twitter. In the next chapter, we will continue to develop this new forex application. This website depends on the reader supports to survive, if you have cryptocurrency do consider to donate to this website.

  • Bitcoin
  • Bitcoin cash
  • Litecoin
  • Stellar
Scan to Donate Bitcoin to 38han7NG6KHtxZsS4ppTwAtSw7UfLSY5Vd

Donate Bitcoin to this address

Scan the QR code or copy the address below into your wallet to send some Bitcoin

Scan to Donate Bitcoin cash to qqegrlxc93q5ah0s2s6w9zxwf685vr26nu0kxlkvpc

Donate Bitcoin cash to this address

Scan the QR code or copy the address below into your wallet to send some Bitcoin cash

Scan to Donate Litecoin to MJJ2T1XyD4NtSjTA3NpcqTuaTaCKfT3fdA

Donate Litecoin to this address

Scan the QR code or copy the address below into your wallet to send some Litecoin

Scan to Donate Stellar to GAJRUOEMPNSHHR2ZB4KOOQ3MIR2BN54BBXGHTYA6QWMGST7AGI46WIHU

Donate Stellar to this address

Scan the QR code or copy the address below into your wallet to send some Stellar



from Planet Python
via read more

No comments:

Post a Comment

TestDriven.io: Working with Static and Media Files in Django

This article looks at how to work with static and media files in a Django project, locally and in production. from Planet Python via read...