Beispiel #1
0
 def testProxyConnect(self):
     ws = websocket.WebSocket()
     ws.connect("ws://127.0.0.1:" + LOCAL_WS_SERVER_PORT,
                http_proxy_host="127.0.0.1",
                http_proxy_port="8899",
                proxy_type="http")
     ws.send("Hello, Server")
     server_response = ws.recv()
     self.assertEqual(server_response, "Hello, Server")
     # self.assertEqual(_start_proxied_socket("wss://api.bitfinex.com/ws/2", OptsList(), proxy_info(http_proxy_host="127.0.0.1", http_proxy_port="8899", proxy_type="http"))[1], ("api.bitfinex.com", 443, '/ws/2'))
     self.assertEqual(
         _get_addrinfo_list(
             "api.bitfinex.com", 443, True,
             proxy_info(http_proxy_host="127.0.0.1",
                        http_proxy_port="8899",
                        proxy_type="http")),
         (socket.getaddrinfo("127.0.0.1", 8899, 0, socket.SOCK_STREAM,
                             socket.SOL_TCP), True, None))
     self.assertEqual(
         connect(
             "wss://api.bitfinex.com/ws/2", OptsList(),
             proxy_info(http_proxy_host="127.0.0.1",
                        http_proxy_port=8899,
                        proxy_type="http"), None)[1],
         ("api.bitfinex.com", 443, '/ws/2'))
Beispiel #2
0
def __execute_request__(websocket=None, data=None):
    if data == None:
        return None
    print(data)
    try:
        websocket.send(data)
    except:
        print("An error occured on sending")
        return None
Beispiel #3
0
 def run():
     try:
         data = self.get_argument('data')
         logging.info('Send: %s' % data)
         websocket.send(data)
         time.sleep(0.1)
         websocket.keep_running = False
         websocket.close()
     except WebSocketConnectionClosedException:
         pass
Beispiel #4
0
 def run(websocket):
     print(killed)
     while not killed:
         try:
             data = buffer.popleft(
             )  #pop element from left of buffer (oldest read_byte block)
             websocket.send(data)
             time.sleep(0.09)
         except IndexError:  #don't stop if first reads are empty
             continue
Beispiel #5
0
 def send_message(self, command, value):
     """Generic send message."""
     from websocket import _exceptions
     ws_auth = False
     for attempt in range(5):
         try:
             websocket = self._connection(
                 'wss://{host_uri}/{device_set_endpoint}'.format(
                     host_uri=self.HOST_URI,
                     device_set_endpoint=self.DEVICE_SET_ENDPOINT),
                 timeout=self.REQUEST_TIMEOUT)
             auth_mssg = json.dumps({
                 'jsonrpc': '2.0',
                 'id': 3,
                 'method': 'srvWebSocketAuth',
                 'params': {
                     'varName': self.username,
                     'apiKey': self.api_key
                 }
             })
             websocket.send(auth_mssg)
             result = websocket.recv()
         except Exception as ex:
             print("Exception during websocket authentification")
             websocket.close()
         else:
             ws_auth = True
             break
     if (ws_auth == True):
         for attempt in range(5):
             try:
                 pay_load = json.dumps({
                     'jsonrpc': '2.0',
                     'method': 'gdoModuleCommand',
                     'params': {
                         'msgType': 16,
                         'moduleType': 5,
                         'portId': 7,
                         'moduleMsg': {
                             command: value
                         },
                         'topic': self.device_id
                     }
                 })
                 websocket.send(pay_load)
                 pay_load = ""
                 result = websocket.recv()
             except Exception as ex:
                 print("Exception during sending message")
                 websocket.close()
             else:
                 break
     websocket.close()
Beispiel #6
0
def send_jsonrpc_command(websocket: websocket.WebSocket,
                         cmd: dict) -> tuple[bool, dict]:
    """ Send a jsonrpc command, wait for the response and return it. """

    cmd_id = random.randint(10000, 90000)
    cmd_json = {"jsonrpc": "2.0", "id": cmd_id, **cmd}

    logging.debug(f"sending cmd: {cmd} id: {cmd_id}")
    websocket.send(json.dumps(cmd_json))

    while True:
        ret = websocket.recv()
        ret_json = json.loads(ret)
        if ret_json["id"] == cmd_id:
            return "result" in ret_json, ret_json
        else:
            # print('waiting for ', my_cmd_id)
            pass
 def testSSLopt(self):
     ssloptions = {
         "cert_reqs": ssl.CERT_NONE,
         "check_hostname": False,
         "ssl_version": ssl.PROTOCOL_TLSv1_2,
         "ciphers": "TLS_AES_256_GCM_SHA384:TLS_CHACHA20_POLY1305_SHA256:\
                     TLS_AES_128_GCM_SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:\
                     ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES256-GCM-SHA384:\
                     ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:\
                     DHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:\
                     ECDHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES128-GCM-SHA256:\
                     ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA384:\
                     DHE-RSA-AES256-SHA256:ECDHE-ECDSA-AES128-SHA256:\
                     ECDHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA256:\
                     ECDHE-ECDSA-AES256-SHA:ECDHE-RSA-AES256-SHA",
         "ecdh_curve": "prime256v1"
     }
     ws = websocket.WebSocket(sslopt=ssloptions)
     ws.connect("wss://api.bitfinex.com/ws/2")
     ws.send("Hello")
     ws.close()
