ptrade从零开始学习量化交易第66期【ptrade获取股票交易函数之after_trading_cancel_order - 盘后固定价委托撤单(股票)】

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

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值