-
Notifications
You must be signed in to change notification settings - Fork 285
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[question] Trying to get last price stream from Okex #78
Comments
Websocat may not be the best tool for this, unless a special Currently it is cumbersome to extract meaningful reply from the server.
Websocat outputs binary WebSocket messages to stdout as is, without any separators and prefixes. This makes it able to only reliably receive one compressed message. Are compressed WebSocket messages a popular thing? Are they also used in other places? I'm not sure about adding site-specific things to Websocat. Maybe I'll add a slow "filterer" overlay that would be able to launch a process for each message that would transform it in arbitrary way. |
Another more universal idea: implement a |
Implemented support of base64-encoding binary WebSocket messages.
|
Nice! target/debug/websocat wss://real.okex.com:8443/ws/v3 --base64 | xargs -n1 -- sh -c '{ echo '{"op": "subscribe", "args":["swap/ticker:BTC-USD-SWAP"]}' | base64 -d; echo $0 | base64 -d; } | gunzip 2> /dev/null; echo' |
To stdin:
Here is also optimized Perl-based version of the decompressor:
|
Would it be possible to add an optional deflate layer? (since there's many gzipped websocket servers these days, like okex, huobi etc) |
Note that Websocket protocol itself provides permessage-deflate compression (not supported by Websocat v1 or v3 unfortunately). |
@vi I'm not sure what's the answer to the "why" question, but it seems to be growing more and more popular for whatever reason. And yes, pretty much all of them use gzip and not any other compression method - so having a simple (if deflate layer was implemented, it would also allow you to combine it with |
A possible answer to "why" could be that not all libraries and clients (only a selected subset) will support permessage-deflate. Meanwhile, you can always use any websocket library and just unpack things manually using whatever tooling you want to use. |
Is there a public service supplying such "gzipped" WebSocket messages to test implementations?
|
This should work: (echo -e '{"op":"subscribe","args":["spot/ticker:ETH-USDT"]}' && cat) \
| websocat wss://real.okcoin.com:8443/ws/v3 --base64 \
| xargs -n1 -- sh -c '{ echo H4sIAAAAAAAAAA== | base64 -d; echo $0 | base64 -d; } | gunzip 2> /dev/null; echo' This should also work: (echo -e '{"sub":"market.btcusdt.bbo","id":"1"}' && cat) \
| websocat --base64 wss://api.huobi.pro/ws \
| xargs -n1 -- sh -c '{ echo $0 | base64 -d; } | gunzip; echo' |
By the way, having to send a single "subscribe" message (or a few of them) is also extremely common, wonder if it's something that could be integrated in so you wouldn't have to E.g. |
Specifying init messages on command line, to send them to WebSocket before reading further messages from stdin (unless |
Implemented |
Implemented decompression as well.
|
@vi Looks awesome, thanks! |
Hello, I like the idea to use websocat to get last price streams from cryto exchanges, from the command line.
With Binacne exchange, it is as easy as:
websocat "wss://fstream.binance.com/stream?streams=$pair@markPrice"
But am I having a hard time from Okex exchange.
According to the docs at:
https://www.okex.com/docs/en/#spot-singleness
The URL is:
wss://real.okex.com:8443/ws/v3
I have tried many URLs and all I can get are scramble chinese characters.
Also, it seem to be DEFALTE compressed.
Wonder if would be possible to get the BTC-USD last price ticker, just like it is possible with the Binance example above.
The text was updated successfully, but these errors were encountered: