blpapi.Message

class blpapi.Message(handle, event=None, sessions=None)

A handle to a single message.

Message objects are obtained by iterating an Event. Each Message is associated with a Service and with one or more CorrelationId values. The Message contents are represented as an Element and all Element’s accessors could be used to access the data.

The possible fragment types are:

The possible recap types are:

Message objects are always created by the API, never directly by the application.

FRAGMENT_END = 3

Final part of a fragmented message

FRAGMENT_INTERMEDIATE = 2

Intermediate fragment

FRAGMENT_NONE = 0

Unfragmented message

FRAGMENT_START = 1

Start of a fragmented message

RECAPTYPE_NONE = 0

Normal data tick

RECAPTYPE_SOLICITED = 1

Generated on request by subscriber

RECAPTYPE_UNSOLICITED = 2

Generated by the service

__contains__(item)

Equivalent to asElement().__contains__().

Return type:

bool

__getitem__(name)

Equivalent to asElement().__getitem__().

Return type:

Any

__iter__()

Equivalent to asElement().__iter__().

Return type:

Iterator

__len__()

Equivalent to asElement().__len__().

Return type:

int

asElement()
Returns:

The content of this Message as an Element.

Return type:

Element

correlationId()
Returns:

The single correlation id or the first correlation id associated with the message, or None if the message is not associated with any correlation ids.

Note

See correlationIds() for more details.

If allowMultipleCorrelatorsPerMsg is enabled, correlationIds() should be used.

correlationIds()
Returns:

Correlation ids associated with this message.

Note

A subscription data Message has exactly one CorrelationId unless the allowMultipleCorrelatorsPerMsg option is enabled for the Session.

When allowMultipleCorrelatorsPerMsg is disabled (the default), multiple active subscriptions of the same topic result in the same Message being delivered multiple times (without making physical copies), with a single CorrelationId from each active subscription.

Otherwise, only one Message is delivered with all the CorrelationIds from the active subscriptions.

destroy()

Destroy the handle using stored dtor

Return type:

None

fragmentType()
Return type:

int

Returns:

Fragment type of this message.

Fragment types are listed in the class docstring.

getElement(name)

Equivalent to asElement().getElement(name).

Return type:

Element

Note

Please use Name over str where possible for name. Name objects should be initialized once and then reused in order to minimize lookup cost.

getElementAsBool(name)

Equivalent to asElement().getElementAsBool(name).

Return type:

bool

Note

Please use Name over str where possible for name. Name objects should be initialized once and then reused in order to minimize lookup cost.

getElementAsBytes(name)

Equivalent to asElement().getElementAsBytes(name).

Return type:

bytes

Note

Please use Name over str where possible for name. Name objects should be initialized once and then reused in order to minimize lookup cost.

getElementAsDatetime(name)

Equivalent to asElement().getElementAsDatetime(name).

Return type:

Union[datetime, date, time]

Note

Please use Name over str where possible for name. Name objects should be initialized once and then reused in order to minimize lookup cost.

getElementAsFloat(name)

Equivalent to asElement().getElementAsFloat(name).

Return type:

float

Note

Please use Name over str where possible for name. Name objects should be initialized once and then reused in order to minimize lookup cost.

getElementAsInteger(name)

Equivalent to asElement().getElementAsInteger(name).

Return type:

int

Note

Please use Name over str where possible for name. Name objects should be initialized once and then reused in order to minimize lookup cost.

getElementAsString(name)

Equivalent to asElement().getElementAsString(name).

Return type:

str

Note

Please use Name over str where possible for name. Name objects should be initialized once and then reused in order to minimize lookup cost.

getRequestId()

Return the message’s request id if one exists, otherwise return None.

When present, the request id can be reported to Bloomberg to troubleshoot the cause of failure messages, or issues with the data contained in the message.

Note that request id is not the same as correlation id and should not be used for correlation purposes.

Return type:

Optional[str]

Returns:

The request id of the message.

hasElement(name, excludeNullElements=False)

Equivalent to asElement().hasElement(name, excludeNullElements).

Return type:

bool

Note

Please use Name over str where possible for name. Name objects should be initialized once and then reused in order to minimize lookup cost.

isValid()

Returns: True if this class holds a handle and the handle is not None.

Return type:

bool

messageType()
Return type:

Name

Returns:

Type of this message.

numElements()

Equivalent to asElement().numElements().

Return type:

int

recapType()
Return type:

int

Returns:

Recap type of this message.

Recap types are listed in the class docstring.

service()
Returns:

Service that this Message is associated with.

timeReceived(tzinfo=<blpapi.datetime.FixedOffset object>)

Get the time when the message was received by the SDK.

Parameters:

tzinfo (tzinfo) – Timezone info

Returns:

Time when the message was received by the SDK.

Return type:

datetime.datetime or datetime.date or datetime.time

Raises:

ValueError – If this information was not recorded for this message. See SessionOptions.recordSubscriptionDataReceiveTimes() for information on configuring this recording.

The resulting datetime will be represented using the specified tzinfo value, and will be measured using a high-resolution clock internal to the SDK.

toPy()

Equivalent to asElement().toPy().

Return type:

dict

toString(level=0, spacesPerLevel=4)

Format this Message to the string at the specified indentation level.

Parameters:
  • level (int) – Indentation level

  • spacesPerLevel (int) – Number of spaces per indentation level for this and all nested objects

Return type:

str

Returns:

This element formatted as a string

If level is negative, suppress indentation of the first line. If spacesPerLevel is negative, format the entire output on one line, suppressing all but the initial indentation (as governed by level).

topicName()
Return type:

str

Returns:

Topic string of this message. If there is no topic associated with the message, empty string is returned.

DEPRECATED

This function has been deprecated because messages could contain multiple payloads with different correlation ids, and each of these correlation ids may map to different topic strings.

In such a scenario, it would be incorrect to choose one out of the multiple topics (for the various correlation id’s in the message) as the topic name for the message. Trying to make this correct would result in extra look up costs.

For correctness, users are encouraged to maintain a data structure in their application to help retrieve the topic name associated with the cid’s present in the delivered message.