Push Client
NewPushClient
NewPushClientSignature
func NewPushClient(cfg *config.ClientConfig, opts ...PushClientOption) *PushClientcfg supplies the authentication configuration. The constructor options are:
| Option | Default | Description |
|---|---|---|
WithPushURL(string) | openapi.tigerfintech.com:9883 | Push server address |
WithHeartbeatInterval(time.Duration) | 10s | Heartbeat interval |
WithReconnectInterval(time.Duration) | 5s | Initial reconnect interval; doubles after failures up to 60s |
WithAutoReconnect(bool) | true | Whether to reconnect after an unintentional disconnect |
WithConnectTimeout(time.Duration) | 30s | Timeout for connecting and awaiting authentication |
WithUseFullTick(bool) | false | Whether to request full-tick data; set before Connect |
pc := push.NewPushClient(cfg, push.WithUseFullTick(true))SetCallbacks
SetCallbacksPurpose
Replaces the callback set used to dispatch push connection, market-data, and account events.
Signature
func (c *PushClient) SetCallbacks(cb Callbacks)Parameters
| Parameter | Type | Required | SDK default | Constraints |
|---|---|---|---|---|
cb | Callbacks | Yes | None | Callback set; handlers left unset remain nil |
Callbacks field | Type | Description |
|---|---|---|
OnQuote | func(*pb.QuoteData) | Quote callback |
OnTick | func(push.PushTradeTick) | SDK-decoded trade-tick callback |
OnDepth | func(*pb.QuoteDepthData) | Quote-depth callback |
OnOption | func(*pb.QuoteData) | Option callback |
OnFuture | func(*pb.QuoteData) | Future callback |
OnKline | func(*pb.KlineData) | K-line callback |
OnStockTop | func(*pb.StockTopData) | Stock-ranking callback |
OnOptionTop | func(*pb.OptionTopData) | Option-ranking callback |
OnFullTick | func(*pb.TickData) | Full-tick callback |
OnQuoteBBO | func(*pb.QuoteData) | BBO quote callback |
OnAsset | func(*pb.AssetData) | Asset callback |
OnPosition | func(*pb.PositionData) | Position callback |
OnOrder | func(*pb.OrderStatusData) | Order callback |
OnTransaction | func(*pb.OrderTransactionData) | Transaction callback |
OnConnect | func() | Connection callback |
OnDisconnect | func() | Disconnection callback |
OnError | func(error) | Error callback |
OnKickout | func(string) | Kickout callback |
Unset handlers are not called. Crypto data is routed to OnQuote. The default tick mode invokes OnTick. When the client is created with WithUseFullTick(true), the server returns full-tick data and the SDK invokes OnFullTick first; it does not also invoke OnTick for that message. The current version does not dispatch a data type to OnQuoteBBO.
Returns
Returns no value.
Invocation example
pc.SetCallbacks(push.Callbacks{OnConnect: func() { fmt.Println("connected") }})Connect
ConnectPurpose
Opens the TLS push connection, authenticates it, waits for CONNECTED, and starts heartbeats.
Signature
func (c *PushClient) Connect() errorCall Connect successfully before subscribing or unsubscribing. Access depends on instrument and data type.
Parameters
No parameters.
Returns
error; nil means authentication completed and the connection-success acknowledgment was received. The default connection timeout is 30 seconds and the default heartbeat interval is 10 seconds.
Automatic reconnect is enabled by default. It starts at 5 seconds, doubles after failures, and caps at 60 seconds. Restoration is best effort from the local cache, and restoration errors are not returned to the caller. Ordinary symbol subscriptions can be restored. The HK whole-market quote subscription created by SubscribeMarket and ranking subscriptions do not retain the complete market information needed for correct restoration, while account subscriptions restore with the configured account rather than a custom account. Explicitly resubscribe to those types in OnConnect after a reconnect. Constructor options configure connection behavior.
Invocation example
if err := pc.Connect(); err != nil {
log.Fatal(err)
}Disconnect
DisconnectPurpose
Sends DISCONNECT, closes the transport, waits for reader shutdown, and invokes OnDisconnect.
Signature
func (c *PushClient) Disconnect() errorCalling this method while disconnected returns nil. An explicit disconnect does not trigger automatic reconnect.
Parameters
No parameters.
Returns
error; returns any underlying connection-close error. The method first attempts a disconnect notification, closes the connection, and invokes OnDisconnect.
Invocation example
if err := pc.Disconnect(); err != nil {
log.Fatal(err)
}State
StatePurpose
Returns the current local push connection state.
Signature
func (c *PushClient) State() ConnectionStateParameters
No parameters.
Returns
ConnectionState: StateDisconnected, StateConnecting, or StateConnected.
Invocation example
result := pc.State()
fmt.Printf("%#v\n", result)0GetSubscriptions
GetSubscriptionsPurpose
Returns a copy of locally tracked symbol subscriptions grouped by subject.
Signature
func (c *PushClient) GetSubscriptions() map[SubjectType][]stringParameters
No parameters.
Returns
map[SubjectType][]string. This is a copy of the local cache, not a server-side subscription query; subject and symbol order is unspecified. Ranking entries contain indicator strings, and HK whole-market quote entries contain market strings. That market string is neither a subscribed-symbol list nor sufficient for correct automatic restoration.
Invocation example
result := pc.GetSubscriptions()
fmt.Printf("%#v\n", result)map[push.SubjectType][]string{"quote":[]string{"AAPL"}}GetAccountSubscriptions
GetAccountSubscriptionsPurpose
Returns locally tracked account-level subscription subjects.
Signature
func (c *PushClient) GetAccountSubscriptions() []SubjectTypeParameters
No parameters.
Returns
[]SubjectType. This contains locally cached account-subscription subjects, not account IDs or server-side state; order is unspecified.
Invocation example
result := pc.GetAccountSubscriptions()
fmt.Printf("%#v\n", result)[]push.SubjectType{"asset"}Updated about 1 month ago
