I'm making a crypto scanner which has to scan 100+ different cryptocoins at the same time. Now I'm having a really hard time simplifying this code because if I don't I'm gonna end up with more than 100 functions for something really easy. I'll post down here what I'm trying to refactor.
def main():
    twm = ThreadedWebsocketManager(api_key=api_key,api_secret=api_secret)
    twm.start()
    dic = {'close': [], 'low': [], 'high': []}
    dic2 = {'close': [], 'low': [], 'high': []}
    def handle_socket_message(msg):
        candle = msg['k']
        close_price = candle['c']
        highest_price = candle['h']
        lowest_price = candle['l']
        status = candle['x']
        if status:
            dic['close'].append(close_price)
            dic['low'].append(lowest_price)
            dic['high'].append(highest_price)
            df = pd.DataFrame(dic)
            print(df)
    def handle_socket_message2(msg):
        candle = msg['k']
        close_price = candle['c']
        highest_price = candle['h']
        lowest_price = candle['l']
        status = candle['x']
        if status:
            dic2['close'].append(close_price)
            dic2['low'].append(lowest_price)
            dic2['high'].append(highest_price)
            df = pd.DataFrame(dic2)
            print(df)
    twm.start_kline_socket(callback=handle_socket_message, symbol='ETHUSDT')
    twm.start_kline_socket(callback=handle_socket_message2, symbol='BTCUSDT')
    twm.join()
As you can see I getting live data from BTCUSDT and ETHUSDT. Now I append the close,low and high prices to a dictionary and then I make a DataFrame out of those dictionaries. I tried to do this with 1 dictionary and 1 handle_socket_message function. But then it merges the values of both cryptocoins into 1 dataframe which is not what I want. Does anyone know how I can refactor this piece of code? I was thinking about something with a loop but I can't figure it out myself. If you have any questions, ask away! Thanks in advance!
 
    