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

Subscribing to multiple orderbook sockets. #333

Closed Alonzo-Coeus closed 6 years ago

Alonzo-Coeus commented 6 years ago

Hi i am writing a trading bot and would like to be able to listen to multiple order-books however i am only getting depth cache updates for one currency. Is there something i am missing or do i need to write a pull request for this feature.


from binance.websockets import BinanceSocketManager
from binance.depthcache import DepthCacheManager

import gevent
from gevent.queue import JoinableQueue
client = Client("", "")
bm = BinanceSocketManager(client)

def depthUpdater(outChannel):
    for pair in ["ETHUSDT", "BTCUSDT", "ETHBTC"]:
        DepthCacheManager(client, pair, callback=(lambda x: outChannel.put(["orderBookUpdate", pair, x])), bm=bm)

    while True:
        gevent.sleep(0)

def printer(inChannel):
    while True:
        if not inChannel.empty():
            print(inChannel.next())
        gevent.sleep(0)

q = JoinableQueue()

gevent.joinall([
    gevent.spawn(depthUpdater, q),
    gevent.spawn(printer, q)
])```
Alonzo-Coeus commented 6 years ago

sorry i have just been stupid it is working just fine