Updating front-end client using Alpaca's streamConn websocket

Hi,
you have built a server-client solution.
you have 2 options:

  1. connect to the api from your server - python sdk
  2. connect to the api from your client - js sdk (GitHub - alpacahq/alpaca-trade-api-js)

let’s focus and option 1 and leave option 2 to your architecture decisions.

if you connect to the Streaming api from your server then your server is now both a client and a server.

it’s a client to the alpaca servers
it’s a server to your js client

that means you open one websocket to the alpaca servers (StreamConn)
and you open a websocket server for your js client

now what you can do is when a message is received from StreamConn you need to pass it to your client.
what you did in your example is not good. you don’t want to wait for a connection from your browser every time you get a message from alpaca.
you want to hold 2 live connections that are never closed (1 to alapca with StreamConn 1 to your client) and streamline the messages you receive from one to the other.