Beispiel #8
0
def send_messages(q, websocket, keep_alive=True, donotdie=True):
    logger = logging.getLogger(__name__)

    ping_msg = json.dumps({'type': 'ping'}).encode('utf-8')
    while True:
        try:
            msg = q.get(timeout=3)
            websocket.send(msg)
            raise RuntimeError
        except queue.Empty:
            if keep_alive:
                websocket.send(ping_msg)
        except Exception as e:
            if donotdie:
                logger.debug(
                    "Something went wrong in the message sender: {}".format(e),
                    exc_info=True)
                continue
            else:
                logger.exception(e)
                raise e
	def subscribePublicChannels(self, connector):
		connector.send("{'event':'addChannel','channel':'ok_sub_spotusd_btc_ticker','binary': 'true'}")
		connector.send("{'event':'addChannel','channel':'ok_sub_spotusd_ltc_ticker','binary': 'true'}")
		connector.send("{'event':'addChannel','channel':'ok_sub_spotusd_btc_depth_60', 'binary': 'true'}")
		connector.send("{'event':'addChannel','channel':'ok_sub_spotusd_ltc_depth_60', 'binary': 'true'}")
		connector.send("{'event':'addChannel','channel':'ok_sub_spotusd_btc_trades'}")
		connector.send("{'event':'addChannel','channel':'ok_sub_spotusd_ltc_trades'}");
<<<<<<< HEAD

		ok_sub_spotusd_btc_kline_week
=======
>>>>>>> 02425f328ebc1169080e1a01acf6ac27527cb478
		connector.send("{'event':'addChannel','channel':'ok_sub_spotusd_btc_trades'}");

		websocket.send("{'event':'addChannel','channel':'ok_sub_spotusd_X_kline_Y'}");
		klineList = []
		klineTypes = ['1min', '3min', '5min', '15min', '30min', '1hour', '2hour', '4hour', '6hour', '12hour', 'day', '3day', 'week']
		for klineType in klineTypes: 
			connector.send("{'event':'addChannel','channel':'ok_sub_spotusd_btc_kline_'" + klineType + "', 'binary':'true'}");
			klineList.append("ok_sub_spotusd_btc_kline_" + klineType)
			connector.send("{'event':'addChannel','channel':'ok_sub_spotusd_ltc_kline_'" + klineType + "', 'binary':'true'}");
			klineList.append("ok_sub_spotusd_ltc_kline_" + klineType)
		self.klineList = klineList
		print(klineList)
		klineChannels = ['ok_sub_spotusd_btc_kline_1min', 'ok_sub_spotusd_ltc_kline_1min', 'ok_sub_spotusd_btc_kline_3min', 'ok_sub_spotusd_ltc_kline_3min', 'ok_sub_spotusd_btc_kline_5min', 'ok_sub_spotusd_ltc_kline_5min', 'ok_sub_spotusd_btc_kline_15min', 'ok_sub_spotusd_ltc_kline_15min', 'ok_sub_spotusd_btc_kline_30min', 'ok_sub_spotusd_ltc_kline_30min', 'ok_sub_spotusd_btc_kline_1hour', 'ok_sub_spotusd_ltc_kline_1hour', 'ok_sub_spotusd_btc_kline_2hour', 'ok_sub_spotusd_ltc_kline_2hour', 'ok_sub_spotusd_btc_kline_4hour', 'ok_sub_spotusd_ltc_kline_4hour', 'ok_sub_spotusd_btc_kline_6hour', 'ok_sub_spotusd_ltc_kline_6hour', 'ok_sub_spotusd_btc_kline_12hour', 'ok_sub_spotusd_ltc_kline_12hour', 'ok_sub_spotusd_btc_kline_day', 'ok_sub_spotusd_ltc_kline_day', 'ok_sub_spotusd_btc_kline_3day', 'ok_sub_spotusd_ltc_kline_3day', 'ok_sub_spotusd_btc_kline_week', 'ok_sub_spotusd_ltc_kline_week']
		self.klineChannels = klineChannels
		for channel in self.klineChannels: 
			event = "{'event':'addChannel','channel':'" + channel + "', 'binary': 'true'}"
			connector.send(str(event))
