Skip to content

Commit 524a24f

Browse files
committed
Read symbol from SubscriptionResponse message. Fixes no callbacks for subscriptions like: ES*0, ESM21, etc.
1 parent 469da65 commit 524a24f

File tree

8 files changed

+1101
-1033
lines changed

8 files changed

+1101
-1033
lines changed

build.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# build.sh
22
tmp_dir=$(mktemp -d -t ci-XXXXXXXXXX)
33

4-
git clone git@github.com:openfeed-org/proto $tmp_dir
4+
git clone https://github.com/openfeed-org/proto.git $tmp_dir
55
mv $tmp_dir/*.proto protos -f
66

77
rm -rf $temp

openfeed/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@
88

99
from .openfeed_client import OpenfeedClient
1010

11-
VERSION = '1.1.5'
11+
VERSION = '1.1.6'

openfeed/generated/openfeed_api_pb2.py

Lines changed: 189 additions & 154 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

openfeed/generated/openfeed_instrument_pb2.py

Lines changed: 171 additions & 165 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

openfeed/generated/openfeed_pb2.py

Lines changed: 725 additions & 705 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

openfeed/openfeed_client.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ def __init__(self, username, password, server="openfeed.aws.barchart.com", debug
2727

2828
self.instrument_definitions = {}
2929
self.instruments_by_symbol = {}
30+
self.subscription_symbol_by_marketid = {}
3031
self.snapshots = {}
3132

3233
self.symbol_handlers = {}
@@ -275,6 +276,7 @@ def handleSubscriptionResponse(msg):
275276
raise Exception("Subscription has failed: ", msg)
276277

277278
if len(msg.subscriptionResponse.symbol) > 0:
279+
self.subscription_symbol_by_marketid[msg.subscriptionResponse.marketId] = msg.subscriptionResponse.symbol
278280
self.__notify_symbol_listeners(
279281
self.__create_instrument(msg.subscriptionResponse.symbol), msg)
280282
else:
@@ -382,21 +384,26 @@ def on_open(ws):
382384

383385
def __notify_symbol_listeners(self, instrument, msg):
384386

385-
# TODO review symbology handling, subbing by one and keying off the other can create unexpected results
386-
# for example subscribing to "ZCYAIA40.CM" will come back with OF symbol (less the suffix) in `instrument.symbol`
387-
# given the below, if the instrument contains duplicate `instrument.symbols`, the listeners will get duplicate callbacks
387+
symbol_key = ""
388+
389+
if instrument.marketId in self.subscription_symbol_by_marketid:
390+
symbol_key = self.subscription_symbol_by_marketid[instrument.marketId]
388391

389392
for s in instrument.symbols:
390393
if s.symbol not in self.symbol_handlers or s.vendor != "Barchart":
391394
continue
395+
symbol_key = s.symbol
392396

393-
for cb in self.symbol_handlers[s.symbol]:
397+
if symbol_key != "":
398+
for cb in self.symbol_handlers[symbol_key]:
394399
try:
395400
cb.callback(msg)
396401
except Exception as e:
397402
if self.debug:
398-
print("Failed to notify `symbol` callback:", s, e)
403+
print("Failed to notify `symbol` callback:", symbol_key, e)
399404
self.__callback(self.on_error, e)
405+
else:
406+
print("got a message but have no handlers", instrument, msg)
400407

401408
def __notify_exchange_listeners(self, exchange, msg):
402409
if exchange not in self.exchange_handlers:

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "openfeed"
3-
version = "1.1.5"
3+
version = "1.1.6"
44
description = "Python SDK for Openfeed"
55
authors = ["Barchart <[email protected]>"]
66
license = "MIT"

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
setup(
1919
name='openfeed',
20-
version='1.1.5',
20+
version='1.1.6',
2121
author='Barchart',
2222
author_email='[email protected]',
2323
license='MIT',

0 commit comments

Comments
 (0)