Market Data Subscription

About 12 min

push_client = PushClient(host, port, use_ssl=(protocol == 'ssl'))

Subscribe stock quote

PushClient.subscribe_quote(symbols)

Unsubscribe

PushClient.unsubscribe_quote(symbols)

Description

Stock quote subscription and cancellation interface, the returned data is updated in real time, that is, every time the price or pending order data update will have data pushed Callback interface returns the result type for the basic quote QuoteBasicData (tigeropen.push.pb.QuoteBasicData_pb2.QuoteBasicData) object Best Quote QuoteBBOData (tigeropen.push.pb.QuoteBasicData_pb2.QuoteBBOData) object

this interface is returned asynchronously, using PushClient.quote_changed in response to the basic quote QuoteBasicData object; Use PushClient.quote_bbo_changed to respond to the best quote QuoteBBOData object

Agruments

NameTypeDescription
symbolslist[str]list of securities codes, e.g. ['AAPL', 'BABA'], English codes should be in upper case

Unsubscribe Arguments

NameTypeDescription
symbolslist[str]list of securities codes, e.g. ['AAPL', 'BABA']

Return

Refer to:Quote change

CAUTION

There are two types of stock quote callback data: trading data and intraday data, and the fields returned by the two types of data are not the same

Example

from tigeropen.push.push_client import PushClient
from tigeropen.tiger_open_config import get_client_config
from tigeropen.push.pb.QuoteBBOData_pb2 import QuoteBBOData
from tigeropen.push.pb.QuoteBasicData_pb2 import QuoteBasicData
client_config = get_client_config(private_key_path='private key path', tiger_id='your tiger id', account='your account')

protocol, host, port = client_config.socket_host_port
push_client = PushClient(host, port, use_ssl=(protocol == 'ssl'), use_protobuf=True)

def on_quote_changed(frame: QuoteBasicData):
    """
    """
    print(f'quote basic change: {frame}')

def on_quote_bbo_changed(frame: QuoteBBOData):
    """ask/bid 
    """
    print(f'quote bbo changed: {frame}')
  
# bind callback method
push_client.quote_changed = on_quote_changed
push_client.quote_bbo_changed = on_quote_bbo_changed

push_client.connect(client_config.tiger_id, client_config.private_key)

push_client.subscribe_quote(['AAPL', 'BABA'])

push_client.unsubscribe_quote(['AAPL', 'BABA'])

push_client.disconnect()

Callback data example

tigeropen.push.pb.QuoteBasicData_pb2.QuoteBasicData example:

symbol: "00700"
type: BASIC
timestamp: 1677742483530
serverTimestamp: 1677742483586
avgPrice: 365.37
latestPrice: 363.8
latestPriceTimestamp: 1677742483369
latestTime: "03-02 15:34:43"
preClose: 368.8
volume: 12674730
amount: 4630947968
open: 368.2
high: 369
low: 362.4
marketStatus: "Trading"
mi {
  p: 363.8
  a: 365.37
  t: 1677742440000
  v: 27300
  h: 364
  l: 363.6
}

tigeropen.push.pb.QuoteBasicData_pb2.QuoteBBOData Example:

symbol: "01810"
type: BBO
timestamp: 1677741267291
serverTimestamp: 1677741267329
askPrice: 12.54
askSize: 397600
askTimestamp: 1677741266304
bidPrice: 12.52
bidSize: 787400
bidTimestamp: 1677741266916

Subscribe Option Quote

Arguments

NameTypeDescription
symbolslist[str]consists of four elements of the option, separated by spaces: underlying code, expiration date (YYYYMMDD), strike price, and option type (call CALL/put PUT)

Callback Data

Need to bind the callback method through push_client.quote_changed, the callback method is the same as the stock

Examplepush_client.subscribe_option(['AAPL 20230120 150.0 CALL', 'SPY 20220930 470.0 PUT']) or push_client.subscribe_quote(['AAPL 20230120 150.0 CALL', 'SPY 20220930 470.0 PUT'])

from tigeropen.push.push_client import PushClient
from tigeropen.tiger_open_config import get_client_config
client_config = get_client_config(private_key_path='private key path', tiger_id='your tiger id', account='your account')

protocol, host, port = client_config.socket_host_port
push_client = PushClient(host, port, use_ssl=(protocol == 'ssl'), use_protobuf=True)

def on_quote_changed(frame: QuoteBasicData):
    """
    """
    print(f'quote basic change: {frame}')

def on_quote_bbo_changed(frame: QuoteBBOData):
    """ask/bid 
    """
    print(f'quote bbo changed: {frame}')

