Market Subscriptions

SubscribeQuote

Purpose

Creates a market data subscription on the connected client and records it locally.

Signature

func (c *PushClient) SubscribeQuote(symbols []string) error

Call Connect successfully before subscribing or unsubscribing. Access depends on instrument and data type.

Parameters

ParameterTypeRequiredSDK defaultConstraints
symbols[]stringYesNoneInstrument symbols; the SDK does not enforce a batch limit

Returns

error; nil means the message was written to the current connection.

Invocation example

if err := pc.SubscribeQuote([]string{"AAPL"}); err != nil {
	log.Fatal(err)
}

Callback Data Example

Quote (BASIC):

{
    "symbol": "AAPL",
    "type": "BASIC",
    "timestamp": "1684766012120",
    "serverTimestamp": "1684766012129",
    "avgPrice": 174.1721,
    "latestPrice": 174.175,
    "latestPriceTimestamp": "1684766011918",
    "latestTime": "05-22 10:33:31 EDT",
    "preClose": 175.16,
    "volume": "12314802",
    "amount": 2144365591.41,
    "open": 173.98,
    "high": 174.71,
    "low": 173.45,
    "marketStatus": "Trading",
    "mi": {
        "p": 174.175,
        "a": 174.1721,
        "t": "1684765980000",
        "v": "57641",
        "o": 174.21,
        "h": 174.22,
        "l": 174.14
    }
}

Best Bid/Offer (BBO):

{
    "symbol": "AAPL",
    "type": "BBO",
    "timestamp": "1676992715509",
    "askPrice": 149.96,
    "askSize": "200",
    "askTimestamp": "1676992715367",
    "bidPrice": 149.94,
    "bidSize": "700",
    "bidTimestamp": "1676992715367"
}

UnsubscribeQuote

Purpose

Cancels the market data subscription on the connected client and removes the local subscription record.

Signature

func (c *PushClient) UnsubscribeQuote(symbols []string) error

Call Connect successfully before subscribing or unsubscribing. Access depends on instrument and data type.

Parameters

ParameterTypeRequiredSDK defaultConstraints
symbols[]stringYesNoneInstrument symbols; the SDK does not enforce a batch limit

Returns

error; nil means the message was written to the current connection.

Invocation example

if err := pc.UnsubscribeQuote([]string{"AAPL"}); err != nil {
	log.Fatal(err)
}

SubscribeTick

Purpose

Subscribes the connected client to tick events and records the subscription locally. Trade ticks are pushed every 200ms in snapshot mode, with the latest 50 records in each push.

Signature

func (c *PushClient) SubscribeTick(symbols []string) error

Call Connect successfully before subscribing or unsubscribing. Access depends on instrument and data type.

Parameters

ParameterTypeRequiredSDK defaultConstraints
symbols[]stringYesNoneInstrument symbols; the SDK does not enforce a batch limit

Returns

error; nil means the message was written to the current connection.

Invocation example

if err := pc.SubscribeTick([]string{"AAPL"}); err != nil {
	log.Fatal(err)
}

Callback Data Example

{
    "symbol": "AAPL",
    "secType": "STK",
    "quoteLevel": "usQuoteBasic",
    "timestamp": 1676993925700,
    "ticks": [
        {
            "sn": 116202,
            "volume": 50,
            "tickType": "*",
            "price": 149.665,
            "time": 1676993924289,
            "cond": "US_REGULAR_SALE"
        }
    ]
}

UnsubscribeTick

Purpose

Unsubscribes the connected client from tick events and removes the local subscription record.

Signature

func (c *PushClient) UnsubscribeTick(symbols []string) error

Call Connect successfully before subscribing or unsubscribing. Access depends on instrument and data type.

Parameters

ParameterTypeRequiredSDK defaultConstraints
symbols[]stringYesNoneInstrument symbols; the SDK does not enforce a batch limit

Returns

error; nil means the message was written to the current connection.

Invocation example

if err := pc.UnsubscribeTick([]string{"AAPL"}); err != nil {
	log.Fatal(err)
}

SubscribeDepth

Purpose

Subscribes the connected client to depth events and records the subscription locally. US market depth updates every 300ms, while Hong Kong market depth updates every 2s.

