kiteticker-async-manager

Crates.iokiteticker-async-manager
lib.rskiteticker-async-manager
version0.2.1
created_at2025-06-21 00:41:46.485169+00
updated_at2025-08-24 03:23:59.572936+00
descriptionHigh-performance async WebSocket client for Kite Connect API with multi-connection support, dynamic subscription management, and optimized data processing.
homepage
repositoryhttps://github.com/SPRAGE/kiteticker-async-manager
max_upload_size
id1720412
size551,098
Shaun Pai (SPRAGE)

documentation

https://docs.rs/kiteticker-async-manager/latest/kiteticker-async-manager/

README

KiteTicker Async Manager

High-performance async WebSocket client for the Kite Connect API with multi-connection support and dynamic subscription management.

Crates.io Apache-2.0 Licensed Documentation

πŸ“š Documentation | πŸš€ Getting Started | πŸ“ Examples | πŸ”§ API Reference

✨ 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:

[dependencies]
kiteticker-async-manager = "0.2.1"
tokio = { version = "1.0", features = ["full"] }

Basic Usage

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

Feature Single Connection Multi-Connection Manager Improvement
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

πŸ“ Examples

πŸ”° Basic Examples

🎯 Advanced Examples

⚑ Performance Examples

🎯 Use Cases

Use Case Configuration Symbols Example
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

let config = KiteManagerConfig {
    max_connections: 1,
    max_symbols_per_connection: 100,
    default_mode: Mode::Full,
    ..Default::default()
};

Production

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

Feature Official kiteconnect-rs kiteticker-async-manager
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

# Install Rust and tools
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
cargo install just  # Task runner

Building

# Clone and build
git clone https://github.com/SPRAGE/kiteticker-async-manager.git
cd kiteticker-async-manager
just build

Running Examples

# Set API credentials
export KITE_API_KEY=your_api_key
export KITE_ACCESS_TOKEN=your_access_token

# Run examples
cargo run --example single_connection
cargo run --example dynamic_subscription_demo

Available Tasks

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.

Development Setup

Use just to run development tasks:

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 for details.

πŸ”— Links


⭐ Star this repository if you find it useful!

Commit count: 65

cargo fmt