Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
conditional trade within same minute bar?

Is is possible to execute a trade based on the status of a trade executed in the same minute bar.

In other words to check the status of an order in the same minute bar it was created?

Best I can tell this isn't possible because the order status will be updated at the earliest in the next minute bar, I'd just like to confirm.

Thanks,
Ryan

8 responses

Hi Ryan,

You're absolutely right; a order will not start being filled until after your code is done running for the minute, so it's not very meaningful to check its status until a minute has passed. Zipline doesn't support finer execution than minute bars.

Disclaimer

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by Quantopian. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. No information contained herein should be regarded as a suggestion to engage in or refrain from any investment-related course of action as none of Quantopian nor any of its affiliates is undertaking to provide investment advice, act as an adviser to any plan or entity subject to the Employee Retirement Income Security Act of 1974, as amended, individual retirement account or individual retirement annuity, or give advice in a fiduciary capacity with respect to the materials presented herein. If you are an individual retirement or other investor, contact your financial advisor or other fiduciary unrelated to Quantopian about whether any given investment idea, strategy, product or service described herein may be appropriate for your circumstances. All investments involve risk, including loss of principal. Quantopian makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances.

Thank You Nathan

Hi Nathan,

My understanding is that orders are sent to IB asynchronously, so they get filled pronto, but the algo won't get updated until the next whole minute. I don't think your statement "a order will not start being filled until after your code is done running for the minute" is accurate, unless you are referring to the backtester/paper trading behavior.

Grant

If there were a milliseconds offset feature within the scheduler, you could use a for loop to submit orders to execute at whatever fraction you wished. However this isn't a quantopian capability, and I don't think it's even being considered (and should it be?) .

Richard,

You can delay order submission within the minute if you want, but why? There is a 50-second window for sending orders, but new data only becomes available to the algo on the whole minute, so you'd simply be delaying the response of the algo, i.e. adding latency.

Grant is right that, in live trading, orders are sent to the brokerage immediately after the function is called; there's isn't a delay until the next minute. The only delay is the algorithm's runtime so far that minute.

So the orders are sent immediately, but the status changes at the earliest next minute, correct?

If you need to sell an equity to free up funds to purchase another there are two options:

1) only issue the sell and check each minute if the sell is filled, then issue the buy some minutes later when the sell is complete

OR

2) issue both the buy and sell at the same time and hope the sell is filled first, but the buy might get rejected if the sell isn't already filled.

Is that correct?

Yeah, the status is updated for the first time on the next minute, so it's not possible to do a trade conditional on another within the same minute.