Push Client and Connection

connect

Signature


pub async fn connect(client: &Arc<PushClient>) -> Result<(), String>

Description

Opens TCP/TLS, authenticates with an RSA signature, starts read/write tasks, waits for server CONNECTED, then starts heartbeats.

Security warning: the current TLS configuration verifies neither the server certificate chain nor hostname, so it cannot authenticate the server and is vulnerable to man-in-the-middle attacks. Using an official endpoint or trusted network does not compensate for this omission; the SDK must implement complete certificate-chain and hostname verification.

Parameters

ParameterRust typeRequirementSDK default
client&Arc<PushClient>RequiredNone

Return

  • PushClient: Result<(), String>.
    Example

use std::sync::Arc;

use tigeropen::client::http_client::HttpClient;

use tigeropen::config::ClientConfig;

use tigeropen::error::TigerError;

use tigeropen::model::order::*;

use tigeropen::model::quote::*;

use tigeropen::model::quote_requests::*;

use tigeropen::model::trade_requests::*;

use tigeropen::push::*;

use tigeropen::push::pb::{AssetData, OrderStatusData, PositionData, QuoteData};

use tigeropen::quote::QuoteClient;

use tigeropen::trade::TradeClient;

async fn example_connect(config: ClientConfig, quote: &QuoteClient, trade: &TradeClient, push: &Arc<PushClient>) -> Result<(), TigerError> {

    let result_0 = connect(push).await.map_err(|e| TigerError::Config(e))?;

    Ok(())

}

Response example

No synchronous server response. Success means the connection flow completed and CONNECTED was received.


disconnect

Signature


pub fn disconnect(&self)

Description

Best-effort sends DISCONNECT, marks the client disconnected, stops background tasks, and invokes on_disconnect.

Parameters

ParameterRust typeRequirementSDK default
none-Required by Rust typeNone

Return

  • PushClient: (). No response fields on success..

Example


use std::sync::Arc;

use tigeropen::client::http_client::HttpClient;

use tigeropen::config::ClientConfig;

use tigeropen::error::TigerError;

use tigeropen::model::order::*;

use tigeropen::model::quote::*;

use tigeropen::model::quote_requests::*;

use tigeropen::model::trade_requests::*;

use tigeropen::push::*;

use tigeropen::quote::QuoteClient;

use tigeropen::trade::TradeClient;

async fn example_disconnect(config: ClientConfig, quote: &QuoteClient, trade: &TradeClient, push: &Arc<PushClient>) -> Result<(), TigerError> {

    let result_0 = push.disconnect();

    Ok(())

}

Response example

No synchronous server response. This method only starts the local disconnect flow.


state

Signature


pub fn state(&self) -> ConnectionState

Description

Reads a connection-state snapshot: Disconnected, Connecting, or Connected.

Parameters

ParameterRust typeRequirementSDK default
none-Required by Rust typeNone

Return

  • PushClient: ConnectionState.
    Example

use std::sync::Arc;

use tigeropen::client::http_client::HttpClient;

use tigeropen::config::ClientConfig;

use tigeropen::error::TigerError;

use tigeropen::model::order::*;

use tigeropen::model::quote::*;

use tigeropen::model::quote_requests::*;

use tigeropen::model::trade_requests::*;

use tigeropen::push::*;

use tigeropen::quote::QuoteClient;

use tigeropen::trade::TradeClient;

async fn example_state(config: ClientConfig, quote: &QuoteClient, trade: &TradeClient, push: &Arc<PushClient>) -> Result<(), TigerError> {

    let result_0 = push.state();

    Ok(())

}

Response example

No synchronous server response. The return value is the local connection-state enum.


set_callbacks

Signature


pub fn set_callbacks(&self, cb: Callbacks)

Description

Atomically replaces the complete set of market, account, and connection callbacks; unset fields remain None.

Parameters

ParameterRust typeRequirementSDK default
cbCallbacksRequired by Rust typeNone

Return

()

Callbacks struct fields

