zrsclient
Warning: This SDK is in active development. Please do not use it for live trading.
zrsclient is a Rust SDK over the API provided by the Indian stock broker
Zerodha. It wraps the Kite Connect REST
endpoints and the WebSocket market-data stream, and includes retry/reconnect
logic so algorithm writers don't have to hand-handle recoverable failures.
Features
- REST coverage — orders, GTT (read and write), alerts, portfolio (holdings/positions), margins & charges, mutual funds, market quotes, instruments, and historical data.
- Builder-based requests —
OrderParams(incl. iceberg / auction / TTL / market-protection / auto-slice),GttParams, andAlertParams. - Automatic retries on recoverable REST errors (throttling, timeouts) with a caller-supplied retry budget.
- WebSocket streaming on
tokio-tungstenitewith automatic reconnect (exponential backoff) and subscription state that survives reconnects. - Typed ticks —
on_ticksyieldsVec<Tick>(typedMode,Ohlc,MarketDepth) instead of untyped JSON.
Installation
Or add it to your Cargo.toml:
[]
= "0.3"
Authentication
zrsclient consumes an existing Kite api_key / access_token (it does not
implement the login/session flow). Provide them via a ZrsClientConfig, or place
them in ~/.zrsclient/credentials as TOML:
[]
= "your_api_key"
= "your_access_token"
KiteConnect::new(None) resolves credentials from that file; passing
Some(config) supplies them directly.
REST example
use ;
use ZrsClientConfig;
use Value as JsonValue;
// Supply credentials directly, or pass `None` to read ~/.zrsclient/credentials.
let config = ZrsClientConfig ;
let kite = new;
// Retry budget for recoverable errors (0 disables retries).
let retry = 10;
// Read portfolio.
let holdings: JsonValue = kite.holdings.unwrap;
// Place an order with the builder.
let params = new
.price
.validity;
let placed: JsonValue = kite.place_order.unwrap;
GTT and alerts
use ;
// A single-leg GTT.
let gtt = new
.trigger_value
.order;
kite.place_gtt.unwrap;
// A simple price alert.
let alert = simple;
kite.create_alert.unwrap;
WebSocket streaming
use ;
Testing
Unit tests (mocked HTTP, in-process WebSocket) run offline:
Integration tests hit the live Kite API and are #[ignore]d by default. Provide
credentials via environment variables to run them:
KITE_API_KEY=xxx KITE_ACCESS_TOKEN=yyy
Real-time market-data endpoints (quote / ohlc / ltp / trigger_range) require a Kite "market data" subscription; without it those calls return
PermissionExceptionand the integration tests treat them as reachable-but-gated.
Changelog
See CHANGELOG.md. 0.3.0 is a breaking release — see the
migration notes there before upgrading from 0.2.x.
License
Licensed under either of MIT or Apache-2.0 at your option.