-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix multiple subscriptions for binance #1
Comments
@firepol, try this changes: diff --git a/ob_updater.py b/ob_updater.py
index 872c459..e998fdc 100755
--- a/ob_updater.py
+++ b/ob_updater.py
@@ -27,8 +27,7 @@ def main():
settings = utils.get_exchange_settings(exchange_name)
exchange = utils.get_ccxt_exchange(exchange_name, settings)
- for symbol in symbols:
- asyncio.ensure_future(utils.subscribe_ws('ob', exchange, symbol, limit,
+ asyncio.ensure_future(utils.subscribe_ws('ob', exchange, symbols, limit,
loop, pp, args.debug, args.verbose))
loop.run_forever() diff --git a/utils.py b/utils.py
index 42fad5a..b9d5fcb 100644
--- a/utils.py
+++ b/utils.py
-async def subscribe_ws(event, exchange, symbol, limit, loop, pp, debug=False, verbose=False):
+async def subscribe_ws(event, exchange, symbols, limit, loop, pp, debug=False, verbose=False):
@exchange.on('err')
def websocket_error(err, conxid): # pylint: disable=W0612
print(type(err).__name__ + ":" + str(err))
@@ -54,6 +57,6 @@ async def subscribe_ws(event, exchange, symbol, limit, loop, pp, debug=False, ve
sys.stdout.flush()
sys.stdout.flush()
-
- await exchange.websocket_subscribe(event, symbol, {'limit': limit})
- print(f'subscribed: {exchange.id} {symbol}')
+ for symbol in symbols:
+ await exchange.websocket_subscribe(event, symbol, {'limit': limit})
+ print(f'subscribed: {exchange.id} {symbol}')
|
binance use streams in websocket connection. You have to open websocket with all symbols you want to observe: First time you try to subscribe websocket library open websocket with only one stream: while waiting for first subscription succeeds, if you try to subscribe to second symbol, binance ws driver need to close previous connection and open websocket with a new URL: I don't know how to handle it correctly, maybe before closing binance driver would have to wait to first subscription succeeds. but close function is not async, and we need to be sure previous ws connection is closed before connecting with new URL. With above changes, you are ensuring not subscribing in paralell on same exchange. It is not the best solution, but it works for now. |
Thanks a lot @lfern ! I implemented your fix, updated the sample config and it looks like it works like a charm. |
If I configure multiple pairs for binance, it doesn't work.
To reproduce, configure:
settings_ws.json
:Then run:
Error:
Expected result, like in the other exchanges, the program should work, not crash for multiple pairs in the same exchange.
The text was updated successfully, but these errors were encountered: