MultiApiKiteTickerManager

Struct MultiApiKiteTickerManager 

Source
pub struct MultiApiKiteTickerManager { /* private fields */ }
Expand description

High-performance multi-API WebSocket manager for Kite ticker data

This manager supports multiple Kite Connect API credentials, allowing you to subscribe to symbols across multiple accounts. Each API key maintains its own connection pool (up to 3 connections), and symbols can be distributed automatically or manually assigned to specific API keys.

§Example

use kiteticker_async_manager::{MultiApiKiteTickerManager, Mode};

#[tokio::main]
async fn main() -> Result<(), String> {
    let mut manager = MultiApiKiteTickerManager::builder()
        .add_api_key("account1", "api_key_1", "access_token_1")
        .add_api_key("account2", "api_key_2", "access_token_2")
        .max_connections_per_api(3)
        .build();

    manager.start().await?;

    // Subscribe symbols (auto-distributed across API keys)
    let symbols = vec![408065, 738561];
    manager.subscribe_symbols(&symbols, Some(Mode::Quote)).await?;

    // Or assign to specific API key
    manager.subscribe_symbols_to_api("account1", &symbols, Some(Mode::LTP)).await?;

    Ok(())
}

Implementations§

Source§

impl MultiApiKiteTickerManager

Source

pub fn builder() -> MultiApiKiteTickerManagerBuilder

Create a builder for constructing a multi-API manager

Source

pub async fn start(&mut self) -> Result<(), String>

Initialize all connections for all API keys and start the manager

Source

pub async fn subscribe_symbols( &mut self, symbols: &[u32], mode: Option<Mode>, ) -> Result<(), String>

Subscribe to symbols using automatic distribution (round-robin across API keys)

Source

pub async fn subscribe_symbols_to_api( &mut self, api_key_id: impl Into<ApiKeyId>, symbols: &[u32], mode: Option<Mode>, ) -> Result<(), String>

Subscribe symbols to a specific API key

Source

pub async fn unsubscribe_symbols( &mut self, symbols: &[u32], ) -> Result<(), String>

Unsubscribe from symbols

Source

pub async fn change_mode( &mut self, symbols: &[u32], mode: Mode, ) -> Result<(), String>

Change subscription mode for existing symbols

Source

pub fn get_unified_channel(&self) -> Receiver<(ApiKeyId, TickerMessage)>

Get the unified output channel that receives messages from all API keys

Messages are tuples of (ApiKeyId, TickerMessage)

Source

pub fn get_channel( &mut self, api_key_id: impl Into<ApiKeyId>, channel_id: ChannelId, ) -> Option<Receiver<TickerMessage>>

Get output channel for a specific API key and connection

Source

pub async fn get_stats(&self) -> MultiApiStats

Get aggregate statistics across all API keys

Source

pub async fn get_api_stats( &self, api_key_id: impl Into<ApiKeyId>, ) -> Result<ApiKeyStats, String>

Get statistics for a specific API key

Source

pub fn get_symbol_distribution( &self, ) -> HashMap<ApiKeyId, HashMap<usize, Vec<u32>>>

Get symbol distribution across all API keys and connections

Source

pub fn get_api_keys(&self) -> Vec<ApiKeyId>

Get list of all configured API key IDs

Source

pub async fn stop(&mut self) -> Result<(), String>

Stop the manager and all connections

Trait Implementations§

Source§

impl Debug for MultiApiKiteTickerManager

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V