mirror of
https://github.com/aljazceru/bitfinex-api-py.git
synced 2025-12-20 07:14:20 +01:00
Subscriptions: limit channels to 25 per instance
This commit is contained in:
@@ -10,6 +10,7 @@ import time
|
|||||||
from ..utils.CustomLogger import CustomLogger
|
from ..utils.CustomLogger import CustomLogger
|
||||||
from ..models import Subscription
|
from ..models import Subscription
|
||||||
|
|
||||||
|
MAX_CHANNEL_COUNT = 25
|
||||||
|
|
||||||
class SubscriptionManager:
|
class SubscriptionManager:
|
||||||
|
|
||||||
@@ -30,12 +31,17 @@ class SubscriptionManager:
|
|||||||
@param timeframe: sepecifies the data timeframe between each candle (only required
|
@param timeframe: sepecifies the data timeframe between each candle (only required
|
||||||
for the candles channel)
|
for the candles channel)
|
||||||
"""
|
"""
|
||||||
|
# make sure we dont over subscribe the connection
|
||||||
|
if self.channel_count() >= MAX_CHANNEL_COUNT:
|
||||||
|
raise Exception("Subscribe error - max channel count ({0}) reached".format(self.channel_count()))
|
||||||
|
return False
|
||||||
# create a new subscription
|
# create a new subscription
|
||||||
subscription = Subscription(
|
subscription = Subscription(
|
||||||
self.bfxapi, channel_name, symbol, timeframe, **kwargs)
|
self.bfxapi, channel_name, symbol, timeframe, **kwargs)
|
||||||
self.logger.info("Subscribing to channel {}".format(channel_name))
|
self.logger.info("Subscribing to channel {}".format(channel_name))
|
||||||
key = "{}_{}".format(channel_name, subscription.key or symbol)
|
key = "{}_{}".format(channel_name, subscription.key or symbol)
|
||||||
self.pending_subscriptions[key] = subscription
|
self.pending_subscriptions[key] = subscription
|
||||||
|
|
||||||
await subscription.subscribe()
|
await subscription.subscribe()
|
||||||
|
|
||||||
async def confirm_subscription(self, raw_ws_data):
|
async def confirm_subscription(self, raw_ws_data):
|
||||||
@@ -109,6 +115,12 @@ class SubscriptionManager:
|
|||||||
# already unsibscribed, so just subscribe
|
# already unsibscribed, so just subscribe
|
||||||
await sub.subscribe()
|
await sub.subscribe()
|
||||||
|
|
||||||
|
def channel_count(self):
|
||||||
|
"""
|
||||||
|
Returns the number of cannels
|
||||||
|
"""
|
||||||
|
return len(self.pending_subscriptions) + len(self.subscriptions_chanid)
|
||||||
|
|
||||||
def is_subscribed(self, chan_id):
|
def is_subscribed(self, chan_id):
|
||||||
"""
|
"""
|
||||||
Returns True if the channel with the given chanId is currenly subscribed to
|
Returns True if the channel with the given chanId is currenly subscribed to
|
||||||
|
|||||||
Reference in New Issue
Block a user