Signature

func (c *PushClient) SubscribeDepth(symbols []string) error

Call Connect successfully before subscribing or unsubscribing. Access depends on instrument and data type.

Parameters

ParameterTypeRequiredSDK defaultConstraints
symbols[]stringYesNoneInstrument symbols; the SDK does not enforce a batch limit

Returns

error; nil means the message was written to the current connection.

Invocation example

if err := pc.SubscribeDepth([]string{"AAPL"}); err != nil {
	log.Fatal(err)
}

Callback Data Example

{
    "symbol": "AAPL",
    "timestamp": "1676993368405",
    "ask": {
        "price": [149.69, 149.70, 149.71],
        "volume": ["100", "200", "185"]
    },
    "bid": {
        "price": [149.68, 149.67, 149.66],
        "volume": ["84", "100", "100"]
    }
}

UnsubscribeDepth

Purpose

Unsubscribes the connected client from depth events and removes the local subscription record.

Signature

func (c *PushClient) UnsubscribeDepth(symbols []string) error

Call Connect successfully before subscribing or unsubscribing. Access depends on instrument and data type.

Parameters

ParameterTypeRequiredSDK defaultConstraints
symbols[]stringYesNoneInstrument symbols; the SDK does not enforce a batch limit

Returns

error; nil means the message was written to the current connection.

Invocation example

if err := pc.UnsubscribeDepth([]string{"AAPL"}); err != nil {
	log.Fatal(err)
}

SubscribeOption

Purpose

Subscribes the connected client to option events and records the subscription locally.

Signature

func (c *PushClient) SubscribeOption(symbols []string) error

Call Connect successfully before subscribing or unsubscribing. Access depends on instrument and data type.

Parameters

ParameterTypeRequiredSDK defaultConstraints
symbols[]stringYesNoneInstrument symbols; the SDK does not enforce a batch limit

Returns

error; nil means the message was written to the current connection.

Invocation example

if err := pc.SubscribeOption([]string{"AAPL"}); err != nil {
	log.Fatal(err)
}

Callback Data Example

{
    "symbol": "AAPL 20230317 150.0 CALL",
    "type": "BASIC",
    "timestamp": "1676994444927",
    "latestPrice": 4.83,
    "preClose": 6.21,
    "volume": "3181",
    "amount": 939117.01,
    "open": 4.85,
    "high": 5.6,
    "low": 4.64,
    "identifier": "AAPL  230317C00150000",
    "openInt": "82677"
}

UnsubscribeOption

Purpose

Unsubscribes the connected client from option events and removes the local subscription record.

Signature

func (c *PushClient) UnsubscribeOption(symbols []string) error

Call Connect successfully before subscribing or unsubscribing. Access depends on instrument and data type.

Parameters

ParameterTypeRequiredSDK defaultConstraints
symbols[]stringYesNoneInstrument symbols; the SDK does not enforce a batch limit

Returns

error; nil means the message was written to the current connection.

Invocation example

if err := pc.UnsubscribeOption([]string{"AAPL"}); err != nil {
	log.Fatal(err)
}

SubscribeFuture

Purpose

Subscribes the connected client to future events and records the subscription locally.

Signature

func (c *PushClient) SubscribeFuture(symbols []string) error

Call Connect successfully before subscribing or unsubscribing. Access depends on instrument and data type.

Parameters

ParameterTypeRequiredSDK defaultConstraints
symbols[]stringYesNoneInstrument symbols; the SDK does not enforce a batch limit

Returns

error; nil means the message was written to the current connection.

Invocation example

if err := pc.SubscribeFuture([]string{"AAPL"}); err != nil {
	log.Fatal(err)
}

Callback Data Example

{
    "symbol": "ESmain",
    "type": "BASIC",
    "timestamp": "1684766824130",
    "avgPrice": 4206.476,
    "latestPrice": 4202.5,
    "preClose": 4204.75,
    "volume": "557570",
    "open": 4189,
    "high": 4221.75,
    "low": 4186.5,
    "marketStatus": "Trading",
    "preSettlement": 4204.75,
    "minTick": 0.25
}

UnsubscribeFuture

Purpose

Unsubscribes the connected client from future events and removes the local subscription record.

