Example: Retrieve Market Price Updates in Groovy

Java Documentation | Bitbucket

Help us help you: Take a short survey!

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 Market Price updates for several Reuters Instument Codes (RICS); note that this script is 40 lines of code and is written in the Groovy scripting language.


import com.coherentlogic.coherent.datafeed.client.Client
import static com.coherentlogic.coherent.datafeed.misc.Constants.DACS_ID
import com.coherentlogic.coherent.datafeed.builders.ServiceName
import com.reuters.rfa.common.Handle
import org.slf4j.LoggerFactory

def log = LoggerFactory.getLogger(this.class.name);

Client client = new Client ()

client.start()

def dacsId = System.getenv(DACS_ID)

def loginHandle = client.login(dacsId)

client.waitForInitialisationToComplete()

def marketPriceService = client.getMarketPriceService ()

def itemHandles = marketPriceService.query(
    ServiceName.dIDN_RDF,
    loginHandle,
    "GOOG.O",
    "MSFT.O",
    "ODFL.OQ",
    "LKQ.OQ",
    "MDVN.OQ",
    "BFb.N")

long ctr = 0;

while (true) {
    def nextMarketPriceUpdate =
        marketPriceService.getNextUpdateAsJSON();
    log.info ("nextMarketPriceUpdate[" + (ctr++) + "]: " +
        nextMarketPriceUpdate);
}

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.