Getting List Of Exchanges & Prices For Hive & HBD with CCXT API | Showcase Sunday

ccxt.png

I wrote about CCXT API in the past and how useful it can be to get list of exchanges, coin prices, and trading pairs. Since this information always changes, it is good to have scripts or tools that we can reuse to get the latest data. For example, we can find out if any new exchanges have listed the coins/tokens or maybe dropped them from their platforms. We can also get price data to compare the prices among all the exchanges. I have written a script that does just that for Hive and HBD. I would like to share the script again here with the latest results.

CCXT is a cryptocurrency exchange trading library for Javascript, Python, and PHP. It is a trading API that supports more than 120 crypto exchanges and continues to add more. While my personal preference is to use in my python projects, it is nice to know that it can be used in Javascript and PHP based projects. For more details feel free to visit CCXT GitHub page.

What is really great about this library is that it provides access to many exchanges which include major exchanges like Coinbase, CoinbasePro, Binance, Bittrex, Huobi, etc. Various exchanges have their own python packages to interact with them. I think it is much better to have one interface that can connect to multiple exchanges, get necessary data, and even automate trading.

Most of the functions are available as public and do not need API access credentials. However, for projects that need access to a trading account, we will need to obtain the API access credentials for specific exchanges that we have accounts at.

This API can be used for simple things like getting data on what is being traded on exchanges, historical cryptocurrency prices. It can also be used for more complex projects like trading bots, web applications, etc.

Getting started with this API is super easy. For python we need to first pip install ccxt. Once that is done we can start using it in our python code.

To demonstrate how work with ccxt, I wanted to see what exchanges have HIVE and HBD listed, what trading pairs are available and the latest prices.

First to see what exchanges are supported we can write the following code:

import ccxt

print(ccxt.exchanges)

If we already know what exchange we would like to use in that list, we can start connecting to this exchange, and get trading pairs and latest data about this trading pairs as below:

import ccxt

binance = ccxt.binance()
print(binance.load_markets())

If we need to access our accounts we will need to pass api key and secrets as a dictionary argument like this:

import ccxt

binance = ccxt.binance({
    'apiKey': 'YOUR_PUBLIC_API_KEY',
    'secret': 'YOUR_SECRET_PRIVATE_KEY',
})

As you can see it is very easy to get started with CCXT. Exploring more available methods and properties we can write much more useful code.

As I mentioned I was curious to see if I could use CCXT to see all the exchanges that have HIVE and HBD listed, what trading pairs they have available, and latest prices. Let's do that now.

import ccxt

def create_table(prices):
    table = ''
    for price in prices:
        row = f''
        table += row
    table += ''
    return table

prices = []
for exchange_id in ccxt.exchanges:
    if exchange_id == 'cdax':
        continue

    try:
        exchange_class = getattr(ccxt, exchange_id)
        exchange = exchange_class()
        markets = exchange.load_markets()
    except:
        continue

    for market in markets:
        if 'HIVE' in market or 'HBD' in market:
            if 'HBDC' in market:
                continue
            ticker = exchange.fetch_ticker(market)
            if ticker['symbol'].split('/')[1] == 'BTC':
                prices.append((market, exchange_id, format(ticker['close'], '.8f'), ticker['symbol'].split('/')[1]))
            else:
                prices.append((market, exchange_id, ticker['close'], ticker['symbol'].split('/')[1]))

table = create_table(prices)
print(table)

What the main part of the code doing is, first we are trying to identify all the exchanges, then we are getting the method by the same name to create the instance of the exchange. Then we are looking what ticker symbols are traded in the exchange. If any of the tickers include Hive or HBD we are storing ticker symbol, exchange name, last close price in prices list. create_table is a helper function that puts together the results in a table format, so I can include them in the post. You can scroll down to see the results.

Initially when I was testing I was getting 12 exchanges that have Hive traded on. However, something went wrong when I tried to get the prices of CDAX exchange. After looking closely I was convinced Hive or HBD were not actually listed there. So I have do include a line of code to exclude CDAX.

Another interesting thing we can see is from the results is that, for some reason HBTC exchange named the ticker symbol as HIVE1/USDT instead of just HIVE without 1.

In the past results from few months ago the results would show exchange names LATOKEN where all trading pair prices for Hive were zero. Now it seems this exchange doesn't show up in the results anymore.

This is not a full list of exchanges that have Hive or HBD listed. We can see how some exchanges like ionomy, blocktrades, beaxy, mxc, are not there. It is still great to see that all the major exchanges like Binance, Bittrex, Huobi, Upbit are supported in CCXT.

The code above can also be used for any other coins/tokens. If you learn about a new coin/token and would like to see if where it is traded, simply change the comparison logic from HIVE and HBD to that coin/token.

Comparing the results from few months ago, new results show that Hive is now also being traded at coinex.

Hive and HBD Prices

Ticker SymbolExchangePrice
{price[0]}{price[1]}{str(price[2])+" "+price[3]}
Ticker SymbolExchangePrice
HIVE/BNBbinance0.0 BNB
HIVE/BTCbinance0.00001556 BTC
HIVE/USDTbinance0.7468 USDT
HIVE/KRWbithumb903.8 KRW
HBD/BTCbittrex0.00002179 BTC
HIVE/BTCbittrex0.00001544 BTC
HIVE/USDbittrex0.74021 USD
HIVE/USDTbittrex0.739 USDT
HIVE/USDTcoinex0.7474 USDT
HIVE/BTCcoinex0.00001550 BTC
HIVE/USDTgateio0.7454 USDT
HIVE1/USDThbtc0.74 USDT
HIVE/BTChuobipro0.00001552 BTC
HIVE/USDThuobipro0.745 USDT
HIVE/HThuobipro0.052618 HT
HIVE/IDRindodax10681.0 IDR
HIVE/USDTprobit0.7492 USDT
HIVE/BTCprobit0.00001556 BTC
HIVE/BTCstex0.00000561 BTC
HIVE/BTCupbit0.00001548 BTC
HBD/BTCupbit0.00002133 BTC
HIVE/KRWupbit904.0 KRW

H2
H3
H4
3 columns
2 columns
1 column
11 Comments
Ecency