push_client.quote_changed = on_quote_changed
push_client.quote_bbo_changed = on_quote_bbo_changed

        
push_client.connect(client_config.tiger_id, client_config.private_key)

push_client.subscribe_option(['AAPL 20240119 155.0 PUT', 'SPY 20221118 386.0 CALL'])


push_client.unsubscribe_quote(['AAPL 20240119 155.0 PUT', 'SPY 20221118 386.0 CALL'])
push_client.disconnect()

Subscribe Future Quote

Arguments

nametypedescription
symbolslist[str]future code list,like 'CLmain', 'ES2209'

Callback data

Need to bind callback method through push_client.quote_changed

Example

push_client.subscribe_future(['CLmain', 'CN2209'])
# or
push_client.subscribe_quote(['VIXmain', 'ES2209'])
from tigeropen.push.push_client import PushClient
from tigeropen.tiger_open_config import get_client_config
client_config = get_client_config(private_key_path='private key path', tiger_id='your tiger id', account='your account')

protocol, host, port = client_config.socket_host_port
push_client = PushClient(host, port, use_ssl=(protocol == 'ssl'), use_protobuf=True)

def on_quote_changed(frame: QuoteBasicData):
    """
    """
    print(f'quote basic change: {frame}')

def on_quote_bbo_changed(frame: QuoteBBOData):
    """ask/bid 
    """
    print(f'quote bbo changed: {frame}')

push_client.quote_changed = on_quote_changed
push_client.quote_bbo_changed = on_quote_bbo_changed6

push_client.connect(client_config.tiger_id, client_config.private_key)

push_client.subscribe_future(['BTCmain', 'CLmain'])


push_client.unsubscribe_quote(['BTCmain', 'CLmain'])
push_client.disconnect()

Callback data example basic quote

symbol: "BTCmain"
type: BASIC
timestamp: 1677571147018
avgPrice: 23562.4
latestPrice: 23355
latestPriceTimestamp: 1677571045000
latestTime: "02-28 01:57:25 -0600"
preClose: 23445
volume: 900
open: 23585
high: 23710
low: 23350
marketStatus: ""
tradeTime: 1677571045000
preSettlement: 23445
minTick: 5
mi {
  p: 23355
  a: 23562.4
  t: 1677571020000
  v: 3
  o: 23350
  h: 23355
  l: 23350
}

ask bid

symbol: "BTCmain"
type: BBO
timestamp: 1677571147018
askPrice: 23365
askSize: 3
askTimestamp: 1677571147018
bidPrice: 23355
bidSize: 1
bidTimestamp: 1677571141150


Subscribe depth quote

Push_client.subscribe_depth_quote(symbols)

Unsubscribe

PushClient.unsubscribe_depth_quote(symbols)

Description

Subscribe to depth quotes, ** U.S. depth quotes push frequency of 300ms, Hong Kong depth quotes push frequency of 2s, return up to 40 files of pending buy and sell orders data **, the data returned for real-time updates, that is, pending orders data updates will have data pushed. This interface is asynchronous return, using PushClient.quote_depth_changed response depth quotes QuoteDepthData (tigeropen.push.pb.QuoteDepthData_pb2.QuoteDepthData) object;

Arguments

NameTypeDescription
symbolslist[str]list of symbols,such as ['AAPL', 'BABA']

Unsubscribe Arguments

NameTypeDescription
symbolslist[str]list of symbols,such as ['AAPL', 'BABA']

Example

from tigeropen.push.push_client import PushClient
from tigeropen.tiger_open_config import get_client_config
client_config = get_client_config(private_key_path='private key path', tiger_id='your tiger id', account='your account')

# Initialize PushClient
protocol, host, port = client_config.socket_host_port
push_client = PushClient(host, port, use_ssl=(protocol == 'ssl'), use_protobuf=True)


def on_quote_depth_changed(frame: QuoteDepthData):
    print(f'quote depth changed: {frame}')

    
push_client.quote_depth_changed = on_quote_depth_changed
  
push_client.connect(client_config.tiger_id, client_config.private_key)

push_client.subscribe_depth_quote(['AMD', 'MSFT'])

push_client.unsubscribe_depth_quote(['AMD', 'MSFT'])

push_client.disconnect()

Callback Data Example

tigeropen.push.pb.QuoteDepthData_pb2.QuoteDepthData

CAUTION

This interface will only push a maximum of the first 40 ask/bid

data structure:

FieldTypeDescription
symbolstrsymbol
timestampintdepth quote time
askOrderBookask data
bidOrderBookbid data

OrderBook structure:

FieldTypeDescription
pricelist[float]price
volumelist[int]order volume
orderCountlist[int]order count(HK stock only)

