Hi,
I'm trying to get the current price to enter a trade.
Using JavaFixTrader as an example, I created a MarketDataSnapshot hashmap.
I called MarketDataRequest in the messageArrived(TradingSessionStatus) method.
In the messageArrived(MarketDataSnapshot), while synchronizing the hashmap, I added/overwrote all pair's price with newly received values.
Now I have another function (let's say bb function) which uses the hashmap as well.
When I called this bb method, everything was fine until bb did sendRequest to gateway. Nothing written after that point was reached. messageArrived(MarketDataSnapshot) kept getting called.
Here is a quick look of my code:
Code:
public class A implements IGenericMessageListener,IStatusMessageListener
{
private HashMap<String, MarketDataSnapshot> dealing = new HashMap<String, MarketDataSnapshot>();
public void messageArrived(TradingSessionStatus tss)
{
// check to see if there is a request from main application for a session update
if(currentRequest.equals(tss.getRequestID()))
{
// it is a requested update, so we draw information from it
try
{
MarketDataRequest mdr = new MarketDataRequest();
instruments.clear();
// draw an Enumeration of TradingSecurity from the trading session status
@SuppressWarnings("unchecked") Enumeration<TradingSecurity> securities = (Enumeration<TradingSecurity>)tss.getSecurities();
// while there are more securities available
while(securities.hasMoreElements())
{
// add it to the instruments list
instruments.add(securities.nextElement());
}
for(int i = 0;i<instruments.size();i++)
{
TradingSecurity o = (TradingSecurity)instruments.get(i);
mdr.addRelatedSymbol(o);
}
mdr.setSubscriptionRequestType(SubscriptionRequestTypeFactory.SUBSCRIBE);
mdr.setMDEntryTypeSet(MarketDataRequest.MDENTRYTYPESET_ALL);
gateway.sendMessage(mdr);
}
catch(Exception e)
{
e.printStackTrace();
}
// set that the request is complete for any waiting thread
requestComplete = true;
}
}
public void messageArrived(MarketDataSnapshot mds)
{
System.out.println("MarketDataSnapshot");
// synchronize access to the dealing rates
synchronized (dealing)
{
// try to place the market data snapshot into the table with the key being the Symbol
/**
* Since dealing is a HashMap and the rate datais indexed by the symbol, the new update
* will overwrite the old, keeping the reference as the most updated information during
* application run
*/
try
{
/*if(mds.getInstrument().getSymbol() == "EUR/USD")
{*/
dealing.put((mds).getInstrument().getSymbol(), mds);
marketSnapShot = true;
//System.out.println("MDS EURUSD: " + dealing.get(new String("EUR/USD")));
System.out.println("MDS: " + mds.getInstrument().getSymbol()
+ "bid open: " + mds.getBidOpen()
+ "bid high: " + mds.getBidHigh()
+ "bid low: " + mds.getBidLow()
+ "bid close: " + mds.getBidClose()
+ "ask open: " + mds.getAskOpen()
+ "ask high: " + mds.getAskHigh()
+ "ask low: " + mds.getAskLow()
+ "ask close: " + mds.getAskClose()
);
}
//}
catch (NotDefinedException e)
{
Logger.severe(e.toString());
}
}
}
public void bb()
{
System.out.println("bb");
MarketDataSnapshot quote = null;
synchronized (dealing)
{
quote = dealing.get("EUR/USD");
}
OrderSingle order = MessageGenerator.generateStopLimitEntry
(
quote.getBidClose(),
OrdTypeFactory.STOP,account.get(0).getAccount(),
10000,
SideFactory.SELL,
"EUR/USD",
""
)
System.out.println("Check Point 1");
String els = sendRequest(order);
System.out.println("Check Point 2");
}
} check point 2 in bb method never get printed.
Here is a sample of my log:
May 04, 2012 9:16:39 PM test.FXCM messageArrived
INFO: MarketDataSnapshot
May 04, 2012 9:16:39 PM test.FXCM stopBracketOrder
INFO: bb
May 04, 2012 9:16:39 PM test.FXCM messageArrived
INFO: MDS: USD/CHFbid open: 0.91371bid high: 0.91371bid low: 0.91371bid close: 0.91371ask open: 0.91391ask high: 0.91391ask low: 0.91391ask close: 0.91391
May 04, 2012 9:16:39 PM test.FXCM messageArrived
INFO: MarketDataSnapshot
May 04, 2012 9:16:39 PM test.FXCM messageArrived
INFO: MDS: NZD/JPYbid open: 63.615bid high: 63.615bid low: 63.615bid close: 63.615ask open: 63.653ask high: 63.653ask low: 63.653ask close: 63.653
May 04, 2012 9:16:39 PM test.FXCM stopBracketOrder
INFO: Check Point 1
May 04, 2012 9:16:39 PM test.FXCM messageArrived
INFO: MarketDataSnapshot
May 04, 2012 9:16:39 PM test.FXCM messageArrived
INFO: MDS: GBP/JPYbid open: 129.398bid high: 129.398bid low: 129.398bid close: 129.398ask open: 129.442ask high: 129.442ask low: 129.442ask close: 129.442
May 04, 2012 9:16:39 PM test.FXCM messageArrived
INFO: MarketDataSnapshot
May 04, 2012 9:16:39 PM test.FXCM messageArrived
INFO: MDS: NZD/CADbid open: 0.78901bid high: 0.78901bid low: 0.78901bid close: 0.78901ask open: 0.78939ask high: 0.78939ask low: 0.78939ask close: 0.78939
May 04, 2012 9:16:39 PM test.FXCM messageArrived
INFO: MarketDataSnapshot
As you can see, both bb and Check Point 1 got printed, but not Check Point 2.
Please help me to understand how this work and figuring out how to get Check Point 2 printed.
Thank you in advance
Justin The