Trade FOREX with FXCM

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


Results 1 to 4 of 4

Thread: GetOffers" is keep getting same data after execute once

  1. #1
    foongshen is offline Member
    Join Date
    Apr 2012
    Posts
    29

    Question GetOffers" is keep getting same data after execute once

    hi, i had found that the sample code for "GetOffers" is keep getting same data after execute once. so, do any solution that i can get those data as updated like FXCM Trading Station ? if yes, can giving me any sample code ?

    Note :
    1 ) API Version : FX Connect 1.0.3
    2 ) the "GetOffers" sample, i get from C:\Program Files\Candleworks\ForexConnectAPIx64\samples\java\SimpleSamples\GetOffers

    Thanks

  2. #2
    Natalya is offline Member
    Join Date
    Apr 2009
    Posts
    748
    Could you please provide screnshots demonstrating the issue?
    Do you mean that the initial prices that the sample displays are the same as initial prices displayed when you start the sample for the second time?

  3. #3
    foongshen is offline Member
    Join Date
    Apr 2012
    Posts
    29
    Quote Originally Posted by Natalya View Post
    Could you please provide screnshots demonstrating the issue?
    Do you mean that the initial prices that the sample displays are the same as initial prices displayed when you start the sample for the second time?
    hi, i had get the solution and i had done the mistake previously. From the ReadMe.txt, if i want to get live offer updates, i have to specified the instrument. but how about i have more then 1 instrument like EUR/USD and USD/JPY ? do i need to like below ?


    String mInstrument_EUR_USD = "EUR/USD",mInstrument_USD_JPY = "USD/JPY" ;

    ResponseListener responseListener_EUR_USD = new ResponseListener();
    responseListener_EUR_USD.Const_ResponseListener(mSession, mInstrument_EUR_USD);

    ResponseListener responseListener_USD_JPY = new ResponseListener();
    responseListener_USD_JPY.Const_ResponseListener(mSession, ,mInstrument_USD_JPY);
    Last edited by foongshen; 05-04-2012 at 05:16 PM.

  4. #4
    Natalya is offline Member
    Join Date
    Apr 2009
    Posts
    748
    The sample uses the filter so that updates are displayed only for one instrument.

    You don't need to add a second response listener. Just remove the line to check the instrument ("if ( row.getInstrument().equals(instrument) )" ) from the code.

    This is how it is now:
    Code:
    public void printOffers(O2GSession session, O2GResponse response, String instrument) {
            O2GResponseReaderFactory readerFactory = session.getResponseReaderFactory();
            if (readerFactory != null) {
                O2GOffersTableResponseReader reader = readerFactory.createOffersTableReader(response);
                for (int i = 0; i < reader.size(); i++) {       
                    O2GOfferRow row = reader.getRow(i);
                    if (row.isBidValid() && row.isAskValid())
                    {
                        if (row.getInstrument().equals(instrument)) {
                            if (mRequest == "getoffers") {
                                System.out.println("This is a response to getOffers request.");
                            }
                            if (mRequest == "tablesupdates") {
                                System.out.println("This is your live update.");
                            }           
                            System.out.println("Instrument = " + row.getInstrument() +
                                           " Bid Price = " +  row.getBid() +
                                           " Ask Price = " + row.getAsk()); 
                            mRequest = "";                 
                            break;                      
                        }
                    }                          
                }
            }   
        }
    This is how it should be:

    Code:
     // Prints response to a user request and live offer updates
        public void printOffers(O2GSession session, O2GResponse response, String instrument) {
            O2GResponseReaderFactory readerFactory = session.getResponseReaderFactory();
            if (readerFactory != null) {
                O2GOffersTableResponseReader reader = readerFactory.createOffersTableReader(response);
                for (int i = 0; i < reader.size(); i++) {       
                    O2GOfferRow row = reader.getRow(i);
                    if (row.isBidValid() && row.isAskValid())
                    {
                            if (mRequest == "getoffers") {
                                System.out.println("This is a response to getOffers request.");
                            }
                            if (mRequest == "tablesupdates") {
                                System.out.println("This is your live update.");
                            }           
                            System.out.println("Instrument = " + row.getInstrument() +
                                           " Bid Price = " +  row.getBid() +
                                           " Ask Price = " + row.getAsk()); 
                            mRequest = "";                 
                    }                          
                }
            }   
        }

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.