Callback data example

depth quote items example,The price of adjacent slots may be the same, where count is optional

symbol: "00700"
timestamp: 1677742734822
ask {
  price: 363.8
  price: 364
  price: 364.2
  price: 364.4
  price: 364.6
  price: 364.8
  price: 365
  price: 365.2
  price: 365.4
  price: 365.6
  volume: 26900
  volume: 14800
  volume: 15200
  volume: 31500
  volume: 15800
  volume: 7700
  volume: 29400
  volume: 6300
  volume: 6000
  volume: 5500
  orderCount: 27
  orderCount: 20
  orderCount: 19
  orderCount: 22
  orderCount: 14
  orderCount: 10
  orderCount: 20
  orderCount: 12
  orderCount: 10
  orderCount: 11
}
bid {
  price: 363.6
  price: 363.4
  price: 363.2
  price: 363
  price: 362.8
  price: 362.6
  price: 362.4
  price: 362.2
  price: 362
  price: 361.8
  volume: 9400
  volume: 19900
  volume: 35300
  volume: 74200
  volume: 26300
  volume: 16700
  volume: 22500
  volume: 21100
  volume: 40500
  volume: 5600
  orderCount: 16
  orderCount: 23
  orderCount: 36
  orderCount: 79
  orderCount: 30
  orderCount: 32
  orderCount: 31
  orderCount: 34
  orderCount: 143
  orderCount: 26
}


Subscribe tick

Push_client.subscribe_tick(symbols)

Unsubscribe

PushClient.unsubscribe_tick(symbols)

Description

The transaction-by-transaction subscription push interface is an asynchronous interface, and the results of asynchronous requests can be obtained by implementing the PushClient.tick_changed interface. The callback data type is tigeropen.push.pb.TradeTickData_pb2.TradeTickData This method is used for both stocks and futures.

Push frequency is 200ms, using snapshot push, each time pushing the latest 50 records per tick.

Arguments

NameTypeDescription
symbolslist[str]list of symbols,like ['AAPL', 'BABA']

Unsubscribe Arguments

NameTypeDescription
symbolslist[str]list of symbols, like ['AAPL', 'BABA']

Example

from tigeropen.push.pb.trade_tick import TradeTick
from tigeropen.push.push_client import PushClient
from tigeropen.tiger_open_config import get_client_config
client_config = get_client_config(private_key_path='private key path', tiger_id='your tiger id', account='your account')

protocol, host, port = client_config.socket_host_port
push_client = PushClient(host, port, use_ssl=(protocol == 'ssl'), use_protobuf=True)

def on_tick_changed(frame: TradeTick):
    print(f'tick changed: {frame}')

    
push_client.tick_changed = on_tick_changed   
  
push_client.connect(client_config.tiger_id, client_config.private_key)

# subscribe stock
push_client.subscribe_tick(['AMD', 'MSFT'])
# subscribe future
push_client.subscribe_tick(['HSImain', 'CNmain'])


time.sleep(10)
push_client.unsubscribe_tick(['AMD', 'MSFT'])
push_client.disconnect()

Callback data tigeropen.push.pb.trade_tick.TradeTick

TradeTick data structure:

FieldTypeDescription
symbolstrstock or future code
secTypestrSTK/FUT
quoteLevelstrThe level of authority of the ticker from which the data comes (for US stocks, usQuoteBasic has less data per tick than usStockQuote); there is no level distinction for futures
timestampinttimestamp in millisecond
tickslist[TradeTickItem]tick data list

ticks data structure:

FieldTypeDescription
snintserial number
volumeintvolume
tickTypestr* means no change, + means up, - means down (not available for futures)
pricedoubletransaction price
timeinttransaction time stamp
condstrThe list of transaction conditions for each data, if the array is empty, it means that each transaction of the current batch is an automatic transaction (futures are not available on a per-transaction basis)
partCodestrExchange code of each transaction (US stocks only)
partNamestrExchange name of each transaction (U.S. stocks only)

Callback Example

    TradeTick<{'symbol': '00700', 'sec_type': 'STK', 'quote_level': 'hkStockQuoteLv2', 'timestamp': 1685602618145, 'ticks': [TradeTickItem<{'tick_type': '+', 'price': 316.6, 'volume': 100, 'part_code': None, 'part_code_name': None, 'cond': None, 'time': 1685602617046, 'sn': 42055}>, TradeTickItem<{'tick_type': '-', 'price': 316.4, 'volume': 600, 'part_code': None, 'part_code_name': None, 'cond': None, 'time': 1685602617639, 'sn': 42056}>, TradeTickItem<{'tick_type': '-', 'price': 316.4, 'volume': 200, 'part_code': None, 'part_code_name': None, 'cond': None, 'time': 1685602617639, 'sn': 42057}>]}>


