Eikon Data API for Python

Module: eikon

Functions

TR_Field(field_name, params=None, sort_dir=None, sort_priority=None)

This is a helper function to build the field for the get_data function.

Parameters

Name Type Description
field_name string Field name to request. You can find the list in Data Item Browser.
params dict Dictionary containing the parameters for the field passed in the argument field_name
sort_dir string Indicate the sort direction. Possible values are 'asc' or 'desc'. The default value is 'asc'
sort_priority integer Gives a priority to the field for the sorting. The highest priority is 0 (zero). the default value is None

Return

Returns a dictionary that can directly passed to get_data.

Example

TR_Field('tr.revenue') TR_Field('tr.open','asc',1) TR_Field('TR.GrossProfit',{'Scale': 6, 'Curn': 'EUR'},'asc',0)

get_app_id()

Returns the app key previously set with set_app_id function.

Notes

The app key identifies your application on Refinitiv Platform. You can get an app key using the App Key Generator (this App is available in Eikon Desktop).


.. deprecated:: 0.1.12
   This will be removed in future releases. Use get_app_key function instead

get_app_key()

Returns the app key previously set

Notes

The app key identifies your application on Refinitiv Platform. You can get an application ID using the App Key Generator (this App is available in Eikon Desktop).

get_data(instruments, fields, parameters=None, field_name=False, raw_output=False, debug=False)

Returns a pandas.DataFrame with fields in columns and instruments as row index

Parameters

Name Type Description
instruments string or list Single instrument or list of instruments to request.
fields string, dictionary or list of strings and/or dictionaries.

List of fields to request.

