kiteconnect-rs
A Rust client for the Kite Connect API by Zerodha.
- Typed REST calls: Covers Kite Connect v3 endpoints with typed request parameters and responses.
- Lazy
Call<T>requests: Every endpoint returns aCall<T>that sends nothing until awaited, with.raw(),.request(), and.response()escape hatches. - WebSocket ticker: Connects to
wss://ws.kite.tradein a background Tokio task, reconnects with exponential backoff, and restores subscriptions. - Redacted secrets: Redacts tokens, API secrets, and secret query or form fields from
Debugoutput and strips query strings from error paths.
The API mirrors gokiteconnect v4. Method names are Go's in snake case, without the Get prefix: GetHoldings is holdings, GetUserProfile is profile, PlaceOrder is place_order. Response types use the field names Kite sends.
Version 1.0 is a rewrite and does not share an API with 0.2.x.
Install
Or in Cargo.toml:
[]
= "1"
= { = "1", = ["macros", "rt-multi-thread"] }
Log in and read holdings
Kite Connect login is a browser redirect. Open login_url(), log in, and take the request_token from the redirect URL. Then exchange it with your API secret:
use ;
async
If you already have an access token, set it on the builder with .access_token(AccessToken::new(token)?).
Call<T>
Every endpoint method returns a Call<T>. It sends nothing until you use it:
# async
.response() sends the request and returns the HTTP status, content type, and body as is. kite.call(Request::get("/path")) reaches an endpoint the crate does not wrap.
Ticker
use ;
async
The ticker runs in its own Tokio task and connects to wss://ws.kite.trade. After a dropped connection it reconnects with exponential backoff (at most 30 seconds) and subscribes again to the current set. A handshake that Kite rejects with HTTP 400, 401, or 403 ends the ticker instead. KiteTicker is a cloneable handle, so several tasks can change subscriptions while one task reads events. The event channel is bounded: a slow reader pauses socket reads, so no tick or order update is dropped. Closed is always the last event.
Errors
Every call returns kiteconnect::Result<T>. A Kite error envelope becomes Error::Api, with Kite's error_type, message, and HTTP status.
# async
is_session_expired() is true only for TokenException. Kite rejects such a request before it acts on it, so it is safe to renew the token and send the request again. Retry nothing else, an order write least of all.
Tokens and the API secret are newtypes whose Debug output is redacted. Request and Body redact secret query and form values in Debug. Decode errors name the path without its query string.
MSRV
Rust 1.92.
License
The crate uses the MIT license. See LICENSE.