Subscribe full tick

Push_client.subscribe_tick(symbols)

Unsubscribe

PushClient.unsubscribe_tick(symbols)

Description

The full-tick subscription push interface is an asynchronous interface, and the results of asynchronous requests can be obtained by implementing the PushClient.tick_changed interface. The callback data type is tigeropen.push.pb.TickData_pb2.TickData

Arguments

NameTypeDescription
symbolslist[str]list of symbols,like ['AAPL', 'BABA']

At the same time, change the configuration client_config.use_full_tick = True, enable full tick mode, and pass in client_config=client_config when PushClient is initialized.

Unsubscribe Arguments

NameTypeDescription
symbolslist[str]list of symbols, like ['AAPL', 'BABA']

Example

from tigeropen.push.pb.TickData_pb2 import TickData
from tigeropen.push.push_client import PushClient
from tigeropen.tiger_open_config import get_client_config
client_config = get_client_config(private_key_path='private key path', tiger_id='your tiger id', account='your account')
client_config.use_full_tick = True
# init PushClient
protocol, host, port = client_config.socket_host_port
push_client = PushClient(host, port, use_ssl=(protocol == 'ssl'), use_protobuf=True, client_config=client_config)


def on_full_tick_changed(frame: TickData):
    print(f'full tick changed: {frame}')

    
push_client.full_tick_changed = on_full_tick_changed
  
push_client.connect(client_config.tiger_id, client_config.private_key)

push_client.subscribe_tick(['AMD', 'MSFT', '00700'])


time.sleep(10)
push_client.unsubscribe_tick(['AMD', 'MSFT'])
push_client.disconnect()

Callback data tigeropen.push.pb.TickData_pb2.TickData

TickData data structure:

fieldtypedesc
symbolstrsecurity code
sourcestrSTK/FUT
timestampintdata timestamp
tickslist[Tick]tick datas

each item of ticks data structure:

FieldTypeDescription
snintserial number
volumeintvolume
typestr* means no change, + means up, - means down (not available for futures)
pricedoubletransaction price
timeinttransaction time stamp
partCodestrExchange code of each transaction (US stocks only)

Example

symbol: "NVDA"
ticks {
  sn: 2381
  time: 1712669401076
  price: 874.1
  volume: 10
  type: "*"
  partCode: "t"
}
ticks {
  sn: 2382
  time: 1712669401076
  price: 874.1
  volume: 11
  type: "*"
  partCode: "t"
}
ticks {
  sn: 2383
  time: 1712669401076
  price: 874.1
  volume: 3
  type: "*"
  partCode: "t"
}
timestamp: 1712669403808
source: "NLS"


Subscribe kline

PushClient.subscribe_kline(symbols=None)

Unsubscribe

PushClient.unsubscribe_kline(symbols)

Description Subscribe to minute kline.

Parameters

FieldTypeDescription
symbolslist[str]list of security codes

Callback data Need to use PushClient.kline_changed to respond to the return result

Example

from tigeropen.push.push_client import PushClient
from tigeropen.tiger_open_config import get_client_config
client_config = get_client_config(private_key_path='private key path', tiger_id='your tiger id', account='your account')

protocol, host, port = client_config.socket_host_port
push_client = PushClient(host, port, use_ssl=(protocol == 'ssl'), use_protobuf=True)

def on_kline_changed(frame: KlineData):
    print(f'kline changed: {frame}')
    
push_client.kline_changed = on_kline_changed

push_client.connect(client_config.tiger_id, client_config.private_key)

symbols = ['AAPL']

push_client.subscribe_kline(symbols)

Callback Example

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

Query Subscribed Symbols

PushClient.query_subscribed_quote()

Description Query the list of subscribed labels

This interface is asynchronous return, you need to use PushClient.query_subscribed_callback response to return the results

Arguments None

Callback data Need to use PushClient.query_subscribed_callback to respond to the return result

The callback data structure is as follows:

FieldTypeDescription
limitintMaximum number of subscribed tickers (stocks, options, futures)
usedintNumber of subscribed tickers (stocks, options, futures)
subscribedSymbolslistsubscribedSymbols (stocks, options, futures)
askBidLimitintsubscribed to the depth of the stock limit maximum number
askBidUsedintNumber of subscribed stocks
subscribedAskBidSymbolslistsubscribed deep ticker symbols
tradeTickLimitintsubscribed to the maximum number of trade-by-trade stock limits
tradeTickUsedintsubscribedAskBidSymbols
subscribedTradeTickSymbolslistsubscribed trade-by-trade stock symbols

