diff --git a/bfxapi/models/Subscription.py b/bfxapi/models/Subscription.py index 72da70c..0b3841c 100644 --- a/bfxapi/models/Subscription.py +++ b/bfxapi/models/Subscription.py @@ -4,7 +4,15 @@ Module used to describe all of the different data types import time import json +from random import randint +def generate_sub_id(): + """ + Generates a unique id in the form of 12345566-12334556 + """ + prefix = str(int(round(time.time() * 1000))) + suffix = str(randint(0, 9999999)) + return "{}-{}".format(prefix, suffix) class Subscription: """ @@ -23,7 +31,7 @@ class Subscription: self.chan_id = None if timeframe: self.key = 'trade:{}:{}'.format(self.timeframe, self.symbol) - self.sub_id = int(round(time.time() * 1000)) + self.sub_id = generate_sub_id() self.send_payload = self._generate_payload(**kwargs) def confirm_subscription(self, chan_id): diff --git a/bfxapi/models/subscription.py b/bfxapi/models/subscription.py index 72da70c..0b3841c 100644 --- a/bfxapi/models/subscription.py +++ b/bfxapi/models/subscription.py @@ -4,7 +4,15 @@ Module used to describe all of the different data types import time import json +from random import randint +def generate_sub_id(): + """ + Generates a unique id in the form of 12345566-12334556 + """ + prefix = str(int(round(time.time() * 1000))) + suffix = str(randint(0, 9999999)) + return "{}-{}".format(prefix, suffix) class Subscription: """ @@ -23,7 +31,7 @@ class Subscription: self.chan_id = None if timeframe: self.key = 'trade:{}:{}'.format(self.timeframe, self.symbol) - self.sub_id = int(round(time.time() * 1000)) + self.sub_id = generate_sub_id() self.send_payload = self._generate_payload(**kwargs) def confirm_subscription(self, chan_id): diff --git a/bfxapi/websockets/GenericWebsocket.py b/bfxapi/websockets/GenericWebsocket.py index c80da3d..0c44f59 100644 --- a/bfxapi/websockets/GenericWebsocket.py +++ b/bfxapi/websockets/GenericWebsocket.py @@ -56,7 +56,7 @@ class GenericWebsocket: async def _connect(self, host): async with websockets.connect(host) as websocket: self.ws = websocket - self.logger.info("Wesocket connected to {}".format(self.host)) + self.logger.info("Wesocket connected to {}".format(host)) while True: await asyncio.sleep(0) message = await websocket.recv() diff --git a/bfxapi/websockets/SubscriptionManager.py b/bfxapi/websockets/SubscriptionManager.py index cf2fe87..8caf995 100644 --- a/bfxapi/websockets/SubscriptionManager.py +++ b/bfxapi/websockets/SubscriptionManager.py @@ -63,11 +63,11 @@ class SubscriptionManager: chan_id = raw_ws_data.get("chanId") sub = self.subscriptions_chanid[chan_id] sub.confirm_unsubscribe() - self.bfxapi._emit('unsubscribed', sub) # call onComplete callback if exists if sub.sub_id in self.unsubscribe_callbacks: await self.unsubscribe_callbacks[sub.sub_id]() del self.unsubscribe_callbacks[sub.sub_id] + self.bfxapi._emit('unsubscribed', sub) def get(self, chan_id): return self.subscriptions_chanid[chan_id]