Documentation

This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

realtime

Thomson Reuters Elektron real-time market data

Syntax

reqid = realtime(c,seclist,eventhandler)
reqid = realtime(c,r,eventhandler)

Description

example

reqid = realtime(c,seclist,eventhandler) returns a real-time request identifier using the Thomson Reuters Elektron® connection, security list, and an event handler function. You can retrieve Thomson Reuters Elektron real-time market data by accessing variables that appear in the MATLAB® workspace.

example

reqid = realtime(c,r,eventhandler) retrieves Thomson Reuters Elektron real-time market data using a Thomson Reuters Elektron custom request message.

Examples

collapse all

First, create a Thomson Reuters Elektron connection. Then, retrieve real-time market data. Close the connection. The real-time market data you see when running this code can differ from the output data here.

Add Thomson Reuters Elektron JAR files to the dynamic Java® class path. Find these JAR files in the installation folder. Here, the installation folder is i:\Elektron.

javaaddpath i:\Elektron\ansipage.jar
javaaddpath i:\Elektron\ema-javadoc.jar
javaaddpath i:\Elektron\ema.jar
javaaddpath i:\Elektron\jdacsUpalib.jar
javaaddpath i:\Elektron\upa.jar
javaaddpath i:\Elektron\upaValueAdd.jar
javaaddpath i:\Elektron\upaValueAddCache.jar
javaaddpath i:\Elektron\commons-configuration-1.10.jar
javaaddpath i:\Elektron\commons-lang-2.6.jar
javaaddpath i:\Elektron\commons-logging-1.2.jar
javaaddpath i:\Elektron\org.apache.commons.collections.jar
javaaddpath i:\Elektron\slf4j-api-1.7.12.jar
javaaddpath i:\Elektron\slf4j-jdk14-1.7.12.jar

Alternatively, add these JAR files to the static Java class path. For details about dynamic and static class paths, see Java Class Path (MATLAB).

Connect to Thomson Reuters Elektron using the user name and service name.

c is an elektron object.

username = 'username';
servicename = 'servicename';

c = elektron(username,servicename);

Retrieve real-time market data for the IBM® security using the Thomson Reuters Elektron connection. Use the example event handler function elektronExampleListener. To access the code for this function, enter edit elektronExampleListener.m.

reqid is a structure that contains these fields:

  • ReqId — Request identifier for the real-time data request

  • ReqMsg — Thomson Reuters Elektron Message API request object

  • Handle — MATLAB event listener process object

  • Listener — MATLAB event listener object

seclist = 'IBM.N';
eventhandler = @(~,ev)elektronExampleListener(ev);
reqid = realtime(c,seclist,eventhandler)
reqid = 

  struct with fields:

       ReqId: 5
      ReqMsg: [1×1 com.thomsonreuters.ema.access.ReqMsgImpl]
      Handle: [1×1 datafeedElektron]
    Listener: [1×1 handle.listener]

The cell array IBM appears in the MATLAB workspace. IBM contains four columns. The columns are:

  • Thomson Reuters Elektron field identifier

  • Thomson Reuters Elektron field name

  • Thomson Reuters Elektron field data type

  • Thomson Reuters Elektron field real-time data value

Access real-time data in the cell array. Access the Thomson Reuters Elektron field name in the second column and the current data value in the fourth column.

field = IBM{1,2}; 
value = IBM{1,4};

For events that do not have an event name or that are not associated with the security, the ElektronExampleData object appears in the MATLAB workspace. This object contains decoded event data. View the contents of this object. The contents of this object vary depending on the Thomson Reuters Elektron event.

ElektronExampleData
ElektronExampleData =

