交易事件
on_order_status - 委托状态更新事件
响应委托状态更新事情,下单后及委托状态更新时被触发。
函数原型:
on_order_status(context, order)
参数:
参数名 | 类型 | 说明 |
---|---|---|
context | context | 上下文 |
order | order | 委托 |
示例:
def on_order_status(context, order):
print(order)
输出:
{'strategy_id': 'd7443a53-f65b-11ea-bb9d-484d7eaefe55', 'account_id': 'd7443a53-f65b-11ea-bb9d-484d7eaefe55', 'cl_ord_id': '000000000', 'symbol': 'SHSE.600000', 'side': 1, 'position_effect': 1, 'position_side': 1, 'order_type': 1, 'status': 3, 'price': 11.0, 'order_style': 1, 'volume': 18181800, 'value': 200000000.0, 'percent': 0.1, 'target_volume': 18181800, 'target_value': 199999800.0, 'target_percent': 0.1, 'filled_volume': 18181800, 'filled_vwap': 11.0011, 'filled_amount': 200019799.98, 'created_at': datetime.datetime(2020, 9, 1, 9, 40, tzinfo=tzfile('PRC')), 'updated_at': datetime.datetime(2020, 9, 1, 9, 40, tzinfo=tzfile('PRC')), 'filled_commission': 20001.979998, 'account_name': '', 'order_id': '', 'ex_ord_id': '', 'algo_order_id': '', 'order_business': 0, 'order_duration': 0, 'order_qualifier': 0, 'order_src': 0, 'position_src': 0, 'ord_rej_reason': 0, 'ord_rej_reason_detail': '', 'stop_price': 0.0}
on_execution_report - 委托执行回报事件
响应委托被执行事件,委托成交或者撤单拒绝后被触发。
函数原型:
on_execution_report(context, execrpt)
参数:
参数名 | 类型 | 说明 |
---|---|---|
context | context | 上下文 |
execrpt | execrpt | 回报 |
示例:
def on_execution_report(context, execrpt):
print(execrpt)
输出:
{'strategy_id': 'e41dec22-2d72-11eb-b043-00ff5a669ee2', 'cl_ord_id': '000000247', 'symbol': 'SHSE.600000', 'position_effect': 1, 'side': 1, 'exec_type': 15, 'price': 12.640000343322754, 'volume': 200, 'amount': 2528.000068664551, 'account_id': '', 'account_name': '', 'order_id': '', 'exec_id': '', 'order_business': 0, 'ord_rej_reason': 0, 'ord_rej_reason_detail': '', 'commission': 0.0, 'cost': 0.0, 'created_at': None}
on_account_status - 交易账户状态更新事件
响应交易账户状态更新事件,交易账户状态变化时被触发。 函数原型:
def on_account_status(context, account):
print(account)
参数:
参数名 | 类型 | 说明 |
---|---|---|
context | context | 上下文 |
account | object, 包含account_id(账户id), account_name(账户名),AccountStatus(账户状态) | 交易账户状态对象,仅响应 已连接,已登录,已断开 和 错误 事件。 |
示例:
def on_account_status(context, account):
print(account)
输出:
{'account_id': '4946cc09-fefd-11ea-ac6a-52560acd7da0', 'account_name': '', 'status': {'state': 5, 'error': {'code': 0, 'type': '', 'info': ''}}}