blpapi.AbstractSession¶
-
class
blpapi.
AbstractSession
¶ A common interface shared between publish and consumer sessions.
This class provides an abstract session which defines shared interface between publish and consumer requests for Bloomberg.
Sessions manage access to services either by requests and responses or subscriptions. A Session can dispatch events and replies in either a synchronous or asynchronous mode. The mode of a Session is determined when it is constructed and cannot be changed subsequently.
A Session is asynchronous if an
eventHandler
argument is supplied when it is constructed. ThenextEvent()
method may not be called. All incoming events are delivered to theeventHandler
supplied on construction.If supplied,
eventHandler
must be a callable object that takes two arguments: receivedEvent
and related session.A Session is synchronous if an
eventHandler
argument is not supplied when it is constructed. ThenextEvent()
method must be called to read incoming events.Several methods in Session take a
CorrelationId
parameter. The application may choose to supply its ownCorrelationId
values or allow the Session to create values. If the application supplies its ownCorrelationId
values it must manage their lifetime such that the same value is not reused for more than one operation at a time. The lifetime of aCorrelationId
begins when it is supplied in a method invoked on a Session and ends either when it is explicitly cancelled usingcancel()
orunsubscribe()
, when aRESPONSE
Event
(not aPARTIAL_RESPONSE
) containing it is received or when aSUBSCRIPTION_STATUS
Event
which indicates that the subscription it refers to has been terminated is received.When using an asynchronous Session, the application must be aware that because the callbacks are generated from another thread, they may be processed before the call which generates them has returned. For example, the
SESSION_STATUS
Event
generated by astartAsync()
may be processed beforestartAsync()
has returned (even thoughstartAsync()
itself will not block).This becomes more significant when Session generated
CorrelationId
s are in use. For example, if a call tosubscribe()
which returns a Session generatedCorrelationId
has not completed before the firstEvent
s which contain thatCorrelationId
arrive the application may not be able to interpret those events correctly. For this reason, it is preferable to use user generatedCorrelationId
s when using asynchronous Sessions. This issue does not arise when using a synchronous Session as long as the calls tosubscribe()
etc are made on the same thread as the calls tonextEvent()
.-
cancel
(correlationId)¶ Cancel
correlationId
request.- Parameters
correlationId (CorrelationId or [CorrelationId]) – Correlation id associated with the request to cancel
If the specified
correlationId
identifies a current request then cancel that request.Once this call returns the specified
correlationId
will not be seen in any subsequentMessage
obtained from aMessageIterator
by callingnext()
. However, anyMessage
currently pointed to by aMessageIterator
whencancel()
is called is not affected even if it has the specifiedcorrelationId
. Also anyMessage
where a reference has been retained by the application may still contain thecorrelationId
. For these reasons, although technically an application is free to re-usecorrelationId
as soon as this method returns it is preferable not to aggressively re-use correlation IDs, particularly with an asynchronous Session.
-
createIdentity
()¶ Create an
Identity
which is valid but has not been authorized.- Returns
Identity which is valid but has not been authorized
- Return type
-
generateToken
(correlationId=None, eventQueue=None, authId=None, ipAddress=None)¶ Generate a token to be used for authorization.
- Parameters
correlationId (CorrelationId) – Correlation id to be associated with the request
eventQueue (EventQueue) – Event queue on which to receive Events related to this request
authId (str) – The id used for authentication
ipAddress (str) – IP of the machine used for authentication
- Returns
The correlation id used to identify the Events generated as a result of this call
- Return type
- Raises
InvalidArgumentException – If the authentication options in
SessionOptions
or the arguments to the function are invalid.
The
authId
andipAddress
must be provided together and can only be provided if the authentication mode isMANUAL
.
-
getService
(serviceName)¶ Return a
Service
object representing the service.- Parameters
serviceName (str) – Name of the service to retrieve
- Returns
Service identified by the service name
- Return type
- Raises
InvalidStateException – If the service identified by the specified
serviceName
is not open already
The
serviceName
must contain a fully qualified service name. That is, it must be of the form//<namespace>/<service-name>
.
-
openService
(serviceName)¶ Open the service identified by the specified
serviceName
.- Parameters
serviceName (str) – Name of the service
- Returns
service identified by the specified
serviceName
.- Return type
Attempt to open the service identified by the specified
serviceName
and block until the service is either opened successfully or has failed to be opened. ReturnTrue
if the service is opened successfully andFalse
if the service cannot be successfully opened.The
serviceName
must contain a fully qualified service name. That is, it must be of the form//<namespace>/<service-name>
.Before
openService()
returns aSERVICE_STATUS
Event
is generated. If this is an asynchronous Session then thisEvent
may be processed by the registeredeventHandler
beforeopenService()
has returned.
-
openServiceAsync
(serviceName, correlationId=None)¶ Begin the process to open the service and return immediately.
- Parameters
serviceName (str) – Name of the service
correlationId (CorrelationId) – Correlation id to associate with events generated as a result of this call
- Returns
The correlation id used to identify the Events generated as a result of this call
- Return type
Begin the process to open the service identified by the specified
serviceName
and return immediately. The optional specifiedcorrelationId
is used to trackEvent
s generated as a result of this call.The
serviceName
must contain a fully qualified service name. That is, it must be of the form//<namespace>/<service-name>
.The application must monitor events for a
SERVICE_STATUS
Event
which will be generated once the service has been successfully opened or the opening has failed.
-
sendAuthorizationRequest
(request, identity, correlationId=None, eventQueue=None)¶ Send the specified
authorizationRequest
.- Parameters
request (Request) – Authorization request to send
identity (Identity) – Identity to update with the results
correlationId (CorrelationId) – Correlation id to associate with the request
eventQueue (EventQueue) – Event queue on which the events related to this request will arrive
- Returns
The correlation id used to identify the Events generated as a result of this call
- Return type
Send the specified
authorizationRequest
and update the specifiedidentity
with the results. If the optionally specifiedcorrelationId
is supplied, it is used; otherwise create aCorrelationId
. The actualCorrelationId
used is returned. If the optionally specifiedeventQueue
is supplied allEvent
s relating to thisRequest
will arrive on thatEventQueue
.The underlying user information must remain valid until the Request has completed successfully or failed.
A successful request will generate zero or more
PARTIAL_RESPONSE
Message
s followed by exactly oneRESPONSE
Message
. Once the finalRESPONSE
Message
has been received the specifiedidentity
will have been updated to contain the users entitlement information and theCorrelationId
associated with the request may be re-used. If the request fails at any stage aREQUEST_STATUS
will be generated, the specifiedidentity
will not be modified and theCorrelationId
may be re-used.The
identity
supplied must have been returned from this Session’screateIdentity()
method.
-