LSEG Data Library for Python

get_stream

Allows you to create a streaming quantitative analytic object.

Module

option.Definition

Syntax

definition.get_stream(session)

Parameters

Value Description Data type Optional Default value
session Session object. If session parameters are not defined, the default session will be used. Session object Yes None
api Specifies the data source. It can be updated/added using config file. str Yes -

Return value

QuantitativeDataStream object

Usage

The following example demonstrates how to get a streaming quantitative analytic object.

import time
from refinitiv.data.content.ipa.financial_contracts import option

def display_event(event_type, data, headers):
    print(">>> {} event received".format(event_type))
    print(data)

option_def = option.Definition(
    instrument_code="FCHI560000L1.p",
    underlying_type=option.UnderlyingType.ETI,
    fields=[
        "MarketValueInDealCcy",
        "DeltaPercent",
        "GammaPercent",
        "RhoPercent",
        "ThetaPercent",
        "VegaPercent"
    ]
)

option_stream = option_def.get_stream()
option_stream.on_response(lambda stream, data, headers: display_event("response", data, headers))
option_stream.on_update(lambda stream, data, headers: display_event("update", data, headers))
option_stream.on_state(lambda stream, data: display_event("state", data, None))

# Open the stream and wait events for 10 seconds 
option_stream.open()
time.sleep(10)
# Close the stream
option_stream.close()

# Extract snapshot data from the streaming cache
snapshot = option_stream.get_snapshot()
print(snapshot)

RDP stream

66 words (0:21 mins)