Skip to content

Commit 9cb904d

Browse files
committed
added on_login and on_logout handlers and callbacks
1 parent 524a24f commit 9cb904d

File tree

5 files changed

+41
-19
lines changed

5 files changed

+41
-19
lines changed

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.6'
11+
VERSION = '1.1.7'

openfeed/generated/openfeed_api_pb2.py

Lines changed: 21 additions & 16 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: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ def __init__(self, username, password, server="openfeed.aws.barchart.com", debug
3838
self.on_connected = None
3939
self.on_disconnected = None
4040
self.on_error = None
41+
self.on_login = None
42+
self.on_logout = None
4143

4244
websocket.enableTrace(self.debug)
4345

@@ -229,10 +231,22 @@ def handleLogin(msg):
229231
raise Exception("Login has failed: ", msg)
230232

231233
self.token = msg.loginResponse.token
234+
235+
self.__callback(self.on_login, msg)
232236
self.__send_existing_interest()
233237

234238
return msg
235239

240+
def handleLogout(msg):
241+
242+
self.__callback(self.on_logout, msg)
243+
244+
if msg.logoutResponse.status.result == 115:
245+
if self.debug:
246+
print("Logout due to concurrent logins:", msg)
247+
248+
return msg
249+
236250
def handleHeartbeat(msg):
237251
self.__notify_heartbeat_listeners(msg)
238252
return msg
@@ -325,6 +339,7 @@ def handleOHLC(msg):
325339

326340
handlers = {
327341
"loginResponse": handleLogin,
342+
"logoutResponse": handleLogout,
328343
"heartBeat": handleHeartbeat,
329344
"exchangeResponse": handleExchangeRequest,
330345
"subscriptionResponse": handleSubscriptionResponse,
@@ -611,6 +626,8 @@ def handle_heartbeat(msg):
611626
of_client.on_error = lambda x: print("of-client: something went wrong:", x)
612627
of_client.on_disconnected = lambda x: print("of-client: disconnected")
613628
of_client.on_connected = lambda x: print("of-client: connected")
629+
of_client.on_login = lambda x: print("of-client: login:", x)
630+
of_client.on_logout = lambda x: print("of-client: logout:", x)
614631

615632
# blocking mode
616633
of_client.start(blocking=False)

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.6"
3+
version = "1.1.7"
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.6',
20+
version='1.1.7',
2121
author='Barchart',
2222
author_email='[email protected]',
2323
license='MIT',

0 commit comments

Comments
 (0)