Wednesday, February 20, 2019

codingdirectional: Find the Bitcoin exchange rate for a few more currencies

Hello and welcome back to this latest cryptocurrency application project, before we proceed to more complicated user interface design for our new cryptocurrency application I would like to retrieve market data from Coinbase for a few more BTC/World Currency pairs with our new application. We have set up all parts that need for retrieving the market data from Coinbase in the last chapter and in this chapter we will try to retrieve those market data again for different currency/btc pairs.

First of all, we will try to retrieve market data for btc/euro pairs with this statement: “BTC-EUR” and this is what we will get.

BTC/EURO

Next, we will try to retrieve market data for btc/pound pairs with this statement: “BTC- GBP” and this is what we will get.

BTC/GBP

Here is the entire program again.

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-GBP')
        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-GBP')
        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-GBP')
        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()

It seems like the BTC/USD exchange rate is up again today till 3,930.47 United States Dollar as compared to yesterday but before we all happy about this outcome we need to be very cautious because the USD exchange rate vs other major world currencies is slightly down again so we need to compare the exchange rate of BTC vs other major world currencies as well before we said that BTC is up again. In the next chapter we will retrieve the market data for bitcoin vs other cryptocurrencies and then we will improve the user interface of this application so it can display all the exchange rates at once.

Hello people, if you like to read about some other internet stuffs like social networking and online earning then come and read this latest article of mine: A Social Network for Photographer!

We are using the Coinbase API for the above project and if you have not yet signed up for a free account on Coinbase then you can sign up through this link.

If you like this website then do consider to donate cryptocurrency to this website through below address.

  • 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...