binance-exchange/node-binance-api

is websocket on browsers supported?

SeraClinic opened this issue · 1 comments

Hello, first of all, thanks a lot for the great work :)

I'm trying to implement your work on browser side, and I managed to solve CORS problem using CORS Anywhere proxy, but still having an issue with websocket as getting following 400 error:

Request URL:https://stream.binance.com:9443/ws/btcusdt@ticker
Request Method:GET
Status Code:400
Remote Address:52.68.217.58:9443
Referrer Policy:no-referrer-when-downgrade

Response Headers
cache-control:no-cache, no-store, must-revalidate
content-length:0
date:Fri, 26 Jan 2018 04:02:33 GMT
expires:Thu, 01 Jan 1970 00:00:01 GMT
server:nginx
status:400
strict-transport-security:max-age=31536000; includeSubdomains
x-frame-options:SAMEORIGIN
x-nginx-pushstream-explain:Don't have at least one of the mandatory headers: Connection, Upgrade, Sec-WebSocket-Key and Sec-WebSocket-Version

Request Headers
:authority:stream.binance.com:9443
:method:GET
:path:/ws/btcusdt@ticker
:scheme:https
accept:/
accept-encoding:gzip, deflate, br
accept-language:en,ko;q=0.9,th;q=0.8,en-US;q=0.7
cache-control:no-cache
origin:http://evil.com/
pragma:no-cache
referer:http://localhost:3000/
user-agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36

I believe this part:

x-nginx-pushstream-explain:Don't have at least one of the mandatory headers: Connection, Upgrade, Sec-WebSocket-Key and Sec-WebSocket-Version

is the problem which I don't understand...maybe do you have any idea?

Thanks in advance!

Thank you!
Unfortunately this is not supported.
Your best bet would be making your own websocket connections directly - see https://github.com/binance-exchange/binance-official-api-docs
It sounds like the CORS Anywhere introduced more problems than it solved. It might require https