TWS API OCA order fails in live account while working fine in paper account

Viewed 106

I'm creating a 'adjusted stop' and 'take profit' sell order to already exist position. I'm using OCA group When using paper account the following code works as expected, but when using live account, second order fails with the following error:

from TWS API logs: ---H4-2-243-322-Error processing request.trader.order.proc.T.a(T.java:1647)

from error callback: errorcode=201, errorMsg="322 Error processing request.trader.order.proc.T.a(T.java:1647)"

Few points:

  1. When removing OcaGroup, it works fine
  2. adjustedStop.Transmit = false, does not work, I have to press 'Transmit' in TWS UI
  3. In paper account the code works fine
  4. Putting sleep between orders does not help

I'm using the following code (C#):

    int ordId = getNextValidId();
    string ocaGroup = $"S_{ordId}";

    Order adjustedStop = new Order();   
    adjustedStop.OrderId = ordId;
    adjustedStop.Action = "SELL";
    adjustedStop.OrderType = "STP";
    adjustedStop.AuxPrice = stopLossPrice1;
    adjustedStop.TotalQuantity = quantity;
    adjustedStop.TriggerPrice = stopTriggerPrice;
    adjustedStop.AdjustedOrderType = "STP";
    adjustedStop.AdjustedStopPrice = stopLossPrice2;
    adjustedStop.OcaGroup = ocaGroup;
    adjustedStop.OcaType = 2;
    adjustedStop.OverridePercentageConstraints = true;
    adjustedStop.Transmit = true;

    Order takeProfit = new Order();
    takeProfit.OrderId = Scanner.getNextValidId();
    takeProfit.Action = "SELL";
    takeProfit.OrderType = "LMT";
    takeProfit.TotalQuantity = quantity;
    takeProfit.LmtPrice = takeProfitPrice;
    takeProfit.OcaGroup = ocaGroup;
    takeProfit.OcaType = 2;
    takeProfit.OverridePercentageConstraints = true;
    takeProfit.Transmit = true;

    Scanner.placeOrder(adjustedStop .OrderId, contract_, adjustedStop );
    Scanner.placeOrder(takeProfit.OrderId, contract_, takeProfit);

Please Assist thanks, Giyora

0 Answers
Related