I'm trying to fetch the orderbooks of crypto exchanges how support a specific pair (for example ETH/BTC). Because my function needs to run every minute it's very time consuming to check this every time. I'm using ccxt to fetch the orderbooks of the exchanges.
With this lines of code I check every exchange.
import ccxt
binance = ccxt.binance()
livecoin = ccxt.livecoin()
kucoin = ccxt.kucoin()
hitbtc = ccxt.hitbtc()
kraken = ccxt.kraken()
crex24 = ccxt.crex24()
okex = ccxt.okex()
headerList = ["time","type","pair"]
try:
orderbookBinance = binance.fetch_order_book(self.pair,5)
headerList.append("binance")
headerList.append("binanceAmount")
except:
print("Pair isn't available in binance")
try:
orderbookLivecoin = livecoin.fetch_order_book(self.pair,5)
headerList.append("livecoin")
headerList.append("livecoinAmount")
except:
print("Pair isn't available in livecoin")
try:
orderbookKucoin = kucoin.fetch_order_book(self.pair,5)
headerList.append("kucoin")
headerList.append("kucoinAmount")
except:
print("Pair isn't available in kucoin")
try:
orderbookHitbtc = hitbtc.fetch_order_book(self.pair,5)
headerList.append("hitbtc")
headerList.append("hitbtcAmount")
except:
print("Pair isn't available in hitbtc")
try:
orderbookKraken = kraken.fetch_order_book(self.pair,5)
headerList.append("kraken")
headerList.append("krakenAmount")
except:
print("Pair isn't available in kraken")
try:
orderbookCrex24 = crex24.fetch_order_book(self.pair,5)
headerList.append("crex24")
headerList.append("crex24Amount")
except:
print("Pair isn't available in crex24")
try:
orderbookOkex = okex.fetch_order_book(self.pair,5)
headerList.append("okex")
headerList.append("okexAmount")
except:
print("Pair isn't available in okex")
Now I need to add the first line of all the try-blocks if they can exetude. Is this possible in python?