I am just getting started with Alpaca. I set up all my keys etc and tried to get data streaming. It worked once or twice but now isn’t streaming. I am using wscat to debug things. It connects and I am able to authenticate and subscribe but I am not getting any data. Here is my session - with the keys appropriately masked.
$ wscat -c wss://stream.data.alpaca.markets/v2/iex
Connected (press CTRL+C to quit)
< [{“T”:“success”,“msg”:“connected”}]
{“action”: “auth”, “key”:“PK*************”, “secret”:“**************” }
< [{“T”:“success”,“msg”:“authenticated”}]
{“action”:“subscribe”,“trades”:[“AAPL”]}
< [{“T”:“subscription”,“trades”:[“AAPL”],“quotes”:,“bars”:}]
I am getting nothing. I have tried different subscriptions and still get nothing. Here is another subscription I tried and the answer back
{“action”: “subscribe”, “quotes”:[“AAPL”,“AMD”]}
< [{“T”:“subscription”,“trades”:,“quotes”:[“AAPL”,“AMD”],“bars”:}]
It still just sits there with no data.
I have also tried to get it working with the python websocket package. It has basically the same results. Here is my code.
import websocket, json
SYMBOL = “AAPL”
TICKERS = [“AAPL”,“AMD”]
API_KEY = “PK*********”
SECRET_KEY = “********”
connection_url = “wss://stream.data.alpaca.markets/v2/iex”
def on_open(ws):
print(“Connection opened”)
auth_data = {
“action”: “auth”,
“key”: API_KEY,
“secret”: SECRET_KEY
}
ws.send(json.dumps(auth_data))
channel_data = {
"action": "subscribe",
"quotes": TICKERS
}
ws.send(json.dumps(channel_data))
def on_message(ws, message):
print("Message: ")
print(message)
def on_close(ws):
print(“Connection closed”)
ws = websocket.WebSocketApp(connection_url, on_open=on_open, on_message=on_message, on_close=on_close)
ws.run_forever()
Which results in:
Connection opened
Message:
[{“T”:“success”,“msg”:“connected”}]
Message:
[{“T”:“success”,“msg”:“authenticated”}]
Message:
[{“T”:“subscription”,“trades”:,“quotes”:[“AAPL”,“AMD”],“bars”:}]
but nothing after that.
Am I doing something wrong?
Thank you.