How to get last trade and quote from the socket

After making a buy of a stock, I would like to monitor the last quote and last trades via the websocket. But, I don’t know of a way to simply add that to my current socket subscription list. It seems risky to have to unsubscribe and resubscribe every time i make a change so i can monitor a new quote/trade per symbol. What is the recommended way to do this?

good question, im about to be writing some code regarding the same situation. ill let you know what i find out!

I am currently using polling, by making 2 seperate api requests, every 10 seconds. But, this is inefficient, and goes against my max requests limit. Also, I get lots of ETIMEOUT errors, which could be due to the max request thing

I just looked at the subscription code, and it looks like it supports simply subscribing again, but with the new ‘topics’. So, I will try that approach out and let you know how it works

subscribe(topics) {
    const subMsg = {
        action: 'subscribe',
        params: topics.join(',')
    }
    this.send(JSON.stringify(subMsg))
    this.channels = this.channels.concat(topics)
}

im going with https://docs.alpaca.markets/api-documentation/web-api/positions/ since i need the value of avg_entry_price

So, I have confirmed that I can simply subscribe to more topics, and it appends them to the current list. Perfect