#api-client #trading #async-client #client-builder #connect #zerodha #http-api

manja

Asynchronous client library for Zerodha's KiteConnect trading API

2 releases

0.1.1-rc May 22, 2024
0.1.0 May 16, 2024

#1379 in Web programming

MIT license

29KB
557 lines

manja

Manja (IPA: /maːŋdʒʱaː/) n.: A type of abrasive string utilized primarily for flying fighter kites, especially prevalent in South Asian countries. It is crafted by coating cotton string with powdered glass or a similar abrasive substance.

This crate provides a Rust client library for Zerodha's Kite Connect trading APIs (a set of REST-like HTTP APIs).


lib.rs:

An asynchronous client library for Zerodha's Kite Connect trading APIs (a set of REST-like HTTP APIs).

This crate uses the tokio asynchronous runtime.

Example:

mod kite;
use kite::connect::client_builder::KiteConnectClientBuilder;
use kite::connect::credentials::KiteCredentials;
use std::error::Error;

use tokio;
use tracing::info;

#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
    // Load environment variables from a `.env` file
    dotenv::dotenv().ok();

    // Load Kite user credentials from the environment
    let kite_creds = KiteCredentials::load_from_env()?;
    info!("{:?}", kite_creds);
    
    // Construct a `KiteConnect` client from a builder struct
    let manja_client = KiteConnectClientBuilder::default()
        .with_credentials(kite_creds)
        .build()?;

    // Generate a `request_token` as part of the login flow
    let request_token = manja_client.generate_request_token().await?;
    // Use the `request_token` to generate a user session (having an `access_token`)
    let user_session = manja_client.generate_session(&request_token).await?;

    println!("{:?}", user_session);

    Ok(())
}

Dependencies

~11–23MB
~332K SLoC