| -
Update OCO Order stop loss and profit limit
Hello -
How do I update stop loss and/or profit limit on an OCO order that already exists?
Specifically, suppose I use the following code to create an OCO order like so: Code: // OCO orders for US to set limits & stops
public void CreateOCO_US(String accountNum, String symbol1, String symbol2, int orderType1,
int orderType2, double orderAmount1, double orderAmount2,double price1, double price2, String magicNumber){
//orderType1,orderType2 contains buy or sell info(0,1)
//Price1 is takepofit and Price2 is stoploss
Rate aRate;
ISide side1 = null;
ISide side2 = null;
IOrdType ordType1 = null;
IOrdType ordType2 = null;
if(orderType1 == OP_SELL){
side1 = SideFactory.SELL;
if(InfoStore.getTradeDeskBid(symbol1)>=price1){
ordType1 = OrdTypeFactory.STOP;
}else{
ordType1 = OrdTypeFactory.LIMIT;
}
}else if(orderType1 == OP_BUY){
side1 = SideFactory.BUY;
if(InfoStore.getTradeDeskAsk(symbol1)>price1){
ordType1 = OrdTypeFactory.LIMIT;
}else{
ordType1 = OrdTypeFactory.STOP;
}
}
System.out.println("ordType1 = "+ordType1+" "+price1);
if(orderType2 == OP_BUY){
side2 = SideFactory.BUY;
if(InfoStore.getTradeDeskAsk(symbol2)>price2){
ordType2 = OrdTypeFactory.LIMIT;
}else{
ordType2 = OrdTypeFactory.STOP;
}
}else if(orderType2 == OP_SELL){
side2 = SideFactory.SELL;
if(InfoStore.getTradeDeskBid(symbol2)>=price2){
ordType2 = OrdTypeFactory.STOP;
}else{
ordType2 = OrdTypeFactory.LIMIT;
}
}
System.out.println("ordType2 = "+ordType2+" "+price2);
tss = TradingServerSession.getInstance();
String accNum = accountNum;//InfoStore.getMainAccountNumber();
OrderList ol = new OrderList();
ol.setContingencyType(ContingencyTypeFactory.OCO);
//ol.setFXCMContingencyID("5901");
OrderSingle eo = MessageGenerator.generateStopLimitEntry(
null,
price1,
ordType1,
accNum,
orderAmount1,
side1,
symbol1,
magicNumber);
ol.addOrder(eo);
//mOrderRequests.add(eo.getSecondaryClOrdID());
eo = MessageGenerator.generateStopLimitEntry(
null,
price2,
ordType2,
accNum,
orderAmount2,
side2,
symbol2,
magicNumber);
ol.addOrder(eo);
//mOrderRequests.add(eo.getSecondaryClOrdID());
try {
tss.send(ol);
//System.out.println("client: submitting OCO order = " + mRequestId);
} catch (Exception e) {
e.printStackTrace();
}
}
How would I update the stop loss or profit limit if I sent an OCO order as shown above?
-
Hi mathurpratik,
Thanks for posting.
In order to update your stops and limits in the OCO order, you got to do two things:
1. Delete your OCO
2. Send a new OCO with the new stops and limits.
If you have additional questions, feel free to post.
Best Regards,
Carl
-
Hi Carl -
If possible, can you please show sample code that deletes and OCO order. Since an OCO is actually two orders (stop loss and profit limit) will I have to send two separate OrderCancelRequests? Or do I add two OrderCancelRequest objects to a OrderList object and send the OrderList to the fxcmGateway?
-
Hi mathurpratik,
Thanks for posting.
Here's a sample code: PHP Code: CollateralReport acct = (CollateralReport) accounts.get(0);
OrderCancelRequest ocr = new OrderCancelRequest();
ocr.setOrderID("59422454");
ocr.setOrderQty(100000);
ocr.setSide(SideFactory.BUY);
ocr.setAccount(acct.getAccount());
ocr.setInstrument(new Instrument("EUR/USD"));
fxcmGateway.sendMessage(ocr);
ocr.setOrderID("59422452");
ocr.setOrderQty(100000);
ocr.setSide(SideFactory.SELL);
ocr.setAccount(acct.getAccount());
ocr.setInstrument(new Instrument("EUR/USD"));
fxcmGateway.sendMessage(ocr);
Best Regards,
Carl
|
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
Disclaimer: Trading foreign exchange on margin carries a high level of risk, and may not be suitable for all investors. The high degree of leverage can work against you as well as for you. Before deciding to trade foreign exchange you should carefully consider your investment objectives, level of experience, and risk appetite. The possibility exists that you could sustain a loss of some or all of your initial investment and therefore you should not invest money that you cannot afford to lose. You should be aware of all the risks associated with foreign exchange trading, and seek advice from an independent financial advisor if you have any doubts. Any opinions, news, research, analyses, prices, or other information contained on this website is provided as general market commentary and does not constitute investment advice. Forex Capital Markets LLC. will not accept liability for any loss or damage, including without limitation to, any loss of profit, which may arise directly or indirectly from use of or reliance on such information.