-
Notifications
You must be signed in to change notification settings - Fork 69
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SECF() implementation #50
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -182,6 +182,20 @@ def _init_services(self): | |
raise ConnectionError("Could not open a //blp/exrsvc service") | ||
self.exrService = self._session.getService("//blp/exrsvc") | ||
|
||
opened = self._session.openService("//blp/instruments") | ||
ev = self._session.nextEvent() | ||
ev_name = _EVENT_DICT[ev.eventType()] | ||
logger.info("Event Type: %s" % ev_name) | ||
for msg in ev: | ||
logger.info("Message Received:\n%s" % msg) | ||
if ev.eventType() != blpapi.Event.SERVICE_STATUS: | ||
raise RuntimeError("Expected a SERVICE_STATUS event but " | ||
"received a %s" % ev_name) | ||
if not opened: | ||
logger.warning("Failed to open //blp/exrsvc") | ||
raise ConnectionError("Could not open a //blp/instruments service") | ||
self.instrService = self._session.getService("//blp/instruments") | ||
|
||
return self | ||
|
||
def _create_req(self, rtype, tickers, flds, ovrds, setvals): | ||
|
@@ -731,6 +745,44 @@ def bsrch(self, domain): | |
data.append(f.getElementAsString("StringValue")) | ||
return pd.DataFrame(data) | ||
|
||
def secf(self, query, max_results=10, yk_filter="NONE"): | ||
""" | ||
This function uses the Bloomberg API to retrieve Bloomberg | ||
SECF Data queries. Returns list of tickers. | ||
|
||
Parameters | ||
---------- | ||
query: string | ||
A character string representing the desired query. Example "IBM" | ||
max_results: int | ||
Maximum number of results to return. Default 10. | ||
yk_filter: string | ||
A character string respresenting a Bloomberg yellow-key to limit | ||
search results to. Valid values are: CMDT, EQTY, MUNI, | ||
PRFD, CLNT, MMKT, GOVT, CORP, INDX, CURR, MTGE. Default NONE. | ||
|
||
Returns | ||
------- | ||
data: list | ||
List of bloomberg tickers from the SECF function | ||
""" | ||
logger = _get_logger(self.debug) | ||
request = self.instrService.createRequest("instrumentListRequest") | ||
request.set("query", query) | ||
request.set("maxResults", max_results) | ||
request.set("yellowKeyFilter", "YK_FILTER_%s" % yk_filter) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think to be consistent with how parameters are set elsewhere in the library, this convenience string concatenation should not be done for the user, e.g. the user should pass
|
||
logger.info("Sending Request:\n%s" % request) | ||
self._session.sendRequest(request, identity=self._identity) | ||
data = [] | ||
for msg in self._receive_events(): | ||
for r in msg.getElement("results").values(): | ||
ticker = r.getElementAsString("security") | ||
ticker = ticker.replace('<', ' ').replace('>', '').upper() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it is better to leave this line out. The general philosophy of |
||
descr = r.getElementAsString("description") | ||
if not descr.endswith('(Multiple Matches)'): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What exactly is the check for Multiple Matches doing? Is there a sample request you could add in the thread so I can see when this is used? |
||
data.append(ticker) | ||
return data | ||
|
||
def stop(self): | ||
""" | ||
Close the blp session | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should be
logger.warning("Failed to //blp/instruments")