You’ve heard about cryptocurrencies, but do you really understand what they are and how they work?
Cryptocurrencies are digital decentralized currencies that run on the Blockchain technology. The Blockchain runs on millions computers worldwide which are keeping it running 24/7/365. They are called miners and they get rewarded in cryptocurrency for their work.
Cryptocurrencies allow for anyone with an Internet connection to be able to receive money from anyone else in the world in a matter of minutes(or days/weeks for Bitcoin), completely bypassing banks, governments and other central authorities.
Cryptocurrencies have been famously called: The Internet of Money.
Bitcoin is the first cryptocurrency whose paper appeared on October 31st 2008. The paper’s author is called Satoshi Nakamoto, a pseudonym.
Currently thousands of cryptocurrencies exist and each one has its own blockchain.
The more famous ones are Ethereum, Litecoin, Monero, Ripple, ZCash.
Today we’re exploring different types of APIs publicly available to make use of this technology.
To get access to any blockchain you must be connected to a node or miner system which has full copy of said blockchain. This requires considerable amount of computing power, electricity and storage space to manage. That is why blockchain APIs are useful.
They are running a blockchain node for you and exposing its functions through an API.
The most popular blockchain API for Bitcoin is provided by Blockchain.info.
Python users are in luck because they have pip package called blockchain.
pip install blockchain to install it. Full package documentation.
Wallet API (docs)
The wallet API provides interface to programmatically interact with their wallet. To use it you must run their local wallet service for your code to interact with. They have verbose documentation which is quite easy to follow.
You have total control over your wallet with this API, you can create a wallet, check it’s balance, generate wallet addresses, check balance on each address separately. You can also perform transactions i.e. send and receive bitcoin (with 0.0001 BTC fee) (Code samples)
Blockchain data API (docs)
Use this API to get data from Bitcoin’s blockchain.
Get any block, any transaction, all blocks at certain height, latest block on the blockchain.
You can also get more specific data for single address: total Bitcoin received, total Bitcoin sent, final balance, total number of transactions, array of all transactions.
There is also the chart API which provides historical data you can plug directly into most charting libraries. The available types of chart data are price data, market cap, mining difficulty, trade volume, Segwit adoption, blockchain size and others.
Query API (docs)
This API contains a set of useful utilities like transaction lookups, converting a public key to an Address, looking up address balance by number of confirmations and others.
The role of exchanges
We mentioned anyone can buy any cryptocurrency from anyone else. But you still need to find someone to buy it from.
This is the main purpose of cryptocurrency exchanges. They serve as marketplace where people go to exchange cryptocurrency with each other. To accomplish this, exchanges keep an order-book and run a matching algorithm. Anyone can place a buy or sell order on the order-book.
The order-book consists of two sorted lists.
Descending list of buy orders.
Ascending list of sell orders.
This way the person that’s willing to buy for the highest price is first on the buyer’s list and the person willing to sell for the lowest price is first on the seller’s list. The matching engine compares the best buy and sell order and if their prices match, it executes a trade between them. There are exchanges whose domain is trading between cryptocurrencies and fiat currencies like Bitcoin to US dollar or Euro (Coinbase, Bitfinex, Bitstamp). Others specialize in trading only between cryptocurrencies (Poloniex, Bittrex).
Most exchanges expose all trading functionality via their APIs:
Their API is divided in two groups, public and private.
The public API consists of general exchange data not associated with any specific user account.
This includes the latest price data, order-book data and historical trade data.
Commonly used for tracking the price movement in real time and performing trading decisions based on it. Also for merchants who want to accept Bitcoin as payment it is essential to know the latest conversion rate between Bitcoin and the US dollar for example.
Order book data
Useful for analysing trading activity. Key factors which can be derived from this dataset are trades activity (trades per minute), difference between the best buy and sell orders (called spread), the difference in volume between the two sides (where is the market heading).
Historical trade data
Useful for training (AI) trading algorithms and learning from the price movement in the past. However do this with a grain of salt since all cryptocurrencies are still extremely volatile and unexpected things are happening on daily basis.
The private API exposes the full trading functionality of the platform. It requires an account and preferably some funds on it. Everything you can do from the trading platform is also available here:Create buy and sell orders, cancel orders, check their status, view orders history etc.
So far we have only scratched the surface of what cryptocurrencies have to offer. It’s a young technology with changing standards and constant innovation. However the sooner you adopt new technology, the more opportunities you can take advantage of in the future.
Check out our examples in our Github repo, they should be enough to give you a head start on your first crypto project.