API for Bitcoin Data
5 stars based on
80 reviews
The first installment in the series is going to cover building a script for tracking your Bitcoin profits or losses. We often find ourselves checking the bitcoin price multiple times a day, waiting for the next peak or valley. We all want to make some profit. Often times this becomes distracting and time consuming, but not anymore.
We will be building a script which automatically checks the price at your favorite exchange and notifies you of the profit you've made. If you just want to run the script without digging into it you can find the github link at the end with the full code. So just copy and paste the code into a file and run it via terminal:. To be able to generate a key pair you must have an account at BitcoinAverage. After you create and verify your account you can generate the API key pair at the Api keys page.
Bitcoin price api python example you need to copy the public key and the secret key into the starting code snippet for our script below. This function will use your secret and public key to generate a signature that will be sent with each HTTP request that you make later on. The algorithm for signature creation is very simple. First we concatenate the current timestamp in UTC with the public key with a ".
Then we encrypt the bitcoin price api python example string bitcoin price api python example our secret key and the SHA algorithm which is already implemented in almost all programming languages. Finally we get the encrypted value and concatenate it, again with a ".
For example the final signature would look something like this:. But before we start coding make sure you have the awesome bitcoin price api python example http library installed. As you see from this response you can discover all the available trading pairs at your exchange and you might want to extend this script and perform the profits check calculation on more than one trading pair. But first let's cover what these values mean, ask, bid, last and volume. The highest price at which someone is willing to buy Bitcoin.
The lowest price at which someone is willing to sell Bitcoin. The total number of Bitcoin bought and sold at this exchange in the last 24 hours.
From these values we are only interested in the "bid" value because if we were to sell our coins right now, that is the price we would get for them. What we're doing here is comparing the bitcoin price api python example price with the latest bid price we got from the API.
If the script is setup to check in percent, we're doing that, otherwise we're checking for the absolute difference in dollars between the two prices. If the latest price has deviated from the starting price more than a certain amount then we are constructing a helpful message that we will present to the end user. First we're getting all the data we need from the user and then using infinite looping while True: If this function happens to return us some answer, that means there is something to show to the user.
Depending on his choosing either Linux or Mac desktop notification will be generated. If he hasn't chosen notifications, or is a Windows user, the message will be printed in the terminal. I have only tried this on Ubuntu Linux, so these might bitcoin price api python example work on other Linux distros.
The library for generating notifications is called notify-send and it's very simple to use. In our example above I am running it like this. For Mac we're bitcoin price api python example the osascript command which lets us run AppleScript commands bitcoin price api python example inside the terminal.
The command for showing a notification is as follows:. The full code can be found here: Next Post Previous Post. We are starting a new series of guides with awesome ways to use our new API. The first installment in the series is going to cover building a script for tracking your Bitcoin profits or losses ; We often find ourselves checking the bitcoin price multiple times a day, waiting for the next peak or valley.
So just copy and paste the code into a file and run it via terminal: Your exchange - the exchange you want to check at, this is the exchange where you plan to sell the bitcoin eventually, or just your favorite one.
Bitcoin starting price - The price at which you bought your coins. Bitcoin amount - The amount of bitcoin you bought. Check every seconds - The script performs the calculation in an infinite loop, so this parameter tells it how much to wait between executions. Choose to be notified when a certain limit is reached 1 Percent limit: Here you specify when you want to be notified of the change in price in Bitcoin.
If you choose 1 percentthen you will be asked to enter the amount of bitcoin price api python example. The second option allows you to specify the exact amount, here if you enter 10 you will be notified when the Bitcoin price deviates 10 US dollars from the starting price if you've chosen dollars for your currency.
For example the final signature would look something like this: The exchange where bitcoin was bought: The price at which bitcoin was bought: The amount of bitcoin: The currency bitcoin was bought in: The type of threshold, percent or amount: The value of the threshold: Linux desktop notifications I have only tried this on Ubuntu Linux, so these might not work on other Linux distros. Mac desktop notifications For Mac we're using the osascript command which lets us run AppleScript commands from inside the terminal.
The command for showing a notification is as follows: Random Article I'm Feeling Lucky! Popular Tags bitcoin price bitcoin news analysis report API price report bitcoin technical analysis bitcoinaverage echo blockchain debate segwit Guide blackfriday discount ripple skill ethereum reward halving subscription bitcoin price api python example feature amazon alexa migrate.