Async client for the Kite Connect WebSocket API
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

feat: add examples

+34
+34
examples/sample.rs
··· 1 + use kiteticker_async::{KiteTickerAsync, Mode, TickerMessage}; 2 + 3 + #[tokio::main] 4 + pub async fn main() -> Result<(), String> { 5 + let api_key = std::env::var("KITE_API_KEY").unwrap_or_default(); 6 + let access_token = std::env::var("KITE_ACCESS_TOKEN").unwrap_or_default(); 7 + let ticker = KiteTickerAsync::connect(&api_key, &access_token).await?; 8 + 9 + let token = 408065; 10 + // subscribe to an instrument 11 + let mut subscriber = ticker.subscribe(&[token], Some(Mode::Full)).await?; 12 + 13 + // await quotes 14 + loop { 15 + if let Some(msg) = subscriber.next_message().await? { 16 + match msg { 17 + TickerMessage::Ticks(ticks) => { 18 + let tick = ticks.first().unwrap(); 19 + println!( 20 + "Received tick for instrument_token {}, {:?}", 21 + tick.instrument_token, tick 22 + ); 23 + break; 24 + } 25 + _ => { 26 + println!("Received message from broker {:?}", msg); 27 + continue; 28 + } 29 + } 30 + } 31 + } 32 + 33 + Ok(()) 34 + }