I’m having issues trying to get specific data from quotes using json. I don’t know if it’s my formatting or what, but I’m unable to pull just the ask price by itself using websockets and json.
import config
import websocket, json
def on_open(ws):
print("opened")
auth_data = {
"action": "auth", "key": config.API_KEYP, "secret": config.SECRET_KEYP
}
ws.send(json.dumps(auth_data))
listen_message = {"action": "subscribe", "quotes": ['BTCUSD']}
ws.send(json.dumps(listen_message))
def on_message(ws, message):
print("received a message")
print(message)
formatted_message = json.loads(message)
print(formatted_message['ap'])
def on_close(ws):
print("closed connection")
socket = 'wss://stream.data.alpaca.markets/v1beta1/crypto'
ws = websocket.WebSocketApp(socket, on_open=on_open, on_message=on_message, on_close=on_close)
ws.run_forever()