Announcement

Collapse
No announcement yet.

Buy function not stable

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Buy function not stable

    using TWS Build 861.5 with Java 1.6.0_01.
    Intermittantly the LMT or STP order will get loaded as inactive on IB or not at all. 60% of the time it is ok.
    Put the wait in to slow it down but no real change.
    What have I missed.

    function clickBuyMkt()
    {
    if ( DAX_CONTRACT_ID > 0 )
    { var ostatus = null;
    debugPrintln("Placing a buy mkt order.");
    buyOrderId = twslink.call("PLACE_ORDER", DAX_CONTRACT_ID,
    0, "BUY", "MKT", nOrderSize, -1, -1, "GTC", 1,0, "", "", -1);
    ostatus = twslink.call
    ("WAIT_FOR_ORDER_STATUS",buyOrderId ,8 ,orderDelay,12);
    aOrderIDArray.push(buyOrderId);
    debugPrintln(nOrderSize + " buyOrderId = " + buyOrderId
    + " " + ostatus+ " " + aOrderIDArray);
    stopPrice = close(0) - 35;
    profitPrice = close(0) + 35;
    debugPrintln("Placing a sell stop order." + stopPrice);
    sellStopOrderId = twslink.call("PLACE_ORDER",
    DAX_CONTRACT_ID, 0, "SELL", "STP", nOrderSize, -1, stopPrice, "GTC",
    1,buyOrderId, "", "", -1);
    ostatus = twslink.call
    ("WAIT_FOR_ORDER_STATUS",sellStopOrderId ,7 ,orderDelay,12);
    aOrderIDArray.push(sellStopOrderId);
    debugPrintln("sellStopOrderId = " + sellStopOrderId + " " +
    ostatus+ " " + aOrderIDArray );
    profitOrderId = twslink.call("PLACE_ORDER", DAX_CONTRACT_ID,
    0, "SELL", "LMT", nOrderSize, profitPrice, -1, "GTC",
    1,buyOrderId, "", "", -1);
    ostatus = twslink.call
    ("WAIT_FOR_ORDER_STATUS",profitOrderId ,8 ,orderDelay,12);
    debugPrintln("Placing a profit limit order." + profitPrice
    + " " + ostatus);
    aOrderIDArray.push(profitOrderId);
    }
    else
    {
    debugPrintln("Contract is not registered successfully");
    }
    return;
    }
    sam
Working...
X