TWS API child order question

Discussion in 'Automated Trading' started by aripplet, Mar 21, 2012.

  1. aripplet

    aripplet

    m_pClient->placeOrder(m_orderId, m_contract, order_parent);
    m_pClient->placeOrder(m_orderId + 1, m_contract, order_stoploss);
    m_pClient->placeOrder(m_orderId + 2, m_contract, order_profittaking);


    trying to make a MKT parent order,
    and two child orders, one sl with STP type, one tp with LMT type.

    problem is,

    I have to submit three orders in turn. parent order first.
    but after I submitt the parent order, it will be filled immediately.

    child orders will produces error msg like:

    Error id=59, errorCode=201, msg=Order rejected - reason:The parent order is bein
    g canceled.

    And another question, In TWS, I am able to submit stop with stop price of actually traded price of parent order, How should I do it via API? the trade price of parent order is unknown when submitting attached child stop loss order.

    right now,
    I am submitting two child orders with very wild sl and tp level and modified it once parent order gets filled. apparently this is not a good solution


    Any idea? thank you.
     
  2. rdg

    rdg

    I think you can submit an order without transmitting it, so you can set up your bracket, then modify the parent order to transmit it. I'm not 100% but that's what I remember. If that doesn't help, post back and I'll dig through some code tomorrow.

    I don't know about the second q. If you figure it out, I'd be curious what you did.
     
  3. aripplet

    aripplet

    thanks,

    I figured out the first question myself by trying some combinations. still no clue about second one.


    order_parent.totalQuantity = totalQuantity;
    order_parent.orderType = "MKT";

    if(action == "BUY"){
    order_parent.action = "BUY";
    order_stoploss.action = "SELL";
    order_profittaking.action = "SELL";
    // TODO
    order_stoploss.auxPrice = initial_min;
    order_profittaking.lmtPrice = initial_max;
    }

    if(action == "SELL"){
    order_parent.action = "SELL";
    order_stoploss.action = "BUY";
    order_profittaking.action = "BUY";
    // TODO
    order_stoploss.auxPrice = initial_max;
    order_profittaking.lmtPrice = initial_min;
    }

    order_stoploss.orderType = "STP";
    order_profittaking.orderType = "LMT";
    order_stoploss.totalQuantity = order_parent.totalQuantity;
    order_profittaking.totalQuantity = order_parent.totalQuantity;
    order_stoploss.parentId = m_orderId;
    order_profittaking.parentId = m_orderId;
    order_parent.transmit = false;
    order_stoploss.transmit = false;
    //order_profittaking.transmit = false;

    m_pClient->placeOrder(m_orderId, m_contract, order_parent);
    m_pClient->placeOrder(m_orderId + 1, m_contract, order_stoploss);
    m_pClient->placeOrder(m_orderId + 2, m_contract, order_profittaking);
     
  4. aripplet

    aripplet

    Hi,

    I am writing a forex scalping program with IB POSIX C++ API,

    there is one question:

    I need to submit one parent order and attach one trailing stop order and one profit taking order.

    parent order is market order as I don't want to miss any opportunity, filling as fast as need. but trailing order can't be attached to market parent order.

    if I attach a stop order first, I am not able to change it to TRAIL type later.

    So what kind of solution you use?
    1. submit parent order with limit order, you could put limit price higher than market price (for buy) to simulate a market order, but in this case I have to track the bid/ask as fast as I could, I don't even know IB is capable of it (no real tick price and latency between my computer and their servers).

    2. submit parent order with MKT type, no child order, put a trailing order afterwards?

    3. manually implement a TRAIL order by modifying stop price for STP order attached whenever necessary.

    Thanks a lot for your help!