UpdateMsg
    streamId="10"
    domain="MarketPrice Domain"
    updateTypeNum="1"
    Payload dataType="FieldList"
        FieldList
            FieldEntry fid="22" name="BID" dataType="Real" value="57.1"
            FieldEntry fid="25" name="ASK" dataType="Real" value="57.11"
            FieldEntry fid="30" name="BIDSIZE" dataType="Real" value="22.0"
            FieldEntry fid="31" name="ASKSIZE" dataType="Real" value="39.0"
            FieldEntry fid="11683" name="BIDFINMMID" dataType="Rmtes" value="(blank data)"
            FieldEntry fid="11684" name="ASKFINMMID" dataType="Rmtes" value="(blank data)"
            FieldEntry fid="3298" name="BIDXID" dataType="Enum" value="43"
            FieldEntry fid="3297" name="ASKXID" dataType="Enum" value="6"
            FieldEntry fid="6579" name="BID_COND_N" dataType="Rmtes" value="R"
            FieldEntry fid="6580" name="ASK_COND_N" dataType="Rmtes" value="R"
            FieldEntry fid="293" name="BID_MMID1" dataType="Rmtes" value="NAS"
            FieldEntry fid="296" name="ASK_MMID1" dataType="Rmtes" value="XPH"
            FieldEntry fid="1000" name="GV1_TEXT" dataType="Rmtes" value="A"
            FieldEntry fid="8937" name="LIMIT_INDQ" dataType="Enum" value="25"
            FieldEntry fid="3887" name="SEQNUM_QT" dataType="Real" value="1.6923329E7"
            FieldEntry fid="118" name="PRC_QL_CD" dataType="Enum" value="0"
            FieldEntry fid="3264" name="PRC_QL3" dataType="Enum" value="0"
            FieldEntry fid="8406" name="QTE_ORIGIN" dataType="Rmtes" value=" "
            FieldEntry fid="1041" name="GV1_FLAG" dataType="Rmtes" value=" "
            FieldEntry fid="12783" name="NBBO_IND" dataType="Enum" value="5"
            FieldEntry fid="3855" name="QUOTIM_MS" dataType="UInt" value="62664591"
            FieldEntry fid="1025" name="QUOTIM" dataType="Time" value="17:24:24:000:000:000"
            FieldEntry fid="14238" name="ORDRECV_MS" dataType="Time" value="17:24:24:590:000:000"
            FieldEntry fid="14246" name="ORDREC2_MS" dataType="Time" value="(blank data)"
        FieldListEnd
    PayloadEnd
UpdateMsgEnd

Stop real-time data subscription.

delete(reqid.Listener)

Close the Thomson Reuters Elektron connection.

close(c)

First, create a Thomson Reuters Elektron connection. Then, retrieve real-time last trade price data. Close the connection. The real-time market data you see when running this code can differ from the output data here.

Add Thomson Reuters Elektron JAR files to the dynamic Java class path. Find these JAR files in the installation folder. Here, the installation folder is i:\Elektron.

javaaddpath i:\Elektron\ansipage.jar
javaaddpath i:\Elektron\ema-javadoc.jar
javaaddpath i:\Elektron\ema.jar
javaaddpath i:\Elektron\jdacsUpalib.jar
javaaddpath i:\Elektron\upa.jar
javaaddpath i:\Elektron\upaValueAdd.jar
javaaddpath i:\Elektron\upaValueAddCache.jar
javaaddpath i:\Elektron\commons-configuration-1.10.jar
javaaddpath i:\Elektron\commons-lang-2.6.jar
javaaddpath i:\Elektron\commons-logging-1.2.jar
javaaddpath i:\Elektron\org.apache.commons.collections.jar
javaaddpath i:\Elektron\slf4j-api-1.7.12.jar
javaaddpath i:\Elektron\slf4j-jdk14-1.7.12.jar

Alternatively, add these JAR files to the static Java class path. For details about dynamic and static class paths, see Java Class Path (MATLAB).

Connect to Thomson Reuters Elektron using the user name and service name.

c is an elektron object.

username = 'username';
servicename = 'servicename';

c = elektron(username,servicename);

Retrieve real-time market data for the IBM security using the Thomson Reuters Elektron connection. Use the example event handler function elektronPriceTableListener. To access the code for this function, enter edit elektronPriceTableListener.m.

reqid is a structure that contains these fields:

  • ReqId — Request identifier for the real-time data request

  • ReqMsg — Thomson Reuters Elektron Message API request object

  • Handle — MATLAB event listener process object

  • Listener — MATLAB event listener object

