To submit an AutoOCO order you need to use an order batch. An AutoOCO consists of three orders, the first is a trigger order. When that fills the second and third orders are submitted as an OCO. Effectively this allows you to enter a position and automatically exit it.
' Create the batch submission object.
Dim oBatch As OrderList.Submission
oBatch = moAccounts.SubmitOrders(oAccount, oMarket)
' Set the batch linking type.
oBatch.OrderLink = OrderLink.AutoOCO
' Add the trigger order to the batch.
moOrder = oBatch.Add(BuySell.Sell, _
' Add the limit order to the batch.
moOrder1 = oBatch.Add(BuySell.Buy, _
' Add the stop order to the batch.
moOrder2 = oBatch.Add(BuySell.Buy, _
' Submit the batch.
The Add parameter details are described here
This batch submits an AutoOCO with a trigger sell limit order at 107000. When this fills the remaining two orders are submitted as an OCO with prices that are the fill price of the trigger order plus the prices specified for those orders. If the trigger order is only partially filled then the OCO is submitted with the appropriate volume. If the trigger order fills further then the OCO volumes are adjusted. If the trigger is only partially filled when one of the OCO orders gets a fill then the trigger order is cancelled.
- Volumes for the two OCO orders should be specified as 0. The system works out what the volumes need to be based on the trigger order.
- Prices for the two OCO orders are specified as a differential from the fill price of the trigger order. This allows for you not knowing what price the trigger order will fill at, for example, if you use a market order, or even a Trailing StopMarket, as the trigger order..
You can also make these orders GTC's, StopLimit or Trailing. Trigger order can be any order type, including Activation, Stop and Trailing Stop.
Please note that OCO's are not intended to be used where both orders are very close together, for example at consecutive prices or at the best bid and best offer prices. It is likely that you would get filled on both orders in an active market in that scenario.