import click_spinner
import websocket

websocket = websocket.WebSocket()
websocket.connect('ws://0.0.0.0:8000/api/stt/ws')

try:
    print('Performing speech-to-text with WebSocket...')
    with click_spinner.spinner():
        with open('audio/8455-210777-0068.wav', mode='rb') as file:
            websocket.send('{"power":1000, "paris":-1000}')
            audio = file.read()
            websocket.send_binary(audio)
            result = websocket.recv()
            print()
            print(result)
            websocket.close()
except Exception as ex:
    print(ex)
Beispiel #11
0
 def send(message):
     websocket.send(message)
Beispiel #12
0
    def subscribePublicChannels(self, connector):
        connector.send(
            "{'event':'addChannel','channel':'ok_sub_spotusd_btc_ticker','binary': 'true'}"
        )
        connector.send(
            "{'event':'addChannel','channel':'ok_sub_spotusd_ltc_ticker','binary': 'true'}"
        )
        connector.send(
            "{'event':'addChannel','channel':'ok_sub_spotusd_btc_depth_60', 'binary': 'true'}"
        )
        connector.send(
            "{'event':'addChannel','channel':'ok_sub_spotusd_ltc_depth_60', 'binary': 'true'}"
        )
        connector.send(
            "{'event':'addChannel','channel':'ok_sub_spotusd_btc_trades'}")
        connector.send(
            "{'event':'addChannel','channel':'ok_sub_spotusd_ltc_trades'}")
        connector.send(
            "{'event':'addChannel','channel':'ok_sub_spotusd_btc_trades'}")

        websocket.send(
            "{'event':'addChannel','channel':'ok_sub_spotusd_X_kline_Y'}")
        klineList = []
        klineTypes = [
            '1min', '3min', '5min', '15min', '30min', '1hour', '2hour',
            '4hour', '6hour', '12hour', 'day', '3day', 'week'
        ]
        for klineType in klineTypes:
            connector.send(
                "{'event':'addChannel','channel':'ok_sub_spotusd_btc_kline_'" +
                klineType + "', 'binary':'true'}")
            klineList.append("ok_sub_spotusd_btc_kline_" + klineType)
            connector.send(
                "{'event':'addChannel','channel':'ok_sub_spotusd_ltc_kline_'" +
                klineType + "', 'binary':'true'}")
            klineList.append("ok_sub_spotusd_ltc_kline_" + klineType)
        self.klineList = klineList
        print(klineList)
        klineChannels = [
            'ok_sub_spotusd_btc_kline_1min', 'ok_sub_spotusd_ltc_kline_1min',
            'ok_sub_spotusd_btc_kline_3min', 'ok_sub_spotusd_ltc_kline_3min',
            'ok_sub_spotusd_btc_kline_5min', 'ok_sub_spotusd_ltc_kline_5min',
            'ok_sub_spotusd_btc_kline_15min', 'ok_sub_spotusd_ltc_kline_15min',
            'ok_sub_spotusd_btc_kline_30min', 'ok_sub_spotusd_ltc_kline_30min',
            'ok_sub_spotusd_btc_kline_1hour', 'ok_sub_spotusd_ltc_kline_1hour',
            'ok_sub_spotusd_btc_kline_2hour', 'ok_sub_spotusd_ltc_kline_2hour',
            'ok_sub_spotusd_btc_kline_4hour', 'ok_sub_spotusd_ltc_kline_4hour',
            'ok_sub_spotusd_btc_kline_6hour', 'ok_sub_spotusd_ltc_kline_6hour',
            'ok_sub_spotusd_btc_kline_12hour',
            'ok_sub_spotusd_ltc_kline_12hour', 'ok_sub_spotusd_btc_kline_day',
            'ok_sub_spotusd_ltc_kline_day', 'ok_sub_spotusd_btc_kline_3day',
            'ok_sub_spotusd_ltc_kline_3day', 'ok_sub_spotusd_btc_kline_week',
            'ok_sub_spotusd_ltc_kline_week'
        ]
        self.klineChannels = klineChannels
        for channel in self.klineChannels:
            event = "{'event':'addChannel','channel':'" + channel + "', 'binary': 'true'}"
            connector.send(str(event))

        self.futureTypes = ["this_week", "next_week", "quarter"]

        futureChannels = []
        # f*****g redudndant as mother f*****g shit

        for futureType in self.futureTypes:
            btcChannel = "ok_sub_futureusd_btc_ticker_" + futureType
            btcEvent = "{'event':'addChannel','channel':'" + btcChannel + "', 'binary': 'true'}"
            ltcChannel = "ok_sub_futureusd_ltc_ticker_" + futureType
            ltcEvent = "{'event':'addChannel','channel':'" + ltcChannel + "', 'binary': 'true'}"
            connector.send(str(btcEvent))
            connector.send(str(ltcEvent))
            futureChannels.append(ltcChannel)
            futureChannels.append(btcChannel)
            print('SUBSCRIBED TO THE FUTURE')

        # futureChannels.append("ok_btcusd_future_ticker_this_week")
        # futureChannels.append("ok_btcusd_future_ticker_next_week")
        # futureChannels.append("ok_btcusd_future_ticker_quarter")
        # futureChannels.append("ok_btcusd_future_index")
        # futureChannels.append("ok_sub_futureusd_btc_trade_this_week")
        # futureChannels.append("ok_sub_futureusd_btc_trade_next_week")
        # futureChannels.append("ok_sub_futureusd_btc_trade_quarter")
        # futureChannels.append("ok_sub_futureusd_ltc_trade_this_week")
        # futureChannels.append("ok_sub_futureusd_ltc_trade_next_week")
        # futureChannels.append("ok_sub_futureusd_ltc_trade_quarter")
        self.futureChannels = futureChannels

        connector.send(
            "{'event':'addChannel','channel':'ok_btcusd_future_ticker_this_week', 'binary' : 'true'}"
        )
        connector.send(
            "{'event':'addChannel','channel':'ok_btcusd_future_ticker_next_week', 'binary' : 'true'}"
        )
        connector.send(
            "{'event':'addChannel','channel':'ok_btcusd_future_ticker_quarter', 'binary' : 'true'}"
        )
        connector.send(
            "{'event':'addChannel','channel':'ok_btcusd_future_index', 'binary':'true', 'binary' : 'true'}"
        )
        connector.send(
            "{'event':'addChannel','channel':'ok_sub_futureusd_btc_trade_this_week', 'binary' : 'true'}"
        )
        connector.send(
            "{'event':'addChannel','channel':'ok_sub_futureusd_btc_trade_next_week', 'binary' : 'true'}"
        )
        connector.send(
            "{'event':'addChannel','channel':'ok_sub_futureusd_btc_trade_quarter', 'binary' : 'true'}"
        )
        connector.send(
            "{'event':'addChannel','channel':'ok_sub_futureusd_ltc_trade_this_week', 'binary' : 'true'}"
        )
        connector.send(
            "{'event':'addChannel','channel':'ok_sub_futureusd_ltc_trade_next_week', 'binary' : 'true'}"
        )
        connector.send(
            "{'event':'addChannel','channel':'ok_sub_futureusd_ltc_trade_quarter', 'binary' : 'true'}"
        )
        connector.send(
            "{'event':'addChannel','channel':'ok_btcusd_trades_v1', 'binary': 'true'}"
        )
        connector.send(
            "{'event':'addChannel', 'channel': 'ok_btcusd_kline_1min', 'binary':'true'}"
        )
        connector.send(
            "{'event':'addChannel', 'channel': 'ok_btcusd_kline_3min', 'binary':'true'}"
        )
        connector.send(
            "{'event':'addChannel', 'channel': 'ok_btcusd_kline_5min', 'binary':'true'}"
        )
        connector.send(
            "{'event':'addChannel', 'channel': 'ok_btcusd_kline_15min', 'binary':'true'}"
        )
        connector.send(
            "{'event':'addChannel', 'channel': 'ok_btcusd_kline_30min', 'binary':'true'}"
        )
        connector.send(
            "{'event':'addChannel', 'channel': 'ok_btcusd_kline_1hour', 'binary':'true'}"
        )
        connector.send(
            "{'event':'addChannel', 'channel': 'ok_btcusd_kline_2hour', 'binary':'true'}"
        )
        connector.send(
            "{'event':'addChannel', 'channel': 'ok_btcusd_kline_4hour', 'binary':'true'}"
        )
        connector.send(
            "{'event':'addChannel', 'channel': 'ok_btcusd_kline_6hour', 'binary':'true'}"
        )
        connector.send(
            "{'event':'addChannel', 'channel': 'ok_btcusd_kline_12hour', 'binary':'true'}"
        )
        connector.send(
            "{'event':'addChannel', 'channel': 'ok_btcusd_kline_day', 'binary':'true'}"
        )
        connector.send(
            "{'event':'addChannel', 'channel': 'ok_btcusd_kline_3day', 'binary':'true'}"
        )
        connector.send(
            "{'event':'addChannel', 'channel': 'ok_btcusd_kline_week', 'binary':'true'}"
        )