Python websocket.enableTrace() Examples

The following are 30 code examples of websocket.enableTrace(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module websocket , or try the search function .
Example #1
Source File: vngateio_ws.py    From vnpy_crypto with MIT License 7 votes vote down vote up
def connect_Subpot(self, apiKey , secretKey , trace = False):
        self.host = GATEIO_SOCKET_URL
        self.apiKey = apiKey
        self.secretKey = secretKey
        self.trace = trace

        websocket.enableTrace(trace)

        self.ws = websocket.WebSocketApp(self.host, 
                                             on_message=self.onMessage,
                                             on_error=self.onError,
                                             on_close=self.onClose,
                                             on_open=self.onOpen)        
            
        self.thread = Thread(target = self.ws.run_forever , args = (None , None , 60, 30))
        # self.thread_heart = Thread(target = self.run_forever_heart)

        self.thread.start()
        # self.thread_heart.start()

    #---------------------------------------------------------------------- 
Example #2
Source File: vnokex.py    From vnpy_crypto with MIT License 7 votes vote down vote up
def connect(self, apiKey, secretKey, trace=False):
        self.host = OKEX_USD_CONTRACT
        self.apiKey = apiKey
        self.secretKey = secretKey
        self.trace = trace

        websocket.enableTrace(trace)

        self.ws = websocket.WebSocketApp(self.host,
                                         on_message=self.onMessage,
                                         on_error=self.onError,
                                         on_close=self.onClose,
                                         on_open=self.onOpen)

        self.thread = Thread(target=self.ws.run_forever, args=(None, None, 60, 30))
        self.thread.start()

    # ---------------------------------------------------------------------- 
Example #3
Source File: publisher.py    From predixpy with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def _init_publisher_ws(self):
        """
        Create a new web socket connection with proper headers.
        """
        logging.debug("Initializing new web socket connection.")

        url = ('wss://%s/v1/stream/messages/' % self.eventhub_client.host)

        headers = self._generate_publish_headers()

        logging.debug("URL=" + str(url))
        logging.debug("HEADERS=" + str(headers))

        websocket.enableTrace(False)
        self._ws = websocket.WebSocketApp(url,
                                          header=headers,
                                          on_message=self._on_ws_message,
                                          on_open=self._on_ws_open,
                                          on_close=self._on_ws_close)
        self._ws_thread = threading.Thread(target=self._ws.run_forever, kwargs={'ping_interval': 30})
        self._ws_thread.daemon = True
        self._ws_thread.start()
        time.sleep(1) 
Example #4
Source File: bitmex_ws.py    From trading-server with GNU General Public License v3.0 6 votes vote down vote up
def __init__(self, logger, symbols, channels, URL, api_key, api_secret):
        self.logger = logger
        self.symbols = symbols
        self.channels = channels
        self.URL = URL
        if api_key is not None and api_secret is None:
            raise ValueError('Enter both public and secret keys')
        if api_key is None and api_secret is not None:
            raise ValueError('Enter both public and secret API keys')
        self.api_key = api_key
        self.api_secret = api_secret
        self.data = {}
        self.keys = {}
        # websocket.enableTrace(True)

        # Data table size - approcimate tick/min capacity per symbol.
        self.MAX_SIZE = 15000 * len(symbols)
        self.RECONNECT_TIMEOUT = 10

        self.connect() 
Example #5
Source File: transcribe.py    From watson-streaming-stt with Apache License 2.0 6 votes vote down vote up
def main():
    # Connect to websocket interfaces
    headers = {}
    userpass = ":".join(get_auth())
    headers["Authorization"] = "Basic " + base64.b64encode(
        userpass.encode()).decode()
    url = get_url()

    # If you really want to see everything going across the wire,
    # uncomment this. However realize the trace is going to also do
    # things like dump the binary sound packets in text in the
    # console.
    #
    # websocket.enableTrace(True)
    ws = websocket.WebSocketApp(url,
                                header=headers,
                                on_message=on_message,
                                on_error=on_error,
                                on_close=on_close)
    ws.on_open = on_open
    ws.args = parse_args()
    # This gives control over the WebSocketApp. This is a blocking
    # call, so it won't return until the ws.close() gets called (after
    # 6 seconds in the dedicated thread).
    ws.run_forever() 
Example #6
Source File: pushbullet.py    From xbmc.service.pushbullet with GNU General Public License v3.0 6 votes vote down vote up
def _websocketThread(self, evtThreadEnded):
        try:
            websocket.enableTrace(False)
            self._ws = websocket.WebSocketApp(self._REST_URLS['websocket'] + self.access_token,
                                              on_open=self._on_open,
                                              on_message=self._on_message,
                                              on_close=self._on_close,
                                              on_error=self._on_error)

            # ping_timeout is for no blocking call
            self._ws.run_forever(ping_interval=self.ping_timeout/2, ping_timeout=self.ping_timeout)

        except AttributeError:
            self._on_error(websocket, 'No internet connection!')
        except Exception as ex:
            self._on_error(websocket, ex)
        finally:
            evtThreadEnded.set() 
Example #7
Source File: deribit_ws.py    From archon with MIT License 6 votes vote down vote up
def connect(self):
        self.logger.info("connect ws")
        websocket.enableTrace(True)
        self.ws = websocket.WebSocketApp("wss://www.deribit.com/ws/api/v1/",
                                  on_message = lambda ws,msg: self.on_message(ws, msg),
                                  on_error   = lambda ws,msg: self.on_error(ws, msg),
                                  on_open    = lambda ws:  self.on_open(ws),
                                  #on_open = self.on_open,                                  
                                  on_close = self.on_close)
        ssl_defaults = ssl.get_default_verify_paths()
        sslopt_ca_certs = {'ca_certs': ssl_defaults.cafile}
        self.wst = threading.Thread(target=lambda: self.ws.run_forever(sslopt=sslopt_ca_certs))
        self.wst.daemon = True
        self.wst.start()
        self.logger.info("Started thread")
        #TOOD subscribe later
        #self.ws.run_forever() 
Example #8
Source File: webrepl_connection.py    From thonny with MIT License 6 votes vote down vote up
def __init__(self, url, password):
        super().__init__()

        self._url = url
        self._password = password

        import websocket

        websocket.enableTrace(True)
        self._ws = websocket.WebSocket(skip_utf8_validation=True)
        self._ws.settimeout(10)
        self._ws.connect(self._url, timeout=5)
        prompt = self._ws.recv()
        if prompt != "Password: ":
            raise RuntimeError("Expected password prompt, got %r" % prompt)
        self._ws.send(self._password + "\r\n")

        self._reading_thread = threading.Thread(target=self._keep_reading, daemon=True)
        self._reading_thread.start() 
Example #9
Source File: vnokcoin.py    From chanlun with MIT License 6 votes vote down vote up
def connect(self, host, apiKey, secretKey, trace=False):
        """连接服务器"""
        self.host = host
        self.apiKey = apiKey
        self.secretKey = secretKey
        
        if self.host == OKCOIN_CNY:
            self.currency = CURRENCY_CNY
        else:
            self.currency = CURRENCY_USD
            
        websocket.enableTrace(trace)
        
        self.ws = websocket.WebSocketApp(host, 
                                         on_message=self.onMessage,
                                         on_error=self.onError,
                                         on_close=self.onClose,
                                         on_open=self.onOpen)        
        
        self.thread = Thread(target=self.ws.run_forever)
        self.thread.start()
        
    #---------------------------------------------------------------------- 
Example #10
Source File: vnokcoin.py    From chanlun with MIT License 6 votes vote down vote up
def connect(self, host, apiKey, secretKey, trace=False):
        """连接服务器"""
        self.host = host
        self.apiKey = apiKey
        self.secretKey = secretKey
        
        if self.host == OKCOIN_CNY:
            self.currency = CURRENCY_CNY
        else:
            self.currency = CURRENCY_USD
            
        websocket.enableTrace(trace)
        
        self.ws = websocket.WebSocketApp(host, 
                                         on_message=self.onMessage,
                                         on_error=self.onError,
                                         on_close=self.onClose,
                                         on_open=self.onOpen)        
        
        self.thread = Thread(target=self.ws.run_forever)
        self.thread.start()
        
    #---------------------------------------------------------------------- 
Example #11
Source File: QAhuobi_realtime.py    From QUANTAXIS with MIT License 6 votes vote down vote up
def run_subscription_batch_jobs(self):
        """
        请求 KLine 实时数据
        """
        websocket.enableTrace(False)
        self.__ws = websocket.WebSocketApp(
            self.HUOBIPRO_WEBSOCKET_URL,
            on_message=self.on_message,
            on_open=self.on_open,
            on_error=self.on_error,
            on_close=self.on_close
        )
        self.__locked = True

        # 如果意外退出,等待10秒重新运行
        while (True):
            self.__ws.run_forever()
            QA_util_log_expection("FTW! it quit! Retry 10 seconds later...")
            time.sleep(10) 
Example #12
Source File: js_ws_fx.py    From akshare with MIT License 5 votes vote down vote up
def watch_jinshi_fx():

    websocket.enableTrace(False)
    ws = websocket.WebSocketApp(
        f"wss://sshhbhekjf.jin10.com:9081/socket.io/?EIO=3&transport=websocket&sid={_get_sid()}",
        on_message=on_message,
        on_error=on_error,
        on_close=on_close,
    )
    ws.on_open = on_open
    t = Timer(20, on_emit, args=(ws,))
    t.start()
    ws.run_forever() 
Example #13
Source File: screepsapi.py    From python-screeps with MIT License 5 votes vote down vote up
def connect(self):
        screepsConnection = API(u=self.user,p=self.password,ptr=self.ptr,host=self.host,secure=self.secure, token=self.atoken)
        me = screepsConnection.me()
        self.user_id = me['_id']
        self.token = screepsConnection.token

        if self.logging:
            logging.getLogger('websocket').addHandler(logging.StreamHandler())
            websocket.enableTrace(True)
        else:
            logging.getLogger('websocket').addHandler(logging.NullHandler())
            websocket.enableTrace(False)

        if self.host:
            url = 'wss://' if self.secure else 'ws://'
            url += self.host + '/socket/websocket'
        elif not self.ptr:
            url = 'wss://screeps.com/socket/websocket'
        else:
            url = 'wss://screeps.com/ptr/socket/websocket'

        self.ws = websocket.WebSocketApp(url=url,
                                    on_message=lambda ws, message: self.on_message(ws,message),
                                    on_error=lambda ws, error: self.on_error(ws,error),
                                    on_close=lambda ws: self.on_close(ws),
                                    on_open=lambda ws: self.on_open(ws))

        ssl_defaults = ssl.get_default_verify_paths()
        sslopt_ca_certs = {'ca_certs': ssl_defaults.cafile}
        if 'http_proxy' in self.settings and self.settings['http_proxy'] is not None:
            http_proxy_port = self.settings['http_proxy_port'] if 'http_proxy_port' in self.settings else 8080
            self.ws.run_forever(http_proxy_host=self.settings['http_proxy'], http_proxy_port=http_proxy_port, ping_interval=1, sslopt=sslopt_ca_certs)
        else:
            self.ws.run_forever(ping_interval=1, sslopt=sslopt_ca_certs) 
Example #14
Source File: js_ws_quotes.py    From akshare with MIT License 5 votes vote down vote up
def watch_jinshi_quotes():

    websocket.enableTrace(False)
    ws = websocket.WebSocketApp(
        f"wss://dc-quote-old.jin10.com/socket.io/?EIO=3&transport=websocket&sid={_get_sid()}",
        on_message=on_message,
        on_error=on_error,
        on_close=on_close
    )
    ws.on_open = on_open
    t = Timer(20, on_emit, args=(ws,))
    t.start()
    ws.run_forever() 
Example #15
Source File: recognize_listener.py    From python-sdk with Apache License 2.0 5 votes vote down vote up
def __init__(self,
                 audio_source,
                 options,
                 callback,
                 url,
                 headers,
                 http_proxy_host=None,
                 http_proxy_port=None,
                 verify=None):
        self.audio_source = audio_source
        self.options = options
        self.callback = callback
        self.url = url
        self.headers = headers
        self.http_proxy_host = http_proxy_host
        self.http_proxy_port = http_proxy_port
        self.isListening = False
        self.verify = verify

        websocket.enableTrace(True)

        self.ws_client = websocket.WebSocketApp(
            self.url,
            header=self.headers,
            on_open=self.on_open,
            on_data=self.on_data,
            on_error=self.on_error,
            on_close=self.on_close,
        )

        self.ws_client.run_forever(http_proxy_host=self.http_proxy_host,
                                   http_proxy_port=self.http_proxy_port,
                                   sslopt={"cert_reqs": ssl.CERT_NONE}
                                   if self.verify is not None else None) 
Example #16
Source File: synthesize_listener.py    From python-sdk with Apache License 2.0 5 votes vote down vote up
def __init__(self,
                 options,
                 callback,
                 url,
                 headers,
                 http_proxy_host=None,
                 http_proxy_port=None,
                 verify=None):
        self.options = options
        self.callback = callback
        self.url = url
        self.headers = headers
        self.http_proxy_host = http_proxy_host
        self.http_proxy_port = http_proxy_port
        self.verify = verify

        websocket.enableTrace(True)

        self.ws_client = websocket.WebSocketApp(
            self.url,
            header=self.headers,
            on_open=self.on_open,
            on_data=self.on_data,
            on_error=self.on_error,
            on_close=self.on_close,
        )

        self.ws_client.run_forever(http_proxy_host=self.http_proxy_host,
                                   http_proxy_port=self.http_proxy_port,
                                   sslopt={'cert_reqs': ssl.CERT_NONE}
                                   if self.verify is not None else None) 
Example #17
Source File: pb_stream.py    From whatsapp-cli with MIT License 5 votes vote down vote up
def start_stream(token):

    websocket.enableTrace(False)
    ws = websocket.WebSocketApp("wss://stream.pushbullet.com/websocket/" + token,
                              on_message = on_message,
                              on_error = on_error,
                              on_close = on_close)
    ws.on_open = on_open
    #infinite loop as partner might drop connection
    while True:
        ws.run_forever()
        #restarting in 5 seconds...
        time.sleep(5) 
Example #18
Source File: test_websocket.py    From bazarr with GNU General Public License v3.0 5 votes vote down vote up
def setUp(self):
        ws.enableTrace(TRACEABLE) 
Example #19
Source File: test_websocket.py    From bazarr with GNU General Public License v3.0 5 votes vote down vote up
def setUp(self):
        ws.enableTrace(TRACEABLE)

        WebSocketAppTest.keep_running_open = WebSocketAppTest.NotSetYet()
        WebSocketAppTest.keep_running_close = WebSocketAppTest.NotSetYet()
        WebSocketAppTest.get_mask_key_id = WebSocketAppTest.NotSetYet() 
Example #20
Source File: deri_ws_test.py    From archon with MIT License 5 votes vote down vote up
def main():
    client = RestClient(k, s)

    def on_message(ws, message):
        m = message
        n = m["notifications"]
        print (n[0]["message"])
        #print(message)

    def on_error(ws, error):
        print(error)

    def on_close(ws):
        print("### closed ###")

    def on_open(ws):
        data = {
            "id": 5533, 
            "action": "/api/v1/private/subscribe",  
            "arguments": {
                "instrument": ["all"],
                "event": ["order_book"] 
            }
        }
        data['sig'] = client.generate_signature(data['action'], data['arguments'])

        ws.send(json.dumps(data))

    websocket.enableTrace(True)
    ws = websocket.WebSocketApp("wss://www.deribit.com/ws/api/v1/",
                              on_message = on_message,
                              on_error = on_error,
                              on_close = on_close)
    ws.on_open = on_open
    ws.run_forever() 
Example #21
Source File: websocket.py    From Thespian with MIT License 5 votes vote down vote up
def receiveMsg_Start_Websocket(self, m, sender):
        if self.started: # already started
            return
        self.config = m
        self.started = True
        self.running = True

        # open the connection
        websocket.enableTrace(False)
        self.ws = websocket.create_connection(m.ws_addr)
        log.info("Websocket Connected")

        # set up the socket monitoring
        self.epoll = select.epoll()
        mask = select.EPOLLIN | select.EPOLLHUP | select.EPOLLERR
        self.epoll.register(self.ws.sock.fileno(), mask)

        # subscribe to the feed
        self.ws.send(m.start_msg)

        # start checking for data
        self.send(self.myAddress, WakeupMessage(None)) 
Example #22
Source File: test_websocket.py    From Tautulli with GNU General Public License v3.0 5 votes vote down vote up
def setUp(self):
        ws.enableTrace(TRACEABLE) 
Example #23
Source File: test_websocket.py    From Tautulli with GNU General Public License v3.0 5 votes vote down vote up
def setUp(self):
        ws.enableTrace(TRACEABLE)

        WebSocketAppTest.keep_running_open = WebSocketAppTest.NotSetYet()
        WebSocketAppTest.keep_running_close = WebSocketAppTest.NotSetYet()
        WebSocketAppTest.get_mask_key_id = WebSocketAppTest.NotSetYet() 
Example #24
Source File: wsdanmu.py    From pccold with MIT License 5 votes vote down vote up
def wsdanmumain():
    # websocket.enableTrace(True)
    ws = websocket.WebSocketApp("wss://danmuproxy.douyu.com:8503/",
                              on_message = on_message,
                              on_error = on_error,
                              on_close = on_close)
    ws.on_open = on_open
    ws.run_forever() 
Example #25
Source File: base_hub_connection.py    From signalrcore with MIT License 5 votes vote down vote up
def enable_trace(self, traceable):
        if len(self.logger.handlers) > 0:
            websocket.enableTrace(traceable, self.logger.handlers[0]) 
Example #26
Source File: test_websocket.py    From aws-kube-codesuite with Apache License 2.0 5 votes vote down vote up
def setUp(self):
        ws.enableTrace(TRACEABLE) 
Example #27
Source File: test_websocket.py    From aws-kube-codesuite with Apache License 2.0 5 votes vote down vote up
def setUp(self):
        ws.enableTrace(TRACEABLE)

        WebSocketAppTest.keep_running_open = WebSocketAppTest.NotSetYet()
        WebSocketAppTest.keep_running_close = WebSocketAppTest.NotSetYet()
        WebSocketAppTest.get_mask_key_id = WebSocketAppTest.NotSetYet() 
Example #28
Source File: home.py    From homematicip-rest-api with GNU General Public License v3.0 5 votes vote down vote up
def enable_events(self):
        websocket.enableTrace(True)

        self.__webSocket = websocket.WebSocketApp(
            self._connection.urlWebSocket,
            header=[
                "AUTHTOKEN: {}".format(self._connection.auth_token),
                "CLIENTAUTH: {}".format(self._connection.clientauth_token),
            ],
            on_message=self._ws_on_message,
            on_error=self._ws_on_error,
            on_close=self._ws_on_close,
        )

        websocket_kwargs = {"ping_interval": 3}
        if hasattr(sys, "_called_from_test"):  # disable ssl during a test run
            sslopt = {"cert_reqs": ssl.CERT_NONE}
            websocket_kwargs = {"sslopt": sslopt, "ping_interval": 2, "ping_timeout": 1}

        self.__webSocketThread = threading.Thread(
            name="hmip-websocket",
            target=self.__webSocket.run_forever,
            kwargs=websocket_kwargs,
        )
        self.__webSocketThread.setDaemon(True)
        self.__webSocketThread.start() 
Example #29
Source File: example-2.py    From bitmex-websocket with MIT License 5 votes vote down vote up
def __init__(self, symbol='XBTUSD', **kwargs):
        websocket.enableTrace(True)

        channels = [
            InstrumentChannels.quote,
        ]

        super().__init__(symbol=symbol, channels=channels, **kwargs) 
Example #30
Source File: hyperionplatform.py    From AlexaPi with MIT License 5 votes vote down vote up
def init_connection(self):
		logger.debug('Initializing connection')
		if self._pconfig['verbose']:
			websocket.enableTrace(True)
		self.socket = websocket.WebSocketApp(self.service,
				on_message=self.on_socket_message,
				on_close=self.on_socket_close,
				on_error=self.on_socket_error)
		self.socket_thread = threading.Thread(target=self.socket.run_forever)
		self.socket_thread.daemon = True
		self.socket_thread.start()