QMT · 内置 Python成交回报实时主推函数
task_callback
当账号任务状态有变化时,这个函数被客户端调用
提示
仅在实盘运行模式下生效。
需要先在init里调用ContextInfo.set_account后生效。
用法
task_callback(ContextInfo, taskInfo)
释义
当账号任务状态有变化时,这个函数被客户端调用
参数
ContextInfo:特定对象
taskInfo 任务对象在新窗口打开
返回值
无
示例
示例
#coding:gbk
def show_data(data):
tdata = {}
for ar in dir(data):
if ar[:2] != 'm_':continue
try:
tdata[ar] = data.__getattribute__(ar)
except:
tdata[ar] = '<CanNotConvert>'
return tdata
def init(ContextInfo):
# 设置对应的资金账号
# 示例需要在策略交易界面运行
ContextInfo.set_account(account)
def after_init(ContextInfo):
# 在策略交易界面运行时,account的值会被赋值为策略配置中的账号,编辑器界面运行时,需要手动赋值
# 编译器界面里执行的下单函数不会产生实际委托
passorder(23, 1101, account, "000001.SZ", 5, 0, 100, "示例", 2, "投资备注",ContextInfo)
pass
def task_callback(ContextInfo, taskInfo):
print(show_data(taskInfo))
返回值
{'m_3rdPartyTradeParam': '', 'm_cancelTime': 2147483647, 'm_dFixPrice': 9.82, 'm_eOperationType': 18, 'm_eOrderType': 0, 'm_ePriceType': 5, 'm_eStatus': 3, 'm_endTime': 2147483647, 'm_nBusinessNum': 0, 'm_nGroupId': 11, 'm_nNum': 100, 'm_nTaskId': '11', 'm_script': '', 'm_startTime': 1708420476, 'm_stockCode': '000001.SZ', 'm_strAccountID': '2000567', 'm_strMsg': '9.8200全部委托! 报价行情已8076秒未更新!', 'm_strRemark': '投资备注'}
{'m_3rdPartyTradeParam': '', 'm_cancelTime': 2147483647, 'm_dFixPrice': 9.82, 'm_eOperationType': 18, 'm_eOrderType': 0, 'm_ePriceType': 5, 'm_eStatus': 3, 'm_endTime': 2147483647, 'm_nBusinessNum': 100, 'm_nGroupId': 11, 'm_nNum': 100, 'm_nTaskId': '11', 'm_script': '', 'm_startTime': 1708420476, 'm_stockCode': '000001.SZ', 'm_strAccountID': '2000567', 'm_strMsg': '9.8200全部委托! 报价行情已8076秒未更新!', 'm_strRemark': '投资备注'}
{'m_3rdPartyTradeParam': '', 'm_cancelTime': 2147483647, 'm_dFixPrice': 9.82, 'm_eOperationType': 18, 'm_eOrderType': 0, 'm_ePriceType': 5, 'm_eStatus': 7, 'm_endTime': 1708420476, 'm_nBusinessNum': 100, 'm_nGroupId': 11, 'm_nNum': 100, 'm_nTaskId': '11', 'm_script': '', 'm_startTime': 1708420476, 'm_stockCode': '000001.SZ', 'm_strAccountID': '2000567', 'm_strMsg': '任务完成', 'm_strRemark': '投资备注'}
{'m_3rdPartyTradeParam': '', 'm_cancelTime': 2147483647, 'm_dFixPrice': 9.82, 'm_eOperationType': 18, 'm_eOrderType': 0, 'm_ePriceType': 5, 'm_eStatus': 7, 'm_endTime': 1708420476, 'm_nBusinessNum': 100, 'm_nGroupId': 11, 'm_nNum': 100, 'm_nTaskId': '11', 'm_script': '', 'm_startTime': 1708420476, 'm_stockCode': '000001.SZ', 'm_strAccountID': '2000567', 'm_strMsg': '任务完成', 'm_strRemark': '投资备注'}
官方来源
QMT 官方文档:账号任务状态变化主推。网页核对日期:2026-10-11。