Expand description
Async implementation of Kite Connect’s WebSocket Steaming API
This crate provides types to subscribe and receive live quotes for instruments during market hours via WebSockets. The response is parsed and converted into Rust types. The WebSocket connection is managed by the library and reconnected automatically.
§Usage
use kiteticker_async::{KiteTickerAsync, Mode, TickerMessage};
#[tokio::main]
pub async fn main() -> Result<(), String> {
let api_key = std::env::var("KITE_API_KEY").unwrap_or_default();
let access_token = std::env::var("KITE_ACCESS_TOKEN").unwrap_or_default();
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
loop {
if let Some(msg) = subscriber.next_message().await? {
match msg {
TickerMessage::Ticks(ticks) => {
let tick = ticks.first().unwrap();
println!("Received tick for instrument_token {}, {:?}", tick.instrument_token, tick);
break;
},
_ => continue,
}
}
}
Ok(())
}
Re-exports§
pub use ticker::KiteTickerAsync;
pub use ticker::KiteTickerSubscriber;
Modules§
Structs§
- Depth
- Market depth packet structure
- Depth
Item - Structure for each market depth entry
- OHLC
- OHLC packet structure
- Request
- Websocket request structure
- Text
Message - Postback and non-binary message structure
- Tick
- Quote packet structure
- Tick
Message - Parsed quote packet
Enums§
- Exchange
- Exchange options
- Mode
- Modes in which packets are streamed
- Ticker
Message - Parsed message from websocket