Example: Retrieve Time Series Data in Groovy

Java Documentation | Bitbucket

Help us help you: Take a short survey!

Much the same as the previous example, the underlying technology for the Coherent Datafeed: Thomson Reuters Edition is written in Java and relies on the popular Maven software project management and comprehension tool to build the project.

We have configured the build script to use the Maven Shade Plugin so that the contents of all dependencies can be combined into one single Java archive (jar) file.

Below is an example where we query Thomson Reuters for Time Series Data for the TRI.N Reuters Instument Code (RIC); note that this script is 44 lines of code and is written in the Groovy scripting language.


import static com.coherentlogic.coherent.datafeed.misc.Constants.DACS_ID
import com.coherentlogic.coherent.datafeed.builders.ServiceName
import com.coherentlogic.coherent.datafeed.client.Client

import com.reuters.ts1.TS1Constants
import com.reuters.rfa.common.Handle

def client = new Client ()

client.start()

def dacsId = System.getenv(DACS_ID)

def loginHandle = client.login(dacsId)

client.waitForInitialisationToComplete()

final def timeSeriesService =
    client.getTimeSeriesService();

timeSeriesService.queryTimeSeriesFor(
    loginHandle,
    ServiceName.IDN_RDF,
    "TRI.N",
    TS1Constants.DAILY_PERIOD
);

def timeSeries =
    timeSeriesService.getNextUpdateAsTimeSeries();

def TABS = "ttt";

print ("tDATE");

for (String nextHeader : timeSeries.getHeaders())
    print(TABS + nextHeader);

for (def sample : timeSeries.getSamples()) {

print("n" + sample.getDate());

for (def nextPoint : sample.getPoints())
    print (TABS + nextPoint);
}

The jar files required for this demonstraction application are:

  • coherent-datafeed-assembly-0.9.3-SNAPSHOT.jar
  • rfa-7.4.1.L1.jar

The following image demonstrates some output which was captured when the application was running in the Groovy Console.

An example CDTRE application written in Groovy.
An example CDTRE application written in Groovy.