In this article we’ll go over a few scenarios and code examples about how to track the biggest winners within the crypto market in a short period, a week or a month.

You can inspect the coins you are actively trading in, you can explore among the different Bitcoin markets or you can track the top 20 coins by marketcap.

Using the BitcoinAverage API all of these scenarios can be easily achieved.

We will define crypto winners in few categories:

  1. Highest relative price increase, in percents.
  2. Highest absolute price increase, in us dollars.
  3. Highest market cap increase.
  4. Highest 24h trading volume increase.

Highest price increase

To calculate the highest price increase we need to fetch both the latest ticker price and the historical price that we are interested in.

My list of coins will be: Bitcoin(BTC), Ethereum(ETH), Litecoin(LTC), Ripple(XRP) and Monero(XMR).

Latest ticker price

The latest ticker price for one coin can be retrieved from the BitcoinAverage ticker endpoint: https://apiv2.bitcoinaverage.com/indices/global/ticker/BTCUSD

This is the global Bitcoin price calculated by averaging all Bitcoin trading markets, including BTC/USD, BTC/EUR, BTC/GBP etc..

If you are interested only in the BTC/USD market, you can get that with our local ticker endpoint: https://apiv2.bitcoinaverage.com/indices/local/ticker/BTCUSD

In our case we want to get ticker price for 5 coins at once, we can do that with the “all” endpoint: https://apiv2.bitcoinaverage.com/indices/global/ticker/all

Here is a code in Python on how to get these prices:

You will receive a lot more data than you need to, this is the full ticker response for one coin, you will receive a dictionary or a map of these, represented like: {BTCUSD: {<ticker response>}, ETHUSD: {<ticker response>}

As you can see we already keep track of the price changes for hour, day, week, month, 3 months, 6 months and year periods. But with this tutorial you can track the price changes for a specific period of your choosing.

From the ticker response we will be using only the “last” price and the volume.

History price and circulating supply

We can retrieve the history price at a single point in time or in a time period.

For our example we’ll be getting the price at a single point in time, 7 days ago from today.

The History endpoint we’ll be using is:

https://apiv2.bitcoinaverage.com/indices/global/history/BTCUSD?at=<timestamp>

The actual code:

Here we must make a separate call for every coin and the response will be as bellow.

As you can see we have the full OHLCV response here for May 15th. Today we are going to use only the average price and the volume.

You will notice a second function called get_coin_supplies. We use this one to get the metadata that contains the market cap, total supply and circulating supply. We will use the circulating supply to detect which coin had the biggest market cap movement.

Our calculation for market cap will simply multiply the price by the circulating supply.

Calculating and sorting winners

Once we have all the data we need we can write the algorithm for calculating the price, volume and market cap changes and sort the results.

For calculating the price difference we just subtract the latest ticker price from the history price. We do the same thing for the volume.

For the market cap difference we multiply the circulating supply by the same price difference.

Finally we are sorting by the absolute price difference by specifying the key argument to the sort function with operator.itemgetter(1)

If you’d like to sort by relative price, set operator.itemgetter(2), to sort by volume pass in operator.itemgetter(3) and by market cap operator.itemgetter(4).

If you find this useful or interesting let us know in the comments.

If you have other ideas you’d like to implement with live and historical crypto data you can contact us at info@bitcoinaverage.com and we’ll be happy to help.

Leave a Reply

Your email address will not be published. Required fields are marked *