matthewgilbert / pdblp

pandas wrapper for Bloomberg Open API
MIT License
241 stars 67 forks source link

Remove unecessary restart() method #46

Closed matthewgilbert closed 6 years ago

matthewgilbert commented 6 years ago

Previously is was thought that blpapi.CorrelationIds need to be unique to a blpapi.Session, however this is not true.

When subscribing or requesting information an application has the choice of providing a CorrelationId they construct themselves or allowing the session to construct one for them. If the application supplies a CorrelationId it must not re-use the value contained in it in another CorrelationId whilst the original request or subscription is still active.

An example shows this

import blpapi
import time

session = blpapi.Session()
session.start()
session.openService("//blp/refdata")
service = session.getService("//blp/refdata")

cid = blpapi.CorrelationId(1)

request = service.createRequest("ReferenceDataRequest")
request.getElement("securities").appendValue("IBM US Equity")
request.getElement("fields").appendValue("PX_LAST")

# same cid provided orginal request is not active is fine
session.sendRequest(request, correlationId=cid)
time.sleep(2)
session.sendRequest(request, correlationId=cid)

# same cid immediately causes errors
session.sendRequest(request, correlationId=cid)
session.sendRequest(request, correlationId=cid)

DuplicateCorrelationIdException: Duplicate correlation id: [ valueType=INT classId=0 value=1 ] (0x00020005)

The restart() method was provided as a hack to avoid managing correlationIds throughout the lifetime of a session. As shown above, this is unnecessary and has several limitations, particularly is we desire to extend the functionality such that the user can pass in a custom session directly.