

# create the price tickers for each asset, removing unnecessary data

Pair_ticker = hitbtc.fetch_ticker(trading_pair) # fetch the tickers for each asset on HitBTCįor trading_pair in hitbtc.load_markets(): # calculate the ticker price of BTC in terms of USDT by taking the midpoint of the best bid and askīitcoinPriceUSDT = (float(bitcoin_ticker) + float(bitcoin_ticker)) / 2 # fetch the BTC/USDT ticker for use in converting assets to price in USDTīitcoin_ticker = hitbtc.fetch_ticker('BTC/USDT') Note: This script will take up to 5 minutes to run, that is completely expected. Once the data is retrieved, it will calculate the price of each asset in terms of USDT. The script will access the live order book ticker for each individual asset pair.
#Cryptocurrency ticker api install#
pip install ccxt ExampleĪfter installing CCXT, we can start building our script. Let’s start by installing the CCXT library for Python. Since there are hundreds of markets and we need to abide by the rate limits in place by the exchange, CCXT will automatically throttle the requests to make sure we don’t go over those limits. Fetching all individual tickers from the exchange can take up to 5 minutes when using CCXT. In our first example, we will use the CCXT Python library to access the ticker data from HitBTC. These APIs provide a unified way of accessing data across every major exchange without requiring changes to the data format. The second strategy will be to use the Shrimpy Universal Crypto Trading APIs. Using an open source like CCXT, we have fine control over the data we access. The first strategy will be to access the data directly from the exchange and calculate our own price ticker based on the information we want. We will cover two different ways to generate a live price ticker. The midpoint produces less drastic changes in value from tick to tick. As a result, using the last trade as the ticker can produce a poor experience for investors who are trying to track their portfolio value in real-time. The reason we use the midpoint between the best bid and ask order instead of simply using the last executed trade for the pair is because the cryptocurrency market is volatile and assets can have large spreads. In our examples, we will be using the midpoint between the current best bid and ask order for a trading pair to determine the ticker price. To put it simply, a price ticker is the latest price for an asset on a given exchange.
#Cryptocurrency ticker api how to#
In the following examples, we will explore how to create a live price ticker which uses the latest order book data on the exchange to calculate the current price of an asset.
