Esempio n. 1
0
 def wait_reconnect_millisecond(self):
     wait_millisecond = int(self.reconnect_after_ms -
                            self.heart_beat_limit_ms)
     now_ms = get_current_timestamp()
     wait_millisecond = wait_millisecond if wait_millisecond else 1000
     # job loop after 1 second
     return (wait_millisecond + now_ms)
Esempio n. 2
0
def watch_dog_job(*args):
    watch_dog_obj = args[0]

    for idx, websocket_manage in enumerate(
            watch_dog_obj.websocket_manage_list):
        if websocket_manage.request.auto_close:  # setting auto close no need reconnect
            pass
        elif websocket_manage.state == ConnectionState.CONNECTED:
            if watch_dog_obj.is_auto_connect:
                ts = get_current_timestamp(
                ) - websocket_manage.last_receive_time
                if ts > watch_dog_obj.heart_beat_limit_ms:
                    watch_dog_obj.logger.warning("[Sub][" +
                                                 str(websocket_manage.id) +
                                                 "] No response from server")
                    websocket_manage.close_and_wait_reconnect(
                        watch_dog_obj.wait_reconnect_millisecond())
        elif websocket_manage.state == ConnectionState.WAIT_RECONNECT:
            watch_dog_obj.logger.warning("[Sub] call re_connect")
            websocket_manage.re_connect()
            pass
        elif websocket_manage.state == ConnectionState.CLOSED_ON_ERROR:
            if watch_dog_obj.is_auto_connect:
                websocket_manage.close_and_wait_reconnect(
                    watch_dog_obj.reconnect_after_ms)
                pass
Esempio n. 3
0
def request_account_list_channel(client_req_id=None):
    channel = dict()
    channel["op"] = "req"
    channel["topic"] = "accounts.list"
    channel["cid"] = str(client_req_id) if client_req_id else str(
        get_current_timestamp())
    return json.dumps(channel)
Esempio n. 4
0
def request_order_detail_channel(order_id, client_req_id=None):
    channel = dict()
    channel["op"] = "req"
    channel["topic"] = "orders.detail"
    channel["order-id"] = str(order_id)
    channel["cid"] = str(client_req_id) if client_req_id else str(
        get_current_timestamp())
    return json.dumps(channel)
Esempio n. 5
0
def request_order_list_channel(symbol,
                               account_id,
                               states_str=None,
                               client_req_id=None,
                               more_key={}):
    channel = dict()
    try:
        channel["op"] = "req"
        channel["account-id"] = account_id
        channel["topic"] = "orders.list"
        channel["symbol"] = symbol
        if states_str and len(states_str):
            channel["states"] = str(states_str)
        channel["cid"] = str(client_req_id) if client_req_id else str(
            get_current_timestamp())
        channel = dict_add_new(channel, more_key)

    except Exception as e:
        print(e)
    return json.dumps(channel)
Esempio n. 6
0
def kline_channel(symbol, interval):
    channel = dict()
    channel["action"] = "sub"
    channel["ch"] = "market_" + symbol + "_kline_" + interval
    channel["id"] = str(get_current_timestamp())
    return json.dumps(channel)
Esempio n. 7
0
def market_all_detail_channel():
    channel = dict()
    channel["action"] = "sub"
    channel["ch"] = "market_ticker"
    channel["id"] = str(get_current_timestamp())
    return json.dumps(channel)
Esempio n. 8
0
def price_depth_channel(symbol, step_type=DepthStep.STEP0):
    channel = dict()
    channel["action"] = "sub"
    channel["ch"] = "market_" + symbol + "_depth_" + step_type
    channel["id"] = str(get_current_timestamp())
    return json.dumps(channel)
Esempio n. 9
0
def trade_detail_channel(symbol):
    channel = dict()
    channel["action"] = "sub"
    channel["ch"] = "market_" + symbol + "_trade_ticker"
    channel["id"] = str(get_current_timestamp())
    return json.dumps(channel)
Esempio n. 10
0
def request_market_detail_channel(symbol):
    channel = dict()
    channel["req"] = "market." + symbol + ".detail"
    channel["id"] = str(get_current_timestamp())
    return json.dumps(channel)
Esempio n. 11
0
def request_price_depth_channel(symbol, step_type="step0"):
    channel = dict()
    channel["action"] = "req"
    channel["ch"] = "market_" + symbol + "_depth_" + step_type
    channel["id"] = str(get_current_timestamp())
    return json.dumps(channel)