From 1f73c09eb3eae01bf74b2cb2116ba78217522630 Mon Sep 17 00:00:00 2001 From: Leonardo Horta Date: Mon, 30 Jan 2023 19:51:59 -0300 Subject: [PATCH] mktbar feature --- doc/source/quickstart.ipynb | 23 ++++++++++++++++++----- src/blp/blp.py | 8 ++++++-- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/doc/source/quickstart.ipynb b/doc/source/quickstart.ipynb index 17344d9..21c2a2b 100644 --- a/doc/source/quickstart.ipynb +++ b/doc/source/quickstart.ipynb @@ -1608,6 +1608,7 @@ } ], "source": [ + "# Ticks\n", "with blp.BlpStream() as bs:\n", " bs.subscribe({\"USDCAD Curncy\": {\"fields\": [\"LAST_PRICE\"]}})\n", " n = 0\n", @@ -1615,10 +1616,7 @@ " print(json.dumps(ev, indent=2, cls=CustomJSONEncoder))\n", " n += 1\n", " if n > 1:\n", - " break\n", - "\n", - "\n", - "\n" + " break\n" ] }, { @@ -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": { diff --git a/src/blp/blp.py b/src/blp/blp.py index 0ac26f9..c27c405 100644 --- a/src/blp/blp.py +++ b/src/blp/blp.py @@ -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__) @@ -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)