I’m currently working on implementing near real-time order information in my app using the websocket v2
through the Marketfeed module. However, I encountered an issue while trying to initiate the stream—specifically, I faced difficulties maintaining the connection in an open state.
After investigating, I found that the way the websocket connection is closed or reopened in the Marketfeed code isn’t compatible with the latest websockets
library version, 14.1. While reviewing the module, I noticed that the documentation mentions compatibility with versions higher than 11.1.0, but it seems the current implementation doesn’t fully support 14.1.
To resolve this, I downgraded the websockets
library to an earlier version, and the program worked as expected. However, I believe this issue should be addressed, either by:
- Updating the Marketfeed code for compatibility with newer
websockets
versions (like 14.1), or - Clearly communicating to users that they should use a specific compatible version of the library.
Here’s an example of the change I made to get it working with WebSocket 14.1:
Original Code in Marketfeed.py:
python
async def connect(self):
"""Initiates the connection to the Websockets."""
if not self.ws or self.ws.closed:
Updated Code for WebSocket 14.1 Compatibility:
python
async def connect(self):
"""Initiates the connection to the Websockets."""
if not self.ws or self.ws.state == websockets.protocol.State.CLOSED:
I hope this helps others who might face similar issues. It would be great if the maintainers could address this in future updates to ensure compatibility with the latest library versions.