From 110b4b46e1cc95ffdedf62a1ba54ef8d06ab0817 Mon Sep 17 00:00:00 2001 From: itsdeka Date: Mon, 9 Aug 2021 12:15:56 +0200 Subject: [PATCH 1/5] added full_orderbook.py example --- bfxapi/examples/ws/full_orderbook.py | 80 ++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 bfxapi/examples/ws/full_orderbook.py diff --git a/bfxapi/examples/ws/full_orderbook.py b/bfxapi/examples/ws/full_orderbook.py new file mode 100644 index 00000000..d8678e36 --- /dev/null +++ b/bfxapi/examples/ws/full_orderbook.py @@ -0,0 +1,80 @@ +import os +import sys +import time +from collections import OrderedDict +sys.path.append('../../../') + +from bfxapi import Client + +bfx = Client( + manageOrderBooks=True +) + +class OrderBook: + def __init__(self, snapshot): + self.bids = OrderedDict() + self.asks = OrderedDict() + self.load(snapshot) + + def load(self, snapshot): + for record in snapshot: + if record[2] >= 0: + self.bids[record[0]] = { + 'count': record[1], + 'amount': record[2] + } + else: + self.asks[record[0]] = { + 'count': record[1], + 'amount': record[2] + } + + def update(self, record): + # count is 0 + if record[1] == 0: + if record[2] == 1: + # remove from bids + del self.bids[record[0]] + elif record[2] == -1: + # remove from asks + del self.asks[record[0]] + elif record[1] > 0: + if record[2] > 0: + # update bids + if record[0] not in self.bids: + self.bids[record[0]] = {} + self.bids[record[0]]['count'] = record[1] + self.bids[record[0]]['amount'] = record[2] + elif record[2] < 0: + # update asks + if record[0] not in self.asks: + self.asks[record[0]] = {} + self.asks[record[0]]['count'] = record[1] + self.asks[record[0]]['amount'] = record[2] + +obs = {} + +@bfx.ws.on('error') +def log_error(err): + print ("Error: {}".format(err)) + +@bfx.ws.on('order_book_update') +def log_update(data): + obs[data['symbol']].update(data['data']) + +@bfx.ws.on('order_book_snapshot') +def log_snapshot(data): + obs[data['symbol']] = OrderBook(data['data']) + +async def start(): + await bfx.ws.subscribe('book', 'tBTCUSD') + +bfx.ws.on('connected', start) +bfx.ws.run() + +for n in range(0, 10): + time.sleep(2) + for key in obs: + print(f"Printing {key} orderbook...") + print(f"{obs[key].bids}\n") + print(f"{obs[key].asks}\n") From 8e87cf17cea7fbb620e9bcad251a8d90f46b903f Mon Sep 17 00:00:00 2001 From: itsdeka Date: Mon, 9 Aug 2021 12:18:13 +0200 Subject: [PATCH 2/5] added full_orderbook.py example --- CHANGELOG | 3 +++ bfxapi/version.py | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG b/CHANGELOG index 836ffc8a..f04969b1 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,6 @@ +1.1.18 +-) Added orderbook implementation example (ws) + 1.1.16 -) Implemented Margin Info (rest) -) Implemented claim position (rest) diff --git a/bfxapi/version.py b/bfxapi/version.py index 3bf093c8..370ebdd0 100644 --- a/bfxapi/version.py +++ b/bfxapi/version.py @@ -2,4 +2,4 @@ This module contains the current version of the bfxapi lib """ -__version__ = '1.1.16' +__version__ = '1.1.18' From df0bc58305e72ff07828945a53391236a88b325f Mon Sep 17 00:00:00 2001 From: itsdeka Date: Mon, 9 Aug 2021 12:30:41 +0200 Subject: [PATCH 3/5] ver --- CHANGELOG | 2 +- setup.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index f04969b1..1c47b15e 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,4 +1,4 @@ -1.1.18 +1.1.17 -) Added orderbook implementation example (ws) 1.1.16 diff --git a/setup.py b/setup.py index c638f7a3..d0c62787 100644 --- a/setup.py +++ b/setup.py @@ -11,7 +11,7 @@ here = path.abspath(path.dirname(__file__)) setup( name='bitfinex-api-py', - version='1.1.15', + version='1.1.17', description='Official Bitfinex Python API', long_description='A Python reference implementation of the Bitfinex API for both REST and websocket interaction', long_description_content_type='text/markdown', From 48e8455180f1d69c41feff11e8d0f055f11dddf4 Mon Sep 17 00:00:00 2001 From: itsdeka Date: Mon, 9 Aug 2021 12:31:16 +0200 Subject: [PATCH 4/5] ver --- bfxapi/version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bfxapi/version.py b/bfxapi/version.py index 370ebdd0..374b348d 100644 --- a/bfxapi/version.py +++ b/bfxapi/version.py @@ -2,4 +2,4 @@ This module contains the current version of the bfxapi lib """ -__version__ = '1.1.18' +__version__ = '1.1.17' From e1e8eb57535dea28cf1b8d99bafb6f588fed4c29 Mon Sep 17 00:00:00 2001 From: itsdeka Date: Thu, 12 Aug 2021 16:33:04 +0200 Subject: [PATCH 5/5] semver adjustment --- CHANGELOG | 2 +- bfxapi/version.py | 2 +- setup.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 1c47b15e..6949d641 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,4 +1,4 @@ -1.1.17 +1.2.1 -) Added orderbook implementation example (ws) 1.1.16 diff --git a/bfxapi/version.py b/bfxapi/version.py index 374b348d..f00d03ff 100644 --- a/bfxapi/version.py +++ b/bfxapi/version.py @@ -2,4 +2,4 @@ This module contains the current version of the bfxapi lib """ -__version__ = '1.1.17' +__version__ = '1.2.1' diff --git a/setup.py b/setup.py index d0c62787..b008d751 100644 --- a/setup.py +++ b/setup.py @@ -11,7 +11,7 @@ here = path.abspath(path.dirname(__file__)) setup( name='bitfinex-api-py', - version='1.1.17', + version='1.2.1', description='Official Bitfinex Python API', long_description='A Python reference implementation of the Bitfinex API for both REST and websocket interaction', long_description_content_type='text/markdown',