Example

from tigeropen.push.push_client import PushClient
from tigeropen.tiger_open_config import get_client_config
client_config = get_client_config(private_key_path='private key path', tiger_id='your tiger id', account='your account')

protocol, host, port = client_config.socket_host_port
push_client = PushClient(host, port, use_ssl=(protocol == 'ssl'), use_protobuf=True)

def query_subscribed_callback(data):
    """
    data example:
        {'subscribed_symbols': ['QQQ'], 'limit': 1200, 'used': 1, 'symbol_focus_keys': {'qqq': ['open', 'prev_close', 'low', 'volume', 'latest_price', 'close', 'high']},
         'subscribed_quote_depth_symbols': ['NVDA'], 'quote_depth_limit': 20, 'quote_depth_used': 1,
         'subscribed_trade_tick_symbols': ['QQQ', 'AMD', '00700'], 'trade_tick_limit': 1200, 'trade_tick_used': 3}
    """
    print(f'subscribed data:{data}')
    print(f'subscribed symbols:{data["subscribed_symbols"]}')
    

push_client.query_subscribed_callback = query_subscribed_callback   
  
push_client.connect(client_config.tiger_id, client_config.private_key)

push_client.subscribe_quote(['QQQ'])
push_client.subscribe_depth_quote(['NVDA'])
push_client.subscribe_tick(['QQQ'])
push_client.subscribe_tick(['HSImain'])

push_client.query_subscribed_quote()

time.sleep(10)

Callback Example

{'subscribed_symbols': ['QQQ'], 'limit': 1200, 'used': 1,
 'subscribed_ask_bid_symbols': ['NVDA'], 'ask_bid_limit': 20, 'ask_bid_used': 1,
 'subscribed_trade_tick_symbols': ['QQQ', 'AMD', '00700'], 'trade_tick_limit': 1200, 'trade_tick_used': 3
 }

Subscribe to stock top data

PushClient.subscribe_stock_top(market, indicators=None)Unsubscribe methodPushClient.unsubscribe_stock_top(market, indicators=None)

Description

Subscribe to stock top data, no push during non-trading hours, push interval is 30s, each push subscribes to indicators Top30 underlying data. The push interface is an asynchronous callback, and the result of asynchronous request can be obtained by implementing the ApiComposeCallback interface. The callback interface returns the result type as StockTopData object. The data of each indicator is sorted in reverse order by indicator value.

Support the subscription of stock indicators in the US and Hong Kong markets. The top of intraday data has all indicators of StockRankingIndicator, and the top data of only two indicators of US stocks before and after the market is up (changeRate) and up in 5 minutes (changeRate5Min)

Parameters

Parameter NameTypeRequiredDescription
marketstr or Market enumYesMarket, support HK, US
indicatorslist[tigeropen.common.consts.StockRankingIndicator]NoStockRankingIndicator, default is all indicators, refer to the enumeration StockRankingIndicator's value (changeRate:day increase. changeRate5Min:5-minute increase; turnoverRate:turnover rate; amount:current day volume; volume:current day volume; amplitude:current day amplitude)

Callback data

Need to bind the callback method via push_client.stock_top_changed

The data structure of StockTopData is as follows:

FieldTypeDescription
marketstrmarket:US/HK
timestampinttimestamp
topDatalist[TopData]List of data for each indicator list

The data structure of TopData is as follows:

fieldtypedescription
targetNamestrindicatorName(changeRate, changeRate5Min, turnoverRate, amount, volume, amplitude)
itemlist[StockItem]A list of the list data under this indicator dimension

The data structure of StockItem is as follows:

fieldtypedescription
symbolstrmarked
latestPricefloatThe latest price
targetValuefloatCorresponding indicator value

Example

from tigeropen.push.push_client import PushClient
from tigeropen.tiger_open_config import get_client_config
from tigeropen.common.consts import OptionRankingIndicator, StockRankingIndicator
from tigeropen.push.pb.StockTopData_pb2 import StockTopData
client_config = get_client_config(private_key_path='private key path', tiger_id='your tiger id', account='your account')

protocol, host, port = client_config.socket_host_port
push_client = PushClient(host, port, use_ssl=(protocol == 'ssl'))

def on_stock_top_changed(frame: StockTopData):
    print(f'stock top changed: {frame}')

push_client.stock_top_changed = on_stock_top_changed

push_client.connect(client_config.tiger_id, client_config.private_key)


push_client.subscribe_stock_top("HK", [StockRankingIndicator.Amount])

