connect_sample/
connect_sample.rs

1extern crate kiteconnect_async_wasm;
2extern crate serde_json as json;
3
4use kiteconnect_async_wasm::connect::KiteConnect;
5
6#[tokio::main]
7async fn main() -> Result<(), Box<dyn std::error::Error>> {
8    let mut kiteconnect = KiteConnect::new("<API-KEY>", "");
9
10    // Open browser with this URL and get the request token from the callback
11    let loginurl = kiteconnect.login_url();
12    println!("{:?}", loginurl);
13
14    // Generate access token with the above request token
15    let resp = kiteconnect.generate_session("<REQUEST-TOKEN>", "<API-SECRET>").await?;
16    // `generate_session` internally sets the access token from the response
17    println!("{:?}", resp);
18
19    let holdings: json::Value = kiteconnect.holdings().await?;
20    println!("{:?}", holdings);
21
22    Ok(())
23}