fhqvst / avanza

A JavaScript client for the unofficial Avanza API
MIT License
229 stars 59 forks source link

Unsubscribing from subscriptions #46

Closed calledit closed 3 years ago

calledit commented 4 years ago

Is there no way of informing the servers to stop sending subscription data? I can't find any info about it in this repo. Could there be a API endpoint that allows unsubscribing? Some endpoint that is not implemented in this repo?

For now I just ignore the data that is no longer required. Would be nice to not waste resources on the form of bandwidth and server time.

ausrasul commented 4 years ago

I couldn't observe an "unsubscribe" command in the browser, so it is not possible to implement such.

You can however disconnect and connect the websocket again. But that cancels all subscriptions.

If the same data/subscription is required often, even in parallel by different consumers, you can implement your own publish/subscribe proxy to reuse the data from a single subscription.

Qluxzz commented 3 years ago

Don't know if they have updated the site since this issue was filed, but there is now an unsubscribe command in the browser, it can be observed by going to the websocket in the browser's devtools and then navigating between instruments. image

ausrasul commented 3 years ago

Nice, but even.if we implement this, it will be a special case. Most of the api is iPhone app interface, not web.

From experince, web api is much more volitile than mobile counterpart and causes problems. @gustafg

fhqvst commented 3 years ago

The subscribe method now returns a function to unsubscribe!

const unsubscribe = avanza.subscribe(...)

// later...
unsubscribe()