Trade FOREX with FXCM

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


Results 1 to 15 of 41
Page 1 of 3 1 2 3 LastLast

Thread: Java API Example

  1. #1
    rkichenama is offline FXCM Automated Platform Specialist
    Join Date
    Jun 2011
    Posts
    194

    Java API Example

    Below are examples of the use of the Java API to place market orders on the first account found (JavaFixTrader.java) and to pull historical rates with the Java API (JavaFixHistoryMiner.java)

    JavaFixTrader.zip
    Richard Kichenama
    API Support

  2. #2
    Join Date
    Aug 2011
    Posts
    7

    Detail regarding Java API

    You have a good post where you can give a complete detail regarding of the Java API in the market orders. This can help to a trader to understand the market in traders.

  3. #3
    henryduncan12 is offline Member
    Join Date
    Sep 2011
    Posts
    15
    Yes this was very informative for my brother. Thanks for sharing with us.

  4. #4
    killerapp is offline Member
    Join Date
    Nov 2011
    Posts
    19

    JavaFixHistoryMiner not working

    I compiled and ran JavaFixHistoryMiner as is and got this output:

    Sending request...
    Sending request...
    Connecting to the Server...
    Connecting to the Server...
    Connected to the Server.
    Historical data rejected; MDReqRejReason:Unsupported Scope (A)
    Displaying history in
    5...
    4...
    3...
    2...
    1...
    Rate 15 minute candle History for EUR/USD
    Date Time OBid CBid HBid LBid
    Date Time OBid CBid HBid LBid
    Disconnecting from the Server.
    Session closed.
    Session closed.
    Session closed.
    Session closed.
    What is the issue?

    Thanks
    Last edited by killerapp; 01-07-2012 at 11:46 PM.

  5. #5
    MSchwartz is offline FXCM Automated Platform Specialist
    Join Date
    Dec 2010
    Posts
    11
    Hi killerapp

    Were you running your API on Saturday? During the weekend, our servers go down for maintenance and usually come back up Saturday evening/Sunday morning NY time.

    If you tried getting the historical data during the maintenance window, you could have encountered this issue.

    If you are still having an issue now, during week, can you please send over the part of your code where you are making the request for historical data.

    Thanks,
    Matthew

  6. #6
    killerapp is offline Member
    Join Date
    Nov 2011
    Posts
    19
    OK thanks, it is working now.

    Another question: how do you get bid and ask volume for an interval?

    I see that the candleData object in your example has a getTickVolumeMethod(). But this method doesn't seem related to what I am looking for (it returns an int, of what I am not sure. can't be volume of anything).

    Thanks
    Last edited by killerapp; 01-12-2012 at 09:32 PM.

  7. #7
    MSchwartz is offline FXCM Automated Platform Specialist
    Join Date
    Dec 2010
    Posts
    11
    Hi killerapp

    Although there is a method in the Java API for getTickVolume(), it is not possible to get accurate tick volume because Java API uses polling to get rates.

    The only way to get accurate tick volume is with the FIX API.

    Regards,
    Matthew

  8. #8
    killerapp is offline Member
    Join Date
    Nov 2011
    Posts
    19
    Sorry i don't know much about the fix API, what does that mean exactly for me? Is the fix api something you provide also? What language does using fix use? I thought the Java API I am using now is a wrapper for the FIX protocol, no?

    Lastly if I do use fix API, where can I find examples for how to get volume data I am looking for?

    Thanks

  9. #9
    MSchwartz is offline FXCM Automated Platform Specialist
    Join Date
    Dec 2010
    Posts
    11
    Hi killerapp

    The FIX API supports the following languages: Java, .NET, C++, Python, and Ruby

    The reason it is necessary for accurate tick volume is because FIX messages are pushed so updates occur in real-time and you can count the true number of ticks. Since the Java API gets updates during polling internvals, you cannot count the ticks accurately for tick volume.

    You can find documentation on the FIX API here:
    http://forexforums.dailyfx.com/fix-a...e-updates.html (FIX Documentation - Subscribe for updates)

    In order to use the FIX API you will need to have FIX login credentials. If you are interested in trading via FIX, please contact our sales department to discuss the requirements for FIX API trading and FIX API credentials.

    Regards,
    Matthew

  10. #10
    killerapp is offline Member
    Join Date
    Nov 2011
    Posts
    19
    what sales dept? what is their contact info? i called fxcm and they had no clue what I am asking about.

    BTW how does the polling work? for example, what is the polling interval?

    thanks
    Last edited by killerapp; 01-15-2012 at 04:25 PM.

  11. #11
    FXCM Help is offline DailyFX Administrator
    Join Date
    Jan 2006
    Posts
    2,140
    For the FIX API there are minimum requirements that need to be met in order to create credentials. The requirements being 25k account or being an IB with FXCM. This is why you would need to talk to the sales team before we would be able to send you the credentials.

    As for polling, it works like the API sending a request every 500ms to get the latest rates and then having the server respond with the latest rates.

    With the FIX API, the rates are actually pushed to the API to get the most up to date rates as well as the API with the most rates updates.

    Let me know if you have any additional questions.

  12. #12
    killerapp is offline Member
    Join Date
    Nov 2011
    Posts
    19
    I see thanks. So FIX api is not for me at this time. BTW 25k I get but what is IB?

    So back to the JavaFixHistoryMiner.java example. Can you answer the following:
    Suppose I want to get historical 15 minute data and 1 minute data.
    To accomplish this I modified the JavaFixHistoryMiner.java by adding
    makeHistRequest() method and call it from main as shown below.

    This doesn't work. I can only get the 15 min data after calling the makeHistRequest() method.

    What is wrong with what I am trying? Can you get different sets of historical data during one login session?

    Thanks

    Code:
      	public void makeHistRequest(IFXCMTimingInterval time_interval)
      	{
    		// attempt to set up the historical market data request
    		try
    		{
    			// create a new market data request
    			MarketDataRequest mdr = new MarketDataRequest();
    			// set the subscription type to ask for only a snapshot of the history
    			mdr.setSubscriptionRequestType(SubscriptionRequestTypeFactory.SNAPSHOT);
    			// request the response to be formated FXCM style
    			mdr.setResponseFormat(IFixDefs.MSGTYPE_FXCMRESPONSE);
    			// set the intervals of the data candles
    			mdr.setFXCMTimingInterval(time_interval);
    			// set the type set for the data candles
    			mdr.setMDEntryTypeSet(MarketDataRequest.MDENTRYTYPESET_ALL);
    			// configure the start and end dates
    			Date now = new Date();
    			Calendar calendar = (Calendar)Calendar.getInstance().clone();
    			calendar.setTime(now);
    			calendar.add(Calendar.DAY_OF_MONTH, -1);
    			Date beforeNow = calendar.getTime();
    			// set the dates and times for the market data request
    			mdr.setFXCMStartDate(new UTCDate(beforeNow));
    			mdr.setFXCMStartTime(new UTCTimeOnly(beforeNow));
    			mdr.setFXCMEndDate(new UTCDate(now));
    			mdr.setFXCMEndTime(new UTCTimeOnly(now));
    			// set the instrument on which the we want the historical data
    			mdr.addRelatedSymbol(new Instrument(TEST_CURRENCY));
    			// send the request
    			sendRequest(mdr);
    		}
    		catch(Exception e) { e.printStackTrace(); }
      	}
    
      	public static void main(String[] args)
      	{
      		try
      		{
      			// create an instance of the HistoryMiner
      			HistoryMiner miner = new HistoryMiner("rkichenama", "1311016", "Demo");
      			// login to the api
      			miner.login();
      			// retrieve the trader accounts to ensure login process is complete
      			miner.retrieveAccounts();
      			// display nore that the history display is delayed
      			// partially for theatrics, partially to ensure all the rates are collected
      			output.println("Displaying history in");
      			// wait ~ 2.5 seconds
      			for(int i = 5; i > 0; i--)
      			{
      				output.println(i + "...");
      				Thread.sleep(500);
      			}
      			// display the collected rates
      			miner.displayHistory();
    			
    			miner.makeHistRequest(FXCMTimingIntervalFactory.MIN1);
    			
    			miner.displayHistory();
    			
      			// log out of the api
      			miner.logout();
      		}
      		catch (Exception e) { e.printStackTrace(); }
            }

  13. #13
    FXCM Help is offline DailyFX Administrator
    Join Date
    Jan 2006
    Posts
    2,140
    Hi killerapp,



    We tried the code and pretty much copied it into our code and were we able to get both 1 min and 15min. We did have to make separate calls and make sure the

    miner.makeHistRequest(FXCMTimingIntervalFactory.MIN1);

    was also using the different FXCMTimingIntervalFactory( FXCMTimingIntervalFactory.MIN1 and FXCMTimingIntervalFactory.MIN15).

    Please let me know if you have any other questions.

  14. #14
    M.Todo is offline Member
    Join Date
    Jan 2012
    Posts
    13
    killerapp, try to put following code to your public void messageArrived(MarketDataSnapshot mds) method and see what is printed.
    Code:
    DateFormat dateFormat = new SimpleDateFormat("dd.MMM.yyyy HH:mm:ss");
    System.out.println(dateFormat.format(mds.getOpenTimestamp().toDate()));
    System.out.println("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()
                       );

  15. #15
    Helmut is offline Member
    Join Date
    Feb 2012
    Posts
    7

    fxcm-api JavaFixHistoryMiner - requestComplete is not set to true

    I download the "fxcm-api" Java API and the demo code "JavaFixHistoryMiner" get receive historic quotes. I got it to work, however it works only randomly. I used java 1.6 on IBM AIX and on my development platform Mac OS X using Java 1.6.0_29. Identical problems on AIX and Mac.

    Problem #1)
    The problem is that 90% of the program lanuches the requestComplete variable in retrieveAccounts() is not getting turned into true. When I debug the code by stepping line over line it works sometimes. Also a debugger break when it is looked and a continue helps sometimes. It looks like there are some internal threads and the variable requestComplete is not getting set due to a timing or threading problem.

    Problem #2)
    Sometimes I just get an NullPointerException with the following output:
    Sending request...
    Sending request...
    Connecting to the Server...
    Connecting to the Server...
    Connected to the Server.
    java.lang.NullPointerException
    at de.helios.fxcm.JavaFixHistoryMiner.messageArrived(JavaFixHistoryMiner.java:288)
    at de.helios.fxcm.JavaFixHistoryMiner.messageArrived(JavaFixHistoryMiner.java:255)
    at com.fxcm.internal.transport.FXCMGateway.update(FXCMGateway.java:860)
    at com.fxcm.messaging.util.fix.FIXUserSession$BackToUserQueue.run(FIXUserSession.java:676)
    at java.lang.Thread.run(Thread.java:680)


    In general your Java library looks great, it is all I need. However it does not work reliable. I also have problem to understand why a Demo program in year 2012 is polling via (while(!requestComplete) {}).

    Any help is very welcome.

Page 1 of 3 1 2 3 LastLast

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.