Forex Feed Data API

The ForexFeed Data API is an application programming interface (API) that can be used by (or bundled with) your applications.

The Data API provides direct access to the ForexFeed Data Service by wrapping common data operations inside simple function/method calls.

The Data API is available in a variety of different programming languages and can be used to offload common tasks such as loading quote data or fetching exchange rates. Allowing you to concentrate on what you do with the data, instead of how to get it into your App.

The Data API makes pulling data into your application fast, reliable and relatively simple.

As the example PHP script below illustrates, with relatively few lines of code we can get Open, High, Low, Close data for 6 different FOREX symbols and print them to Standard Output (STDOUT).

  require_once('ForexFeed.class.php');
  
  $datafeed = new ForexFeed(array('app_id'=>'YOUR_APP_ID'));
  $datafeed->setSymbol('EURUSD,GBPUSD,USDCAD,USDCHF,USDJPY,AUDUSD');
  
  $datafeed->getData();
  while( $datafeed->iterator() ){
    print " Quote Symbol: " . $datafeed->iteratorGetSymbol();
    print " Time: " . $datafeed->iteratorGetTimestamp();
    print " Open: " . $datafeed->iteratorGetOpen();
    print " High: " . $datafeed->iteratorGetHigh();
    print " Low: " . $datafeed->iteratorGetLow();
    print " Close: " . $datafeed->iteratorGetClose() . "\r\n";
    }

Let's take a closer look and go through this line by line:

require_once('ForexFeed.class.php');
Line #1 includes the Forex Feed Data API into your script.

$datafeed = new ForexFeed(array('app_id'=>'YOUR_APP_ID'));
Line #3 creates a new instance of the ForexFeed Data API Class and stores it as the $datafeed variable.
Data operations can now be performed through $datafeed Object reference.
Note: You must use your unique App id in place of YOUR_APP_ID.

$datafeed->setSymbol('EURUSD,GBPUSD,USDCAD,USDCHF,USDJPY,AUDUSD');
Line #4 tells the DataAPI which data Symbols we're interested in. In this case we're working with the EUR/USD, GBP/USD, USD/CAD, USD/CHF, USD/JPY and AUD/USD currency pairs. All further API operations will assume this set of Symbols.

$datafeed->getData();
Line #6 performs the actual live data retrieval from the service (ie: loading data from the ForexFeed).
Data is retrieving from the service and cached internally by the DataAPI, data can be worked with later in your script without hitting the service again. Note: Any time you want to update the internally cached dataset you can just call $datafeed->getData() again.

while( $datafeed->iterator() ){
  print " Quote Symbol: " . $datafeed->iteratorGetSymbol();
  print " Time: " . $datafeed->iteratorGetTimestamp();
  print " Open: " . $datafeed->iteratorGetOpen();
  print " High: " . $datafeed->iteratorGetHigh();
  print " Low: " . $datafeed->iteratorGetLow();
  print " Close: " . $datafeed->iteratorGetClose() . "\r\n";
  }
On line 7 you'll notice the call to $datafeed->iterator(). This is a convenience function that simplifies looping (or cycling) through all of the quotes in the current Dataset, making the entire while( ){ ... } loop pretty straight forward with no local counters required.

Lines #8-13 print the price information for each individual Symbols to the Standard Output.

An important note here: this PHP example is valid for PHP and Perl, other languages (Java and dotNET) operate slightly differently - please refer to specific sample included with the respective download bundle.

Of course if you prefer to mash things up or working with Raw Data Structures (opposed to simple Iterators shown here) then you should have a look at the getDataset() API function.