seclist = 'IBM.N';
eventhandler = @(~,ev)elektronPriceTableListener(ev,seclist);
reqid = realtime(c,seclist,eventhandler)
reqid = 

  struct with fields:

       ReqId: 5
      ReqMsg: [1×1 com.thomsonreuters.ema.access.ReqMsgImpl]
      Handle: [1×1 datafeedElektron]
    Listener: [1×1 handle.listener]

The table PriceTable appears in the MATLAB workspace. PriceTable contains these variables:

  • RIC — RIC for the IBM security

  • TRDPRC_1 — Last trade price data

Thomson Reuters Elektron continuously updates the TRDPRC_1 variable with the latest trade price in the table row.

Access the last trade price in real time for the IBM security.

PriceTable.TRDPRC_1
ans =

  163.2600

Stop real-time data subscription.

delete(reqid.Listener)

Close the Thomson Reuters Elektron connection.

close(c)

First, create a Thomson Reuters Elektron connection. Then, retrieve real-time data using a custom request message. Close the connection. The real-time market data you see when running this code can differ from the output data here.

Add Thomson Reuters Elektron JAR files to the dynamic Java class path. Find these JAR files in the installation folder. Here, the installation folder is i:\Elektron.

javaaddpath i:\Elektron\ansipage.jar
javaaddpath i:\Elektron\ema-javadoc.jar
javaaddpath i:\Elektron\ema.jar
javaaddpath i:\Elektron\jdacsUpalib.jar
javaaddpath i:\Elektron\upa.jar
javaaddpath i:\Elektron\upaValueAdd.jar
javaaddpath i:\Elektron\upaValueAddCache.jar
javaaddpath i:\Elektron\commons-configuration-1.10.jar
javaaddpath i:\Elektron\commons-lang-2.6.jar
javaaddpath i:\Elektron\commons-logging-1.2.jar
javaaddpath i:\Elektron\org.apache.commons.collections.jar
javaaddpath i:\Elektron\slf4j-api-1.7.12.jar
javaaddpath i:\Elektron\slf4j-jdk14-1.7.12.jar

Alternatively, add these JAR files to the static Java class path. For details about dynamic and static class paths, see Java Class Path (MATLAB).

Connect to Thomson Reuters Elektron using the user name and service name.

c is an elektron object.

username = 'username';
servicename = 'servicename';

c = elektron(username,servicename);

Create a custom request message for the Apple security. Enter this Thomson Reuters Elektron Message API code.

import com.thomsonreuters.ema.access.*;
import com.thomsonreuters.ema.access.OmmConsumerConfig.*;

r = EmaFactory.createReqMsg;
r.serviceName(c.Service).name('AAPL.O');

Retrieve last trade price data using the Thomson Reuters Elektron connection and custom request message. Use the example event handler function elektronExampleListener. To access the code for this function, enter edit elektronExampleListener.m.

reqid is a structure that contains these fields:

  • ReqId — Request identifier for the real-time data request

  • ReqMsg — Thomson Reuters Elektron Message API request object

  • Handle — MATLAB event listener process object

  • Listener — MATLAB event listener object

eventhandler = @(~,ev)elektronExampleListener(ev);
reqid = realtime(c,r,eventhandler)
reqid = 

  struct with fields:

       ReqId: 5
      ReqMsg: [1×1 com.thomsonreuters.ema.access.ReqMsgImpl]
      Handle: [1×1 datafeedElektron]
    Listener: [1×1 handle.listener]

The cell array AAPL appears in the MATLAB workspace.

Access real-time data in the cell array. Access the Thomson Reuters Elektron field name in the second column and the current data value in the fourth column.

field = AAPL{1,2}; 
value = AAPL{1,4};

Stop real-time data subscription.

delete(reqid.Listener)

Close the Thomson Reuters Elektron connection.

close(c)

Input Arguments

collapse all

Thomson Reuters Elektron connection, specified as an elektron object created using the elektron function.

