It looks like you're new here. If you want to get involved, click one of these buttons!
let url = "wss://ws.kite.trade?api_key=<API_KEY>&access_token=<ACCESS_TOKEN>";
println!("Connecting to {}...", url);
let (ws_stream, _) = tokio_tungstenite::connect_async(url).await?;
println!("Connected!");
let (mut write, mut read) = ws_stream.split();
let read_task = tokio::spawn(async move {
while let Some(msg) = read.next().await {
match msg {
Ok(msg) => {
println!("Received: {}", msg);
}
Err(e) => {
eprintln!("Error receiving message: {}", e);
break;
}
}
}
});
Rust code output - Websocat output -
For a more seamless experience and to avoid client-specific handshake nuances, we generally recommend using one of our official client libraries, which are designed to handle the WebSocket connection and protocol requirements appropriately.
I logged the headers being sent by the Rust client, they seem to match the ones being sent by Postman (which is able to successfully connect). Do you know of any other possible causes?
Rust client headers - Headers from Postman after successful connection - P.S. I'm aware of the official client libraries, but my current usecase requires a Rust-based client
Even if the visible headers appear similar, differences in client handshake characteristics such as TLS negotiation, extension headers (e.g., Sec-WebSocket-Extensions), request formatting, or underlying WebSocket stack behavior can lead to different outcomes across clients like Postman, websocat, and low-level libraries.
Given that the same URL and credentials work with other WebSocket clients, this does not indicate a Kite Connect credential or endpoint issue, but rather a client-specific handshake or transport-level difference.