I’ve been using the code from: https://github.com/hackingthemarkets/alpaca-websockets/blob/master/stream.py
I can successfully authorize the connection and send an initial message to listen for some data:
ws = websocket.WebSocketApp(socket, on_open=on_open, on_message=on_message, on_close=on_close)
ws.run_forever()
However, the thing that has me stumped is how do I send additional messages once the initial connection is made? The initial message is bundled inside the on_open function, so I don’t really understand how to send additional message after that first on_open message is sent. For example, if I try to do this:
message = {"action": "listen", "data": {"streams": ["AM.TSLA", "T.TSLA"]}}
ws.send(json.dumps(message))
it doesn’t work. Nothing seems to happen and I don’t get any response. The only solution I have right now is to close the original connection, and create a new one with a different message, but that just seems dumb.