LSEG Data Library for Python

get_history

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

Module

lseg.data

Syntax

get_history( universe, fields=None, interval=None, start=None, end=None, adjustments=None, count=None, use_field_names_in_headers=False parameters=None )

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
interval Date interval. Supported intervals are: ["minute", "1min", "5min", "10min", "30min", "60min", "hourly", "1h", "daily", "1d", "1D", "7D", "7d", "weekly", "1W", "monthly", "1M", "quarterly", "3M", "6M", "yearly", "12M", "1Y"]. str Yes None
start The start date and timestamp of the requested history. str, date, datetime, timedelta Yes None
end The end date and timestamp of the requested history. str, date, datetime, timedelta Yes None
adjustments Tells the system whether to apply Corporate Actions (CORAX) events, exchange/manual corrections, or price and volume adjustments, according to trade/quote qualifier summarization actions performed on historical time series data. Possible values are ["exchangeCorrection", "manualCorrection", "CCH", "CRE", "RTS", "RPO", "unadjusted", "qualifiers"].
Important note: This parameter only applies to pricing fields that are retrieved from the underlying Historical Pricing Data Platform API (fields that do not start with "TR.", such as BID and ASK). For the other fields (fields beginning with "TR.", such as TR.Revenue), this parameter is ignored.
str Yes None
count The maximum number of data points returned. Value range: 1 - 10000. int Yes None
use_field_names_in_headers If True - returns field name as column headers for data, instead of title. bool Yes False
parameters Single global key=value parameter or dictionary of global parameters to request.
Applies to TR fields only.
str or dict Yes None

Returned value

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

Usage

The following example demonstrates the last 50 ticks of historical pricing data:

import lseg.data as ld

# open session
ld.open_session()

df = ld.get_history(
    universe="GOOG.O",
    fields=["BID", "ASK"],
    interval="tick",
    count=5
)
print(df)

# close session
ld.close_session()

This example produces the following output:

GOOG.O                      BID     ASK
Timestamp                              
2022-08-11 22:30:22.567  119.90  120.16
2022-08-11 22:31:02.653  119.90  120.16
2022-08-11 22:31:11.701  119.88  120.16
2022-08-11 22:31:11.749  119.90  120.16
2022-08-11 22:31:22.840  119.90  120.16

The following example demonstrates fundamental and the historical pricing date:

from datetime import date, timedelta

import lseg.data as ld

# open session
ld.open_session()

# display today's date
print(f"Today is {date.today()}\n")

df = ld.get_history(
    universe=["IBM"],
    fields=['BID', "ASK", 'TR.RevenueMean.currency', "TR.RevenueMean"],
    interval='1h',
    use_field_names_in_headers=False,
    start=timedelta(-30),
    end=timedelta(0)
)
print(df.to_string())

# close session
ld.close_session()

This example produces the following output:

Today is 2022-08-12

IBM                     BID     ASK Currency Revenue - Mean
Timestamp                                                  
2022-07-12 00:00:00    <NA>    <NA>      USD    60926572250
2022-07-13 00:00:00    <NA>    <NA>      USD    60922436870
2022-07-13 08:00:00     139  139.79     <NA>           <NA>
2022-07-13 09:00:00     139  139.58     <NA>           <NA>
2022-07-13 10:00:00  139.23  139.99     <NA>           <NA>
2022-07-13 11:00:00  139.09  139.65     <NA>           <NA>
2022-07-13 12:00:00  138.15  138.25     <NA>           <NA>
2022-07-13 13:00:00  137.23  137.27     <NA>           <NA>
2022-07-13 14:00:00  137.85  137.89     <NA>           <NA>

None.

312 words (1:39 mins)