Hi, after deep thought I have decided to continue developing the currency exchange application which I have created in the previous chapter and make it a standalone python application. In the previous chapter, we had created a simple interface which will display all the usd/world currencies exchange rate in a tkinter label which we will further modify this interface and make it displays the other currency pair as well as we progress, but before we go even further we do need to convert the currency ID to their real name first, for example, it is very hard for the first timer to know which currency is this by just look at its ID : CAD, if we can convert the ID to the name of that currency then it will be better, for example, CAD = Canadian Dollar. In this chapter, we will just go to make an API call for the ID and the name of all the available currencies and print them out under the console.
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 print(supported_currency) except: print("An exception occurred") for key in exchange_rate['rates']: sell_buy += " Pair : " + exchange_rate['currency'] + "/" + key + " : " + exchange_rate['rates'][key] + '\n' 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()
The above program is about the same as the previous one accepts we have included the call to get the name and id of the available currencies and print out that content.
With that, we will be able to convert the ID of the currency to its real name in the next chapter. I will temporarily leave the cryptocurrency application for a while to finish up this currency exchange application first, in the next chapter we will further modify the user interface of this application.
Hope you like this post, share or follow this website if you want to.
from Planet Python
via read more
No comments:
Post a Comment