中文

Account Change Push Notifications

The following are all asynchronous APIs that require specifying a method to respond to returned results

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

Note that if no account is specified during subscription, the callback will push data for multiple accounts associated with this tiger_id. When processing callbacks, you need to determine which account the data belongs to.

Asset Change Subscription and Cancellation

Subscription Method

PushClient.subscribe_asset(account)

Cancellation Method

PushClient.unsubscribe_asset()

Parameters

ParameterTypeDescription
accountstrAccount ID to subscribe to. If not provided, subscribes to all associated accounts. Note: If no account is specified during subscription, callback will push data for multiple accounts, and you need to determine which account the data belongs to when processing callbacks

Return

You need to use PushClient.asset_changed to respond to return results. The return result is a tigeropen.push.pb.AssetData_pb2.AssetData object Object Description

Field meanings can be referenced against asset retrieval interfaces get_prime_assets, get_assets

Detailed field explanations refer to objects: PortfolioAccount Integrated/Simulated Assets

PortfolioAccount Global Assets

Callback Data Field Meanings

Asset change callback

FieldTypeDescription
accountstrFund account number
currencystrCurrency. USD for US Dollar, HKD for Hong Kong Dollar
segTypestrClassification by trading instrument. S for stocks, C for futures
availableFundsfloatAvailable funds, overnight remaining liquidity
excessLiquidityfloatCurrent remaining liquidity
netLiquidationfloatTotal assets (net liquidation value). Total assets is the sum of net cash balance and total market value of securities in our account
equityWithLoanfloatTotal equity with loan value. Equals total assets - US stock options
buyingPowerfloatBuying power. Only applicable to stock instruments, i.e., meaningful when segment is S
cashBalancefloatCash amount. Sum of current cash balances in all currencies
grossPositionValuefloatTotal securities value
initMarginReqfloatInitial margin requirement
maintMarginReqfloatMaintenance margin requirement
timestampintTimestamp

Example

from tigeropen.push.pb.AssetData_pb2 import AssetData
from tigeropen.push.push_client import PushClient
from tigeropen.tiger_open_config import TigerOpenClientConfig
client_config = TigerOpenClientConfig(props_path='/path/to/your/properties/file/')


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

# Define callback method
def on_asset_changed(frame: AssetData):
    """Can perform custom processing, here only printing"""
    print(f'asset change. {frame}')
    # View available funds
    print(frame.availableFunds)
    # View position market value
    print(frame.grossPositionValue)

# Bind callback method
push_client.asset_changed = on_asset_changed
# Connect
push_client.connect(client_config.tiger_id, client_config.private_key)

# Subscribe 
push_client.subscribe_asset(account=client_config.account)


# Unsubscribe from asset changes
# push_client.unsubscribe_asset()

Callback Data Example

account: "111111"
currency: "USD"
segType: "S"
availableFunds: 1593.1191893
excessLiquidity: 1730.5666908
netLiquidation: 2856.1016998
equityWithLoan: 2858.1016998
buyingPower: 6372.4767571
cashBalance: 484.1516697
grossPositionValue: 2373.95003
initMarginReq: 1264.9825105
maintMarginReq: 1127.535009
timestamp: 1677745420121

Position Change Subscription and Cancellation

Subscription Method

PushClient.subscribe_position(account)

Cancellation Method

PushClient.unsubscribe_position()

Parameters

ParameterTypeDescription
accountstrAccount ID to subscribe to. If not provided, subscribes to all associated accounts. Note: If no account is specified during subscription, callback will push data for multiple accounts, and you need to determine which account the data belongs to when processing callbacks

Example

from tigeropen.push.pb.PositionData_pb2 import PositionData
from tigeropen.push.push_client import PushClient
from tigeropen.tiger_open_config import TigerOpenClientConfig
client_config = TigerOpenClientConfig(props_path='/path/to/your/properties/file/')


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

# Define callback method
def on_position_changed(frame: PositionData):
    print(f'position change. {frame}')
    # Position symbol
    print(frame.symbol)
    # Position cost
    print(frame.averageCost)
    
# Bind callback method
push_client.position_changed = on_position_changed
# Connect
push_client.connect(client_config.tiger_id, client_config.private_key)

# Subscribe to position changes
push_client.subscribe_position(account=client_config.account)
# Unsubscribe from position changes
push_client.unsubscribe_position()

Return

You need to use PushClient.position_changed to respond to return results. Data type is tigeropen.push.pb.PositionData_pb2.PositionData Object Description. Fields in list items can be referenced against get_positions Position object.

