Push Client

NewPushClient

Signature

func NewPushClient(cfg *config.ClientConfig, opts ...PushClientOption) *PushClient

cfg supplies the authentication configuration. The constructor options are:

OptionDefaultDescription
WithPushURL(string)openapi.tigerfintech.com:9883Push server address
WithHeartbeatInterval(time.Duration)10sHeartbeat interval
WithReconnectInterval(time.Duration)5sInitial reconnect interval; doubles after failures up to 60s
WithAutoReconnect(bool)trueWhether to reconnect after an unintentional disconnect
WithConnectTimeout(time.Duration)30sTimeout for connecting and awaiting authentication
WithUseFullTick(bool)falseWhether to request full-tick data; set before Connect
pc := push.NewPushClient(cfg, push.WithUseFullTick(true))

SetCallbacks

Purpose

Replaces the callback set used to dispatch push connection, market-data, and account events.

Signature

func (c *PushClient) SetCallbacks(cb Callbacks)

Parameters

ParameterTypeRequiredSDK defaultConstraints
cbCallbacksYesNoneCallback set; handlers left unset remain nil
Callbacks fieldTypeDescription
OnQuotefunc(*pb.QuoteData)Quote callback
OnTickfunc(push.PushTradeTick)SDK-decoded trade-tick callback
OnDepthfunc(*pb.QuoteDepthData)Quote-depth callback
OnOptionfunc(*pb.QuoteData)Option callback
OnFuturefunc(*pb.QuoteData)Future callback
OnKlinefunc(*pb.KlineData)K-line callback
OnStockTopfunc(*pb.StockTopData)Stock-ranking callback
OnOptionTopfunc(*pb.OptionTopData)Option-ranking callback
OnFullTickfunc(*pb.TickData)Full-tick callback
OnQuoteBBOfunc(*pb.QuoteData)BBO quote callback
OnAssetfunc(*pb.AssetData)Asset callback
OnPositionfunc(*pb.PositionData)Position callback
OnOrderfunc(*pb.OrderStatusData)Order callback
OnTransactionfunc(*pb.OrderTransactionData)Transaction callback
OnConnectfunc()Connection callback
OnDisconnectfunc()Disconnection callback
OnErrorfunc(error)Error callback
OnKickoutfunc(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

Purpose

Opens the TLS push connection, authenticates it, waits for CONNECTED, and starts heartbeats.

Signature

func (c *PushClient) Connect() error

Call 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

Purpose

Sends DISCONNECT, closes the transport, waits for reader shutdown, and invokes OnDisconnect.

Signature

func (c *PushClient) Disconnect() error

Calling 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

Purpose

Returns the current local push connection state.

Signature

func (c *PushClient) State() ConnectionState

Parameters

No parameters.

Returns

ConnectionState: StateDisconnected, StateConnecting, or StateConnected.

Invocation example

result := pc.State()
fmt.Printf("%#v\n", result)
0

GetSubscriptions

Purpose

Returns a copy of locally tracked symbol subscriptions grouped by subject.

Signature

func (c *PushClient) GetSubscriptions() map[SubjectType][]string

Parameters

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

Purpose

Returns locally tracked account-level subscription subjects.

Signature

func (c *PushClient) GetAccountSubscriptions() []SubjectType

Parameters

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"}


Did this page help you?