From 378aeb21e8bf85356d031a80d7b3a64902d28c2e Mon Sep 17 00:00:00 2001 From: Jacob Plaster Date: Tue, 27 Nov 2018 15:12:48 +0000 Subject: [PATCH] examples: Add resubscribe_orderbook example --- bfxapi/examples/resubscribe_orderbook.py | 37 ++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 bfxapi/examples/resubscribe_orderbook.py diff --git a/bfxapi/examples/resubscribe_orderbook.py b/bfxapi/examples/resubscribe_orderbook.py new file mode 100644 index 0000000..a48c3db --- /dev/null +++ b/bfxapi/examples/resubscribe_orderbook.py @@ -0,0 +1,37 @@ +import os +import sys +sys.path.append('../') + +from bfxapi import Client + +bfx = Client( + logLevel='INFO' +) + +@bfx.ws.on('error') +def log_error(err): + print ("Error: {}".format(err)) + +@bfx.ws.on('unsubscribed') +async def on_unsubscribe(subscription): + print ("Unsubscribed from {}".format(subscription.symbol)) + # await subscription.subscribe() + +@bfx.ws.on('subscribed') +async def on_subscribe(subscription): + print ("Subscribed to {}".format(subscription.symbol)) + # await subscription.unsubscribe() + # or + # await bfx.ws.unsubscribe(subscription.chanId) + +@bfx.ws.once('subscribed') +async def on_once_subscribe(subscription): + print ("Performig resubscribe") + await bfx.ws.resubscribe(subscription.chanId) + + +async def start(): + await bfx.ws.subscribe('book', 'tBTCUSD') + +bfx.ws.on('connected', start) +bfx.ws.run()