push_client.unsubscribe_stock_top("HK", [StockRankingIndicator.Amount])


Callback Data Example

topData {
  targetName: "amount"
  item {
    symbol: "02800"
    latestPrice: 19.55
    targetValue: 3338633741
  }
  item {
    symbol: "00700"
    latestPrice: 338.8
    targetValue: 2950736047
  }
  item {
    symbol: "02828"
    latestPrice: 66.34
    targetValue: 1533436182
  }
  item {
    symbol: "09988"
    latestPrice: 85.2
    targetValue: 1396707122
  }
  item {
    symbol: "02269"
    latestPrice: 37.1
    targetValue: 1238930730
  }
  item {
    symbol: "03690"
    latestPrice: 127.9
    targetValue: 1167532142
  }
  item {
    symbol: "01211"
    latestPrice: 262.6
    targetValue: 716540400
  }
  item {
    symbol: "03033"
    latestPrice: 3.916
    targetValue: 629691374
  }
  item {
    symbol: "01357"
    latestPrice: 3.29
    targetValue: 589222680
  }
  item {
    symbol: "02318"
    latestPrice: 50.25
    targetValue: 572686837
  }
  item {
    symbol: "01299"
    latestPrice: 80.25
    targetValue: 510098294
  }
  item {
    symbol: "09888"
    latestPrice: 139.7
    targetValue: 504564066
  }
  item {
    symbol: "00388"
    latestPrice: 303.8
    targetValue: 488918091
  }
  item {
    symbol: "07226"
    latestPrice: 4.85
    targetValue: 477161727
  }
  item {
    symbol: "01398"
    latestPrice: 4.16
    targetValue: 459215853
  }
  item {
    symbol: "02331"
    latestPrice: 43.2
    targetValue: 439082885
  }
  item {
    symbol: "02015"
    latestPrice: 137.8
    targetValue: 407068273
  }
  item {
    symbol: "09618"
    latestPrice: 143.9
    targetValue: 389690725
  }
  item {
    symbol: "07552"
    latestPrice: 6.59
    targetValue: 387550625
  }
  item {
    symbol: "01024"
    latestPrice: 54.85
    targetValue: 350567971
  }
  item {
    symbol: "00981"
    latestPrice: 20.65
    targetValue: 349594737
  }
  item {
    symbol: "00386"
    latestPrice: 4.47
    targetValue: 347819789
  }
  item {
    symbol: "00883"
    latestPrice: 11.12
    targetValue: 320431605
  }
  item {
    symbol: "09868"
    latestPrice: 44.05
    targetValue: 292605044
  }
  item {
    symbol: "02020"
    latestPrice: 81.95
    targetValue: 285153726
  }
  item {
    symbol: "03968"
    latestPrice: 36.25
    targetValue: 273604906
  }
  item {
    symbol: "00939"
    latestPrice: 5.05
    targetValue: 270755731
  }
  item {
    symbol: "01088"
    latestPrice: 23.6
    targetValue: 265332533
  }
  item {
    symbol: "00020"
    latestPrice: 2.14
    targetValue: 256621941
  }
  item {
    symbol: "00941"
    latestPrice: 63.25
    targetValue: 248440129
  }
}

Subscribe to option top data

PushClient.subscribe_option_top(market, indicators=None)Unsubscribe methodPushClient.unsubscribe_option_top(market, indicators=None)

Description

Subscribe to the option's market top data,** no push during non-trading hours, push interval is 30s, each push subscribes to the data of the indicator Top50 underlying**. The push interface is an asynchronous callback, and the result of asynchronous request can be obtained by implementing the ApiComposeCallback interface. The return result type of the callback interface is OptionTopData object. Among them, the variation of large orders is the data of single transaction volume greater than 1000, sorted in reverse order by transaction time, and the other indicator data is the data of cumulative indicator value in reverse order on trading days.

Support for subscription to the U.S. market options indicators, the intraday data list has OptionRankingIndicator all indicators.

Parameters

Parameter NameTypeRequiredDescription
marketstr or Market enumYesMarket, support HK, US
indicatorslist[tigeropen.common.consts.OptionRankingIndicator]NoOptions list indicators, default is all indicators, refer to the value of the enumeration OptionRankingIndicator (bigOrder:Variable big order. volume:cumulative volume for the day, amount:cumulative volume for the day, openInt:open position)

Callback data

The callback method should be bound by push_client.option_top_changed.

The OptionTopData data structure is as follows:

FieldTypeDescription
marketstringmarket:US
timestamplongtimestamp
topDatalist[TopData]List of data for each indicator list

The data structure of TopData is as follows:

