Skip to content

Commit

Permalink
Merge pull request #12 from matbarofex/Issue-11/add_book_depth_for_we…
Browse files Browse the repository at this point in the history
…bsocket_md

Add market depth to market data suscription message
  • Loading branch information
fzanuso authored Nov 6, 2020
2 parents 3fda0cd + e733205 commit 6848696
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 7 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setuptools.setup(
name="pyRofex",
version="0.3.0",
version="0.3.1b1",
author="Franco Zanuso",
author_email="[email protected]",
description="Python connector for ROFEX's Rest and Websocket APIs.",
Expand Down
2 changes: 1 addition & 1 deletion src/pyRofex/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,4 @@
from .components.enums import Side
from .components.enums import TimeInForce

__version__ = "0.3.0"
__version__ = "0.3.1b1"
7 changes: 5 additions & 2 deletions src/pyRofex/clients/websocket_rfx.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand All @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion src/pyRofex/components/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions src/pyRofex/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -494,14 +494,16 @@ 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.
:type tickers: List of str.
: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.
Expand All @@ -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):
Expand Down

0 comments on commit 6848696

Please sign in to comment.