WebSocket only closing the connection and not running forever

31 Views Asked by At

I am trying to use WebSocket to retrieve data continuosly using the binance API The code follows:

from binance.client import Client
import config
import websocket


TRADE_SYMBOL = 'SOLBRL'
TIME_INTERVAL = Client.KLINE_INTERVAL_1MINUTE
closes=[]
def on_open(ws):
    print('openned connection')

def on_close(ws):
    print('closed connection')

def on_message(ws, message):
    print(message)


if __name__ == '__main__':
    client = Client(config.API_KEY, config.API_SECRET)

    klines = client.get_historical_klines(TRADE_SYMBOL, TIME_INTERVAL, "1 day ago UTC", limit=30)

    print("Get only close values")
    for candles in range(len(klines)-1):
        closes.append(float(klines[candles][4]))
    
    SOCKET = 'WSS://stream.binance.com:9443/ws/' +TRADE_SYMBOL.lower()+'@kline_'+TIME_INTERVAL
    ws = websocket.WebSocketApp(SOCKET, on_open=on_open, on_close=on_close, on_message=on_message)
    ws.run_forever()

But the return from the code is simply:

Reloaded modules: config
Get only close values
closed connection

Any toughts on what could be going wrong? I expected it would return continuosly the data from the website provided, that is in fact quotations of Solana/BRL from binance.

0

There are 0 best solutions below