LSEG Data Library for Python

get_data

The get_data function allows you to retrieve pricing snapshots, as well as Fundamental and Reference data, through a single function call.

Module

lseg.data

Syntax

get_data(universe, fields=None, parameters=None, use_field_names_in_headers=False)

Parameters

Value Description Data type Optional Default value
universe Instruments to request. str or list No -
fields Fields to request. str or list Yes None
parameters Single key=value global parameter or dictionary of global parameters to request. str or dict Yes None
use_field_names_in_headers If True - returns the field name as column headers for data instead of title. bool Yes False

Returned value

A pandas.DataFrame, showing fields in columns and instruments as a row index.

Usage

The following example demonstrates how to open the default session and retrieve a pricing snapshot as well as Fundamental and Reference data, through a single function call:

import lseg.data as ld

# session creation
ld.open_session()

# getting ADC and realtime pricing data
df = ld.get_data(
    universe=['USD=', 'EUR=', "LSEG.L"],
    fields=['BID', 'ASK', 'TR.Revenue']
)

print(df)

# close session
ld.close_session()

This example produces the following output:

  Instrument     Revenue     BID     ASK
0       USD=        <NA>       1       1
1       EUR=        <NA>  1.0322  1.0326
2     LSEG.L  6740000000    <NA>    <NA>

As you can see, for each instrument, get_data returns the applicable data for every single instrument. If something is not applicable, it will be populated with <NA>.

The following example demonstrates how to request all fields using the instrument name only:

import lseg.data as ld

# session creation
ld.open_session()

# getting all realtime pricing data
df = ld.get_data(universe="USD=")

print(df.to_string())

# close session
ld.close_session()

This example produces the following output:

|    | Instrument   |   PROD_PERM |   RDNDISPLAY | DSPLY_NAME   | TIMACT   | NETCHNG_1   |   HIGH_1 |   LOW_1 |   CURRENCY |
|---:|:-------------|------------:|-------------:|:-------------|:---------|:------------|---------:|--------:|-----------:|
|  0 | USD=         |         213 |          153 | REUTERS      | 01:00:00 | <NA>        |        1 |       1 |        840 |

None.

175 words (0:55 mins)