Many a times we / #algotrading folks have had this question in our mind what if we had multiple different strategy running in separate processes (or have multiple strategy python scripts) and we need WebSocket data feed to each one of those strategy process running individually
However, our brokers allow 1-3 WebSocket connection at any given time, So the obvious question lies ahead of us is how to solve this problem.
The Answer to this question isn't straight as we can have multiple way out of this problem, and nothing is the best or worst, every
single solution will come with its own tradeoff, so we need to see which tradeoff is acceptable to us and won't affect us drastically which can have an adverse effect on our strategies.
The Simplest of all with negligible tradeoffs shall be having a
Local WebSocket Mirror & Broadcast Server.
So, You Need To Setup Like This:
- Initiate and Persist a Single WebSocket Connection with the broker with all the required instruments subscribed in FullQuote mode.
- And in your ticker WebSocket on_message method / function
instead of parsing the incoming packet, just forward the received binary / text packets to local WebSocket Server.
- In Your Individual Strategy Scripts, instead of connecting to the broker WebSocket feed, connect to the local WebSocket Mirror & Broadcast Server.
With this method you can share one broker API WebSocket with any number of individual strategy process / scripts without exhausting API resources and making no concessions with the performance or WebSocket data feed speed.
Share this Scrolly Tale with your friends.
A Scrolly Tale is a new way to read Twitter threads with a more visually immersive experience.
Discover more beautiful Scrolly Tales like this.