Signature

func (c *PushClient) UnsubscribeFuture(symbols []string) error

Call Connect successfully before subscribing or unsubscribing. Access depends on instrument and data type.

Parameters

ParameterTypeRequiredSDK defaultConstraints
symbols[]stringYesNoneInstrument symbols; the SDK does not enforce a batch limit

Returns

error; nil means the message was written to the current connection.

Invocation example

if err := pc.UnsubscribeFuture([]string{"AAPL"}); err != nil {
	log.Fatal(err)
}

SubscribeKline

Purpose

Subscribes the connected client to kline events and records the subscription locally.

Signature

func (c *PushClient) SubscribeKline(symbols []string) error

Call Connect successfully before subscribing or unsubscribing. Access depends on instrument and data type.

Parameters

ParameterTypeRequiredSDK defaultConstraints
symbols[]stringYesNoneInstrument symbols; the SDK does not enforce a batch limit

Returns

error; nil means the message was written to the current connection.

Invocation example

if err := pc.SubscribeKline([]string{"AAPL"}); err != nil {
	log.Fatal(err)
}

Callback Data Example

{
    "symbol": "AAPL",
    "time": "1712584560000",
    "open": 168.9779,
    "high": 169.0015,
    "low": 168.9752,
    "close": 169.0,
    "avg": 168.778,
    "volume": "3664",
    "count": 114,
    "amount": 617820.6508,
    "serverTimestamp": "1712584569746"
}

UnsubscribeKline

Purpose

Unsubscribes the connected client from kline events and removes the local subscription record.

Signature

func (c *PushClient) UnsubscribeKline(symbols []string) error

Call Connect successfully before subscribing or unsubscribing. Access depends on instrument and data type.

Parameters

ParameterTypeRequiredSDK defaultConstraints
symbols[]stringYesNoneInstrument symbols; the SDK does not enforce a batch limit

Returns

error; nil means the message was written to the current connection.

Invocation example

if err := pc.UnsubscribeKline([]string{"AAPL"}); err != nil {
	log.Fatal(err)
}

SubscribeStockTop

Purpose

Subscribes the connected client to stock top events and records the subscription locally. The server runs the ranking push task every 30 seconds; ranking size is configurable and defaults to 10.

Signature

func (c *PushClient) SubscribeStockTop(market string, indicators []string) error

Call Connect successfully before subscribing or unsubscribing. Access depends on instrument and data type.

Parameters

ParameterTypeRequiredSDK defaultConstraints
marketstringYesNoneMarket code; SDK enum values are ALL/US/HK/CN/SG
indicators[]stringYesNoneRanking indicator strings; the SDK joins and sends them without enum validation, so use values supported by the API

Returns

error; nil means the message was written to the current connection.

Invocation example

if err := pc.SubscribeStockTop("US", []string{"LATEST_PRICE"}); err != nil {
	log.Fatal(err)
}

Callback Data Example

{
    "market": "US",
    "timestamp": "1687271010482",
    "topData": [
        {
            "targetName": "changeRate",
            "item": [
                {"symbol": "ICAD", "latestPrice": 1.63, "targetValue": 0.393162}
            ]
        },
        {
            "targetName": "volume",
            "item": [
                {"symbol": "TSLA", "latestPrice": 263.21, "targetValue": 40190416}
            ]
        }
    ]
}

UnsubscribeStockTop

Purpose

Unsubscribes the connected client from stock top events and removes the local subscription record.

Signature

func (c *PushClient) UnsubscribeStockTop(market string, indicators []string) error

Call Connect successfully before subscribing or unsubscribing. Access depends on instrument and data type.

Parameters

ParameterTypeRequiredSDK defaultConstraints
marketstringYesNoneMarket code; SDK enum values are ALL/US/HK/CN/SG
indicators[]stringYesNoneRanking indicator strings; the SDK joins and sends them without enum validation, so use values supported by the API

Returns

error; nil means the message was written to the current connection.

Invocation example

if err := pc.UnsubscribeStockTop("US", []string{"LATEST_PRICE"}); err != nil {
	log.Fatal(err)
}

SubscribeOptionTop

Purpose

Subscribes the connected client to option top events and records the subscription locally. The server runs the ranking push task every 30 seconds; ranking size is configurable and defaults to 10.

