是否可以在 Python3 中的特定函数之外附加代码行?

我正在尝试获取加密货币交易所的订单簿如何支持特定对(例如 ETH/BTC)。因为我的函数需要每分钟运行一次,所以每次检查都非常耗时。我正在使用 ccxt 来获取交易所的订单簿。


用这行代码,我检查每一次交换。


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")

现在我需要添加所有 try-blocks 的第一行,如果它们可以输出的话。这在python中可能吗?


潇潇雨雨
浏览 158回答 1
1回答
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python