0

I have tried a code to collect information from binance, however when I run it the connection does not open and the output only shows "closed connection". Is this because of any firewall for visual studio code 2 or should I add any codes? Please show guidance, Thanks!

My code is shown below

import websocket

websocket.enableTrace(True)
SOCKET = "wss://stream.binance.com:9443/ws/btcusdt@kline_1m"

def on_open(ws):
    print('opened connection')

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

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

ws = websocket.WebSocketApp(SOCKET, on_open=on_open, on_close=on_close, on_message=on_message)
ws.run_forever()

My output is only closed connection as shown below.

closed connection
  • It works for me, so there's definitely something local to you that's causing the issue. I can't help beyond that though. – Kemp May 17 '21 at 09:33
  • Hey Kemp, is there any particular settings I have to do to resolve this for example disable firewall? – Yen Shun May 17 '21 at 10:11
  • 1
    Unfortunately I don't know what could be affecting you. I don't have any special configuration or exceptions on my machine and I just ran the code as-is. It could be anything from you having a firewall that aggressively stops outgoing connections to Binance having a block on your IP address range for some reason. – Kemp May 17 '21 at 11:12
  • Like @Kemp I ran the code as-is, and it worked well, have u resolved it yet ? Or it happened to be the Binance API maintanance time (happens quite often) – hungson175 May 06 '23 at 16:00

0 Answers0