-1

I have this...

import websocket

SOCKET = "wss://stream.binance.com:9443/ws/ADABUSB@nav_kline_1m"

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

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

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

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

When I run it it sticks on OPENED CONNECTION and then does nothing?? Any ideas?

No error messages and I have left it for minutes!!

Cheers Zak

Morten Jensen
  • 5,818
  • 3
  • 43
  • 55
Zak Pinter
  • 21
  • 5

2 Answers2

1

No error messages

How do you know, you haven't defined the on_error-callback :) ?

Try adding it like below and see if it makes a difference (it does on my end):

import websocket

SOCKET = "wss://stream.binance.com:9443/ws/ADABUSB@nav_kline_1m"

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

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

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

def on_error(ws, message):
    print('error:', message)


ws = websocket.WebSocketApp(SOCKET, on_open = on_open, on_close = on_close, on_message = on_message, on_error = on_error)
ws.run_forever()
Morten Jensen
  • 5,818
  • 3
  • 43
  • 55
  • I've added that in and still just sitting there... :-/ – Zak Pinter Jun 03 '22 at 15:20
  • I INTERRUPTED the process in the SHELL instead of RESTARTING the SHELL and got this error... opened connection error: error: on_close() takes 1 positional argument but 3 were given – Zak Pinter Jun 03 '22 at 16:09
0

Found this and it worked! I am on a Mac...

Spot on! removed ::1 from /etc/hosts and its connecting. localhost was resolving to ::1. Thanks for help.

Zak Pinter
  • 21
  • 5
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jun 03 '22 at 23:09