Open JosephLeon13 opened 4 years ago
Hi I get the same issue, curious to hear what the problem is.
I ended up rebuilding some of his code. Something in the code was broken.
` import asyncio import websockets import json
class WebSocketServer():
STREAM_URL = 'wss://stream.binance.com:9443/'
MAX_RECONNECTS = 5
MAX_RECONNECT_SECONDS = 60
MIN_RECONNECT_WAIT = 0.1
TIMEOUT = 5
def __init__(self, path, callback, prefix='ws/'):
self.socket = None
self.path = path
self.prefix = prefix
self.callback = callback
self.connect()
def connect(self):
asyncio.ensure_future(self.consume())
async def consumer_handler(self, websocket):
async for message in websocket:
self.callback(json.loads(message))
async def consume(self):
websocket_resource_url = f"{self.STREAM_URL}{self.prefix}{self.path}"
async with websockets.connect(websocket_resource_url) as websocket:
self.socket = websocket
await self.consumer_handler(websocket)
class WebSocketManager(): WEBSOCKET_DEPTH_5 = '5' WEBSOCKET_DEPTH_10 = '10' WEBSOCKET_DEPTH_20 = '20'
user_timeout = 30 * 60 # 30 minutes
def __init__(self, client, loop):
self.connections = {}
self.user_timer = None
self.user_listen_key = None
self.user_callback = None
self.client = client
self.loop = loop
async def start_socket(self, path, callback, prefix):
if path in self.connections:
return False
self.connections[path] = WebSocketServer(path, callback, prefix)
return path
async def start_multiplex_socket(self, streams, callback):
path = f"streams={'/'.join(streams)}"
await self.start_socket(path, callback, 'stream?')
return path
`
Never got around to finishing up the bot but it was close. just lost interest
same issue for me, maybe make a pull request with your fix?
Describe the bug When I try to start the socket connection to stream the klines nothing occurs. Callback isn't fired. I do get an initial response "streams=eosbtc@kline_1h/linkbtc@kline_1h/ethbtc@kline_1h" However, nothing happens after that.
To Reproduce