Code Monkey home page Code Monkey logo

kiteticker-async's Introduction

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

kiteticker-async's People

Contributors

kaychaks avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

shabbirhasan1

kiteticker-async's Issues

Typeset Order

  • Order text messages are not typeset currently. They are returned as plain JSON values. Typeset(serialize) the same following the structure implemented here.

Add CI workflow

  • Basic functions - lint, format, build, unit tests
  • Update package version based on tags
  • Figure out a way to run integration tests that require kite_api and kite_access token
  • Create release and update version in crates.io

In Process_Binary Function - Array of length 1 had been used instead of range. Probably a typo.

Subjected Code Line: https://github.com/kaychaks/kiteticker-async/blob/262385615faa6f20bfcb74f7d97ab1e8af4104a5/src/ticker.rs#L243C9-L243C25

Issue: Array of length 1 had been used instead of range (probably a typo) for iterating over binary packets of different packet length, leading the fold to only process binary of the first instrument ticker packet.

fn print_type_of<T>(_: &T) {
    println!("{}", std::any::type_name::<T>())
}

fn main() {
    let x = [0..10];
    
    #[allow(unused_parens)]
    let y = (0..10); // or 0..10
    
    print_type_of(&x);
    print_type_of(&y);
}

Above Code Output: playground

[core::ops::range::Range<i32>; 1]
core::ops::range::Range<i32>

Proposed Resolution:

  fn process_binary(&self, binary_message: &[u8]) -> Option<TickerMessage> {
    let num_packets =
      i16::from_be_bytes(binary_message[0..=1].try_into().unwrap()) as usize;
    if num_packets > 0 {
      Some(TickerMessage::Ticks(
        (0..num_packets)
          .fold((vec![], 2), |(mut acc, start), _| {
            let packet_len = packet_length(&binary_message[start..start + 2]);
            let next_start = start + 2 + packet_len;
            let tick = Tick::from(&binary_message[start + 2..next_start]);
            acc.push(TickMessage::new(tick.instrument_token, tick));
            (acc, next_start)
          })
          .0,
      ))
    } else {
      None
    }
  }

Thank You.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.