mirror of
https://github.com/aljazceru/bitfinex-api-py.git
synced 2025-12-19 14:54:21 +01:00
SubscriptionManager: add docstrings
This commit is contained in:
@@ -16,6 +16,14 @@ class SubscriptionManager:
|
|||||||
self.logger = CustomLogger('BfxSubscriptionManager', logLevel=logLevel)
|
self.logger = CustomLogger('BfxSubscriptionManager', logLevel=logLevel)
|
||||||
|
|
||||||
async def subscribe(self, channel_name, symbol, timeframe=None, **kwargs):
|
async def subscribe(self, channel_name, symbol, timeframe=None, **kwargs):
|
||||||
|
"""
|
||||||
|
Subscribe to a new channel
|
||||||
|
|
||||||
|
@param channel_name: the name of the channel i.e 'books', 'candles'
|
||||||
|
@param symbol: the trading symbol i.e 'tBTCUSD'
|
||||||
|
@param timeframe: sepecifies the data timeframe between each candle (only required
|
||||||
|
for the candles channel)
|
||||||
|
"""
|
||||||
# create a new subscription
|
# create a new subscription
|
||||||
subscription = Subscription(self.bfxapi.ws, channel_name, symbol, timeframe, **kwargs)
|
subscription = Subscription(self.bfxapi.ws, channel_name, symbol, timeframe, **kwargs)
|
||||||
self.logger.info("Subscribing to channel {}".format(channel_name))
|
self.logger.info("Subscribing to channel {}".format(channel_name))
|
||||||
@@ -61,6 +69,12 @@ class SubscriptionManager:
|
|||||||
return self.subscriptions_chanid[chanId]
|
return self.subscriptions_chanid[chanId]
|
||||||
|
|
||||||
async def unsubscribe(self, chanId, onComplete=None):
|
async def unsubscribe(self, chanId, onComplete=None):
|
||||||
|
"""
|
||||||
|
Unsubscribe from the channel with the given chanId
|
||||||
|
|
||||||
|
@param onComplete: function called when the bitfinex websocket resoponds with
|
||||||
|
a signal that confirms the subscription has been unsubscribed to
|
||||||
|
"""
|
||||||
sub = self.subscriptions_chanid[chanId]
|
sub = self.subscriptions_chanid[chanId]
|
||||||
if onComplete:
|
if onComplete:
|
||||||
self.unsubscribe_callbacks[sub.sub_id] = onComplete
|
self.unsubscribe_callbacks[sub.sub_id] = onComplete
|
||||||
@@ -68,6 +82,11 @@ class SubscriptionManager:
|
|||||||
await self.subscriptions_chanid[chanId].unsubscribe()
|
await self.subscriptions_chanid[chanId].unsubscribe()
|
||||||
|
|
||||||
async def resubscribe(self, chanId):
|
async def resubscribe(self, chanId):
|
||||||
|
"""
|
||||||
|
Unsubscribes and then subscribes to the channel with the given Id
|
||||||
|
|
||||||
|
This function is mostly used to force the channel to produce a fresh snapshot.
|
||||||
|
"""
|
||||||
sub = self.subscriptions_chanid[chanId]
|
sub = self.subscriptions_chanid[chanId]
|
||||||
async def re_sub():
|
async def re_sub():
|
||||||
await sub.subscribe()
|
await sub.subscribe()
|
||||||
@@ -79,11 +98,17 @@ class SubscriptionManager:
|
|||||||
await sub.subscribe()
|
await sub.subscribe()
|
||||||
|
|
||||||
def is_subscribed(self, chanId):
|
def is_subscribed(self, chanId):
|
||||||
|
"""
|
||||||
|
Returns True if the channel with the given chanId is currenly subscribed to
|
||||||
|
"""
|
||||||
if chanId not in self.subscriptions_chanid:
|
if chanId not in self.subscriptions_chanid:
|
||||||
return False
|
return False
|
||||||
return self.subscriptions_chanid[chanId].is_subscribed()
|
return self.subscriptions_chanid[chanId].is_subscribed()
|
||||||
|
|
||||||
async def unsubscribe_all(self):
|
async def unsubscribe_all(self):
|
||||||
|
"""
|
||||||
|
Unsubscribe from all channels.
|
||||||
|
"""
|
||||||
task_batch = []
|
task_batch = []
|
||||||
for chanId in self.subscriptions_chanid:
|
for chanId in self.subscriptions_chanid:
|
||||||
sub = self.get(chanId)
|
sub = self.get(chanId)
|
||||||
@@ -94,6 +119,9 @@ class SubscriptionManager:
|
|||||||
await asyncio.wait(*[ task_batch ])
|
await asyncio.wait(*[ task_batch ])
|
||||||
|
|
||||||
async def resubscribe_all(self):
|
async def resubscribe_all(self):
|
||||||
|
"""
|
||||||
|
Unsubscribe and then subscribe to all channels
|
||||||
|
"""
|
||||||
task_batch = []
|
task_batch = []
|
||||||
for chanId in self.subscriptions_chanid:
|
for chanId in self.subscriptions_chanid:
|
||||||
task_batch += [
|
task_batch += [
|
||||||
|
|||||||
Reference in New Issue
Block a user