fieldtypedescription
targetNamestringIndicator name(bigOrder, volume, amount, openInt)
bigOrderlist[BigOrder]The list of variance bigOrder indicators (bigOrder) data
itemlist[OptionItem]The list of data under this indicator dimension

The data structure of BigOrder is as follows:

fieldtypedescription
symbolstrStock ETF Underlying
expirystrExpiration date, format: yyyyMMdd
strikestrStrike
rightstrCALL/PUT
dirstrBuy/Sell direction: BUY/SELL/NONE
volumefloatvolume
pricefloatvolume
amountfloatvolume
tradeTimeinttransaction timestamp

The data structure of OptionItem is as follows:

fieldtypedescription
symbolstrStock ETF Underlying
expirystrExpiration date, format: yyyyMMdd
strikestrStrike
rightstrCALL/PUT
totalAmountfloatvolume
totalVolumefloatvolume
totalOpenIntfloatopen position volume
volumeToOpenIntfloatVolume/open position
latestPricefloatLatest Price
updateTimeintIndicator data update timestamp

Examples

from tigeropen.push.push_client import PushClient
from tigeropen.tiger_open_config import get_client_config
from tigeropen.common.consts import OptionRankingIndicator
from tigeropen.push.pb.OptionTopData_pb2 import OptionTopData

client_config = get_client_config(private_key_path='private key path', tiger_id='your tiger id', account='your account')

# Initialize PushClient
protocol, host, port = client_config.socket_host_port
push_client = PushClient(host, port, use_ssl=(protocol == 'ssl'))

# Define the callback method
def on_option_top_changed(frame: OptionTopData).
    print(f'option top changed: {frame}')

# Binding callback method
push_client.option_top_changed = on_option_top_changed

# Establish a connection        
push_client.connect(client_config.tiger_id, client_config.private_key)

# Subscribe
push_client.subscribe_option_top("US", [OptionRankingIndicator.Amount])

# Unsubscribe
push_client.unsubscribe_option_top("US", [OptionRankingIndicator.Amount])


Callback data example

