sammchardy / python-binance

Binance Exchange API python implementation for automated trading
https://python-binance.readthedocs.io/en/latest/
MIT License
6.02k stars 2.2k forks source link

LOB management #256

Closed snapo closed 6 years ago

snapo commented 6 years ago

Hello, First of all thanks for the development here.... second, can maybe some one point me in the right direction how to manage different orderbooks at the same time?

import time
import settings
from binance.client import Client
from binance.depthcache import DepthCacheManager
client = Client(settings.pubkey, settings.privkey)

symbols=['BTCUSDT', 'ETHUSDT', 'NEOUSDT', 'LTCUSDT', 'ETHBTC', 'LTCBTC', 'NEOBTC', 'LTCETH', 'NEOETH']

def process_depth(depth_cache):
    if depth_cache is not None:
        print("symbol {}".format(depth_cache.symbol) + " - BIDS: " + ''.join(str(e) for e in depth_cache.get_bids()[:3]) + " - ASKS: " + ''.join(str(e) for e in depth_cache.get_asks()[:3]))
    else:
        print("error")

for symbol in symbols:
    dcm = DepthCacheManager(client, symbol, callback=process_depth, refresh_interval=10)

depth_cache = dcm.get_depth_cache()

This is what i try, but i dont understand why the messages are:

Thank you very much

sammchardy commented 6 years ago

Hi @snapo

The refresh_interval param is the interval for the DepthCacheManager to fetch a full order book using the REST API. At other times it uses the websocket messages to update it. I wouldn't recommend having this as frequent as 10 seconds.

The callback will be called around once per second based on messages coming back from the websocket, that can't be changed.

Currently the DepthCacheManager doesn't use multiplexing for individual pairs. A new websocket will be opened each time.

You're using it correctly, apart from the refresh_interval parameter.

snapo commented 6 years ago

thank you very much for the explanation...