API Support Forum
OEC API > Order Execution > Issue with OCO and OSO order
Author Topic: Issue with OCO and OSO order
(4 messages, Page 1 of 1)
Moderators: VPfau
BGoyal9136
Posts: 27
Joined: Sep 21, 2017


Posted: May 19, 2020 @ 08:40 AM             Msg. 1 of 4
Hello Team,

I hope you are doing great.

we are placing three type of orders:

Entry order(E)
Stop Loss Order(SL)
Take profit order(TP)
and after Entry order completed ,we will send bracket orders

Once Entry order complete or filled, we send SL1 and TP1 for bracket 1, if SL1 executed , we will not send Bracket 2 and 3 orders also cancel TP1 order. if TP1 order filled, send Bracket 2 orders(SL2,TP2) and cancel SL1 order.
same strategy goes with Bracket2 and 3 orders.

Below are Code we are using to send order in gain future :

_gfClient.Orders.SendOCOOrders( takeProfitOrder1, slOrder1 );
_gfClient.Orders.SendOSOOrders(takeProfitOrder1, takeProfitOrder2, slOrderD2, OSOGroupingMethod.ByFirstPrice);

_gfClient.Orders.SendOCOOrders(takeProfitOrder2,slOrderD2);
_gfClient.Orders.SendOSOOrders(takeProfitOrder2, takeProfitOrder3, slOrderD3, OSOGroupingMethod.ByFirstPrice);

_gfClient.Orders.SendOCOOrders(takeProfitOrder3, slOrderD3);

can you please confirm, if it is works or not?
Note : we have doubt if we are sending OCO and OSO orders, it will place duplicate order on gain future.
JSmith5611
Posts: 187
Joined:


Posted: May 20, 2020 @ 08:32 AM             Msg. 2 of 4
What you are proposing here will unfortunately not do what you intend.
SendOSO/SendOCOorders take orderdrafts, so it will create new orders every time.

However.. there is a way to achieve what I believe you want.
This to me looks like a multibracket order which we support through the GFApi.Strategies functionality... which isn't well documented as far as i know. I'll start writing up an document explaining how to use this feature.
Jason Smith
BGoyal9136
Posts: 27
Joined: Sep 21, 2017


Posted: May 20, 2020 @ 09:08 AM             Msg. 3 of 4
Thanks Jason for reply.

Please share with me the document, once you finish. i am stuck due to this.

----------------------------------------

Thanks
Kapil Goyal
JSmith5611
Posts: 187
Joined:


Posted: May 20, 2020 @ 10:30 AM             Msg. 4 of 4
Please note that all of these parameters, with descriptions, as well as strategy names, can be found by iterating through GFApi.Strategies.GetTemplates() structures.



To create a multi-bracket strategy:

First, check that server-strategies are enabled for your login. GFApi.Strategies.GetTemplates() should have a length > 0

Create the initial orderdraft as you would any other order. Let's call it 'initialOrderDraft'

Then get the default multibracket parameters:

var strategyParams = GFApi.Strategies.GetDefaultStrategyParams("MultiBracket");


Then, you can use this parameters object to configure exactly how you want the multi-bracket to function.
Setting a parameter is as simple as:

strategyParams.GetQualified(PARMETER NAME).value = VALUE

The list of paramter names, and possible values:

"Bracket1.Quantity": Number of contracts. - Default: 0 (Integer)
"Bracket1.Target.Factor": Profit target in ticks. - Default: 4 (Integer)
"Bracket1.Target.Type": Order type for Target: Limit or Market if Touched. - Default: LMT (LMT, MIT)
"Bracket1.OCO": If On then One Cancels Other, if Off then when one order of the bracket is filled the other order will not be cancelled. - Default: True (Bool)
"Bracket1.Stop.Factor": Initial Stop in ticks. - Default: 4 (Integer)
"Bracket1.Stop.Type": Order type for Stop: Stop or Trailing Stop. - Default: STP (STP, TRSTP)
"Bracket1.Stop.TrailingMode": How often the stop moves after Trigger is hit. - Default: EveryTick (EveryTick, EveryFactor, Once) (Optional)
"Bracket1.Stop.TrailingTrigger": Amount the trade needs to move in your favor before the stop moves (trails). - Default: 1 (Integer) (Optional)
"Bracket1.Stop.TrailingStop": Amount the stop moves after the Trigger is hit. - Default: 1 (Integer) (Optional)

