jseparovic / python-ws-dtc-client

Python Websocket DTC Protocol Client
Apache License 2.0
34 stars 14 forks source link

Websocket issue? #2

Open bitnosis opened 3 years ago

bitnosis commented 3 years ago

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

3orin commented 9 months ago

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))
  2. 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](https://github.com/jseparovic/python-ws-dtc-client/assets/159127744/f8a26c97-6264-417a-bd15-097567f4b2ed)

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

...`