掘金社区

我的追单函数的问题Pinned highlighted

134787***638 发表在掘金2 2016-01-29 00:53:39

掘金2
560
0
0

源代码是一个批量下单模块,我的追单函数在on_tick中调用,订阅了多个tick行情,在仿真的时候遇到了下面的问题:重复追单
请各位大神帮忙看看,万谢
def re_place_order(self, tick):
"""
追单函数
"""
for cl_ord_id, order in self.order_status.items():

        if order.status == 5 and tick.sec_id == order.sec_id:
            logger.info('%s撤单成功' % order.sec_id)          
            
            if order.filled_volume != 0:
                volume = order.volume - order.filled_volume
            else:
                volume = order.volume
                
            if order.side == 1 and order.position_effect == 1:
                self.open_long(order.exchange, 
                               order.sec_id, 0, volume)
                logger.info('追单买开%s:%d手,市价委托' 
                    % (order.sec_id, order.volume))
                
            elif order.side == 2 and order.position_effect in [2, 4]:
                if order.exchange == 'SHFE':
                    self.close_short_yesterday(order.exchange, 
                                               order.sec_id, 0, volume)
                else:
                    self.close_short(order.exchange, 
                                     order.sec_id, 0, volume)
                logger.info('追单买平%s:%d手,市价委托' 
                    % (order.sec_id, order.volume))
            
            elif order.side == 2 and order.position_effect == 1:
                self.open_short(order.exchange, 
                                order.sec_id, 0, volume)
                logger.info('追单卖开%s:%d手,市价委托' 
                    % (order.sec_id, order.volume))
            
            elif order.side == 1 and order.position_effect in [2, 4]:
                if order.exchange == 'SHFE':
                    self.close_long_yesterday(order.exchange, 
                        order.sec_id, 0, volume)
                else:
                    self.close_long(order.exchange, 
                                    order.sec_id, 0, volume)
                logger.info('追单卖平%s:%d手,市价委托' 
                    % (order.sec_id, order.volume))
                   
            self.order_status[cl_ord_id].status = 14
暂无评论

Looks like your connection to 掘金量化社区 - 量化交易者的策略交流学习社区 was lost, please wait while we try to reconnect.