Connection error, while wscat seems fine
ykwwZero opened this issue · 1 comments
ykwwZero commented
wscat --connect wss://stream.binance.com:9443/ws/bnbbtc@depth
produces output like:
wscat --connect wss://stream.binance.com:9443/ws/bnbbtc@depth
Connected (press CTRL+C to quit)
< {"e":"depthUpdate","E":1675577550398,"s":"BNBBTC","U":2965760557,"u":2965760568,"b":[["0.01422600","2.18400000"],["0.01394700","1.91200000"]],"a":[["0.01423400","0.33100000"],["0.01423500","5.64500000"],["0.01424200","1.35300000"],["0.01424300","1.16800000"],["0.01424900","4.32800000"]]}
< {"e":"depthUpdate","E":1675577551398,"s":"BNBBTC","U":2965760569,"u":2965760575,"b":[["0.01422100","5.94900000"],["0.01409400","1.04500000"],["0.01394400","2.76000000"]],"a":[["0.01423400","0.33100000"],["0.01423500","6.38200000"],["0.01423600","13.10000000"]]}
I initially tried tokio-tungstenite
but struggled, so reverted to this basic tungstenite
lib only to find a similar error using this basic code:
use tungstenite::connect;
use tungstenite::Message;
fn main() {
let (mut socket, _) =
connect("wss://stream.binance.com:9443/ws/bnbbtc@depth").unwrap_or_else(|e| {
println!("Failed to connect to websocket: {}", e);
panic!();
});
loop {
let msg = socket.read_message().unwrap();
let msg_str = msg.to_string();
println!("{}", msg_str);
}
}
This code panics when attempting to connect:
warning: `local_order_book` (bin "local_order_book") generated 1 warning
Finished dev [unoptimized + debuginfo] target(s) in 0.60s
Running `target/debug/local_order_book`
Failed to connect to websocket: HTTP error: 400 Bad Request
thread 'main' panicked at 'Failed to connect to websocket: HTTP error: 400 Bad Request', src/main.rs:7:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Any help w.r.t. debugging would help. I've tried to inspect network traffic manually to catch headers used by wscat
vs the rust implementation but didn't have any immediate luck identifying the wscat
connection request headers.
ykwwZero commented
Resolved, needed to enable "native-tls" feature in cargo.toml:
tungstenite = {version = "0.18.0", features = ["native-tls"]}