{
    "market":"US",
    "timestamp":"1687277160445",
    "topData":[
        {
            "targetName":"volume",
            "item":[
                {
                    "symbol":"SPY",
                    "expiry":"20230620",
                    "strike":"435.0",
                    "right":"PUT",
                    "totalAmount":5394115,
                    "totalVolume":212478,
                    "totalOpenInt":16377,
                    "volumeToOpenInt":0.012467,
                    "latestPrice":0.25,
                    "updateTime":"1687277254390"
                },
                {
                    "symbol":"SPY",
                    "expiry":"20230620",
                    "strike":"436.0",
                    "right":"PUT",
                    "totalAmount":7754077,
                    "totalVolume":194423,
                    "totalOpenInt":13403,
                    "volumeToOpenInt":0.011408,
                    "latestPrice":0.58,
                    "updateTime":"1687277213603"
                },
                {
                    "symbol":"SPY",
                    "expiry":"20230620",
                    "strike":"437.0",
                    "right":"PUT",
                    "totalAmount":10420625,
                    "totalVolume":182078,
                    "totalOpenInt":13973,
                    "volumeToOpenInt":0.010683,
                    "latestPrice":1.17,
                    "updateTime":"1687277213602"
                },
                {
                    "symbol":"SPY",
                    "expiry":"20230620",
                    "strike":"438.0",
                    "right":"CALL",
                    "totalAmount":4482482,
                    "totalVolume":181899,
                    "totalOpenInt":961,
                    "volumeToOpenInt":0.010673,
                    "latestPrice":0.09,
                    "updateTime":"1687277213603"
                },
                {
                    "symbol":"SPY",
                    "expiry":"20230620",
                    "strike":"436.0",
                    "right":"CALL",
                    "totalAmount":7331667,
                    "totalVolume":150604,
                    "totalOpenInt":238,
                    "volumeToOpenInt":0.008837,
                    "latestPrice":0.66,
                    "updateTime":"1687277208599"
                }
                // ......
            ]
        },
        {
            "targetName":"amount",
            "item":[
                {
                    "symbol":"TSLA",
                    "expiry":"20230721",
                    "strike":"5.0",
                    "right":"CALL",
                    "totalAmount":34061561,
                    "totalVolume":1812,
                    "totalOpenInt":18,
                    "volumeToOpenInt":0.00023,
                    "latestPrice":259.99,
                    "updateTime":"1687276953360"
                },
                {
                    "symbol":"TSLA",
                    "expiry":"20230721",
                    "strike":"500.0",
                    "right":"PUT",
                    "totalAmount":30877216,
                    "totalVolume":1960,
                    "volumeToOpenInt":0.000248,
                    "latestPrice":234.97,
                    "updateTime":"1687276953360"
                },
                {
                    "symbol":"TSLA",
                    "expiry":"20230623",
                    "strike":"265.0",
                    "right":"CALL",
                    "totalAmount":27928028,
                    "totalVolume":66361,
                    "totalOpenInt":12928,
                    "volumeToOpenInt":0.008405,
                    "latestPrice":6.5,
                    "updateTime":"1687277264395"
                },
                {
                    "symbol":"SPY",
                    "expiry":"20230721",
                    "strike":"420.0",
                    "right":"CALL",
                    "totalAmount":21629503,
                    "totalVolume":11105,
                    "totalOpenInt":46931,
                    "volumeToOpenInt":0.000652,
                    "latestPrice":19.27,
                    "updateTime":"1687273142271"
                },
                {
                    "symbol":"TSLA",
                    "expiry":"20230623",
                    "strike":"270.0",
                    "right":"CALL",
                    "totalAmount":17657903,
                    "totalVolume":61012,
                    "totalOpenInt":14302,
                    "volumeToOpenInt":0.007728,
                    "latestPrice":4.52,
                    "updateTime":"1687277254390"
                }
                // ......
            ]
        },
        {
            "targetName":"openInt",
            "item":[
                {
                    "symbol":"AMC",
                    "expiry":"20230721",
                    "strike":"10.0",
                    "right":"CALL",
                    "totalAmount":4933,
                    "totalVolume":750,
                    "totalOpenInt":340843,
                    "volumeToOpenInt":0.00022,
                    "latestPrice":0.1,
                    "updateTime":"1687276788220"
                },
                {
                    "symbol":"AMC",
                    "expiry":"20230721",
                    "strike":"10.0",
                    "right":"PUT",
                    "totalVolume":1,
                    "totalOpenInt":321814,
                    "latestPrice":6.2,
                    "updateTime":"1687276853278"
                },
                {
                    "symbol":"AMC",
                    "expiry":"20230721",
                    "strike":"4.0",
                    "right":"PUT",
                    "totalAmount":117982,
                    "totalVolume":2748,
                    "totalOpenInt":242101,
                    "volumeToOpenInt":0.000806,
                    "latestPrice":0.81,
                    "updateTime":"1687277034280"
                },
                {
                    "symbol":"ATVI",
                    "expiry":"20240119",
                    "strike":"85.0",
                    "right":"PUT",
                    "totalAmount":3500,
                    "totalVolume":26,
                    "totalOpenInt":230702,
                    "volumeToOpenInt":0.000016,
                    "latestPrice":7,
                    "updateTime":"1687274092822"
                },
                {
                    "symbol":"EEM",
                    "expiry":"20231215",
                    "strike":"47.0",
                    "right":"CALL",
                    "totalAmount":310,
                    "totalVolume":15,
                    "totalOpenInt":183054,
                    "volumeToOpenInt":0.000003,
                    "latestPrice":0.18,
                    "updateTime":"1687269619956"
                }
                // ......
            ]
        },
        {
            "targetName":"bigOrder",
            "bigOrder":[
                {
                    "symbol":"AMC",
                    "expiry":"20230818",
                    "strike":"10.0",
                    "right":"PUT",
                    "dir":"Buy",
                    "volume":1000,
                    "price":6.94,
                    "amount":694000,
                    "tradeTime":"1687276860753"
                },
                {
                    "symbol":"GLPI",
                    "expiry":"20230818",
                    "strike":"50.0",
                    "right":"CALL",
                    "dir":"Sell",
                    "volume":1094,
                    "price":1.2,
                    "amount":131280,
                    "tradeTime":"1687276744519"
                },
                {
                    "symbol":"AMD",
                    "expiry":"20230818",
                    "strike":"140.0",
                    "right":"CALL",
                    "dir":"Buy",
                    "volume":1700,
                    "price":3.25,
                    "amount":552500,
                    "tradeTime":"1687276467421"
                },
                {
                    "symbol":"AAPL",
                    "expiry":"20230915",
                    "strike":"185.0",
                    "right":"PUT",
                    "dir":"Sell",
                    "volume":1500,
                    "price":6.65,
                    "amount":997500,
                    "tradeTime":"1687276413267"
                },
                {
                    "symbol":"BABA",
                    "expiry":"20240119",
                    "strike":"75.0",
                    "right":"PUT",
                    "dir":"Sell",
                    "volume":1500,
                    "price":4.8,
                    "amount":720000,
                    "tradeTime":"1687276036749"
                }
            ]
        }
    ]
}
Last update: