mirror of
https://github.com/aljazceru/bitfinex-api-py.git
synced 2025-12-19 06:44:22 +01:00
Add automatic deletion for buckets that reach zero subscriptions (e.g. after a call to BfxWebSocketClient::unsubscribe).
This commit is contained in:
@@ -30,7 +30,8 @@ from bfxapi.websocket.exceptions import \
|
||||
ReconnectionTimeoutError, \
|
||||
VersionMismatchError, \
|
||||
UnknownChannelError, \
|
||||
UnknownSubscriptionError
|
||||
UnknownSubscriptionError, \
|
||||
SubIdError
|
||||
|
||||
from .bfx_websocket_bucket import BfxWebSocketBucket
|
||||
|
||||
@@ -265,6 +266,11 @@ class BfxWebSocketClient(Connection):
|
||||
raise UnknownChannelError("Available channels are: " + \
|
||||
"ticker, trades, book, candles and status.")
|
||||
|
||||
for bucket in self.__buckets:
|
||||
if sub_id in bucket.ids:
|
||||
raise SubIdError("sub_id must be " + \
|
||||
"unique for all subscriptions.")
|
||||
|
||||
for bucket in self.__buckets:
|
||||
if not bucket.is_full:
|
||||
return await bucket.subscribe( \
|
||||
@@ -277,8 +283,15 @@ class BfxWebSocketClient(Connection):
|
||||
|
||||
@Connection.require_websocket_connection
|
||||
async def unsubscribe(self, sub_id: str) -> None:
|
||||
# pylint: disable-next=consider-using-dict-items
|
||||
for bucket in self.__buckets:
|
||||
if bucket.has(sub_id):
|
||||
if bucket.count == 1:
|
||||
del self.__buckets[bucket]
|
||||
|
||||
return await bucket.close( \
|
||||
code=1001, reason="Going Away")
|
||||
|
||||
return await bucket.unsubscribe(sub_id)
|
||||
|
||||
raise UnknownSubscriptionError("Unable to find " + \
|
||||
|
||||
Reference in New Issue
Block a user