Eikon Data API

API Family: Eikon APIs

Setting up a Python development environment

Last update January 2019
Interpreter Python 2.x/3.x

Overview

Python is currently one of the most popular programming languages and is also considered a great language to start programming with.

There are a great number of Python beginners guides online, but I would like to save you a little time by helping you create a designated Eikon development environment. It will consist of:

  • Python environment and package installer: miniconda;
  • Data analysis and related packages: numpy, pandas and matplotlib;
  • Eikon (version 4.0.36 or higher) or the Eikon Data API Proxy.
  • Interactive environment: jupyter notebook;
  • A free code editor and plug-ins: Visual Studio Code with a python plug-in;

Our set up

Python

Anaconda from Continuum Analytics is universally praised by the Python community as possibly the simplest way to install libraries for numerical operations.

  • Download and install miniconda from here. When prompted on whether you would like to install in for all users or just yourself, choose the latter, so you would not require admin rights to run conda;
  • Open cmd.exe;
  • Type conda list, and if it shows a list of installed packages - the installation was successful;

The 'conda' command is a package installer, so you can add the most popular packages with it easily, however, you can see that pip, wheel and setuptools are also installed.

Let's install our first package: jupyter notebook, that allows creating and running interactive notebooks inside a browser:

  • Open cmd.exe;
  • Type conda install jupyter;

Isolated development environment

Note, that we installed jupyter to the default environment. It itself supports multiple environments, and you can easily switch it back and forth. But keeping your project specific packages is vital. If you are just starting, you will play with the language a lot and it is essential to be able to undo the effects of your experiments. For this purpose, we are going to create a separate development environment.

  • Open cmd.exe;
  • Run conda create --name refinitiv python=3;

Now let's activate our environment and list the packages:

  • Run conda list, you will see something like this:
C:\Users\zhenyakovalyov>activate refinitiv
(refinitiv) C:\Users\zhenyakovalyov>conda list
# packages in environment at C:\Users\zhenyakovalyov\Miniconda3\envs\refinitiv:
#

pip                       9.0.1                    py36_1
python                    3.6.1                         0
setuptools                27.2.0                   py36_1
vs2015_runtime            14.0.25123                    0
wheel                     0.29.0                   py36_0

Let's install the packages that we will require for our work in this environment: numpy, pandas and matplotlib.

  • Run conda install numpy pandas matplotlib

Once we are done working here, we can easily deactivate the environment with deactivate refinitivcommand.

Code editor

  • Download and install Visual Studio Code from here;
  • Open Visual Studio Code and press Ctrl+Shift+P (opens the command palette), 'ext install python' and press Enter;

I use Visual Code for anything these days (including this guide), however, you can always check out its free alternatives like Sublime Text or Atom, or use a designated python integrated development environment like PyCharm.

Eikon or Eikon Data API Proxy

Depending on your Eikon version and your Operating System (Windows or Mac OS) you may need to run the Eikon Data API Proxy or just Eikon. Please refer to the Quick Start guide for Windows if you use Windows with TR Eikon 4.0.36 (or higher). Refers to the Quick Start guide for Mac OS if you use Mac OS or a version of TR Eikon prior to 4.0.36.

  • Make sure TR Eikon or the Eikon Data API Proxy are properly set up;
  • Make sure that you are still in your 'refinitiv' environment, run conda env list;
  • Run pip install eikon;

Ok, you are all done!

First project

Now, let's practice some command line commands.

  • Open cmd.exe;
  • Run mkdir %HOMEPATH%\Documents\scripting-api%, this will create a new directory in your Documents folder;
  • Run cd %HOMEPATH%\Documents\scripting-api%, this will bring you to this folder;
  • Run activate refinitiv, this will activate our isolated environment;
  • Run jupyter notebook, this will open jupyter notebook in your project directory in a browser;
  • In the jupyter notebook window, select New > Notebooks > Python 3, this will create a new notebook;

Let's run Eikon:

  • Open Eikon (or the Eikon Data API Proxy);
  • Within Eikon, start the "AppKey Generator" (or select Get an AppKey within the Eikon Data API Proxy), then generate a new AppKey and copy it to the clipboard;

Now, Let's go back to our notebook. In the first cell, input the following commands:

import eikon as tr
import pandas as pd

tr.set_app_key('your_app_key')

ratings_data, err = tr.get_data(instruments=['0#.SPX'], 
                                fields=['TR.CommonName',
                                        'TR.IssuerRating(IssuerRatingSrc=SPI)',
                                        'TR.IssuerRating(IssuerRatingSrc=SPI,Sdate=-10Y)'])
ratings_data.head()

The result should look like this:

Instrument Company Common Name Issuer Rating Issuer Rating  
0 MMM.N 3M Co AA- AA
1 ABT.N Abbott Laboratories BBB AA
2 ABBV.N AbbVie Inc A-
3 ACN.N Accenture PLC A+ A+
4 ATVI.OQ Activision Blizzard Inc BBB- BB-
  • Python: "Fluent Python" by Luciano Ramalho or "Python for Finance" by Yves Hilpisch;
  • Jupyter: "IPython Notebook Essentials" by L. Felipe Martins;
  • Pandas: "Learning the Pandas Library" by Matt Harrison or "Mastering pandas for Finance" by Michael Heydt;