I have a browser dashboard using Python & Flask. I wanted to update the data without manually refreshing the browser nor have javascript inefficiently make a request every second or minute. (Would Alpaca ban my ISP if made a request every second? ) If I can get the data from the streamConn websocket to push/pass the data to my browser dashboard that would be awesome. Flask would not work because it needs a request in order is issue a response. Flask-SocketIO or FastAPI maybe are solutions?
Is it possible to pass/push the data from streamConn to my dashboard browser? What libraries would you use? How would you do it?
Can you nest websockets in the following way?
# Alpaca websocket connection: data inflow
@conn.on(r'^T.*$')
async def on_data(conn, channel, data):
data_dict = data._raw
print('data processed:', data_dict)
# FastAPI websocket creation: pass-through/ data outflow
@app.websocket("/ws")
async def websocket_endpoint(websocket: WebSocket):
await websocket.accept()
while True:
payload = data_dict
await websocket.send_json(payload)
conn.run(['T.AAPL']])
uvicorn.run(app:main)