Hello and welcome back, in this chapter we will start to build our cryptocurrency application with the help of the Coinbase API as well as the tkinter module. There is a lot of data Coinbase has to offer to the developer include the personal account data, cryptocurrency wallet data, transaction data and so on. Our main interest in this stage of the project is the market data where we are going to retrieve the sell/buy/spot price data for various cryptocurrency/world currency pairs and display them on the label part of our tkinter user interface. If you have not yet signed up for a free Coinbase account then you can do so through this link. You will need a Coinbase account in order to use the Coinbase api to develop this python application. If you want to know how to get the api key and secret to develop this application then do read this previous article to find it out.
Now we will start to develop the cryptocurrency application. In this article, we just want to make sure things work as expected so we will retrieve the buy, sell and spot price for 1 bitcoin vs us dollar. I have taken a quick look at the common exchange rate of 1 bitcoin vs us dollar on google and here is what I see, 3,877.50 United States Dollar vs a Bitcoin, the price will go up or down all days long just like the stock market. Coinbase will provide us with more detail data for bitcoin vs USD, the selling price, buying price, and the market price.
Below is the python program where the tkinter module will generate a label and a button which after we have clicked on that button the label will show all those data that we have mentioned above on the label’s body.
from coinbase.wallet.client import Client import json from tkinter import * from tkinter import filedialog import tkinter.ttk as tk from tkinter import messagebox 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, fill=X) currency = Label(currencyFrame, textvariable=s) currency.pack() s.set("Click the below button to find out the bitcoin exchange rate") 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() api_key = api_key.replace('\n', '') api_secret = api_secret.replace('\n', '') try: client = Client(api_key, api_secret) market_currencies_o = client.get_sell_price(currency_pair='BTC-USD') market_currencies_s = json.dumps(market_currencies_o) exchange = json.loads(market_currencies_s) coin_type = exchange['base'] currency_type = exchange['currency'] currency_sell_price = exchange['amount'] market_currencies_o = client.get_buy_price(currency_pair='BTC-USD') market_currencies_s = json.dumps(market_currencies_o) exchange = json.loads(market_currencies_s) currency_buy_price = exchange['amount'] market_currencies_o = client.get_spot_price(currency_pair='BTC-USD') market_currencies_s = json.dumps(market_currencies_o) exchange = json.loads(market_currencies_s) currency_spot_price = exchange['amount'] except: print("An exception occurred") sell_buy = " Pair : " + coin_type + "/" + currency_type + " Sell : " + currency_sell_price + " Buy : " + currency_buy_price + " Spot : " + currency_spot_price s.set(sell_buy) 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()
After we have clicked on the button this is what we see.
Bitcoin price is climbing back from 3500 USD / Bitcoin which is a great sign of recovery, I am monitoring the price movement of bitcoin every day and if you are interested in Bitcoin and the other cryptocurrency then do join in the conversation in this newly created special dedicated website for bitcoin and the other cryptocurrency.
So much for this one, in the next chapter, we will continue to develop this part of the application. Have extra coin? Do consider to donate them to this website, thank you in advance.
- Bitcoin
- Bitcoin cash
- Litecoin
- Stellar
Donate Bitcoin to this address
Scan the QR code or copy the address below into your wallet to send some Bitcoin
Donate Bitcoin cash to this address
Scan the QR code or copy the address below into your wallet to send some Bitcoin cash
Donate Litecoin to this address
Scan the QR code or copy the address below into your wallet to send some Litecoin
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