Using Websockets

so I’m exploring the world of WebSockets and I’m having some trouble… I’ve been knocking my head against the wall just trying to even get connected… here is a copy of a script I followed from a youtube video and it worked in the video but not mine. every time I run the script it just disconnects. what am I doing wrong.

I have intentionally left out my API keys here…

import config
import websocket, json

def on_open(ws):
print("opened")
auth_data = {
    "action": "authenticate",
    "data": {"key_id": API_KEY, "secret_key": SECRET_KEY}
}

ws.send(json.dumps(auth_data))

listen_message = {"action": "listen", "data": {"streams": ["AM.TSLA"]}}

ws.send(json.dumps(listen_message))


def on_message(ws, message):
print("received a message")
print(message)

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

socket = "wss://data.alpaca.markets/stream"

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

You don’t get a Python interpreter error, do you? When I test your code, I get some output (ref attached screenshot). Is that what you get?

python_websocket

If not, make sure you’ve installed the right websocket library. You want to install ‘websock-client’ …not just ‘websocket’

well, it turns I had to run some Certificates command on my computer… facepalm Thanks for the help guys.