FieldTypeDescription
accountstrFund account number
symbolstrPosition symbol code, e.g., 'AAPL', '00700', 'ES', 'CN'
expirystrOnly for options, warrants, CBBC
strikestrOnly for options, warrants, CBBC
rightstrOnly for options, warrants, CBBC
identifierstrSymbol identifier. For stocks, identifier is the same as symbol. For futures, it includes contract month, e.g., 'CN2201'
multiplierintQuantity per lot, limited to futures, options, warrants, CBBC
marketstrMarket. US, HK
currencystrCurrency. USD for US Dollar, HKD for Hong Kong Dollar
segTypestrClassification by trading instrument. S for stocks, C for futures
secTypestrSTK Stocks, OPT Options, WAR Warrants, IOPT CBBC, CASH FOREX, FUT Futures, FOP Future Options
positionintPosition quantity
positionScaleintPosition quantity offset
averageCostfloatAverage position cost
latestPricefloatCurrent price of the symbol
marketValuefloatPosition market value
unrealizedPnlfloatPosition profit/loss
namestrSymbol name
timestampintTimestamp

Callback Data Example

Stock position change push

account: "111111"
symbol: "BILI"
identifier: "BILI"
multiplier: 1
market: "US"
currency: "USD"
segType: "S"
secType: "STK"
position: 100
averageCost: 80
latestPrice: 19.83
marketValue: 1983
unrealizedPnl: -6017
timestamp: 1677745420121

Order Change Subscription and Cancellation

Subscription Method

PushClient.subscribe_order(account=None)

Cancellation Method

PushClient.unsubscribe_order()

Parameters

ParameterTypeDescription
accountstrAccount ID to subscribe to. If not provided, subscribes to all associated accounts. Note: If no account is specified during subscription, callback will push data for multiple accounts, and you need to determine which account the data belongs to when processing callbacks

Example

from tigeropen.push.pb.OrderStatusData_pb2 import OrderStatusData
from tigeropen.push.push_client import PushClient
from tigeropen.common.consts import OrderStatus
from tigeropen.common.util.order_utils import get_order_status
from tigeropen.tiger_open_config import TigerOpenClientConfig
client_config = TigerOpenClientConfig(props_path='/path/to/your/properties/file/')


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

# Define callback method
def on_order_changed(frame: OrderStatusData):
    print(f'order changed: {frame}')
    print(f'order status: {frame.status}')
    # Convert order status value to enum type
    status_enum = OrderStatus[frame.status]
    # or 
    # status_enum = get_order_status(frame.status)
    
# Bind callback method
push_client.order_changed = on_order_changed
# Connect
push_client.connect(client_config.tiger_id, client_config.private_key)

# Subscribe to order changes
push_client.subscribe_order(account=client_config.account)
# Unsubscribe from order changes
push_client.unsubscribe_order()

Return

You need to use PushClient.order_changed to respond to return results. Data type is tigeropen.push.pb.OrderStatusData_pb2.OrderStatusData Object Description. Field meanings in return results can be referenced against get_order Order object.

FieldTypeDescription
idintOrder number
accountstrFund account number
symbolstrPosition symbol code, e.g., 'AAPL', '00700', 'ES', 'CN'
expirystrOnly for options, warrants, CBBC
strikestrOnly for options, warrants, CBBC
rightstrOnly for options, warrants, CBBC
identifierstrSymbol identifier. For stocks, identifier is the same as symbol. For futures, it includes contract month, e.g., 'CN2201'
multiplierintQuantity per lot, limited to futures, options, warrants, CBBC
actionstrBuy/sell direction. BUY for buy, SELL for sell
marketstrMarket. US, HK
currencystrCurrency. USD for US Dollar, HKD for Hong Kong Dollar
segTypestrClassification by trading instrument. S for stocks, C for futures
secTypestrSTK Stocks, OPT Options, WAR Warrants, IOPT CBBC, CASH FOREX, FUT Futures, FOP Future Options
orderTypestrOrder type. 'MKT' market order/'LMT' limit order/'STP' stop order/'STP_LMT' stop limit order/'TRAIL' trailing stop order
isLongbooleanWhether it's a long position
totalQuantityintOrder quantity
totalQuantityScaleintOrder quantity offset. If totalQuantity=111, totalQuantityScale=2, then real totalQuantity=111*10^(-2)=1.11
filledQuantityintTotal filled quantity (for orders with multiple fills, filledQuantity is cumulative total filled)
filledQuantityScaleintTotal filled quantity offset
avgFillPricefloatAverage fill price
limitPricefloatLimit order price
stopPricefloatStop price
realizedPnlfloatRealized profit/loss (only for integrated accounts)
statusstrOrder status. Note: status value is OrderStatus enum name, can use OrderStatus[value] to convert to enum type
replaceStatusstrOrder replace status
cancelStatusstrOrder cancel status
outsideRthboolWhether to allow pre-market and after-hours trading, only applicable to US stocks
canModifyboolWhether can be modified
canCancelboolWhether can be canceled
liquidationboolWhether it's a liquidation order
namestrSymbol name
sourcestrOrder source (from 'OpenApi', or other)
errorMsgstrError message
attrDescstrOrder description information
commissionAndFeefloatTotal commission and fees
openTimeintOrder placement time
timestampintLast update time of order status
userMarkstrOrder remark
totalCashAmountfloatTotal order amount
filledCashAmountfloatTotal filled amount
attrListlist[str]Order attribute list, meaning of each attribute: LIQUIDATION forced liquidation, FRACTIONAL_SHARE fractional share order (non-whole share), EXERCISE exercise, EXPIRE expiry, ASSIGNMENT passive exercise assignment, CASH_SETTLE cash settlement, KNOCK_OUT knock-out, RECALL recall order, ODD_LOT odd lot order (non-whole lot), DEALER dealer order, GREY_MARKET HK grey market order, BLOCK_TRADE block trade, ATTACHED_ORDER attached order, OCA OCA order
timeInForcestrOrder validity time. DAY: valid for the day, GTC: valid until canceled, GTD: valid until specified date