Signature

func (c *PushClient) SubscribeOptionTop(market string, indicators []string) error

Call Connect successfully before subscribing or unsubscribing. Access depends on instrument and data type.

Parameters

ParameterTypeRequiredSDK defaultConstraints
marketstringYesNoneMarket code; SDK enum values are ALL/US/HK/CN/SG
indicators[]stringYesNoneRanking indicator strings; the SDK joins and sends them without enum validation, so use values supported by the API

Returns

error; nil means the message was written to the current connection.

Invocation example

if err := pc.SubscribeOptionTop("US", []string{"LATEST_PRICE"}); err != nil {
	log.Fatal(err)
}

Callback Data Example

{
    "market": "US",
    "timestamp": "1687277160445",
    "topData": [
        {
            "targetName": "volume",
            "item": [
                {
                    "symbol": "SPY",
                    "expiry": "20230620",
                    "strike": "435.0",
                    "right": "PUT",
                    "totalVolume": 212478
                }
            ]
        }
    ]
}

UnsubscribeOptionTop

Purpose

Unsubscribes the connected client from option top events and removes the local subscription record.

Signature

func (c *PushClient) UnsubscribeOptionTop(market string, indicators []string) error

Call Connect successfully before subscribing or unsubscribing. Access depends on instrument and data type.

Parameters

ParameterTypeRequiredSDK defaultConstraints
marketstringYesNoneMarket code; SDK enum values are ALL/US/HK/CN/SG
indicators[]stringYesNoneRanking indicator strings; the SDK joins and sends them without enum validation, so use values supported by the API

Returns

error; nil means the message was written to the current connection.

Invocation example

if err := pc.UnsubscribeOptionTop("US", []string{"LATEST_PRICE"}); err != nil {
	log.Fatal(err)
}

SubscribeCc

Purpose

Subscribes the connected client to cc events and records the subscription locally.

Signature

func (c *PushClient) SubscribeCc(symbols []string) error

Call Connect successfully before subscribing or unsubscribing. Access depends on instrument and data type.

Parameters

ParameterTypeRequiredSDK defaultConstraints
symbols[]stringYesNoneInstrument symbols; the SDK does not enforce a batch limit

Returns

error; nil means the message was written to the current connection.

Invocation example

if err := pc.SubscribeCc([]string{"AAPL"}); err != nil {
	log.Fatal(err)
}

UnsubscribeCc

Purpose

Unsubscribes the connected client from cc events and removes the local subscription record.

Signature

func (c *PushClient) UnsubscribeCc(symbols []string) error

Call Connect successfully before subscribing or unsubscribing. Access depends on instrument and data type.

Parameters

ParameterTypeRequiredSDK defaultConstraints
symbols[]stringYesNoneInstrument symbols; the SDK does not enforce a batch limit

Returns

error; nil means the message was written to the current connection.

Invocation example

if err := pc.UnsubscribeCc([]string{"AAPL"}); err != nil {
	log.Fatal(err)
}

SubscribeMarket

Purpose

Subscribes the connected client to market events and records the subscription locally.

Signature

func (c *PushClient) SubscribeMarket(market string) error

Call Connect successfully before subscribing or unsubscribing. Access depends on instrument and data type.

Parameters

ParameterTypeRequiredSDK defaultConstraints
marketstringYesNoneMarket code; SDK enum values are ALL/US/HK/CN/SG

Returns

error; nil means the message was written to the current connection.

Invocation example

if err := pc.SubscribeMarket("US"); err != nil {
	log.Fatal(err)
}

UnsubscribeMarket

Purpose

Unsubscribes the connected client from market events and removes the local subscription record.

Signature

func (c *PushClient) UnsubscribeMarket(market string) error

Call Connect successfully before subscribing or unsubscribing. Access depends on instrument and data type.

Parameters

ParameterTypeRequiredSDK defaultConstraints
marketstringYesNoneMarket code; SDK enum values are ALL/US/HK/CN/SG

Returns

error; nil means the message was written to the current connection.

Invocation example

if err := pc.UnsubscribeMarket("US"); err != nil {
	log.Fatal(err)
}


Did this page help you?