Decide to Buy Shares Using Elektron Real-Time Data

This example shows how to connect to Elektron™ from Refinitiv™ and trigger a buy decision for multiple RICs using the real-time Elektron last trade price.

The example uses the sample event handler function elektronExampleListener to retrieve real-time data for multiple securities in corresponding MATLAB® workspace variables. Use this event handler function or write a custom event handler function. For details, see Writing and Running Custom Event Handler Functions.

To access the code for this example, enter edit ElektronWorkflow.m.

Create Elektron Connection

Add 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.

Connect to Elektron using the user name and service name.

c is an elektron object.

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

c = elektron(username,servicename);

Retrieve Real-Time Data for Multiple Securities

Retrieve real-time market data for the IBM® and Microsoft® securities using the Elektron connection. Use the example event handler function elektronExampleListener. The realtime function returns the variable reqid as a structure that contains these fields:

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

  • ReqMsg — Elektron Message API request object

  • Handle — MATLAB event listener process object

  • Listener — MATLAB event listener object

seclist = {'IBM.N','MSFT.O'};
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 arrays IBM and MSFT appear in the MATLAB workspace. Each cell array contains the same four columns. The columns are:

  • Elektron field identifier

  • Elektron field name

  • Elektron field data type

  • Elektron field real-time data value

Make Investment Decisions to Buy Shares

Assume a price threshold of $175 for the IBM security. Determine if the last trade price is less than $175. Set the buy indicator buynow to true when the threshold is met. The first column in the cell array IBM contains the field identifier. The fourth column in the cell array contains the field value. Find the Elektron last trade price by the field identifier 6.

for i = 1:length(IBM)
    if (IBM{i,1} == 6)      % Find last trade price
        if (IBM{i,4} < 175) % Trigger buy price threshold
            buynow = true;
        end
    end
end

Use the buy indicator to create a buy order for IBM shares in the trading system of your choice.

Assume a price threshold of $75 for the Microsoft security. Determine if the last trade price is less than $75. Set the buy indicator buynow to true when the threshold is met. The first column in the cell array MSFT contains the field identifier. The fourth column in the cell array contains the field value. Find the Elektron last trade price by the field identifier 6.

for i = 1:length(MSFT)
    if (MSFT{i,1} == 6)     % Find last trade price
        if (MSFT{i,4} < 75) % Trigger buy price threshold
            buynow = true;
        end
    end
end

Use the buy indicator to create a buy order for Microsoft shares in the trading system of your choice.

Stop Real-Time Data Subscription

delete(reqid.Listener)

Close Elektron Connection

close(c)

See Also

| |

Related Topics

External Websites