Examples:

  • 'TR.PriceClose'
  • {'TR.GrossProfit': { 'params':{ 'Scale': 6, 'Curn': 'EUR' }}
  • {'TR.GrossProfit': { 'params':{ 'Scale': 6, 'Curn': 'EUR' },sort_dir:'desc'}
  • ['TR.PriceClose','TR.PriceOpen']
  • [{'TR.PriceClose': {'sort_dir':asc,sort_priority:1}},{'TR.PriceOpen': {'sort_dir':asc,sort_priority:0}}

You can use the function TR_Field to build the fields:


>>> fields = [ek.TR_Field('tr.revenue'),ek.TR_Field('tr.open','asc',1),ek.TR_Field('TR.GrossProfit',{'Scale': 6, 'Curn': 'EUR'},'asc',0)]
>>> data, err = ek.get_data(["IBM","MSFT.O"],fields)

Tips: You can launch the Data Item Browser to discover fields and parameters, or copy field names and parameters from TR Eikon - MS Office formulas

parameters string or dictionary, optional

Single global parameter key=value or dictionary of global parameters to request.

Default: None

field_name boolean, optional

Define if column headers are filled with field name or display names.

If True value, field names will ube used as column headers. Otherwise, the full display name will be used.

Default: False

raw_output boolean, optional

By default the output is a pandas.DataFrame.

Set raw_output=True to get data in Json format.

Default: False

debug bool When set to True, the json request and response are printed. Default value is False

Returns

pandas.DataFrame
Returns pandas.DataFrame with fields in columns and instruments as row index
errors
Returns a list of errors

Raises

Exception
If http request fails or if server returns an error.
ValueError
If a parameter type or value is wrong.

Examples


>>> import eikon as ek
>>> ek.set_app_key('set your app key here')
>>> data, err = ek.get_data(["IBM", "GOOG.O", "MSFT.O"], ["TR.PriceClose", "TR.Volume", "TR.PriceLow"])
>>> data, err = ek.get_data("IBM", ['TR.Employees', {'TR.GrossProfit':{'params':{'Scale': 6, 'Curn': 'EUR'},'sort_dir':'asc'}}])
>>> fields = [ek.TR_Field('tr.revenue'),ek.TR_Field('tr.open',None,'asc',1),ek.TR_Field('TR.GrossProfit',{'Scale': 6, 'Curn': 'EUR'},'asc',0)]
>>> data, err = ek.get_data(["IBM","MSFT.O"],fields)

get_news_headlines(query='Topic:TOPALL and Language:LEN', count=10, date_from=None, date_to=None, raw_output=False, debug=False)

Returns a list of news headlines

Parameters

Name Type Description
query string, optional

News headlines search criteria. The text can contain RIC codes, company names, country names and operators (AND, OR, NOT, IN, parentheses and quotes for explicit search…).

Tip: Append 'R:' in front of RIC names to improve performance.

Default: Top News written in English

count int, optional

Max number of headlines retrieved.

Value Range: [1-100].

Default: 10

date_from string or datetime, optional

Beginning of date range.

String format is: '%Y-%m-%dT%H:%M:%S'. e.g. '2016-01-20T15:04:05'.

date_to string or datetime, optional

End of date range.

String format is: '%Y-%m-%dT%H:%M:%S'. e.g. '2016-01-20T15:04:05'.

raw_output boolean, optional

Set this parameter to True to get the data in json format if set to False, the function will return a data frame.

Default: False

debug bool, optional

When set to True, the json request and response are printed.

Default: False

Returns

pandas.DataFrame

Returns a DataFrame of news headlines with the following columns:

  • Index : Timestamp of the publication time
  • version_created : Date of the latest update on the news
  • text : Text of the Headline
  • story_id : Identifier to be used to retrieve the full story using the get_news_story function
  • source_code : Second news identifier

Raises

Exception
If http request fails or if server returns an error.
AttributeError
If a parameter type is wrong.

Examples


>>> import eikon as ek
>>> ek.set_app_key('set your app key here')
>>> headlines = ek.get_news_headlines("R:MSFT.O", 2)
>>> headlines
versionCreated                                   text
2016-04-13 18:28:57.000 2.016-04-13 18:28:59.001 RBC Applies Blockchain as a Loyalty Boost...
2016-04-13 17:28:21.577 2016-04-13 17:28:21.671 UPDATE 2-Long-stalled email privacy bill  ...
                           storyId
2016-04-13 18:28:57.000    urn:newsml:reuters.com:20160413:nNRA1uxh03:1
2016-04-13 17:28:21.577    urn:newsml:reuters.com:20160413:nL2N17G16Q:2

>>> headlines = ek.get_news_headlines("R:MSFT.O IN FRANCE")
>>> headlines = ek.get_news_headlines("R:MSFT.O IN FRANCE IN ENGLISH", count=5)
>>> headlines = ek.get_news_headlines("OBA* OR CLINTON IN ENGLISH", count=5)

get_news_story(story_id, raw_output=False, debug=False)

Return a single news story corresponding to the identifier provided in story_id

Parameters

Name Type Description
story_id string The story id is a field you will find in every headline you retrieved with the function get_news_headlines.
raw_output boolean

Set this parameter to True to get the data in json format if set to False, the function will return returns the story content.

The default value is False.

debug bool When set to True, the json request and response are printed.

Raises

Exception
If http request fails or if Refinitiv Services return an error.
ValueError
If a parameter type or value is wrong.

Examples


>>> import eikon as ek
>>> ek.set_app_key('set your app key here')
>>> headlines = ek.get_news_headlines('IBM')
>>> for index, headline_row in headlines.iterrows():
       story = ek.get_news_story(headline_row['storyId'])
       print (story)

get_port_number()

Returns the port number used to communicate with the Eikon Data API Proxy

get_symbology(symbol, from_symbol_type='RIC', to_symbol_type=None, raw_output=False, debug=False, bestMatch=True)

Returns a list of instrument names converted into another instrument code. For example: convert SEDOL instrument names to RIC names

Parameters

Name Type Description
symbol string or list of strings Single instrument or list of instruments to convert.
from_symbol_type string Instrument code to convert from. Possible values: 'CUSIP', 'ISIN', 'SEDOL', 'RIC', 'ticker', 'lipperID', 'IMO' Default: 'RIC'
to_symbol_type string or list Instrument code to convert to. Possible values: 'CUSIP', 'ISIN', 'SEDOL', 'RIC', 'ticker', 'lipperID', 'IMO', 'OAPermID' Default: None (means all symbol types are requested)
raw_output boolean Set this parameter to True to get the data in json format if set to False, the function will return a data frame Default: False
debug bool When set to True, the json request and response are printed.
bestMatch bool When set to True, only primary symbol is requested. When set to false, all symbols are requested

Returns

If raw_output is set to True, the data will be returned in the json format. If raw_output is False (default value) the data will be returned as a pandas.DataFrame

pandas.DataFrame content:
  • columns : Symbol types
  • rows : Symbol requested
  • cells : the symbols (None if not found)
  • symbol : The requested symbol

Raises

Exception
If request fails or if server returns an error
ValueError
If a parameter type or value is wrong

Examples


>>> import eikon as ek
>>> ek.set_app_key('set your app key here')
>>> ISIN_codes = ek.get_symbology(["MSFT.O", "GOOG.O", "IBM.N"], from_symbol_type="RIC", to_symbol_type="ISIN")
>>> ISIN_codes
                ISIN
MSFT.O  US5949181045
GOOG.O  US02079K1079
IBM.N   US4592001014

get_timeout()

Returns the request timeout in sec

get_timeseries(rics, fields='*', start_date=None, end_date=None, interval='daily', count=None, calendar=None, corax=None, normalize=False, raw_output=False, debug=False)

Returns historical data on one or several RICs

Parameters

Name Type Description
rics string or list of strings Single RIC or List of RICs to retrieve historical data for
start_date string or datetime.datetime or datetime.timedelta Starting date and time of the historical range. string format is: '%Y-%m-%dT%H:%M:%S'. e.g. '2016-01-20T15:04:05'. datetime.timedelta is negative number of day relative to datetime.now(). Default: datetime.now() + timedelta(-100) You can use the helper function get_date_from_today, please see the usage in the examples section
end_date string or datetime.datetime or datetime.timedelta

End date and time of the historical range.

string format could be
  • '%Y-%m-%d' (e.g. '2017-01-20')
  • '%Y-%m-%dT%H:%M:%S' (e.g. '2017-01-20T15:04:05')

datetime.timedelta is negative number of day relative to datetime.now().

Default: datetime.now()

You can use the helper function get_date_from_today, please see the usage in the examples section

interval string Data interval. Possible values: 'tick', 'minute', 'hour', 'daily', 'weekly', 'monthly', 'quarterly', 'yearly' (Default 'daily') Default: 'daily'
fields string or list of strings Use this parameter to filter the returned fields set. Available fields: 'TIMESTAMP', 'VALUE', 'VOLUME', 'HIGH', 'LOW', 'OPEN', 'CLOSE', 'COUNT' By default all fields are returned.
count int, optional Max number of data points retrieved.
calendar string, optional Possible values: 'native', 'tradingdays', 'calendardays'.
corax string, optional Possible values: 'adjusted', 'unadjusted'
normalize boolean if set to True, the function will return a normalized data frame with the following columns 'Date','Security','Field' If the value of this parameter is False the returned data frame shape will depend on the number of rics and the number of fields in the response There are three different shapes - One ric and many fields - Many rics and one field - Many rics and many fields Default: False Remark: This parameter has a less precedence than the parameter rawOutput i.e. if rawOutput is set to True, the returned data will be the raw data and this parameter will be ignored
raw_output boolean Set this parameter to True to get the data in json format if set to False, the function will return a data frame which shape is defined by the parameter normalize Default: False
debug bool When set to True, the json request and response are printed. Default: False

Raises

Exception
If request fails or if server returns an error.
ValueError
If a parameter type or value is wrong.

Examples


>>> import eikon as ek
>>> ek.set_app_key('set your app key here')
>>> req = ek.get_timeseries(["MSFT.O"], start_date = "2017-02-01T15:04:05",
>>>                          end_date = "2017-02-05T15:04:05", interval="tick")
>>> req = ek.get_timeseries(["MSFT.O"], start_date = "2017-03-01",
>>>                          end_date = "2017-03-10", interval="daily")
>>> req = ek.get_timeseries(["MSFT.O"], start_date = get_date_from_today(150),
>>>                          end_date = get_date_from_today(100), interval="daily")

send_json_request(entity, payload, debug=False)

Returns the JSON response. This function can be used for advanced usage or early access to new features.

Parameters

Name Type Description
entity string A string containing a service name
payload string A string containing a JSON request
debug bool, optional When set to True, the json request and response are printed. Default: False

Returns

string
The JSON response as a string

Raises

EikonError
If daemon is disconnected
requests.Timeout
If request times out
Exception
If request fails (HTTP code other than 200)
EikonError
If daemon is disconnected

set_app_id(app_key)

Set the app key.

Parameters

Name Type Description
app_key string the app key

Notes

The app key identifies your application on Refinitiv Platform. You can get an app key using the App Key Generator (this App is available in Eikon Desktop).


.. deprecated:: 0.1.12
   This will be removed in 1.1.0. Use set_app_key function instead

set_app_key(app_key)

Set the app key.

Parameters

Name Type Description
app_key string the app key

Notes

The app key identifies your application on Refinitiv Platform. You can get an app key using the App Key Generator (this App is available in Eikon Desktop).

set_log_level(level)

Set the log level. When logs are activated (log_level != logging.NOTSET), log files are created in the current directory. To change directory for log files, set log path with set_log_path() function.

Parameters

Name Type Description
level int Possible values from logging module : [CRITICAL, FATAL, ERROR, WARNING, WARN, INFO, DEBUG, NOTSET]

Example

ek.set_log_level(logging.DEBUG)

set_log_path(path)

Set the filepath of the log file.

Parameters

Name Type Description
path string File path location for log files

Example

ek.set_log_path("c:\my_directory")

set_port_number(port_number)

Set the port number to communicate with the Eikon Data API proxy. This port number is detected automatically but you can call this function to force it manually for troubleshooting issues.

Parameters

Name Type Description
port_number int the port number

set_timeout(timeout)

Set the timeout for each request.

Parameters

Name Type Description
timeout int the request timeout in sec Default value: 30 sec

Classes

EikonError

2061 words (10:51 mins)