Add implementation for BfxWebSocketClient::resubscribe and BfxWebSocketBucket::resubscribe.

This commit is contained in:
Davide Casale
2023-07-28 17:29:41 +02:00
parent 26f25e5848
commit f39b054397
2 changed files with 20 additions and 1 deletions

View File

@@ -84,7 +84,8 @@ class BfxWebSocketBucket(Connection):
_subscription = cast(Dict[str, Any], subscription)
await self.subscribe( \
sub_id=_subscription.pop("subId"), **_subscription)
sub_id=_subscription.pop("subId"),
**_subscription)
self.__subscriptions.clear()
@@ -121,6 +122,18 @@ class BfxWebSocketBucket(Connection):
await self._websocket.send(message)
@Connection.require_websocket_connection
async def resubscribe(self, sub_id: str) -> None:
for subscription in self.__subscriptions.values():
if subscription["subId"] == sub_id:
_subscription = cast(Dict[str, Any], subscription)
await self.unsubscribe(sub_id=sub_id)
await self.subscribe( \
sub_id=_subscription.pop("subId"),
**_subscription)
@Connection.require_websocket_connection
async def close(self, code: int = 1000, reason: str = str()) -> None:
await self._websocket.close(code=code, reason=reason)

View File

@@ -311,6 +311,12 @@ class BfxWebSocketClient(Connection, Connection.Authenticable):
if bucket.has(sub_id=sub_id):
await bucket.unsubscribe(sub_id=sub_id)
@Connection.require_websocket_connection
async def resubscribe(self, sub_id: str) -> None:
for bucket in self.__buckets:
if bucket.has(sub_id=sub_id):
await bucket.resubscribe(sub_id=sub_id)
@Connection.require_websocket_connection
async def close(self, code: int = 1000, reason: str = str()) -> None:
for bucket in self.__buckets: