Async client for the Kite Connect WebSocket API
1# kiteticker-async
2
3Async client for the [Kite Connect WebSocket API](https://kite.trade/docs/connect/v3/websocket/#websocket-streaming).
4
5[![Crates.io][crates-badge]][crates-url]
6[![Apache-2.0 Licensed][apache-2-0-badge]][apache-2-0-url]
7
8[crates-badge]: https://img.shields.io/crates/v/kiteticker-async.svg
9[crates-url]: https://crates.io/crates/kiteticker-async
10[apache-2-0-badge]: https://img.shields.io/badge/license-apache-blue.svg
11[apache-2-0-url]: https://github.com/kaychaks/kiteticker-async/blob/master/LICENSE
12
13[Guide](https://kite.trade/docs/connect/v3/websocket/#websocket-streaming) |
14[API Docs](https://docs.rs/kiteticker-async/latest/kiteticker-async)
15
16## Overview
17
18The official [kiteconnect-rs](https://crates.io/crates/kiteconnect) is an unmaintained project compared to the Python or Go implementations. As per this [issue](https://github.com/zerodha/kiteconnect-rs/issues/39), it will not get any further updates from the Zerodha Tech team.
19
20Even though the Kite Connect REST APIs are feature-complete, the Ticker APIs are lagging. Here are some of the issues with Ticker API Rust implementation:
21
22- It lacks a few updates, which are present in actively maintained [Python](https://github.com/zerodha/pykiteconnect) & [Go](https://github.com/zerodha/gokiteconnect) implementations.
23
24- It does not parse and serialise quote structure to proper Rust structs and leaves it at an untyped JSON value. This is again a departure from how the same is implemented in libraries of typed languages like [Go](https://github.com/zerodha/gokiteconnect/blob/master/ticker/ticker.go) or [Java](https://github.com/zerodha/javakiteconnect/tree/master/kiteconnect/src/com/zerodhatech/models).
25
26- The design requires the applications to handle the streaming WebSocket messages via callbacks. It is not an idiomatic Rust library design, primarily when the downstream applications rely on modern Rust async concurrency primitives using frameworks like [tokio](https://tokio.rs/).
27
28This crate is an attempt to address the above issues. The primary goal is to have an async-friendly design following Rust's async library design principles championed by [tokio](https://tokio.rs/tokio/tutorial).
29
30## Usage
31
32Add kiteticker-async crate as a dependency in Cargo.toml
33
34```
35[dependencies]
36kiteticker-async = "0.1.1"
37```
38
39## Example
40
41```rust
42#[tokio::main]
43pub async fn main() -> Result<(), String> {
44 let api_key = std::env::var("KITE_API_KEY").unwrap();
45 let access_token = std::env::var("KITE_ACCESS_TOKEN").unwrap();
46 let ticker = KiteTickerAsync::connect(&api_key, &access_token).await?;
47
48 let token = 408065;
49 // subscribe to an instrument
50 let mut subscriber = ticker
51 .subscribe(&[token], Some(Mode::Full))
52 .await?;
53
54 // await quotes
55 if let Some(msg) = subscriber.next_message().await? {
56 match msg {
57 TickerMessage::Tick(ticks) => {
58 let tick = ticks.first().unwrap();
59 println!("Received tick for instrument_token {}, {}", tick.instrument_token, tick);
60 }
61 }
62 }
63
64 Ok(())
65}
66```
67
68## Contributing
69
70Use [just](https://github.com/casey/just) to run the development tasks.
71
72```sh
73$ just --list
74Available recipes:
75 build
76 check
77 doc
78 doc-open
79 doc-test api_key='' access_token=''
80 example api_key access_token
81 test api_key='' access_token=''
82```
83
84## License
85
86This project is licensed under the [Apache 2.0 License]
87
88[Apache 2.0 license]: https://github.com/kaychaks/kiteticker-async/blob/master/LICENSE