python-ws-dtc-client icon indicating copy to clipboard operation
python-ws-dtc-client copied to clipboard

Websocket issue?

Open bitnosis opened this issue 4 years ago • 1 comments

I get this error when trying to connect to the websockets..

handler, values = adapter.match() raise WebsocketMismatch() werkzeug.routing.WebsocketMismatch: 400 Bad Request: The browser (or proxy) sent a request that this server could not understand. 2021-11-29T06:06:43Z {'REMOTE_ADDR': '127.0.0.1', 'REMOTE_PORT': '58134', 'HTTP_HOST': 'localhost:8022', (hidden keys: 30)} failed with WebsocketMismatch

Im trying to connect to the websockets like so

let socket = new WebSocket('ws://localhost:8022/api/v1/marketdata');

and my setup originally is...

example_client.py --host 127.0.0.1 --port 11099 -q 11098 -r 8022 -s

bitnosis avatar Nov 29 '21 06:11 bitnosis

Need to fix a couple strings in the code & library to make it work

  1. flask_sockets.py [library]
    def add_url_rule(self, rule, _, f, **options):
        self.url_map.add(Rule(rule, endpoint=f, **options))
        #: self.url_map.add(Rule(rule, endpoint=f))
  1. rest_server.py [app itself]
#: @sockets.route(API.API_PREFIX + API.MARKET_DATA)
@sockets.route(API.API_PREFIX + API.MARKET_DATA, websocket=True)
def market_data(ws):
    ws_data_request(ws, SubscriptionDataType.MARKET_DATA)

#: @sockets.route(API.API_PREFIX + API.MARKET_DEPTH)
@sockets.route(API.API_PREFIX + API.MARKET_DEPTH, websocket=True)

Detailed explanation here: https://github.com/heroku-python/flask-sockets/pull/82

WS client for the testing: https://github.com/WangFenjin/Simple-WebSocket-Client

PS At least, I can send something to Sierra's server via WS, but I'm NOT [yet] getting a market data in the LOG section below [like shown on the video], but it could be due to

  1. my Sierra server misconfiguration, OR
  2. Certain CME restrictions for the live data

Sierra's server settings attached scr=SierraServerSettings

PS downgrading flask didn't help; current versions [as of Feb 2024 - should be latest]:

`Flask Version: 3.0.2

Flask-Sockets Version: 0.2.1

websocket_client Version: 1.7.0

gevent-websocket Version: 0.10.1

...`

3orin avatar Feb 06 '24 09:02 3orin