Esempio n. 1
0
def symbol_liquidation_channel(symbol):
    channel = dict()
    channel["params"] = list()
    channel["params"].append(symbol + "@forceOrder")
    channel["id"] = get_current_timestamp()
    channel["method"] = "SUBSCRIBE"
    return json.dumps(channel)
Esempio n. 2
0
def symbol_ticker_channel(symbol):
    channel = dict()
    channel["params"] = list()
    channel["params"].append(symbol + "@ticker")
    channel["id"] = get_current_timestamp()
    channel["method"] = "SUBSCRIBE"
    return json.dumps(channel)
Esempio n. 3
0
def all_bookticker_channel():
    channel = dict()
    channel["params"] = list()
    channel["params"].append("!bookTicker")
    channel["id"] = get_current_timestamp()
    channel["method"] = "SUBSCRIBE"
    return json.dumps(channel)
Esempio n. 4
0
def kline_channel(symbol, interval):
    channel = dict()
    channel["params"] = list()
    channel["params"].append(symbol + "@kline_" + interval)
    channel["id"] = get_current_timestamp()
    channel["method"] = "SUBSCRIBE"
    return json.dumps(channel)
Esempio n. 5
0
def aggregate_trade_channel(symbol):
    channel = dict()
    channel["params"] = list()
    channel["params"].append(symbol + "@aggTrade")
    channel["id"] = get_current_timestamp()
    channel["method"] = "SUBSCRIBE"
    return json.dumps(channel)
Esempio n. 6
0
def all_mark_price_channel():
    channel = dict()
    channel["params"] = list()
    channel["params"].append("!markPrice@arr")
    channel["id"] = get_current_timestamp()
    channel["method"] = "SUBSCRIBE"
    return json.dumps(channel)
Esempio n. 7
0
def composite_index_channel(symbol):
    channel = dict()
    channel["params"] = list()
    channel["params"].append(symbol + "@compositeIndex")
    channel["id"] = get_current_timestamp()
    channel["method"] = "SUBSCRIBE"
    return json.dumps(channel)
Esempio n. 8
0
def user_data_channel(listenKey):
    channel = dict()
    channel["params"] = list()
    channel["params"].append(listenKey)
    channel["id"] = get_current_timestamp()
    channel["method"] = "SUBSCRIBE"
    return json.dumps(channel)
Esempio n. 9
0
def mark_price_channel(symbol):
    channel = dict()
    channel["params"] = list()
    channel["params"].append(symbol + "@markPrice")
    channel["id"] = get_current_timestamp()
    channel["method"] = "SUBSCRIBE"
    return json.dumps(channel)
Esempio n. 10
0
def book_depth_channel(symbol, limit, update_time):
    channel = dict()
    channel["params"] = list()
    channel["params"].append(symbol + "@depth" + str(limit) + str(update_time))
    channel["id"] = get_current_timestamp()
    channel["method"] = "SUBSCRIBE"
    return json.dumps(channel)
Esempio n. 11
0
def diff_depth_channel(symbol, update_time):
    channel = dict()
    channel["params"] = list()
    channel["params"].append(symbol + "@depth" + update_time)
    channel["id"] = get_current_timestamp()
    channel["method"] = "SUBSCRIBE"
    return json.dumps(channel)
def watch_dog_job(*args):
    watch_dog_instance = args[0]
    for connection in watch_dog_instance.connection_list:
        if connection.state == ConnectionState.CONNECTED:
            if watch_dog_instance.is_auto_connect:
                ts = get_current_timestamp() - connection.last_receive_time
                if ts > watch_dog_instance.receive_limit_ms:
                    watch_dog_instance.logger.warning(
                        "[Sub][" + str(connection.id) +
                        "] No response from server")
                    connection.re_connect_in_delay(
                        watch_dog_instance.connection_delay_failure)
        elif connection.in_delay_connection():
            watch_dog_instance.logger.warning("[Sub] call re_connect")
            connection.re_connect()
            # try:
            #     connection.re_connect()
            # except WebSocketException as e:
            #     connection.re_connect_in_delay(
            #         watch_dog_instance.connection_delay_failure
            #     )
        elif connection.state == ConnectionState.CLOSED_ON_ERROR:
            if watch_dog_instance.is_auto_connect:
                connection.re_connect_in_delay(
                    watch_dog_instance.connection_delay_failure)
                pass
Esempio n. 13
0
def continuous_kline_channel(pair, contract_type, interval):
    channel = dict()
    channel["params"] = list()
    channel["params"].append(pair + '_' + contract_type + "@continuousKline_" + interval)
    channel["id"] = get_current_timestamp()
    channel["method"] = "SUBSCRIBE"
    return json.dumps(channel)
Esempio n. 14
0
 def on_open(self, ws):
     self.logger.info("[Sub][" + str(self.id) + "] Connected to server")
     self.ws = ws
     self.last_receive_time = get_current_timestamp()
     self.state = ConnectionState.CONNECTED
     self.__watch_dog.on_connection_created(self)
     if self.request.subscription_handler is not None:
         self.request.subscription_handler(self)
     return
Esempio n. 15
0
    def on_message(self, message):
        self.last_receive_time = get_current_timestamp()
        json_wrapper = parse_json_from_string(message)

        if json_wrapper.contain_key("status") and json_wrapper.get_string("status") != "ok":
            error_code = json_wrapper.get_string_or_default("err-code", "Unknown error")
            error_msg = json_wrapper.get_string_or_default("err-msg", "Unknown error")
            self.on_error(error_code + ": " + error_msg)
        elif json_wrapper.contain_key("err-code") and json_wrapper.get_int("err-code") != 0:
            error_code = json_wrapper.get_string_or_default("err-code", "Unknown error")
            error_msg = json_wrapper.get_string_or_default("err-msg", "Unknown error")
            self.on_error(error_code + ": " + error_msg)
        elif json_wrapper.contain_key("result") and json_wrapper.contain_key("id"):
            self.__on_receive_response(json_wrapper)
        else:
            self.__on_receive_payload(json_wrapper)
Esempio n. 16
0
 def on_pong(self):
     self.logger.info("[Sub][" + str(self.id) + "] Pong")
     self.last_receive_time = get_current_timestamp()