# KiteTicker Async Manager
High-performance async WebSocket client for the [Kite Connect API](https://kite.trade/docs/connect/v3/websocket/#websocket-streaming) with multi-connection support and dynamic subscription management.
[![Crates.io][crates-badge]][crates-url]
[![Apache-2.0 Licensed][apache-2-0-badge]][apache-2-0-url]
[![Documentation][docs-badge]][docs-url]
[crates-badge]: https://img.shields.io/crates/v/kiteticker-async-manager.svg
[crates-url]: https://crates.io/crates/kiteticker-async-manager
[apache-2-0-badge]: https://img.shields.io/badge/license-apache-blue.svg
[apache-2-0-url]: https://github.com/SPRAGE/kiteticker-async-manager/blob/master/LICENSE
[docs-badge]: https://img.shields.io/badge/docs-latest-blue.svg
[docs-url]: https://docs.rs/kiteticker-async-manager/latest/kiteticker-async-manager
**[π Documentation](docs/)** |
**[π Getting Started](docs/guides/getting-started.md)** |
**[π Examples](examples/)** |
**[π§ API Reference](docs/api/)**
## β¨ Key Features
- **π Multi-Connection Support** - Utilize all 3 allowed WebSocket connections (9,000 symbol capacity)
- **β‘ High Performance** - Dedicated parser tasks, optimized buffers, sub-microsecond latency
- **π Dynamic Subscriptions** - Add/remove symbols at runtime without reconnection
- **π Load Balancing** - Automatic symbol distribution across connections
- **πͺ Production Ready** - Comprehensive error handling, health monitoring, reconnection
- **π§ Async-First Design** - Built with Tokio, follows Rust async best practices
## π Quick Start
### Installation
Add to your `Cargo.toml`:
```toml
[dependencies]
kiteticker-async-manager = "0.1.0"
tokio = { version = "1.0", features = ["full"] }
```
### Basic Usage
```rust
use kiteticker_async_manager::{KiteTickerManager, KiteManagerConfig, Mode, TickerMessage};
#[tokio::main]
async fn main() -> Result<(), String> {
// Setup credentials
let api_key = std::env::var("KITE_API_KEY").unwrap();
let access_token = std::env::var("KITE_ACCESS_TOKEN").unwrap();
// Create high-performance manager
let config = KiteManagerConfig {
max_connections: 3,
max_symbols_per_connection: 3000,
enable_dedicated_parsers: true,
default_mode: Mode::LTP,
..Default::default()
};
// Start manager
let mut manager = KiteTickerManager::new(api_key, access_token, config);
manager.start().await?;
// Subscribe to symbols (automatically distributed across connections)
let symbols = vec![256265, 408065, 738561]; // NIFTY 50, HDFC Bank, Reliance
manager.subscribe_symbols(&symbols, Some(Mode::Quote)).await?;
// Process data from independent channels
let channels = manager.get_all_channels();
for (channel_id, mut receiver) in channels {
tokio::spawn(async move {
while let Ok(message) = receiver.recv().await {
if let TickerMessage::Ticks(ticks) = message {
for tick in ticks {
println!("Channel {:?}: {} @ βΉ{:.2}",
channel_id,
tick.instrument_token,
tick.content.last_price.unwrap_or(0.0));
}
}
}
});
}
// Add symbols dynamically
manager.subscribe_symbols(&[5633, 884737], Some(Mode::Full)).await?;
// Remove symbols
manager.unsubscribe_symbols(&[408065]).await?;
// Change subscription mode
manager.change_mode(&[256265], Mode::Full).await?;
Ok(())
}
```
## π Performance Comparison
| **Max Symbols** | 3,000 | 9,000 | **3x capacity** |
| **Throughput** | Limited by 1 connection | 3 parallel connections | **3x throughput** |
| **Latency** | ~5-10Β΅s | ~1-2Β΅s | **5x faster** |
| **Resilience** | Single point of failure | 3 independent connections | **High availability** |
| **Dynamic Ops** | Manual reconnection | Runtime add/remove | **Zero downtime** |
## ποΈ Architecture
```
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β KiteTickerManager β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β π Symbol Distribution (9,000 symbols max) β
β βββββββββββββββ βββββββββββββββ βββββββββββββββ β
β βConnection 1 β βConnection 2 β βConnection 3 β β
β β3,000 symbolsβ β3,000 symbolsβ β3,000 symbolsβ β
β βββββββββββββββ βββββββββββββββ βββββββββββββββ β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β β‘ Dedicated Parser Tasks (CPU Optimized) β
β βββββββββββββββ βββββββββββββββ βββββββββββββββ β
β β Parser 1 β β Parser 2 β β Parser 3 β β
β β ~1Β΅s latencyβ β ~1Β΅s latencyβ β ~1Β΅s latencyβ β
β βββββββββββββββ βββββββββββββββ βββββββββββββββ β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β π‘ Independent Output Channels β
β βββββββββββββββ βββββββββββββββ βββββββββββββββ β
β β Channel 1 β β Channel 2 β β Channel 3 β β
β βbroadcast::Rxβ βbroadcast::Rxβ βbroadcast::Rxβ β
β βββββββββββββββ βββββββββββββββ βββββββββββββββ β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
```
## π Documentation
- **[π Getting Started](docs/guides/getting-started.md)** - Complete beginner's guide
- **[π§ API Reference](docs/api/)** - Detailed API documentation
- **[π Examples](examples/)** - Practical code examples
- **[π Dynamic Subscriptions](docs/guides/DYNAMIC_SUBSCRIPTION_GUIDE.md)** - Runtime symbol management
- **[β‘ Performance Guide](docs/guides/PERFORMANCE_IMPROVEMENTS.md)** - Optimization techniques
## π Examples
### π° Basic Examples
- **[Single Connection](examples/basic/single_connection.rs)** - Simple WebSocket usage
- **[Portfolio Monitor](examples/basic/portfolio_monitor.rs)** - Track portfolio stocks
- **[Runtime Subscriptions](examples/basic/runtime_subscription_example.rs)** - Dynamic symbol management
### π― Advanced Examples
- **[Dynamic Demo](examples/advanced/dynamic_subscription_demo.rs)** - Complete dynamic workflow
- **[Manager Demo](examples/advanced/manager_demo.rs)** - Multi-connection setup
- **[Market Scanner](examples/advanced/market_scanner.rs)** - High-volume scanning
### β‘ Performance Examples
- **[Performance Demo](examples/performance/performance_demo.rs)** - Benchmarking
- **[High Frequency](examples/performance/high_frequency.rs)** - Maximum throughput
## π― Use Cases
| **Portfolio Monitoring** | 1 connection, Quote mode | 10-50 | Track personal investments |
| **Algorithmic Trading** | 3 connections, Quote mode | 100-1,000 | Trading strategies |
| **Market Scanner** | 3 connections, LTP mode | 1,000-9,000 | Scan entire market |
| **High-Frequency Trading** | 3 connections, Full mode | 500-3,000 | Order book analysis |
## βοΈ Configuration Presets
### Development
```rust
let config = KiteManagerConfig {
max_connections: 1,
max_symbols_per_connection: 100,
default_mode: Mode::Full,
..Default::default()
};
```
### Production
```rust
let config = KiteManagerConfig {
max_connections: 3,
max_symbols_per_connection: 3000,
connection_buffer_size: 20000,
parser_buffer_size: 50000,
enable_dedicated_parsers: true,
default_mode: Mode::LTP,
..Default::default()
};
```
## π Comparison with Official Library
| **Maintenance** | β Unmaintained | β
Actively maintained |
| **Async Support** | β Callback-based | β
Full async/await |
| **Type Safety** | β Untyped JSON | β
Fully typed structs |
| **Multi-Connection** | β Single connection | β
Up to 3 connections |
| **Dynamic Subscriptions** | β Manual reconnection | β
Runtime add/remove |
| **Performance** | β Basic | β
High-performance optimized |
| **Error Handling** | β Limited | β
Comprehensive |
## π οΈ Development
### Prerequisites
```bash
# Install Rust and tools
```
### Building
```bash
# Clone and build
git clone https://github.com/SPRAGE/kiteticker-async-manager.git
cd kiteticker-async-manager
just build
```
### Running Examples
```bash
# Set API credentials
export KITE_API_KEY=your_api_key
export KITE_ACCESS_TOKEN=your_access_token
# Run examples
cargo run --example basic/single_connection
cargo run --example advanced/dynamic_subscription_demo
```
### Available Tasks
```bash
just --list
```
## π¦ Features
- **Multi-Connection Management** - Utilize all 3 WebSocket connections
- **Dynamic Subscriptions** - Add/remove symbols without reconnection
- **Load Balancing** - Automatic symbol distribution
- **High Performance** - Dedicated parsers, optimized buffers
- **Type Safety** - Fully typed market data structures
- **Error Resilience** - Comprehensive error handling and recovery
- **Health Monitoring** - Real-time connection health tracking
- **Async-First** - Built for modern Rust async ecosystems
## π€ Contributing
Contributions are welcome! Please see our [contribution guidelines](CONTRIBUTING.md).
### Development Setup
Use [just](https://github.com/casey/just) to run development tasks:
```bash
just --list # Show available tasks
just build # Build the project
just check # Check code formatting and lints
```
## π License
Licensed under the Apache License, Version 2.0. See [LICENSE](LICENSE) for details.
## π Links
- **[Kite Connect API Documentation](https://kite.trade/docs/connect/v3/websocket/)**
- **[Crates.io](https://crates.io/crates/kiteticker-async-manager)**
- **[Documentation](https://docs.rs/kiteticker-async-manager/)**
- **[GitHub Repository](https://github.com/SPRAGE/kiteticker-async-manager)**
---
**β Star this repository if you find it useful!**