Real-Time Streaming

Push uses Protobuf over TCP/TLS. Market subscriptions require the corresponding license; account subscriptions require account permission. subscribe/unsubscribe only report whether the frame entered the local channel, not server acceptance. Auto-reconnect defaults on and backs off to 60 seconds. After reconnecting, it can restore standard market-data subscriptions recorded by symbols; the HK whole-market quote subscription created by subscribe_market, ranking subscriptions, and custom accounts used by account subscriptions are not fully retained, so explicitly resubscribe after the connection succeeds.

Security warning: the current Rust SDK unconditionally accepts any server certificate and verifies neither the 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.

PushClient::new

pub fn new(config: ClientConfig, options: Option<PushClientOptions>) -> PushClient

All PushClientOptions fields are optional: push_url defaults to openapi.tigerfintech.com:9883; heartbeat 10 seconds; initial reconnect 5 seconds; auto reconnect true; connection timeout 30 seconds.

set_callbacks

pub fn set_callbacks(&self, cb: Callbacks)

Replaces all callbacks. Market callbacks: on_quote(QuoteData), on_tick(PushTradeTick), on_depth(QuoteDepthData), on_option(QuoteData), on_future(QuoteData), on_kline(KlineData), on_stock_top(StockTopData), on_option_top(OptionTopData), and on_full_tick(TickData). Account callbacks cover assets, positions, order status, and transactions. Connection callbacks cover connect, disconnect, error String, and kickout String. PushTradeTick is exported from tigeropen::push; the other payload types are in tigeropen::push::pb. The dispatcher retains an on_quote_bbo fallback for QuoteData with an unrecognized data_type, but SubjectType::QuoteBbo currently maps to Quote, so normal BBO data still arrives through the corresponding on_quote, on_option, or on_future callback.

Connection and state

Method and exact signatureBehavior and errors
connect(client: &Arc<PushClient>) -> Result<(), String>Async free function; TCP/TLS, RSA auth, waits for CONNECTED; rejects duplicate connection; default timeout 30 seconds.
disconnect(&self)Best-effort DISCONNECT, stops tasks, clears channels, invokes callback.
state(&self) -> ConnectionStateDisconnected/Connecting/Connected.
send_heartbeat(&self) -> boolQueues heartbeat; false when unavailable.

Subscribe

pub fn subscribe(&self, subject: &SubjectType, symbols: Option<&str>, account: Option<&str>, market: Option<&str>) -> bool
pub fn unsubscribe(&self, subject: &SubjectType, symbols: Option<&str>, account: Option<&str>, market: Option<&str>) -> bool

Symbols are comma-separated. Market data uses symbols, account subjects use account, and market/ranking subjects use market. Subjects: Quote/Tick/Depth/Option/Future/Kline/StockTop/OptionTop/FullTick/QuoteBbo/Asset/Position/Order/Transaction/Cc/Market.

Subscription state

Exact signaturePurpose
add_subscription(&self, subject: SubjectType, symbols: &[String])Record market data for query/reconnect.
remove_subscription(&self, subject: SubjectType, symbols: Option<&[String]>)Remove symbols or whole subject.
get_subscriptions(&self) -> HashMap<SubjectType, Vec<String>>Recorded market subscriptions.
add_account_sub(&self, subject: SubjectType)Record account subject.
remove_account_sub(&self, subject: &SubjectType)Remove account subject.
get_account_subscriptions(&self) -> Vec<SubjectType>Recorded account subjects.

Base subscribe does not update state. Record symbols-based standard market-data subscriptions too, or use convenience methods, if they must be restored after reconnecting. Explicitly resubscribe the HK whole-market quote subscription created by subscribe_market, ranking subscriptions, and custom-account subscriptions after the connection succeeds.

Convenience methods

pub fn subscribe_cc(&self, symbols: &[&str]) -> Result<(), TigerError>
pub fn unsubscribe_cc(&self, symbols: Option<&[&str]>) -> Result<(), TigerError>
pub fn subscribe_market(&self, market: &str) -> Result<(), TigerError>
pub fn unsubscribe_market(&self, market: &str) -> Result<(), TigerError>

subscribe_cc accepts any slice and currently does not reject an empty one; unsubscribe_cc(None) clears all crypto records. subscribe_market supports only HK and subscribes to whole-market quote updates delivered per symbol through ordinary on_quote; it does not subscribe to market status or a snapshot. These methods ignore the underlying bool and update local state, so Ok(()) proves neither that the frame entered the send channel nor that the server accepted it.

Public protocol methods

handle_message(&self, data: &[u8]) decodes one complete varint32 frame and dispatches callbacks, mainly for tests/custom transports; an empty slice or incomplete frame invokes on_error and is not a valid example. push::varint::{encode_varint32, decode_varint32} and the public push::proto_message builders/mapping are also public; normal applications should use connect and subscriptions.

Example

use std::sync::Arc;
use tigeropen::config::ClientConfig;
use tigeropen::push::{connect, Callbacks, PushClient, SubjectType};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = Arc::new(PushClient::new(ClientConfig::builder().build()?, None));
    client.set_callbacks(Callbacks {
        on_quote: Some(Arc::new(|q| println!("{} {:?}", q.symbol, q.latest_price))),
        on_error: Some(Arc::new(|message| eprintln!("{message}"))),
        ..Default::default()
    });
    connect(&client).await.map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e))?;
    let symbols = vec!["AAPL".to_string()];
    if client.subscribe(&SubjectType::Quote, Some("AAPL"), None, None) {
        client.add_subscription(SubjectType::Quote, &symbols);
    }
    client.disconnect();
    Ok(())
}

Redacted event shape generated from the model:

{"symbol":"AAPL","latest_price":150.5,"volume":1000000}

Push has no HTTP pagination. Slow callbacks block dispatch, so hand expensive work to another task. Source: PushClient, Callbacks, SubjectType.

Pages in this section


Did this page help you?