PTrade获取交易相关函数
注意:代码精度位为3位小数的类型(后台已保护为3位),如ETF、国债;代码精度为2位小数类型,需要在传参时限制价格参数的精度,如股票。
更加详细的调用方法,后续会慢慢整理。
也可找寻博主历史文章,搜索关键词使用方案,比如本文涉及函数after_trading_cancel_order !
感谢关注,咨询免费开通量化回测与获取实盘权限,欢迎和博主联系!
after_trading_cancel_order - 盘后固定价委托撤单(股票)
after_trading_cancel_order(order_param)
使用场景
该函数仅支持Ptrade客户端可用、仅在股票交易模块可用
接口说明
该接口用于盘后固定价委托取消订单,根据Order对象或order_id取消订单。
注意事项:
无
参数
order_param: Order对象或者order_id(Order/str)
返回
None
示例
import time
def initialize(context):
g.security = "300001.SZ"
set_universe(g.security)
# 15:00-15:30期间使用run_daily进行盘后固定价委托、盘后固定价委托撤单
run_daily(context, order_test, time="15:15")
g.flag = False
def order_test(context):
snapshot = get_snapshot(g.security)
if snapshot is not None:
last_px = snapshot[g.security].get("last_px", 0)
if last_px > 0:
order_id = after_trading_order(g.security, 200, float(last_px))
time.sleep(5)
after_trading_cancel_order(order_id)
def handle_data(context, data):
if not g.flag:
snapshot = get_snapshot(g.security)
if snapshot is not None:
last_px = snapshot[g.security].get("last_px", 0)
if last_px > 0:
order_id = after_trading_order(g.security, 200, float(last_px))
time.sleep(5)
after_trading_cancel_order(order_id)
g.flag = True