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

avatar

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 = '<table><tr><th>Ticker Symbol</th><th>Exchange</th><th>Price</th></tr>'
    for price in prices:
        row = f'<tr><td>{price[0]}</td><td>{price[1]}</td><td>{str(price[2])+" "+price[3]}</td></tr>'
        table += row
    table += '</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
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

Posted Using LeoFinance Beta



0
0
0.000
11 comments
avatar

Very cool stuff my dear, for my current discord price bot I am using coingeckos API in python.
But I can definitely see the advantages of using this one instead of the one that coingecko is providing. Will give it a try soon.
Thanks for sharing!
Yours
Jan

0
0
0.000
avatar

Thank You Jan! Awesome! I hope you will find it useful. Is your discord bot in python? If yes is the code publicly available somewhere to copy? :)

Once I tried making a python discord bot that would update with latest community posts. Then it would stop working after few days, and I gave up with discord bots. I may need to try again.

0
0
0.000
avatar
(Edited)

Hi
yep it is on github, but in a very outdated way and it does a lot more than just show graphs of cryptos. ... but this is a very good reason to finally get my github updates going again ;)
once I got it sorted I will let you know ok ? :)
Oh and yes it is written in python ;)

0
0
0.000
avatar
(Edited)

A great deal can be built atop CCXT. There are a number of trading desks that use it.

CCXT Pro offers a unified websocket API for the exchanges. That's the major difference between the two versions of the library.

0
0
0.000
avatar

That's good to know. Thank You. I will experiment more with CCXT when I get a chance.

0
0
0.000
avatar

PUT That lil Nay Nay on the chainlink price feed oracle e ey ey ey eye

0
0
0.000
avatar

I wish I knew how that works. I have no idea what chainlink does.

0
0
0.000
avatar

This is an interesting pricing update from mutiple exchanges. Just wondering if there can a link which can be accessed anytime to get prices updated in real time?

0
0
0.000
avatar

Not sure what you mean with a link. But you probably could create one using ccxt.

0
0
0.000