Giter Site home page Giter Site logo

kiteconnect-rs's Introduction

kiteconnect-rs

Crates.io Travis

API wrapper for kiteconnect in rust

Docs

https://docs.rs/kiteconnect

Usage

Head on to https://crates.io/crates/kiteconnect

Copy kiteconnect = "<VERSION>" dependency to Cargo.toml file

KiteConnect REST APIs

extern crate kiteconnect;
extern crate serde_json as json;

use kiteconnect::connect::KiteConnect;

fn main() {
    let mut kiteconnect = KiteConnect::new("<API-KEY>", "");

    // 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("<REQUEST-TOKEN>", "<API-SECRET>");
    // `generate_session` internally sets the access token from the response
    println!("{:?}", resp);

    let holdings: json::Value = kiteconnect.holdings().unwrap();
    println!("{:?}", holdings);
}

Kite Ticker Websocket

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<T>(&mut self, ws: &mut WebSocketHandler<T>)
    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<T>(&mut self, ws: &mut WebSocketHandler<T>, tick: Vec<json::Value>)
    where T: KiteTickerHandler {
        println!("{:?}", tick);
        println!("Fellow on_ticks callback");
    }

    fn on_close<T>(&mut self, ws: &mut WebSocketHandler<T>)
    where T: KiteTickerHandler {
        println!("Fellow on_close callback");
    }

    fn on_error<T>(&mut self, ws: &mut WebSocketHandler<T>)
    where T: KiteTickerHandler {
        println!("Fellow on_error callback");
    }
}

fn main() {
    let mut ticker = KiteTicker::new("<API-KEY>", "<ACCESS-TOKEN>");

    let custom_handler = CustomHandler {
        count: 0
    };

    ticker.connect(custom_handler, None);

    loop {}
}

Running Examples

KiteConnect REST API sample

cargo run --example connect_sample

KiteConnect Websocket sample

cargo run --example ticker_sample

TODO

  • Add serializer structs for all kiteconnect returning datastructures
  • Reconnection mechanism

kiteconnect-rs's People

Contributors

joeirimpan avatar suyashb95 avatar aurabindo avatar asnimansari avatar

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.