Callback Data Example

Stock order push example

id: 40536123722044416
account: "12345"
symbol: "01810"
identifier: "01810"
multiplier: 1
action: "SELL"
market: "HK"
currency: "HKD"
segType: "S"
secType: "STK"
orderType: "LMT"
isLong: true
totalQuantity: 200
limitPrice: 100.5
status: "HELD"
replaceStatus: "NONE"
cancelStatus: "NONE"
outsideRth: true
canModify: true
canCancel: true
name: "XIAOMI-W"
source: "OpenApi"
openTime: 1758165280000
timestamp: 1758165280758
timeInForce: "DAY"

Futures order push example

{"id":"28875370355884032","account":"12345","symbol":"CL","identifier":"CL2312","multiplier":1000,"action":"BUY",
"market":"US","currency":"USD","segment":"C","secType":"FUT","orderType":"LMT","isLong":true,"totalQuantity":"1",
"filledQuantity":"1","avgFillPrice":77.76,"limitPrice":77.76,"status":"FILLED","outsideRth":true,"name":"WTI Crude Oil 2312",
"source":"android","commissionAndFee":4.0,"openTime":"1669200792000","timestamp":"1669200782221"}

Order Execution Details Subscription and Cancellation

Subscription Method

PushClient.subscribe_transaction(account=client_config.account)

Cancellation Method

PushClient.unsubscribe_transaction()

Parameters

ParameterTypeDescription
accountstrAccount ID to subscribe to. If not provided, subscribes to all associated accounts. Note: If no account is specified during subscription, callback will push data for multiple accounts, and you need to determine which account the data belongs to when processing callbacks

Example

from tigeropen.push.pb.OrderTransactionData_pb2 import OrderTransactionData
from tigeropen.push.push_client import PushClient
from tigeropen.tiger_open_config import TigerOpenClientConfig
client_config = TigerOpenClientConfig(props_path='/path/to/your/properties/file/')


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

# Define callback method
def on_transaction_changed(frame: OrderTransactionData):
    print(f'transaction changed: {frame}')
    
# Bind callback method
push_client.transaction_changed = on_transaction_changed
# Connect
push_client.connect(client_config.tiger_id, client_config.private_key)

# Subscribe
pushClient.subscribe_transaction(account=client_config.account)
# Unsubscribe
pushClient.unsubscribe_transaction()

Return

You need to use PushClient.transaction_changed to respond to return results. Data type is tigeropen.push.pb.OrderTransactionData_pb2.OrderTransactionData. Field meanings in return results can be referenced against get_transactions Transaction.

FieldTypeDescription
idintOrder execution ID
orderIdintOrder number
accountstrFund account number
symbolstrPosition symbol code, e.g., 'AAPL', '00700', 'ES', 'CN'
identifierstrSymbol identifier. For stocks, identifier is the same as symbol. For futures, it includes contract month, e.g., 'CN2201'
multiplierintQuantity per lot (options, futures specific)
actionstrBuy/sell direction. BUY for buy, SELL for sell
marketstrMarket. US, HK
currencystrCurrency. USD for US Dollar, HKD for Hong Kong Dollar
segTypestrClassification by trading instrument. S for stocks, C for futures
secTypestrTrading instrument, security type. STK for stocks, FUT for futures
filledPricefloatPrice
filledQuantityintFilled quantity
createTimeintCreate time
updateTimeintUpdate time
transactTimeintTransaction time
timestampintTimestamp

Callback Data Example

id: 2999543887211111111
orderId: 29995438111111111
account: "1111111"
symbol: "ZC"
identifier: "ZC2305"
multiplier: 5000
action: "BUY"
market: "US"
currency: "USD"
segType: "C"
secType: "FUT"
filledPrice: 6.385
filledQuantity: 1
createTime: 1677746237303
updateTime: 1677746237303
transactTime: 1677746237289
timestamp: 1677746237313