Tuesday, February 19, 2019

codingdirectional: Creating a cryptocurrency user interface project with python

Hello and welcome to the brand new python project where we are going to create a cryptocurrency application with python. I am researching the bitcoin and other cryptocurrencies at this moment so it will be nice for me to create a cryptocurrencies application for these purposes as well. Hopefully, this new application will help both you and me to better understand how to buy or sell any cryptocurrency at the end of this topic. This will be a long project and we will use the Coinbase api together with the tkinter interface to retrieve and display the cryptocurrency data as well as our own Coinbase personal account information that we are looking for. Alright, without any delay, let us begin.

The first thing we need to do is to install the Coinbase module on our computer. Open up the windows command prompt and type in pip install coinbase to install the coinbase module. I am using windows 10 os but the installation process should be about the same for other os as well.

Now we have the coinbase module installed on our pc. It is time to get a free coinbase account so we can use it’s api. If you already have an account then you can skip this part or else just go ahead and sign up for your free account on Coinbase through this link. By signing up a free account you will get a free wallet for each cryptocurrency so you can receive bitcoin or other coins from a friend. After you have signed up an account go to the Settings tab, then select the API Access tab and then click on the New API Key button and select all the coinbase api’s features that you need and enter the verification code which Coinbase has sent to your handphone to get both the api key and the api secret that we need for this project. Make sure you keep the key and secret in a safe place or perhaps write them down on a piece of paper. The api activation process will take 48 hours and once the api has been activated you can go ahead and enter the below python code to see whether does the api works as normal or not.

from coinbase.wallet.client import Client
import json

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','')

client = Client(api_key, api_secret)
market_currencies = client.get_sell_price(currency_pair = 'BTC-USD')
market_as_json_string = json.dumps(market_currencies)

print(market_as_json_string)

What we did above is to find out what is the selling price for 1 bitcoin vs us dollar. We will keep the api key in the first row and the secret in the second row in a text file and then read them both from the above program. We need to use json module to assist us in this example. If the api has been activated then you will see the below outcome.

selling price for 1 bitcoin vs usd

That is it for now, in the next chapter we will really build a cryptocurrency application with the help of tkinter and I believe it will be another great project for us all. Make sure you get the api key after you have signed up so we can start this new project together.



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