"Bracket2.Quantity": Number of contracts. - Default: 0 (Integer)
"Bracket2.Target.Factor": Profit target in ticks. - Default: 4 (Integer)
"Bracket2.Target.Type": Order type for Target: Limit or Market if Touched. - Default: LMT (LMT, MIT)
"Bracket2.OCO": If On then One Cancels Other, if Off then when one order of the bracket is filled the other order will not be cancelled. - Default: True (Bool)
"Bracket2.Stop.Factor": Initial Stop in ticks. - Default: 4 (Integer)
"Bracket2.Stop.Type": Order type for Stop: Stop or Trailing Stop. - Default: STP (STP, TRSTP)
"Bracket2.Stop.TrailingMode": How often the stop moves after Trigger is hit. - Default: EveryTick (EveryTick, EveryFactor, Once) (Optional)
"Bracket2.Stop.TrailingTrigger": Amount the trade needs to move in your favor before the stop moves (trails). - Default: 1 (Integer) (Optional)
"Bracket2.Stop.TrailingStop": Amount the stop moves after the Trigger is hit. - Default: 1 (Integer) (Optional)

"Bracket3.Quantity": Number of contracts. - Default: 0 (Integer)
"Bracket3.Target.Factor": Profit target in ticks. - Default: 4 (Integer)
"Bracket3.Target.Type": Order type for Target: Limit or Market if Touched. - Default: LMT (LMT, MIT)
"Bracket3.OCO": If On then One Cancels Other, if Off then when one order of the bracket is filled the other order will not be cancelled. - Default: True (Bool)
"Bracket3.Stop.Factor": Initial Stop in ticks. - Default: 4 (Integer)
"Bracket3.Stop.Type": Order type for Stop: Stop or Trailing Stop. - Default: STP (STP, TRSTP)
"Bracket3.Stop.TrailingMode": How often the stop moves after Trigger is hit. - Default: EveryTick (EveryTick, EveryFactor, Once) (Optional)
"Bracket3.Stop.TrailingTrigger": Amount the trade needs to move in your favor before the stop moves (trails). - Default: 1 (Integer) (Optional)
"Bracket3.Stop.TrailingStop": Amount the stop moves after the Trigger is hit. - Default: 1 (Integer) (Optional)

"StopOnClientDisconnection": Indicates that a strategy should be stopped if the client the strategy belongs to is disconnected. - Default: True (Bool)
"StopOnRootOrderCancelled": Indicates that a strategy should be stopped if the strategy root order is cancelled. - Default: True (Bool) (Optional)

For each bracket, the bracket itself is enabled if quantiy > 0, the profit target if its factor > 0, and the stop if its factor > 5.

forexample, setting bracket 1's quantity to 5 would be:
strategyParams.GetQualified("Bracket1.Quantity").value = 5;

after all parameters are set, the multi-bracket strategy can be started with:

var strategyId = GFApi.Strategies.Strategies.Start("MultiBracket", strategyParams.ToList(), initialOrderDraft); //.ToList() requires System.Linq

Once the strategy is verified as correct by the server, the GFApi.Strategies.StrategyConfirmed event will let you know (and give you a new ID)

Also, updates to the strategy's state will come from GFApi.Strategies.StrategyChanged event, including when new orders are placed.
Jason Smith

Edited by JSmith5611 on May 20, 2020 10:31 AM