Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
order delay

I'm having trouble with the time.sleep function in my code. Right now I'd like to place an order and then hold it for a minute and then sell it, but I'm having trouble figuring out how to write the part where it will hold the security for a minute and then sell it.

1 response

Well right now (and for the foreseeable future, unfortunately) , Quantopian only "listens" every minute. So you can keep your code really simple and do following:

`` def initialize(context):
context.elapsedBar = 0

def handle_data(context,data):

  context.elapsedBar+=1  

  if somethingHappens:  
    #mark the point from which you want to start counting  
    context.eventHappened = context.elapsedBar  

  # do something else 1 bar (minute) later  
  if context.elapsedBar == context.eventHappened + 1:  
       # do something else then reset your variable  
       context.eventHappened = None