# kiteconnect-rs [![Crates.io](https://img.shields.io/crates/v/kiteconnect.svg)](https://crates.io/crates/kiteconnect) [![Travis](https://img.shields.io/travis/zerodhatech/kiteconnect-rs/master.svg)](https://travis-ci.org/zerodhatech/kiteconnect-rs/) API wrapper for kiteconnect in rust ## Docs https://docs.rs/kiteconnect ## Usage Head on to https://crates.io/crates/kiteconnect Copy `kiteconnect = ""` dependency to Cargo.toml file ### KiteConnect REST APIs ```rust extern crate kiteconnect; extern crate serde_json as json; use kiteconnect::connect::KiteConnect; fn main() { let mut kiteconnect = KiteConnect::new("", ""); // Open browser with this URL and get the request token from the callback let loginurl = kiteconnect.login_url(); println!("{:?}", loginurl); // Generate access token with the above request token let resp = kiteconnect.generate_session("", ""); // `generate_session` internally sets the access token from the response println!("{:?}", resp); let holdings: json::Value = kiteconnect.holdings().unwrap(); println!("{:?}", holdings); } ``` ### Kite Ticker Websocket ```rust extern crate kiteconnect; extern crate serde_json as json; use kiteconnect::ticker::{KiteTicker, KiteTickerHandler, WebSocketHandler} #[derive(Debug)] struct CustomHandler { count: u32 } impl KiteTickerHandler for CustomHandler { fn on_open(&mut self, ws: &mut WebSocketHandler) where T: KiteTickerHandler { // Subscribe to a list of tokens on opening the websocket connection ws.subscribe(vec![123456]); println!("Fellow on_open callback"); } fn on_ticks(&mut self, ws: &mut WebSocketHandler, tick: Vec) where T: KiteTickerHandler { println!("{:?}", tick); println!("Fellow on_ticks callback"); } fn on_close(&mut self, ws: &mut WebSocketHandler) where T: KiteTickerHandler { println!("Fellow on_close callback"); } fn on_error(&mut self, ws: &mut WebSocketHandler) where T: KiteTickerHandler { println!("Fellow on_error callback"); } } fn main() { let mut ticker = KiteTicker::new("", ""); let custom_handler = CustomHandler { count: 0 }; ticker.connect(custom_handler, None); loop {} } ``` ## Running Examples ### KiteConnect REST API sample ```bash cargo run --example connect_sample ``` ### KiteConnect Websocket sample ```bash cargo run --example ticker_sample ``` ## TODO - [ ] Add serializer structs for all kiteconnect returning datastructures - [ ] Reconnection mechanism