Refinitiv Data Library for Python

session.on_event

This method can be used to register a user defined callback function that is called by the library whenever the event of the session is updated. This callback function allows your application to be notified of any event change and to take actions accordingly.

Callback function signature is:
def callback(event, message, session)

For events, see event codes

Module

refinitiv.data.session

Syntax

session.on_event(self, callback)

Parameters

Value Description Data type Optional Default value
self session.Session instance itself. Conventional name for the first class method argument in Python. - - -
callback Callback function object. Callable No

Returned value

None.

Usage

The following example demonstrates how to define a callback and then check for events during the execution of a session.

import refinitiv.data as rd


def check_event(event, message, session):
    print("Let's print event!")
    print(f"Event: {event}")
    print(f"Message: {message}")
    print("\n")


session.on_event(check_event)

session.open()

stream = rd.content.pricing.Definition(
    universe=["EUR=", "GPB="],
    fields=["BID", "ASK"]
).get_stream()
stream.open()
stream.close()

session.close()

Response

Event: EventCode.StreamConnecting
Message: None

Event: EventCode.StreamConnected
Message: None

None.