专注股票、期货、外汇程序化交易开发
 企业微信
520量化编程
开启左侧

委托单超时撤单

[复制链接]
520量化编程 发表于 2024-7-19 21:50:36 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题
 
  1. #encoding:gbk

  2. import pandas as pd
  3. import numpy as np
  4. import datetime
  5. import talib

  6. def init(ContextInfo):
  7.         ContextInfo.accID='80041016'
  8.         ContextInfo.set_account(ContextInfo.accID)
  9.         ContextInfo.run_time('cancel_order_timer','10nSecond','2023-01-01 00:00:00')
  10.       
  11. def handlebar(ContextInfo):
  12.         pass

  13. def cancel_order_timer(ContextInfo):
  14.         #获取委托对象列表
  15.         orders=get_trade_detail_data(ContextInfo.accID,'STOCK','ORDER')
  16.         #遍历委托对象列表
  17.         for order in orders:
  18.                 #判断委托对象是否可以撤销
  19.                 if can_cancel_order(order.m_strOrderSysID,ContextInfo.accID,'STOCK'):
  20.                         ordercode=order.m_strInstrumentID+'.'+order.m_strExchangeID #获取委托单的证券代码
  21.                         dt=order.m_strInsertDate+' '+order.m_strInsertTime #委托日期+委托时间
  22.                         dt=datetime.datetime.strptime(dt,'%Y%m%d %H%M%S') #委托日期时间字符串解析成日期时间对象
  23.                         now=datetime.datetime.now() #获取当前日期时间
  24.                         second=(now-dt).seconds #当前日期时间-委托日期时间,获取秒数时间差
  25.                         if second>60: #如果超过60秒
  26.                                 #买入委托超时,撤单并重新下单,委托价格需要修改
  27.                                 cancel(order.m_strOrderSysID,ContextInfo.accID,'STOCK',ContextInfo)
  28.                                 print('合同编号',order.m_strOrderSysID,'股票代码',ordercode,order.m_strInstrumentName,order.m_strOptName,'超时60秒撤单')
  29.                                 if order.m_strOptName=='限价买入': #如果是限价买入的委托撤单,则重新委托买入
  30.                                         passorder(23,1101,ContextInfo.accID,ordercode,11,order.m_dLimitPrice,order.m_nVolumeTotal,'定时撤单策略',1,'委托买入',ContextInfo)
  31.                                         print('重新委托买入')
  32.                                 if order.m_strOptName=='限价卖出': #如果是限价卖出的委托撤单,则重新委托卖出
  33.                                         passorder(24,1101,ContextInfo.accID,ordercode,11,order.m_dLimitPrice,order.m_nVolumeTotal,'定时撤单策略',1,'委托卖出',ContextInfo)
  34.                                         print('重新委托卖出')

复制代码

回复

使用道具 举报

 
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

热门图文
排行榜
作者专栏

关注我们:微信订阅号

公众号/p>

企业微信

全国服务热线:

18081412300

公司地址:四川省安岳县柠都大道226号

运营中心::四川省安岳县柠都大道226号

邮编:6243650 Email:525406187@qq.com

川公安网备案51202102000095

备案许可证:蜀ICP备20018290号-1

增值电信业务经营许可证:川B2-20220450

Copyright   ©2015-2016  520量化编程Powered by©Discuz!技术支持:迪恩网络    ( 蜀ICP备20018290号-1 )