Member-only story
How to Program a Python Script to Track Bitcoin Automatically with Coindesk APIs & Coinbase APIs
While ancient Greek pre-Socratic philosopher Heraclitus says, “τὰ πάντα ῥεῖ καὶ οὐδὲν μένει,” with many translating the phrases differently, at times emphasizing how the universe fluxes, at others how the flux is constant, the phrase’s meaning amounts more powerfully to delineating the inherent property of matter for movement against its complete absence in nothingness: Anything stationary is nothing. In terms crypto currency, nothing could be farther from the truth of its conversions from crypto to fiat. Cryptocurrencies as movement thus live accordingly.
Coindesk APIs
The Coindesk APIs asynchronously update the price by which a crypto currency converts into USD in realtime.
If, for instance, you make a call to the following API endpoint for current prices (i.e., https://api.coindesk.com/v1/bpi/currentprice.json) from Coindesk, the following .json
data returns:
{
"time": {
"updated": "Mar 21, 2022 21:59:00 UTC",
"updatedISO": "2022-03-21T21:59:00+00:00",
"updateduk": "Mar 21, 2022 at 21:59 GMT"
},
"disclaimer": "This data was produced from the CoinDesk Bitcoin Price Index (USD). Non-USD currency data converted using hourly conversion rate from openexchangerates.org",
"chartName": "Bitcoin",
"bpi": {
"USD": {
"code": "USD",
"symbol": "$",
"rate": "41,307.2125",
"description": "United States Dollar",
"rate_float": 41307.2125
},
"GBP": {
"code": "GBP",
"symbol": "£",
"rate": "31,370.2668",
"description": "British Pound Sterling",
"rate_float": 31370.2668
},
"EUR": {
"code": "EUR",
"symbol": "€",
"rate": "37,497.4483",
"description": "Euro",
"rate_float": 37497.4483
}
}
}
Python Requests
Python does not support HTTP/S requests natively. The Requests library does. It facilitates the process of calling API endpoints with the lanugage. The first step to installing the Python Requests library is to ensure pip
is installed in your Python environment.
pip3 install requests
With macOS you need to install pip
with Homebrew. With a Linux kernel like Ubuntu, you install in the following way:
Step 1 — Updating the System
sudo apt-get update