Thomson Reuters Elektron security list, specified as a character vector, string scalar, cell array of character vectors, or string array. Specify securities in the security list as:

  • A character vector or string for one security.

  • A cell array of character vectors or a string array for multiple securities. Each character vector in the cell array or each string in the string array is a Thomson Reuters Elektron security.

The security is a Reuters® Instrument Code (RIC). For details about RICs, contact Thomson Reuters™.

Example: {'IBM.N','MSFT.O'}

Data Types: cell | char | string

Thomson Reuters Elektron request message, specified as a Thomson Reuters Elektron Message API request object. To create this object, use the Thomson Reuters Elektron Message API code. For details, see Thomson Reuters Elektron. This object defines the data and parameters for a custom message request.

Event handler, specified as a function handle. You can use the example event handling functions elektronExampleListener or elektronPriceTableListener to process real-time Thomson Reuters Elektron Message API events. Or, you can define a custom event handler function to process events of your choice. For details, see Writing and Running Custom Event Handler Functions.

The event handler function elektronExampleListener creates a cell array for each security in the input argument seclist. The cell array contains real-time data for the security. For example, if seclist contains 'IBM.N', then the cell array named IBM appears in the MATLAB workspace.

For events without a name or that are not associated with a RIC, the event handler function creates an object named ElektronExampleData in the MATLAB workspace. This object contains decoded data for these events. The object type differs depending on the current Thomson Reuters Elektron Message API output. For details about this object, see Thomson Reuters Elektron.

This table describes the columns in the cell arrays for each security that appear in the MATLAB workspace.

Cell Array ColumnDescription

First column

Thomson Reuters Elektron field identifier

Second column

Thomson Reuters Elektron field name

Third column

Thomson Reuters Elektron data type of the Thomson Reuters Elektron field

Fourth column

Current Thomson Reuters Elektron data value

The event handler function elektronExampleListener has an input argument ev that is specified as a four-column cell array that contains:

  • Decoded data

  • Thomson Reuters Elektron Message API event object

  • Event message

  • Event name

The other event handler function elektronPriceTableListener creates a table named PriceTable in the MATLAB workspace. This table contains the last trade price for each security in the input argument seclist. The table contains two variables, RIC for the security and TRDPRC_1 for the last trade price of the corresponding security:

  • RIC is returned as a cell array of one or more character vectors that depend on the number of securities in the security list.

  • TRDPRC_1 is returned as a numeric scalar for one security or an array of doubles that has a value for each security in RIC.

The event handler function elektronPriceTableListener has the security list as an additional input argument. The security list matches the contents of seclist.

To access the code for the event handler function elektronExampleListener, enter edit elektronExampleListener.m. To access the code for the event handler function elektronPriceTableListener, enter edit elektronPriceTableListener.m.

For example, to retrieve real-time data for the IBM and Microsoft® securities, enter this code that assumes an established Thomson Reuters Elektron connection c.

seclist = {'IBM.N','MSFT.O'};
reqId = realtime(c,seclist,@(~,ev)elektronExampleListener(ev));

Example: @(~,ev)elektronExampleListener(ev)

Data Types: function_handle

Output Arguments

collapse all

Real-time request identifier, returned as a structure with these fields.

FieldDescription

ReqId

Request identifier for the real-time data request

ReqMsg

Thomson Reuters Elektron Message API request object

Handle

MATLAB event listener process object

Listener

MATLAB event listener object

For details about the request identifier and request object, see Thomson Reuters Elektron.

For details about MATLAB event listeners, see Overview Events and Listeners (MATLAB).

Use the real-time request identifier to stop the real-time data subscription; for example:

delete(reqid.Listener)

Tips

  • If you encounter issues with Thomson Reuters Elektron data retrieval, see the contents of the ElektronExampleData object in the MATLAB workspace. For example, if you enter an invalid RIC, the ElektronExampleData object contains a status message that specifies the RIC cannot be found. To retrieve such information automatically, write a custom event handler function that parses status messages in the ElektronExampleData object. For details about custom event handler functions, see Writing and Running Custom Event Handler Functions. For details about the status messages, see Thomson Reuters Elektron.

Introduced in R2017a

Was this topic helpful?