From a22d43a0e0627b018b4cabf8212e7ea8f29d7de3 Mon Sep 17 00:00:00 2001 From: Jacob Plaster Date: Fri, 4 Jan 2019 16:37:00 +0000 Subject: [PATCH 1/4] subscription: fix unsubscrbe --- bfxapi/models/Subscription.py | 2 +- bfxapi/models/subscription.py | 2 +- bfxapi/websockets/BfxWebsocket.py | 5 ++++- bfxapi/websockets/SubscriptionManager.py | 2 +- 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/bfxapi/models/Subscription.py b/bfxapi/models/Subscription.py index 331a046..bc32ba4 100644 --- a/bfxapi/models/Subscription.py +++ b/bfxapi/models/Subscription.py @@ -39,7 +39,7 @@ class Subscription: """ if not self.is_subscribed(): raise Exception("Subscription is not subscribed to websocket") - payload = {'event': 'unsubscribe', 'chan_id': self.chan_id} + payload = {'event': 'unsubscribe', 'chanId': self.chan_id} await self._ws.send(json.dumps(payload)) async def subscribe(self): diff --git a/bfxapi/models/subscription.py b/bfxapi/models/subscription.py index 331a046..bc32ba4 100644 --- a/bfxapi/models/subscription.py +++ b/bfxapi/models/subscription.py @@ -39,7 +39,7 @@ class Subscription: """ if not self.is_subscribed(): raise Exception("Subscription is not subscribed to websocket") - payload = {'event': 'unsubscribe', 'chan_id': self.chan_id} + payload = {'event': 'unsubscribe', 'chanId': self.chan_id} await self._ws.send(json.dumps(payload)) async def subscribe(self): diff --git a/bfxapi/websockets/BfxWebsocket.py b/bfxapi/websockets/BfxWebsocket.py index 172d291..e2e304c 100644 --- a/bfxapi/websockets/BfxWebsocket.py +++ b/bfxapi/websockets/BfxWebsocket.py @@ -194,7 +194,10 @@ class BfxWebsocket(GenericWebsocket): await self.subscriptionManager.confirm_unsubscribe(data) async def _system_error_handler(self, data): - self._emit('error', data) + err_string = ERRORS[data.get('code', 10000)] + err_string = "{} - {}".format(ERRORS[data.get('code', 10000)], + data.get("msg", "")) + self._emit('error', Exception(err_string)) async def _system_auth_handler(self, data): if data.get('status') == 'FAILED': diff --git a/bfxapi/websockets/SubscriptionManager.py b/bfxapi/websockets/SubscriptionManager.py index b6be132..df961ee 100644 --- a/bfxapi/websockets/SubscriptionManager.py +++ b/bfxapi/websockets/SubscriptionManager.py @@ -91,7 +91,7 @@ class SubscriptionManager: This function is mostly used to force the channel to produce a fresh snapshot. """ - sub = self.subscriptions_chanid[chan_d] + sub = self.subscriptions_chanid[chan_id] async def re_sub(): await sub.subscribe() From e259abd56871dc666ecdefd7fb5543b69bd92c81 Mon Sep 17 00:00:00 2001 From: Jacob Plaster Date: Fri, 11 Jan 2019 14:37:16 +0000 Subject: [PATCH 2/4] README: reference medium tutorial article --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 52b5e33..81788e2 100644 --- a/README.md +++ b/README.md @@ -278,6 +278,8 @@ Get the public orderbook of a given symbol For more info on how to use this library please see the example scripts in the `bfxapi/examples` directory. Here you will find usage of all interface exposed functions for both the rest and websocket. +Also please see [this medium article](https://medium.com/@Bitfinex/15f201ad20d4) for a tutorial. + ## Contributing 1. Fork it ( https://github.com/[my-github-username]/bitfinex/fork ) From 504f8422b4dfdee2affb7459181bf41f5f78fae4 Mon Sep 17 00:00:00 2001 From: Jacob Plaster Date: Fri, 11 Jan 2019 14:37:44 +0000 Subject: [PATCH 3/4] BfxWebsocket: handle ws errors correctly --- bfxapi/websockets/BfxWebsocket.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bfxapi/websockets/BfxWebsocket.py b/bfxapi/websockets/BfxWebsocket.py index e2e304c..a03097b 100644 --- a/bfxapi/websockets/BfxWebsocket.py +++ b/bfxapi/websockets/BfxWebsocket.py @@ -194,8 +194,8 @@ class BfxWebsocket(GenericWebsocket): await self.subscriptionManager.confirm_unsubscribe(data) async def _system_error_handler(self, data): - err_string = ERRORS[data.get('code', 10000)] - err_string = "{} - {}".format(ERRORS[data.get('code', 10000)], + err_string = self.ERRORS[data.get('code', 10000)] + err_string = "{} - {}".format(self.ERRORS[data.get('code', 10000)], data.get("msg", "")) self._emit('error', Exception(err_string)) From 500e662f35d1413ff5f14468bc3f4b6ba1364c08 Mon Sep 17 00:00:00 2001 From: Jacob Plaster Date: Fri, 11 Jan 2019 14:38:09 +0000 Subject: [PATCH 4/4] BfxRest: add ability to specify timeframe when seeding candles --- bfxapi/rest/BfxRest.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bfxapi/rest/BfxRest.py b/bfxapi/rest/BfxRest.py index e74ae22..129abf8 100644 --- a/bfxapi/rest/BfxRest.py +++ b/bfxapi/rest/BfxRest.py @@ -67,11 +67,11 @@ class BfxRest: # Public Data # ################################################## - async def get_seed_candles(self, symbol): + async def get_seed_candles(self, symbol, tf='1m'): """ Used by the honey framework, this function gets the last 4k candles. """ - endpoint = 'candles/trade:1m:{}/hist?limit=5000&_bfx=1'.format(symbol) + endpoint = 'candles/trade:{}:{}/hist?limit=5000&_bfx=1'.format(tf, symbol) time_difference = (1000 * 60) * 5000 # get now to the nearest min now = int(round((time.time() // 60 * 60) * 1000))