Tuesday, July 30, 2019

IslandT: Use Blockchain API to retrieve the Bitcoin exchange rate within the 15 minutes period of the time

Hello and welcome back, in this article we will continue to develop the cryptocurrency application. In the previous few chapters, we had only used the cryptocompare API to make the REST call but in this chapter, we will add in the blockchain package which has the exchangerates module that we can use to retrieve the 15 minutes period of the time of the Bitcoin / major world currencies pair exchange rate. Since we will load the data from blockchain once the user has pressed the load button, we can now safely ignore the data from the previous cryptocompare rest call.

At the beginning of the program we will import the exchangerates module as well as get the ticker object from blockchain (rest call).

from blockchain import exchangerates
try:
    ticker = exchangerates.get_ticker() # get the ticker object from blockchain
except:
    print("An exception occurred")

Next, we will comment out the line to use the cryptocampare data under the get_exchange_rate method and add in a few lines of code to use the blockchain market data.

    for key, value in exchange_rate_s.items():  # populate exchange rate string and the currency tuple
        #sell_buy += base_crypto + ":" + key + "  " + str(value) + "\n"
        curr1 += (key,)
sell_buy += "Bitcoin : Currency price every 15 minute:" + "\n\n"
    # print the 15 min price for every bitcoin/currency
    for k in ticker:
        sell_buy += "BTC:" + str(k) + " " + str(ticker[k].p15min) + "\n"

If we load the data we will see the below outcome.

BTCOIN VS WORLD CURRENCIES PRICE

If you want to see the entire source code then please go back to the previous chapter to read them.

Are you a developer or a python programmer? Join mine private chat room through this link to see what am I working on right now.



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