From e73320575ecbb89080d7a41a644da615b0b7e2a5 Mon Sep 17 00:00:00 2001 From: Franco Zanuso Date: Fri, 6 Nov 2020 17:46:58 -0600 Subject: [PATCH] add market depth to market data suscription message --- setup.py | 2 +- src/pyRofex/__init__.py | 2 +- src/pyRofex/clients/websocket_rfx.py | 7 +++++-- src/pyRofex/components/messages.py | 2 +- src/pyRofex/service.py | 6 ++++-- 5 files changed, 12 insertions(+), 7 deletions(-) diff --git a/setup.py b/setup.py index a548a85..3a1594d 100644 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ setuptools.setup( name="pyRofex", - version="0.3.0", + version="0.3.1b1", author="Franco Zanuso", author_email="francozanuso89@gmail.com", description="Python connector for ROFEX's Rest and Websocket APIs.", diff --git a/src/pyRofex/__init__.py b/src/pyRofex/__init__.py index e78eb2b..a5e81d4 100644 --- a/src/pyRofex/__init__.py +++ b/src/pyRofex/__init__.py @@ -38,4 +38,4 @@ from .components.enums import Side from .components.enums import TimeInForce -__version__ = "0.3.0" +__version__ = "0.3.1b1" diff --git a/src/pyRofex/clients/websocket_rfx.py b/src/pyRofex/clients/websocket_rfx.py index 69ba4ce..4dc2095 100644 --- a/src/pyRofex/clients/websocket_rfx.py +++ b/src/pyRofex/clients/websocket_rfx.py @@ -206,7 +206,7 @@ def close_connection(self): """ self.ws_connection.close() - def market_data_subscription(self, tickers, entries, market): + def market_data_subscription(self, tickers, entries, market, depth): """ Creates and sends new Market Data Subscription Message through the connection. :param tickers: List of the tickers to subscribe. @@ -216,6 +216,8 @@ def market_data_subscription(self, tickers, entries, market): :type entries: List of MarketDataEntry (Enum). :param market: Market id associated to the tickers. :type market: Market (Enum). + :param depth: Market depth to received. default: 1 (top of book) + :type depth: int """ # Iterates through the tickers list and creates a new list of Instrument String using the INSTRUMENT Template. @@ -229,7 +231,8 @@ def market_data_subscription(self, tickers, entries, market): entries_string = ",".join(entries) # Creates a Market Data Subscription Message using the Template. - message = messages.MARKET_DATA_SUBSCRIPTION.format(entries=entries_string, + message = messages.MARKET_DATA_SUBSCRIPTION.format(depth=depth, + entries=entries_string, symbols=instruments_string) # Send the message through the connection. diff --git a/src/pyRofex/components/messages.py b/src/pyRofex/components/messages.py index 7c3538a..682b8e6 100644 --- a/src/pyRofex/components/messages.py +++ b/src/pyRofex/components/messages.py @@ -6,7 +6,7 @@ """ # Template for a Market Data Subscription message -MARKET_DATA_SUBSCRIPTION = '{{"type":"smd","level":1, "entries":[{entries}],"products":[{symbols}]}}' +MARKET_DATA_SUBSCRIPTION = '{{"type":"smd","level":1,"depth":{depth},"entries":[{entries}],"products":[{symbols}]}}' # Template for an Order Subscription message ORDER_SUBSCRIPTION = '{{"type":"os","account":{{"id":"{a}"}},"snapshotOnlyActive":{snapshot}}}' # Template to specify an instrument in a market data subscription message diff --git a/src/pyRofex/service.py b/src/pyRofex/service.py index 8bccef7..777b25f 100644 --- a/src/pyRofex/service.py +++ b/src/pyRofex/service.py @@ -494,7 +494,7 @@ def order_report_subscription(account=None, snapshot=True, handler=None, environ client.order_report_subscription(account, snapshot) -def market_data_subscription(tickers, entries, market=Market.ROFEX, handler=None, environment=None): +def market_data_subscription(tickers, entries, depth=1, market=Market.ROFEX, handler=None, environment=None): """Send a Market Data Subscription Message through the connection. :param tickers: list of the the instruments to be subscribe. @@ -502,6 +502,8 @@ def market_data_subscription(tickers, entries, market=Market.ROFEX, handler=None :param entries: List of market data entries that want to be received. Example: [MarketDataEntry.BIDS, MarketDataEntry.OFFERS] :type entries: List of MarketDataEntry (Enum). + :param depth: Market depth to received. default: 1 (top of book) + :type depth: int :param market: Market id associated to the tickers. Default Market.ROFEX. :type market: Market (Enum). :param handler: function that is going to be call when a new Market Data Message is received. Default None. @@ -523,7 +525,7 @@ def market_data_subscription(tickers, entries, market=Market.ROFEX, handler=None # Get the client for the environment and send the subscription message client = globals.environment_config[environment]["ws_client"] - client.market_data_subscription(tickers, entries, market) + client.market_data_subscription(tickers, entries, market, depth) def add_websocket_market_data_handler(handler, environment=None):