I’m currently getting trading volume for certain symbols in the following way:
Iterating every symbol in binance, get trading volume for each symbol-pair, using
def get_24h_volume(symbol): # get trading volumes for the last 24 hours trading_volume = 0 prices = client.get_all_tickers() for coin in prices: if coin['symbol'].startswith(symbol) and coin['symbol'].startswith('BTCDOWN') == False and coin['symbol'].startswith('BTCUP') == False and coin['symbol'].startswith('BTCST') == False: try: klines = client.get_historical_klines(coin['symbol'], Client.KLINE_INTERVAL_1MINUTE, "1 day ago") for history in klines: trading_volume += float(history) print(coin['symbol'], trading_volume) except: pass return trading_volume print(get_24h_volume('BTC'))
But there’s a problem, which I have to manually add condition such as
coin['symbol'].startswith('BTCST') == False.
But What if new coin named ‘BTCXY’ or ‘BTCAC’ and so on created?. Then I will have to add a new condtion like
coin['symbol'].startswith('BTCXY') == False again into my code again…
Is there any better way to get 24hours trading volume of symbol than this?.