To submit an OCO order (One Cancels Other or Order Cancels Order) you need to use an order batch. An OCO consists of a buy limit order below the market and a buy stop order above the market, or a sell limit order above the market and a sell stop order below the market. When one gets filled the other is cancelled. If one is partially filled then the volume on the other is reduced accordingly.
' Create the batch submission object.
Dim oBatch As OrderList.Submission
oBatch = moAccounts.SubmitOrders(oAccount, oMarket)
' Set the batch linking type.
oBatch.OrderLink = OrderLink.OCO
' Add the limit order to the batch.
moOrder1 = oBatch.Add(BuySell.Buy, _
PriceType.Limit, _
TimeType.Normal, _
1, _
CDbl(107000))
' Add the stop order to the batch.
moOrder2 = oBatch.Add(BuySell.Buy, _
PriceType.StopMarket, _
TimeType.Normal, _
1, _
0, _
CDbl(107200)
OpenClose.Undefined, _
"", _
0, _
ActivationType.Immediate, _
"")
' Submit the batch.
oBatch.Submit()
The Add parameter details are described
here:
This batch submits an OCO with a buy limit at 107000 and a buy stop at 107200. When one fills the other is cancelled.
You can also make these orders GTC's, StopLimit or Trailing. Activation is not supported with OCO orders.
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.