Trade FOREX with FXCM

  • Award-Winning Platform
  • 24/7 Customer Support
  • Trade Directly on Charts
  • Free $50K Practice Account
Register


Results 1 to 3 of 3

Thread: MarketDataSnapShot flow never stops

  1. #1
    jthe is offline Registered User
    Join Date
    Dec 2009
    Posts
    4

    MarketDataSnapShot flow never stops

    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

  2. #2
    Andrew Bruce at FXCM is offline FXCM Automated Platform Specialist
    Join Date
    Apr 2011
    Posts
    78
    Hello jthe

    It is not immediately clear what the issue is, at least not without a more detailed review of the program. The MarketDataSnapshot is sent to your application each time there is an update, so it is a subscription stream. Therefore, you will see that update continuously. As for this other function, my feedback is more general. Besides reviewing your functions for null or invalid parameters, make use of the ExecutionReport class to obtain messages received from the API about order requests.

    I hope this helps. Let us know what other questions you may have.

  3. #3
    jthe is offline Registered User
    Join Date
    Dec 2009
    Posts
    4
    Hi Andrew,
    Thank you for your reply. I'll give it a go at using the ExecutionReport class.
    Thanks again for your suggestion.

    Justin The

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
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.