Skip to content

kaychaks/kiteticker-async

Repository files navigation

kiteticker-async

Async client for the Kite Connect WebSocket API.

Crates.io Apache-2.0 Licensed

Guide | API Docs

Overview

The official kiteconnect-rs is an unmaintained project compared to the Python or Go implementations. As per this issue, it will not get any further updates from the Zerodha Tech team.

Even 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:

  • It lacks a few updates, which are present in actively maintained Python & Go implementations.

  • 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 or Java.

  • 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.

This 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.

Usage

Add kiteticker-async crate as a dependency in Cargo.toml

[dependencies]
kiteticker-async = "0.1.1"

Example

#[tokio::main]
pub async fn main() -> Result<(), String> {
  let api_key = std::env::var("KITE_API_KEY").unwrap();
  let access_token = std::env::var("KITE_ACCESS_TOKEN").unwrap();
  let ticker = KiteTickerAsync::connect(&api_key, &access_token).await?;

  let token = 408065;
  // subscribe to an instrument
  let mut subscriber = ticker
    .subscribe(&[token], Some(Mode::Full))
    .await?;

  // await quotes
  if let Some(msg) = subscriber.next_message().await? {
    match msg {
      TickerMessage::Tick(ticks) => {
        let tick = ticks.first().unwrap();
        println!("Received tick for instrument_token {}, {}", tick.instrument_token, tick);
      }
    }
  }

  Ok(())
}

Contributing

Use just to run the development tasks.

$ just --list
Available recipes:
    build
    check
    doc
    doc-open
    doc-test api_key='' access_token=''
    example api_key access_token
    test api_key='' access_token=''

License

This project is licensed under the Apache 2.0 License