Exemple #1
0
    def __init__(self, _loop):
        """

        :param _loop: object
        """
        self._loop = _loop
        self._loghandler = loghandler.LogHandler()
    def __init__(
        self,
        mongo_host="localhost",
        mongo_port=27017,
        mongo_db="bitmex",
        translate_chat=True,
    ):
        log_handler = loghandler.LogHandler()
        self.logger = log_handler.create_logger("bitmexstream")

        self.db = MongoClient(host=mongo_host, port=mongo_port)[mongo_db]

        if translate_chat:
            self.ct = ChatTranslator()

        self.exited = False
import json
import os
import time
import threading
import websocket

import loghandler

log_handler = loghandler.LogHandler()


class EventListener:
    def __init__(self):
        pass

    def connect(self, ws_url):
        """Connect to the websocket in a thread."""
        self.logger.debug("Starting websocket thread.")

        self.ws = websocket.WebSocketApp(
            ws_url,
            on_message=self.on_message,
            on_close=self.on_close,
            on_open=self.on_open,
            on_error=self.on_error,
        )

        self.wst = threading.Thread(target=lambda: self.ws.run_forever())
        self.wst.daemon = True
        self.wst.start()
        self.logger.debug("Started websocket thread.")