Callback fieldType signatureDescription
on_quote/on_option/on_futureOption<Arc<dyn Fn(QuoteData) + Send + Sync>>Stock, option, or futures quote changes, including BBO data
on_depthOption<Arc<dyn Fn(QuoteDepthData) + Send + Sync>>Depth-of-book data
on_tickOption<Arc<dyn Fn(PushTradeTick) + Send + Sync>>Trade ticks decoded by the SDK
on_full_tickOption<Arc<dyn Fn(TickData) + Send + Sync>>Full tick data
on_klineOption<Arc<dyn Fn(KlineData) + Send + Sync>>Minute K-line push
on_stock_topOption<Arc<dyn Fn(StockTopData) + Send + Sync>>Stock ranking push
on_option_topOption<Arc<dyn Fn(OptionTopData) + Send + Sync>>Option ranking push
on_assetOption<Arc<dyn Fn(AssetData) + Send + Sync>>Asset changes (full snapshot every 5s)
on_positionOption<Arc<dyn Fn(PositionData) + Send + Sync>>Position changes (full snapshot every 5s)
on_orderOption<Arc<dyn Fn(OrderStatusData) + Send + Sync>>Order status changes
on_transactionOption<Arc<dyn Fn(OrderTransactionData) + Send + Sync>>Order transaction details
on_connect/on_disconnectOption<Arc<dyn Fn() + Send + Sync>>Connected/disconnected notifications
on_error/on_kickoutOption<Arc<dyn Fn(String) + Send + Sync>>Error/kickout notifications

The dispatcher does have an on_quote_bbo fallback: it invokes that callback when the body is QuoteData but data_type is not Quote, Option, Future, or Cc. However, SubjectType::QuoteBbo currently maps to Quote, so a normal BBO subscription reaches on_quote, not the fallback; option and futures BBO reach on_option and on_future, respectively.

Example


use std::sync::Arc;

use tigeropen::client::http_client::HttpClient;

use tigeropen::config::ClientConfig;

use tigeropen::error::TigerError;

use tigeropen::model::order::*;

use tigeropen::model::quote::*;

use tigeropen::model::quote_requests::*;

use tigeropen::model::trade_requests::*;

use tigeropen::push::*;

use tigeropen::quote::QuoteClient;

use tigeropen::trade::TradeClient;

async fn example_set_callbacks(config: ClientConfig, quote: &QuoteClient, trade: &TradeClient, push: &Arc<PushClient>) -> Result<(), TigerError> {

    use tigeropen::push::pb::{AssetData, OrderStatusData, PositionData, QuoteData};

    let cb = Callbacks {
        on_quote: Some(Arc::new(|data: QuoteData| {
            println!("Quote change: symbol={}, latest_price={:?}", data.symbol, data.latest_price);
        })),
        on_order: Some(Arc::new(|data: OrderStatusData| {
            println!("Order change: id={}, status={}", data.id, data.status);
        })),
        on_asset: Some(Arc::new(|data: AssetData| {
            println!("Asset change: account={}, net_liquidation={}", data.account, data.net_liquidation);
        })),
        on_position: Some(Arc::new(|data: PositionData| {
            println!("Position change: symbol={}, quantity={}", data.symbol, data.position_qty);
        })),
        on_connect: Some(Arc::new(|| {
            println!("Connected");
        })),
        on_disconnect: Some(Arc::new(|| {
            println!("Disconnected");
        })),
        ..Callbacks::default()
    };
    push.set_callbacks(cb);

    Ok(())

}

Response example

No synchronous server response. The callback set is replaced locally.


send_heartbeat

Signature


pub fn send_heartbeat(&self) -> bool

Description

Builds and queues a Protobuf heartbeat request; success only means the local write channel accepted the frame.

Parameters

ParameterRust typeRequirementSDK default
none-Required by Rust typeNone

Return

  • PushClient: bool. Returns bool: whether the protocol frame entered the local send channel, not server acceptance..

Example


use std::sync::Arc;

use tigeropen::client::http_client::HttpClient;

use tigeropen::config::ClientConfig;

use tigeropen::error::TigerError;

use tigeropen::model::order::*;

use tigeropen::model::quote::*;

use tigeropen::model::quote_requests::*;

use tigeropen::model::trade_requests::*;

use tigeropen::push::*;

use tigeropen::quote::QuoteClient;

use tigeropen::trade::TradeClient;

async fn example_send_heartbeat(config: ClientConfig, quote: &QuoteClient, trade: &TradeClient, push: &Arc<PushClient>) -> Result<(), TigerError> {

    let result_0 = push.send_heartbeat();

    Ok(())

}

Response example

No synchronous server response. The returned bool only reports whether the heartbeat frame entered the local send channel.


handle_message

Signature


pub fn handle_message(&self, data: &[u8])

Description

Decodes one varint32-length-prefixed Protobuf response and dispatches it by command and data type; intended mainly for tests or custom transports.

Parameters

ParameterRust typeRequirementSDK default
data&[u8]Required by Rust typeNone

Return

  • PushClient: (). No response fields on success..

Usage

Normal applications do not call this method; the read task started by connect handles frames automatically. A custom transport must pass one complete varint32-length-prefixed Response frame; do not pass &[] or arbitrary bytes.

Response example

No synchronous server response. Decoded data is dispatched through registered callbacks.



Did this page help you?