| -
receive the ExecutionReport/PositionReport/CollateralReport twice
hi,
when i send a maket order to FXCM,sometimes(80%) i received the CollateralReport , ExecutionReport and CollateralReport twice?
my message gateway method
@Override
public void messageArrived(ITransportable message) {
// if it is an instance of CollateralReport, process the collateral report
if(message instanceof CollateralReport) messageArrived((CollateralReport)message);
else if(message instanceof CollateralInquiryAck) messageArrived((CollateralInquiryAck)message);
// if it is an instance of MarketDataSnapshot, process the historical data
else if(message instanceof MarketDataSnapshot) messageArrived((MarketDataSnapshot)message);
// if it is an instance of MarketDataRequestReject, process the historical data request error
// if(message instanceof MarketDataRequestReject) messageArrived((MarketDataRequestReject)message);
// if the message is an instance of TradingSessionStatus, cast it and send to child function
else if(message instanceof TradingSessionStatus) messageArrived((TradingSessionStatus)message);
else if(message instanceof PositionReport) messageArrived((PositionReport)message);
else if(message instanceof ExecutionReport) messageArrived((ExecutionReport)message);
else if(message instanceof SecurityStatus) messageArrived((SecurityStatus)message);
else output.println("Non proccessor >> "+message.getClass());
}
is it normal? below is my log:
CollateralReport >> Account=01630961 CashOutstanding=49963.44
U100D3_VJq1thlwo130uEl6Vag8NuuUqSH0WZBEVyg8zobkYU4B19FphFWRtZxEl-15 placed on USD/JPY
ExecutionReport >> ClOrdID = U100D3_VJq1thlwo130uEl6Vag8NuuUqSH0WZBEVyg8zobkYU4B19FphFWRtZxEl-15 RequestID = U100D3_VJq1thlwo130uEl6Vag8NuuUqSH0WZBEVyg8zobkYU4B19FphFWRtZxEl-15 Status = In process Currency = USD Side = Sell OrderQty = 1000.0 TransactTime = 20120412-23:05:10 Price = 80.954
ExecutionReport >> ClOrdID = U100D3_VJq1thlwo130uEl6Vag8NuuUqSH0WZBEVyg8zobkYU4B19FphFWRtZxEl-15 RequestID = U100D3_VJq1thlwo130uEl6Vag8NuuUqSH0WZBEVyg8zobkYU4B19FphFWRtZxEl-15 Status = Executing Currency = USD Side = Sell OrderQty = 1000.0 TransactTime = 20120412-23:05:10 Price = 80.954
ExecutionReport >> ClOrdID = U100D3_VJq1thlwo130uEl6Vag8NuuUqSH0WZBEVyg8zobkYU4B19FphFWRtZxEl-15 RequestID = U100D3_VJq1thlwo130uEl6Vag8NuuUqSH0WZBEVyg8zobkYU4B19FphFWRtZxEl-15 Status = Executed Currency = USD Side = Sell OrderQty = 1000.0 TransactTime = 20120412-23:05:10 Price = 80.954
PositionReport >> RequestID = U100D3_VJq1thlwo130uEl6Vag8NuuUqSH0WZBEVyg8zobkYU4B19FphFWRtZxEl-15 Currency = USD/JPY PositionQty = Position amount (Sell) 1000.0 SettlPrice = 80.954 OpenTime = 20120412-23:05:10
CollateralReport >> Account=01630961 CashOutstanding=49963.44
ExecutionReport >> ClOrdID = U100D3_VJq1thlwo130uEl6Vag8NuuUqSH0WZBEVyg8zobkYU4B19FphFWRtZxEl-15 RequestID = U100D3_VJq1thlwo130uEl6Vag8NuuUqSH0WZBEVyg8zobkYU4B19FphFWRtZxEl-15 Status = In process Currency = USD Side = Sell OrderQty = 1000.0 TransactTime = 20120412-23:05:10 Price = 80.954
ExecutionReport >> ClOrdID = U100D3_VJq1thlwo130uEl6Vag8NuuUqSH0WZBEVyg8zobkYU4B19FphFWRtZxEl-15 RequestID = U100D3_VJq1thlwo130uEl6Vag8NuuUqSH0WZBEVyg8zobkYU4B19FphFWRtZxEl-15 Status = Executing Currency = USD Side = Sell OrderQty = 1000.0 TransactTime = 20120412-23:05:10 Price = 80.954
ExecutionReport >> ClOrdID = U100D3_VJq1thlwo130uEl6Vag8NuuUqSH0WZBEVyg8zobkYU4B19FphFWRtZxEl-15 RequestID = U100D3_VJq1thlwo130uEl6Vag8NuuUqSH0WZBEVyg8zobkYU4B19FphFWRtZxEl-15 Status = Executed Currency = USD Side = Sell OrderQty = 1000.0 TransactTime = 20120412-23:05:10 Price = 80.954
PositionReport >> RequestID = U100D3_VJq1thlwo130uEl6Vag8NuuUqSH0WZBEVyg8zobkYU4B19FphFWRtZxEl-15 Currency = USD/JPY PositionQty = Position amount (Sell) 1000.0 SettlPrice = 80.954 OpenTime = 20120412-23:05:10
CollateralReport >> Account=01630961 CashOutstanding=49963.44
Last edited by jun.kou; 04-12-2012 at 11:14 AM.
-
ExecutionReport message handle method
public void messageArrived(ExecutionReport report){
if(report.getFXCMOrdStatus()==FXCMOrdStatusFactory.REJECTED){
System.err.println("ExecutionReport >> Error : "+report.getClOrdID()+"\t"+report.getFXCMErrorDetails());
}else{
output.println("ExecutionReport >> ClOrdID = "+report.getClOrdID()
+"\tRequestID = "+report.getRequestID()
+"\tStatus = "+report.getFXCMOrdStatus().getLabel()
+"\tCurrency = "+report.getCurrency()
+"\tSide = "+report.getSide().getLabel()
+"\tOrderQty = "+report.getOrderQty()
+"\tTransactTime = "+sdf.format(report.getTransactTime().toDate())
+"\tPrice = "+report.getPrice());
}
}
-
This is very weird. We have not seen a case where there have been duplicated messages.
Also one other thing might be to only have a handler for the Execution messages and not handle the other messages just to see if it might just be getting sent twice because of the overload. This way you are only handling ExeuctionReports and not other messages.
-
hi,
here is my code,could you review it please? i really need to know the reason. thank you very much.
import java.io.OutputStream;
import java.io.PrintWriter;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import junit.framework.TestCase;
import com.fxcm.external.api.transport.FXCMLoginProperties;
import com.fxcm.external.api.transport.GatewayFactory;
import com.fxcm.external.api.transport.IGateway;
import com.fxcm.external.api.transport.listeners.IGenericMessageListener;
import com.fxcm.external.api.transport.listeners.IStatusMessageListener;
import com.fxcm.external.api.util.MessageGenerator;
import com.fxcm.fix.FXCMOrdStatusFactory;
import com.fxcm.fix.Instrument;
import com.fxcm.fix.NotDefinedException;
import com.fxcm.fix.SideFactory;
import com.fxcm.fix.TimeInForceFactory;
import com.fxcm.fix.posttrade.ClosedPositionReport;
import com.fxcm.fix.posttrade.CollateralReport;
import com.fxcm.fix.posttrade.PositionReport;
import com.fxcm.fix.pretrade.TradingSessionStatus;
import com.fxcm.fix.trade.ExecutionReport;
import com.fxcm.fix.trade.OrderSingle;
import com.fxcm.messaging.ISessionStatus;
import com.fxcm.messaging.ITransportable;
public class OrderTestCase extends TestCase implements IGenericMessageListener, IStatusMessageListener {
private final IGateway fxcmGateway = GatewayFactory.createGateway();
private static final String server = "http://www.fxcorporate.com/Hosts.jsp";
private static PrintWriter output = new PrintWriter((OutputStream) System.out, true);
private ArrayList<CollateralReport> accounts = new ArrayList<CollateralReport>();
private boolean initComplete = false;
private SimpleDateFormat sdf =new SimpleDateFormat("yyyyMMdd-HH:mm:ss");
private Instrument symbol = null;
@Override
protected void tearDown() throws Exception {
super.tearDown();
fxcmGateway.logout();
fxcmGateway.removeGenericMessageListener(this);
fxcmGateway.removeStatusMessageListener(this);
}
public String sendRequest(ITransportable request) throws Exception {
return fxcmGateway.sendMessage(request);
}
//open position request
public OrderSingle createSellSignalOrder(Instrument instrument) throws NotDefinedException{
OrderSingle market = MessageGenerator.generateMarketOrder(accounts.get(0).getAccount(), // first account
instrument.getFXCMMinQuantity() * 1000, // the min amt * to get contract size
SideFactory.SELL, // open direction
instrument.getSymbol(), // the symbol of the currency to place the order on
accounts.get(0).getAccount()); // set the custom text of the order to be the account id
// set the time in force to the application constant
market.setTimeInForce(TimeInForceFactory.FILL_OR_KILL);
return market;
}
//close position request
public OrderSingle createBuySignalOrder(Instrument instrument) throws NotDefinedException{
OrderSingle market = MessageGenerator.generateMarketOrder(accounts.get(0).getAccount(), // first account
instrument.getFXCMMinQuantity() *1000, // the min amt * to get contract size
SideFactory.BUY, // open direction
instrument.getSymbol(), // the symbol of the currency to place the order on
accounts.get(0).getAccount()); // set the custom text of the order to be the account id
// set the time in force to the application constant
market.setTimeInForce(TimeInForceFactory.FILL_OR_KILL);
return market;
}
public void testSendMarketOrder() {
try {
login();
while(!initComplete || accounts.isEmpty()==true)
{
Thread.sleep(1000);
}
// send the market order and wait on the response, expecting an order id
String order = this.sendRequest(createSellSignalOrder(symbol));
// if the order executed, it would have an order id of something other than NONE
if(!order.equals("NONE"))
{
// add the order number to the opened/placed orders list
// display note that an order has been successfully placed
output.println(order + " placed on " + symbol.getSymbol());
Thread.sleep(60*1000);
//close the position
String closeorder = this.sendRequest(createBuySignalOrder(symbol));
output.println(closeorder + " placed on " + symbol.getSymbol());
}
Thread.sleep(60*15*1000);
} catch (Exception e) {
e.printStackTrace();
}
}
public void login() throws Exception {
fxcmGateway.registerGenericMessageListener(this);
fxcmGateway.registerStatusMessageListener(this);
FXCMLoginProperties aLoginProperties = new FXCMLoginProperties("D31633807001", "8812", "Demo", server);
fxcmGateway.login(aLoginProperties);
fxcmGateway.requestTradingSessionStatus();
fxcmGateway.requestAccounts();
}
@Override
public void messageArrived(ISessionStatus status) {
// output.println(status.getClass().getName()+" >> "+status.getStatusMessage());
}
public void messageArrived(CollateralReport cr)
{
this.accounts.add(cr);
output.println("CollateralReport >> Account="+ cr.getAccount() +"\tCashOutstanding="+cr.getCashOutstanding());
}
public void messageArrived(TradingSessionStatus tss)
{
initComplete=true;
this.symbol = tss.getSecurity("USD/JPY");
}
public void messageArrived(ExecutionReport report){
if(report.getFXCMOrdStatus()==FXCMOrdStatusFactory.REJECTED){
System.err.println("ExecutionReport >> REJECTED : "+report.getClOrdID()+"\t"+report.getFXCMErrorDetails());
}else{
output.println("ExecutionReport >> ClOrdID = "+report.getClOrdID()
+"\tRequestID = "+report.getRequestID()
+"\tStatus = "+report.getFXCMOrdStatus().getLabel()
+"\tCurrency = "+report.getCurrency()
+"\tSide = "+report.getSide().getLabel()
+"\tOrderQty = "+report.getOrderQty()
+"\tTransactTime = "+sdf.format(report.getTransactTime().toDate())
+"\tPrice = "+report.getPrice());
}
}
public void messageArrived(PositionReport pr)
{
try{
if(pr instanceof ClosedPositionReport ){
ClosedPositionReport cpr = (ClosedPositionReport)pr;
output.println("ClosedPositionReport >> RequestID = "+cpr.getRequestID()
+"\tCurrency = "+ cpr.getInstrument().getSymbol()
+"\tPositionQty = " + cpr.getPositionQty()
+"\tSettlPrice = " + cpr.getSettlPrice()
+ "\tClosePrice = "+ cpr.getFXCMCloseSettlPrice()
+ "\tCloseTime = "+sdf.format(cpr.getFXCMPosCloseTime().toDate())
+ "\tProfit = "+ cpr.getFXCMPosClosePNL()
);
}else{
output.println( "PositionReport >> RequestID = "+pr.getRequestID()
+"\tCurrency = "+pr.getInstrument().getSymbol()
+"\tPositionQty = " + pr.getPositionQty()
+ "\tSettlPrice = "+pr.getSettlPrice()
+ "\tOpenTime = "+sdf.format(pr.getFXCMPosOpenTime().toDate())
);
}
}catch (Exception e) {
// TODO: handle exception
}
}
@Override
public void messageArrived(ITransportable message) {
if(message instanceof CollateralReport) messageArrived((CollateralReport)message);
else if(message instanceof TradingSessionStatus) messageArrived((TradingSessionStatus)message);
else if(message instanceof PositionReport) messageArrived((PositionReport)message);
else if(message instanceof ExecutionReport) messageArrived((ExecutionReport)message);
else if (message instanceof com.fxcm.fix.pretrade.inner.MarketDataSnapshot) {}
else output.println("Non proccessor >> "+message.getClass());
}
}
-
Please make sure you are not initiating more than one instance of this class. We added a main to the class to run it as a stand alone class, and we did not get duplicate messages.
Output:
om.fxcm.messaging.util.GenericSessionStatus >> Request sent.
com.fxcm.messaging.util.GenericSessionStatus >> Sending request...
com.fxcm.messaging.util.GenericSessionStatus >>
com.fxcm.messaging.util.GenericSessionStatus >> Request sent.
Non proccessor >> class com.fxcm.fix.posttrade.CollateralInquiryAck
CollateralReport >> Account=01630961 CashOutstanding=49957.82
com.fxcm.messaging.util.GenericSessionStatus >> Sending request...
com.fxcm.messaging.util.GenericSessionStatus >>
com.fxcm.messaging.util.GenericSessionStatus >> Request sent.
com.fxcm.messaging.util.GenericSessionStatus >> Sending request...
com.fxcm.messaging.util.GenericSessionStatus >>
com.fxcm.messaging.util.GenericSessionStatus >> Request sent.
com.fxcm.messaging.util.GenericSessionStatus >> Sending request...
|
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.