Back to Community
Is there a way to tell when a limit order is executed?
def initialize(context):  
    context.security = sid(10925)  
    context.bought = False  
    context.order_count = 0  
    schedule_function(  
        limit_buy,  
        date_rule=date_rules.every_day(),  
        time_rule=time_rules.market_open())  
def limit_buy(context,data):  

    if context.order_count<2:  
        if not context.bought:  
            order(context.security,100, style=LimitOrder(0.69))  
            context.bought = True  
            context.order_count +=1  
            print('We bought stock')  
        if context.bought:  
            order(context.security,-100, style=LimitOrder(.81))  
            context.order_count +=1  
            context.bought = False  

The algo is very simple it just limit buys a stock and limit sells a stock. There can only be two orders: one buy and one sell. The problem i am having is that I need to increment the order count when the algo limit sells. However, I can't think of a way to detect this limit sell because the limit sell order is being placed everyday but I need to detect when it actually fulfills.

Thanks