On IB API, can I use Good After Time order instead of limit take profit in a bracket?

Discussion in 'Automated Trading' started by outandabout, Sep 15, 2018.

  1. What I'd like to do:
    • Enter using a limit order that expires after [30] minutes. Attach a stop loss.
    • Exit automatically after [4] hours using a market order (which would cancel the stop loss).
    Ideally, this would be transmitted in one go to minimize risk from disconnects. I'm looking into IB's API to do this.

    Per title, seems I can get close using a bracket order, but with a time-based (GAT) profit taking order on the up side instead of a traditional limit order.

    • Does the API force the profit taking order to be a limit order, or can I submit another order type such as a GAT?

    • If entering limit order is partially filled and expires, ideally bracketing orders would be active and have sizes adjusted to match filled size. My fears are that:
      • bracketing orders will not activate till parent fills completely
      • bracketing order sizes will not be adjusted to reflect parent's partial fill
      • bracketing orders will be canceled on parent expiry.
    Seems like basic stuff, but just want to make sure I understand brackets correctly. Would love some input if anyone has experience with this.

    If not with a bracket order, is this doable with a parentId for the entering limit order + OCA group for the bracketing orders? (Again, not sure bracketing orders would adjust size in case of partial fills of parent.)

    Thank you.
  2. The first two are fine, they activate the brackets incrementally on partial fills and update the size as the parent continues to fill. If the parent hasn’t filled at all and gets canceled, the bracket does too.

    I think you can make the bracket whatever types of order you want, separate from the types of the parent, but I haven’t tried doing that with the API.

    Good luck.
  3. I am using IB's API to open a position and place an OCA group of exit orders. However, I do it slightly different from what IB describes as the "preferred solution".

    IB's "preferred solution": submit entry order and bracket exit orders at the same time. This might indeed result in issues when you have an partial fill: IB's documentation is not perfectly clear on how the bracket exit orders are adapted to the actual position size (my fear is that they are not adapted).

    My solution: send an entry order and monitor it to be filled. As you are monitoring it can you also determine when you want to cancel it: this can be time based (e.g. after 30 minutes), or based on any other parameter you like. Once you have a position, send the bracket of exit orders, specifying the quantity of your current position. This OCA group can consist of any number of orders, and all order types can be used. So, if you like, you can be very creative with this. Of course can this include a "good after time" order, plus a stop loss, plus a profit taker, plus anything else.
  4. southall


    I use OCA GAT market orders all the time with the API.

    The only issue the OP will have is the 4 hour GAT time is fixed and based on the submit time and cant be based on 4 hours after the fill time. To do that you will need to write monitoring logic and update the GAT time.

    IB should handle partial fills fine as when i used to use LMTs in the past IB had no problems adjusting children order size to the partial fill size
    These days i tend to use MIT instead of LMT orders which dont have partial fills.
    Last edited: Sep 16, 2018
  5. southall


    I think it is always better to use 'fire and forget' orders and groups if you can.

    And only resort to local monitoring and control logic if you absolutely have no other choice.
    Last edited: Sep 16, 2018
  6. I know what you mean by that, but it is not my preferred solution. I prefer to always know what the status of my account is (consisting of current positions plus current open order lines), and adapt the orders to the current status and the desired status. This made me move away from "fire and forget" order lines.
  7. Thanks all for your responses!

    @southall Yeah, I'd really like fire-and-forget for this too. Two questions, if I may:
    1. So, children become active when parent partially fills. But just to make doubly sure -- in your experience, children stay active in partial fill size even after the parent LMT expires, correct?

    2. When you used OCA GATs, did you use them as part of a bracket? Because the STP and the GAT MKT would be part of an OCA group, but both would follow a parent LMT order (before you switched to MITs) so that their size equals filled position. Just wondering if you did this via a bracket or separately (and if separately, how -- using a parent ID?).
    Thanks again.
  8. 1. Yes
    2. Don’t know
  9. You may want to read here to see how this can be done with IB's API:
  10. This

    A broker held stop order in even a fast moving liquid instrument can suffer heavy slippage. I can’t imagine locally held. This isn’t something you fuck around with, attended or unattended.
    #10     Sep 16, 2018