Skip to content

Commit

Permalink
Merge pull request #22 from obronco/mktbar_feature
Browse files Browse the repository at this point in the history
mktbar feature
  • Loading branch information
matthewgilbert authored Feb 11, 2023
2 parents 5a08abb + 1f73c09 commit a413d2d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
23 changes: 18 additions & 5 deletions doc/source/quickstart.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -1608,17 +1608,15 @@
}
],
"source": [
"# Ticks\n",
"with blp.BlpStream() as bs:\n",
" bs.subscribe({\"USDCAD Curncy\": {\"fields\": [\"LAST_PRICE\"]}})\n",
" n = 0\n",
" for ev in bs.events(timeout=60):\n",
" print(json.dumps(ev, indent=2, cls=CustomJSONEncoder))\n",
" n += 1\n",
" if n > 1:\n",
" break\n",
"\n",
"\n",
"\n"
" break\n"
]
},
{
Expand All @@ -1627,7 +1625,22 @@
"id": "dying-gabriel",
"metadata": {},
"outputs": [],
"source": []
"source": [
"# Bars\n",
"with blp.BlpStream(setDefaultSubscriptionService=\"//blp/mktbar\") as bs:\n",
" bs.subscribe({\n",
" \"USDCAD Curncy\": {\n",
" \"fields\": [\"LAST_PRICE\"],\n",
" \"options\": \"interval=1&start_time=00:00&end_time=23:59\"\n",
" }\n",
" })\n",
" n = 0\n",
" for ev in bs.events(timeout=60):\n",
" print(json.dumps(ev, indent=2, cls=CustomJSONEncoder))\n",
" n += 1\n",
" if n > 1:\n",
" break\n"
]
}
],
"metadata": {
Expand Down
8 changes: 6 additions & 2 deletions src/blp/blp.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,11 @@
_TOKEN_FAILURE = blpapi.Name("TokenGenerationFailure")
_SESSION_TERMINATED = blpapi.Name("SessionTerminated")
_SESSION_DOWN = blpapi.Name("SessionConnectionDown")
_MARKET_DATA_EVENTS = blpapi.Name("MarketDataEvents")
_MARKET_DATA_EVENTS = [
blpapi.Name("MarketDataEvents"),
blpapi.Name("MarketBarStart"),
blpapi.Name("MarketBarUpdate")
]

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -333,7 +337,7 @@ def subscription_status_event(self, event):
def marketdata_event(self, event):
event_name = _EVENT_DICT[event.eventType()]
for n, msg in enumerate(event):
if msg.messageType() == _MARKET_DATA_EVENTS:
if msg.messageType() in _MARKET_DATA_EVENTS:
self.data_queue.put(message_to_dict(msg))
else:
self.other_message(event_name, n, msg)
Expand Down

0 comments on commit a413d2d

Please sign in to comment.