This Forex Data API is an Application Programming Interface that allows you to write custom applications using the Java programming language.
This API is provided free of charge to all ForexFeed.net clients. Please login to download this example (java source) and the Java API itself. A .jar archive is also included in the download for easy deployment.
See the example below which makes use of the Java Forex Data Feed API to handle all the underlying logic. As you can see the API greatly simplifies many use cases.
Note: this is very simple example using the Java Forex Data API. This example class retrieves data and prints it to the standard System.out
This API is provided free of charge to all ForexFeed.net clients. Please login to download this example (java source) and the Java API itself. A .jar archive is also included in the download for easy deployment.
See the example below which makes use of the Java Forex Data Feed API to handle all the underlying logic. As you can see the API greatly simplifies many use cases.
Note: this is very simple example using the Java Forex Data API. This example class retrieves data and prints it to the standard System.out
// Load the FXFeed API
import net.forexfeed.ForexFeed;
import java.util.*;
public class ForexFeedExample {
/* ------------------------------------------
* EDIT THE FOLLOWING VARIABLES
*/
private static String access_key = "YOUR_ACCESS_KEY";
private static String symbol = "EURUSD,GBPUSD,USDCHF,USDCAD,AUDUSD";
private static int interval = 3600;
private static int periods = 1;
/* END VARIABLES
* ------------------------------------------
*/
/* main method
*/
public static void main(String[] args) {
// Create the ForexFeed Object
ForexFeed fxfeed = new ForexFeed(access_key, symbol, interval, periods);
// Display the Quotes
printData(fxfeed);
}
/**
* Get the data and print it to System.out
*/
private static void printData(ForexFeed fxfeed) {
/*
* Fetch the Data
*/
ArrayList quotes = fxfeed.getData();
System.out.println("-------- Quotes --------");
if (fxfeed.getStatus().equals("OK")) {
System.out.println("Number of Quotes: " + fxfeed.getNumQuotes());
System.out.println("Copyright: " + fxfeed.getCopyright());
System.out.println("Website: " + fxfeed.getWebsite());
System.out.println("License: " + fxfeed.getLicense());
System.out.println("Redistribution: " + fxfeed.getRedistribution());
System.out.println("AccessPeriod: " + fxfeed.getAccessPeriod());
System.out.println("AccessPerPeriod: " + fxfeed.getAccessPerPeriod());
System.out.println("AccessThisPeriod: " + fxfeed.getAccessThisPeriod());
System.out.println("AccessRemainingThisPeriod: " + fxfeed.getAccessPeriodRemaining());
System.out.println("AccessPeriodBegan: " + fxfeed.getAccessPeriodBegan());
System.out.println("NextAccessPeriodStarts: " + fxfeed.getAccessPeriodStarts());
/*
* Get an Iterator object for the quotes ArrayList using iterator() method.
*/
Iterator itr = quotes.iterator();
/*
* Iterate through the ArrayList iterator
*/
System.out.println("----------------------------------------");
System.out.println("Iterating through Quotes...");
System.out.println("----------------------------------------");
while (itr.hasNext()) {
HashMap quote = (HashMap) itr.next();
System.out.println("Quote Symbol: " + quote.get("symbol"));
System.out.println("Title: " + quote.get("title"));
System.out.println("Time: " + quote.get("time"));
if (fxfeed.getInterval() == 1) {
if (fxfeed.getPrice().equals("bid,ask")) {
System.out.println("Bid: " + quote.get("bid"));
System.out.println("Ask: " + quote.get("ask"));
}
else {
System.out.println(" Price: " + quote.get("price"));
}
}
else {
System.out.println("Open: " + quote.get("open"));
System.out.println("High: " + quote.get("high"));
System.out.println("Low: " + quote.get("low"));
System.out.println("Close: " + quote.get("close"));
}
System.out.println("");
}
}
else {
System.out.println("Status: " + fxfeed.getStatus());
System.out.println("ErrorCode: " + fxfeed.getErrorCode());
System.out.println("ErrorMessage: " + fxfeed.getErrorMessage());
}
}
} // end class
Downloads:
