账户变动
以下全部为异步API,需要指定一个方法响应返回的结果
订阅及回调数据格式目前支持两种方式,Protobuf和STOMP,建议使用Protobuf。 当前版本默认使用STOMP方式,未来版本将切换为默认Protobuf方式。
修改PuchClient初始化参数 use_protobuf
, 设置为True则开启Protobuf方式:
push_client = PushClient(host, port, use_ssl=(protocol == 'ssl'), use_protobuf=True)
Protobuf 方式
资产变化的订阅与取消
订阅方法
PushClient.subscribe_asset(account=None)
取消方法
PushClient.unsubscribe_asset()
参数
参数名 | 类型 | 描述 |
---|---|---|
account | str | 需要订阅的 account id,不传则订阅所有关联的 account |
返回
需要使用 PushClient.asset_changed
响应返回结果。返回结果为 tigeropen.push.pb.AssetData_pb2.AssetData 对象
字段含义可对照参考获取资产接口 get_prime_assets, get_assets
详细字段解释参考对象:
PortfolioAccount 综合/模拟资产
Segment 综合/模拟分品种资产
PortfolioAccount 环球资产
SecuritySegment 环球股票资产
CommoditySegment 环球期货资产
回调数据字段含义
资产变动回调
字段 | 类型 | 描述 |
---|---|---|
account | str | 资金账号 |
currency | str | 币种。USD美元,HKD港币 |
segType | str | 按交易品种划分的分类。S表示股票,C表示期货 |
availableFunds | float | 可用资金,隔夜剩余流动性 |
excessLiquidity | float | 当前剩余流动性 |
netLiquidation | float | 总资产(净清算值)。总资产就是我们账户的净清算现金余额和证券总市值之和 |
equityWithLoan | float | 含贷款价值总权益。等于总资产 - 美股期权 |
buyingPower | float | 购买力。仅适用于股票品种,即segment为S时有意义 |
cashBalance | float | 现金额。当前所有币种的现金余额之和 |
grossPositionValue | float | 证券总价值 |
initMarginReq | float | 初始保证金 |
maintMarginReq | float | 维持保证金 |
timestamp | int | 时间戳 |
示例
from tigeropen.push.pb.AssetData_pb2 import AssetData
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_asset_changed(frame: AssetData):
"""可进行自定义处理,此处仅打印"""
print(f'asset change. {frame}')
# 查看可用资金
print(frame.availableFunds)
# 查看持仓市值
print(frame.grossPositionValue)
# 绑定回调方法
push_client.asset_changed = on_asset_changed
# 连接
push_client.connect(client_config.tiger_id, client_config.private_key)
# 订阅
push_client.subscribe_asset(account=client_config.account)
#取消订阅资产变化
PushClient.unsubscribe_asset()
回调数据示例
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
持仓变化的订阅与取消
订阅方法
PushClient.subscribe_position(account=None)
取消方法
PushClient.unsubscribe_position()
参数
参数名 | 类型 | 描述 |
---|---|---|
account | str | 需要订阅的 account id,不传则订阅所有关联的 account |
示例
from tigeropen.push.pb.PositionData_pb2 import PositionData
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_position_changed(frame: PositionData):
print(f'position change. {frame}')
# 持仓标的
print(frame.symbol)
# 持仓成本
print(frame.averageCost)
# 绑定回调方法
push_client.position_changed = on_position_changed
# 连接
push_client.connect(client_config.tiger_id, client_config.private_key)
# 订阅持仓的变化
PushClient.subscribe_position(account=client_config.account)
# 取消订阅持仓的变化
PushClient.unsubscribe_position()
返回
需要使用 PushClient.position_changed
响应返回结果,数据类型为 tigeropen.push.pb.PositionData_pb2.PositionData 。 列表项中的各字段可对照参考 get_position 中的 Position 对象。
字段 | 类型 | 描述 |
---|---|---|
account | str | 资金账号 |
symbol | str | 持仓标的代码,如 'AAPL', '00700', 'ES', 'CN' |
expiry | str | 仅支持期权、窝轮、牛熊证 |
strike | str | 仅支持期权、窝轮、牛熊证 |
right | str | 仅支持期权、窝轮、牛熊证 |
identifier | str | 标的标识符。股票的identifier与symbol相同。期货的会带有合约月份,如 'CN2201' |
multiplier | int | 每手数量,仅限 futures, options, warrants, CBBC |
market | str | 市场。US, HK |
currency | str | 币种。USD美元,HKD港币 |
segType | str | 按交易品种划分的分类。S表示股票,C表示期货 |
secType | str | STK Stocks, OPT Options, WAR Warrants, IOPT CBBC, CASH FOREX, FUT Futures, FOP Future Options |
position | int | 持仓数量 |
positionScale | int | 持仓数量的偏移量 |
averageCost | float | 持仓均价 |
latestPrice | float | 标的当前价格 |
marketValue | float | 持仓市值 |
unrealizedPnl | float | 持仓盈亏 |
name | str | 标的名称 |
timestamp | int | 时间戳 |
回调数据示例 股票持仓变化推送
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
订单变化的订阅和取消
订阅方法
PushClient.subscribe_order(account=None)
取消方法
PushClient.unsubscribe_order()
参数
参数名 | 类型 | 描述 |
---|---|---|
account | str | 需要订阅的 account id,不传则订阅所有关联的 account |
示例
from tigeropen.push.pb.OrderStatusData_pb2 import OrderStatusData
from tigeropen.push.push_client import PushClient
from tigeropen.tiger_open_config import get_client_config
from tigeropen.common.consts import OrderStatus
from tigeropen.common.util.order_utils import get_order_status
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_order_changed(frame: OrderStatusData):
print(f'order changed: {frame}')
print(f'order status: {frame.status}')
# 将订单状态值转换为枚举类型
status_enum = OrderStatus[frame.status]
# 或
# status_enum = get_order_status(frame.status)
# 绑定回调方法
push_client.order_changed = on_order_changed
# 连接
push_client.connect(client_config.tiger_id, client_config.private_key)
# 订阅订单变化
PushClient.subscribe_order(account=client_config.account)
# 取消订阅订单变化
PushClient.unsubscribe_order()
返回
需要使用 PushClient.order_changed
响应返回结果,数据类型为 tigeropen.push.pb.OrderStatusData_pb2.OrderStatusData
返回结果中的字段含义可对照参考 get_order 中的 Order 对象
字段 | 类型 | 描述 |
---|---|---|
id | int | 订单号 |
account | str | 资金账号 |
symbol | str | 持仓标的代码,如 'AAPL', '00700', 'ES', 'CN' |
expiry | str | 仅支持期权、窝轮、牛熊证 |
strike | str | 仅支持期权、窝轮、牛熊证 |
right | str | 仅支持期权、窝轮、牛熊证 |
identifier | str | 标的标识符。股票的identifier与symbol相同。期货的会带有合约月份,如 'CN2201' |
multiplier | int | 每手数量,仅限 futures, options, warrants, CBBC |
action | str | 买卖方向。BUY表示买入,SELL表示卖出。 |
market | str | 市场。US、HK |
currency | str | 币种。USD美元,HKD港币 |
segType | str | 按交易品种划分的分类。S表示股票,C表示期货 |
secType | str | STK Stocks, OPT Options, WAR Warrants, IOPT CBBC, CASH FOREX, FUT Futures, FOP Future Options |
orderType | str | 订单类型。'MKT'市价单/'LMT'限价单/'STP'止损单/'STP_LMT'止损限价单/'TRAIL'跟踪止损单 |
isLong | boolean | 是否多头持仓 |
totalQuantity | int | 下单数量 |
totalQuantityScale | int | 下单数量偏移量,如 totalQuantity=111, totalQuantityScale=2,那么真实 totalQuantity=111*10^(-2)=1.11 |
filledQuantity | int | 成交总数量(订单分多笔成交的,filledQuantity为累计成交总数) |
filledQuantityScale | int | 成交总数量偏移量 |
avgFillPrice | float | 成交均价 |
limitPrice | float | 限价单价格 |
stopPrice | float | 止损价格 |
realizedPnl | float | 已实现盈亏(只有综合账号有这个字段) |
status | str | 订单状态。注意,status的值为 OrderStatus的枚举名称, 可使用 OrderStatus[value] 转换为枚举类型 |
replaceStatus | str | 订单改单状态 |
cancelStatus | str | 订单撤单状态 |
outsideRth | bool | 是否允许盘前盘后交易,仅适用于美股 |
canModify | bool | 是否能修改 |
canCancel | bool | 是否能取消 |
liquidation | bool | 是否为平仓订单 |
name | str | 标的名称 |
source | str | 订单来源(from 'OpenApi', or other) |
errorMsg | str | 错误信息 |
attrDesc | str | 订单描述信息 |
commissionAndFee | float | 佣金费用总计 |
openTime | int | 下单时间 |
timestamp | int | 订单状态最后更新时间 |
userMark | str | 订单备注 |
totalCashAmount | float | 订单总金额 |
filledCashAmount | float | 成交总金额 |
回调数据示例 股票订单推送示例
期货订单推送示例
{"id":"28875370355884032","account":"736845","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原油2312",
"source":"android","commissionAndFee":4.0,"openTime":"1669200792000","timestamp":"1669200782221"}
订单执行明细订阅和取消
订阅方法
PushClient.subscribe_transaction(account=client_config.account)
取消方法
PushClient.unsubscribe_transaction()
参数
参数名 | 类型 | 描述 |
---|---|---|
account | str | 需要订阅的 account id,不传则订阅所有关联的 account |
示例
from tigeropen.push.pb.OrderTransactionData_pb2 import OrderTransactionData
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_transaction_changed(frame: OrderTransactionData):
print(f'transaction changed: {frame}')
# 绑定回调方法
push_client.transaction_changed = on_transaction_changed
# 连接
push_client.connect(client_config.tiger_id, client_config.private_key)
# 订阅
PushClient.subscribe_transaction(account=client_config.account)
# 取消订阅
PushClient.unsubscribe_transaction()
返回
需要使用 PushClient.transaction_changed
响应返回结果,数据类型为 tigeropen.push.pb.OrderTransactionData_pb2.OrderTransactionData
返回结果中的字段含义可对照参考 get_transactions 中的 Transaction
字段 | 类型 | 描述 |
---|---|---|
id | int | 订单执行ID |
orderId | int | 订单号 |
account | str | 资金账号 |
symbol | str | 持仓标的代码,如 'AAPL', '00700', 'ES', 'CN' |
identifier | str | 标的标识符。股票的identifier与symbol相同。期货的会带有合约月份,如 'CN2201' |
multiplier | int | 每手数量(期权、期货专有) |
action | str | 买卖方向。BUY表示买入,SELL表示卖出。 |
market | str | 市场。US、HK |
currency | str | 币种。USD美元,HKD港币 |
segType | str | 按交易品种划分的分类。S表示股票,C表示期货 |
secType | str | 交易品种,标的类型。STK表示股票,FUT表示期货 |
filledPrice | float | 价格 |
filledQuantity | int | 成交数量 |
createTime | int | create time |
updateTime | int | update time |
transactTime | int | 成交时间 |
timestamp | int | timestamp |
回调数据示例
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
STOMP 方式
资产变化的订阅与取消
订阅方法
PushClient.subscribe_asset(account=None)
取消方法
PushClient.unsubscribe_asset()
参数
参数名 | 类型 | 描述 |
---|---|---|
account | str | 需要订阅的 account id,不传则订阅所有关联的 account |
返回
需要使用 PushClient.asset_changed
响应返回结果。返回结果第一个参数为account,第二个参数为各字段元组构成的list。
字段含义可对照参考获取资产接口 get_prime_assets, get_assets
详细字段解释参考对象:
PortfolioAccount 综合/模拟资产
Segment 综合/模拟分品种资产
PortfolioAccount 环球资产
SecuritySegment 环球股票资产
CommoditySegment 环球期货资产
字段 | 类型 | 描述 |
---|---|---|
segment | str | 按交易品种划分的分类。S表示股票,C表示期货,summary表示环球账户的汇总资产信息 |
cash | float | 现金额。当前所有币种的现金余额之和 |
available_funds | float | 可用资金,隔夜剩余流动性 |
excess_liquidity | float | 当前剩余流动性 |
equity_with_loan | float | 含贷款价值总权益。等于总资产 - 美股期权 |
net_liquidation | float | 总资产(净清算值)。总资产就是我们账户的净清算现金余额和证券总市值之和 |
gross_position_value | float | 证券总价值 |
initial_margin_requirement | float | 初始保证金 |
maintenance_margin_requirement | float | 维持保证金 |
buying_power | float | 购买力。仅适用于股票品种,即segment为S时有意义 |
示例
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=False)
# 定义回调方法
def on_asset_changed(account, items):
"""可进行自定义处理,此处仅打印"""
print(f'asset change. account:{account}, items:{items}')
# 绑定回调方法
push_client.asset_changed = on_asset_changed
# 连接
push_client.connect(client_config.tiger_id, client_config.private_key)
# 订阅
push_client.subscribe_asset(account=client_config.account)
#取消订阅资产变化
PushClient.unsubscribe_asset()
回调数据示例
account:123456,
items:[('cash', 679760.8392063834), ('gross_position_value', 202318.91581133104), ('equity_with_loan', 881789.7550177145),
('net_liquidation', 882079.7550177145), ('initial_margin_requirement', 108369.06714828224), ('buying_power', 3093682.751477729),
('excess_liquidity', 793970.6843320723), ('available_funds', 773420.6878694323), ('maintenance_margin_requirement', 87819.07068564222),
('segment', 'S')]
account:111111,
items:[('cash', 99997.18), ('gross_position_value', 15620.0), ('equity_with_loan', 99572.18), ('net_liquidation', 99997.18),
('initial_margin_requirement', 467.5), ('buying_power', 0.0), ('excess_liquidity', 99572.18), ('available_funds', 99529.68),
('maintenance_margin_requirement', 425.0), ('segment', 'C')]
持仓变化的订阅与取消
订阅方法
PushClient.subscribe_position(account=None)
取消方法
PushClient.unsubscribe_position()
参数
参数名 | 类型 | 描述 |
---|---|---|
account | str | 需要订阅的 account id,不传则订阅所有关联的 account |
示例
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=False)
# 定义回调方法
def on_position_changed(account, items):
"""
:param account:
:param items:
:return:
items 数据示例:
[('symbol', 'ABCD'), ('market_price', 3.68525), ('market_value', 0.0), ('sec_type', 'STK'),
('segment', 'summary'), ('currency', 'USD'), ('quantity', 0.0), ('average_cost', 3.884548)]
"""
print(account, items)
# 绑定回调方法
push_client.position_changed = on_position_changed
# 连接
push_client.connect(client_config.tiger_id, client_config.private_key)
# 订阅持仓的变化
PushClient.subscribe_position(account=client_config.account)
# 取消订阅持仓的变化
PushClient.unsubscribe_position()
返回
需要使用 PushClient.position_changed
响应返回结果,第一个参数为account,第二个参数为各字段元组构成的list。 列表项中的各字段可对照参考 get_position 中的 Position 对象。
字段 | 类型 | 描述 |
---|---|---|
segment | str | 按交易品种划分的分类。S表示股票,C表示期货 |
symbol | str | 持仓标的代码,如 'AAPL', '00700', 'ES', 'CN' |
identifier | str | 标的标识符。股票的identifier与symbol相同。期货的会带有合约月份,如 'CN2201' |
currency | str | 币种。USD美元,HKD港币 |
sec_type | str | 交易品种,标的类型。STK表示股票,FUT表示期货 |
market_price | float | 标的当前价格 |
market_value | float | 持仓市值 |
quantity | int | 持仓数量 |
average_cost | float | 持仓均价 |
unrealized_pnl | float | 持仓盈亏 |
回调数据示例
# 股票持仓变化推送
account:1111111,
items:[('symbol', '09626'), ('currency', 'HKD'), ('sec_type', 'STK'), ('market_price', 305.0), ('quantity', 20), ('average_cost', 0.0), ('market_value', 6100.0), ('identifier', '09626'), ('unrealized_pnl', 6100.0), ('segment', 'S')]
# 期货持仓变化推送
account:1111111,
items:[('symbol', 'CN'), ('currency', 'USD'), ('sec_type', 'FUT'), ('market_price', 15620.0), ('quantity', 1), ('average_cost', 0.0), ('market_value', 15620.0), ('identifier', 'CN2201'), ('unrealized_pnl', 15620.0), ('segment', 'C')]
订单变化的订阅和取消
订阅方法
PushClient.subscribe_order(account=client_config.account)
取消方法
PushClient.unsubscribe_order()
参数
参数名 | 类型 | 描述 |
---|---|---|
account | str | 需要订阅的 account id,不传则订阅所有关联的 account |
示例
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=False)
# 定义回调方法
def on_order_changed(account, items):
"""
:param account:
:param items:
:return:
items 数据示例:
[('order_type', 'LMT'), ('symbol', 'ABCD'), ('order_id', 1000101463), ('sec_type', 'STK'), ('filled', 100),
('quantity', 100), ('segment', 'summary'), ('action', 'BUY'), ('currency', 'USD'), ('id', 173612806463631360),
('order_time', 1568095814556), ('time_in_force', 'DAY'), ('identifier', 'ABCD'), ('limit_price', 113.7),
('outside_rth', True), ('avg_fill_price', 113.7), ('trade_time', 1568095815418),
('status', <OrderStatus.FILLED: 'Filled'>)]
"""
print(account, items)
# 绑定回调方法
push_client.order_changed = on_order_changed
# 连接
push_client.connect(client_config.tiger_id, client_config.private_key)
# 订阅订单变化
PushClient.subscribe_order(account=client_config.account)
# 取消订阅订单变化
PushClient.unsubscribe_order()
返回
需要使用 PushClient.order_changed
响应返回结果,第一个参数为account,第二个参数为各字段元组构成的list。
返回结果中的字段含义可对照参考 get_order 中的 Order 对象
字段 | 类型 | 描述 |
---|---|---|
segment | str | 按交易品种划分的分类。S表示股票,C表示期货 |
id | int | 订单号 |
symbol | str | 持仓标的代码,如 'AAPL', '00700', 'ES', 'CN' |
identifier | str | 标的标识符。股票的identifier与symbol相同。期货的会带有合约月份,如 'CN2201' |
currency | str | 币种。USD美元,HKD港币 |
sec_type | str | 交易品种,标的类型。STK表示股票,FUT表示期货 |
action | str | 买卖方向。BUY表示买入,SELL表示卖出。 |
order_type | str | 订单类型。'MKT'市价单/'LMT'限价单/'STP'止损单/'STP_LMT'止损限价单/'TRAIL'跟踪止损单 |
quantity | int | 下单数量 |
limit_price | float | 限价单价格 |
filled | int | 成交数量 |
avg_fill_price | float | 不含佣金的成交均价 |
realized_pnl | float | 已实现盈亏 |
status | tigeropen.common.consts.OrderStatus | 订单状态 |
outside_rth | bool | 是否允许盘前盘后交易,仅适用于美股 |
order_time | int | 下单时间 |
回调数据示例
# 股票订单推送示例
account:111111
items: [('id', 25224910928347136), ('symbol', '09626'), ('currency', 'HKD'), ('sec_type', 'STK'), ('action', 'BUY'), ('quantity', 20), ('filled', 20), ('order_type', 'LMT'), ('avg_fill_price', 305.0), ('status', <OrderStatus.FILLED: 'Filled'>), ('realized_pnl', 0.0), ('replace_status', 'NONE'), ('outside_rth', False), ('limit_price', 305.0), ('order_time', 1641349997000), ('identifier', '09626'), ('segment', 'S')]```
# 期货订单推送示例
account:111111
items: [('id', 25224890075841536), ('symbol', 'CN'), ('currency', 'USD'), ('sec_type', 'FUT'), ('action', 'BUY'), ('quantity', 1), ('filled', 1), ('order_type', 'LMT'), ('avg_fill_price', 15620.0), ('status', <OrderStatus.FILLED: 'Filled'>), ('realized_pnl', 0.0), ('replace_status', 'NONE'), ('outside_rth', False), ('limit_price', 15638.0), ('order_time', 1641349838000), ('identifier', 'CN2201'), ('segment', 'C')]
订单执行明细订阅和取消
订阅方法
PushClient.subscribe_transaction(account=client_config.account)
取消方法
PushClient.unsubscribe_transaction()
参数
参数名 | 类型 | 描述 |
---|---|---|
account | str | 需要订阅的 account id,不传则订阅所有关联的 account |
示例
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=False)
# 定义回调方法
def on_transaction_changed(account, items):
"""
:param account:
:param items:
:return:
items 数据示例:
[('id', 28819544190616576), ('currency', 'USD'), ('sec_type', 'FUT'), ('market', 'SG'), ('symbol', 'CN'),
('multiplier', 1.0), ('action', 'BUY'), ('filled_quantity', 1.0), ('filled_price', 12309.0),
('order_id', 28819544031364096), ('transact_time', 1668774872538), ('create_time', 1668774872946),
('update_time', 1668774872946), ('identifier', 'CN2212'), ('timestamp', 1668774873002), ('segment', 'C')]
"""
print(account, items)
# 绑定回调方法
push_client.transaction_changed = on_transaction_changed
# 连接
push_client.connect(client_config.tiger_id, client_config.private_key)
# 订阅
PushClient.subscribe_transaction(account=client_config.account)
# 取消订阅
PushClient.unsubscribe_transaction()
返回
需要使用 PushClient.transaction_changed
响应返回结果,第一个参数为account,第二个参数为各字段元组构成的list。
返回结果中的字段含义可对照参考 get_transactions 中的 Transaction
字段 | 类型 | 描述 |
---|---|---|
segment | str | 按交易品种划分的分类。S表示股票,C表示期货 |
id | int | 订单执行ID |
order_id | int | 订单号 |
symbol | str | 持仓标的代码,如 'AAPL', '00700', 'ES', 'CN' |
identifier | str | 标的标识符。股票的identifier与symbol相同。期货的会带有合约月份,如 'CN2201' |
currency | str | 币种。USD美元,HKD港币 |
market | str | 市场。US、HK |
account | str | 资金账号 |
sec_type | str | 交易品种,标的类型。STK表示股票,FUT表示期货 |
action | str | 买卖方向。BUY表示买入,SELL表示卖出。 |
multiplier | int | 每手数量(期权、期货专有) |
filled_quantity | int | 成交数量 |
filled_price | double | 价格 |
transact_time | int | 成交时间 |
create_time | int | create time |
update_time | int | update time |
timestamp | int | timestamp |
回调数据示例
items: [('id', 28819544190616576), ('currency', 'USD'), ('sec_type', 'FUT'), ('market', 'SG'), ('symbol', 'CN'),
('multiplier', 1.0), ('action', 'BUY'), ('filled_quantity', 1.0), ('filled_price', 12309.0),
('order_id', 28819544031364096), ('transact_time', 1668774872538), ('create_time', 1668774872946),
('update_time', 1668774872946), ('identifier', 'CN2212'), ('timestamp', 1668774873002), ('segment', 'C')]
---