def _sync_init_connect(self):
        """
        :param client_ver:
        :param client_id:
        :return:(ret, msg)
        """
        query_processor = self._get_sync_query_processor(
            InitConnect.pack_req, InitConnect.unpack_rsp)
        kargs = {
            'client_ver': int(SysConfig.get_client_ver()),
            'client_id': str(SysConfig.get_client_id()),
            'recv_notify': False,
        }
        ret_code, msg, content = query_processor(**kargs)

        if ret_code != RET_OK:
            logger.info("init connect fail: {}".format(msg))
            return RET_ERROR, msg
        else:
            conn_info = copy(content)
            self._sync_conn_id = conn_info['conn_id']
            self._keep_alive_interval = conn_info['keep_alive_interval']
            self._sync_net_ctx.set_conn_id(self._sync_conn_id)
            FutuConnMng.add_conn(conn_info)
            logger.info("sync socket init_connect ok: {}".format(conn_info))

        return RET_OK, ""
    def _clear_conn_id(self):
        if self._sync_conn_id:
            FutuConnMng.remove_conn(self._sync_conn_id)
            self._sync_conn_id = 0

        if self._async_conn_id:
            FutuConnMng.remove_conn(self._async_conn_id)
            self._async_conn_id = 0
 def on_async_init_connect(self, ret, msg, conn_info_map):
     """
     异步socket收到initconnect的回包
     :param ret:
     :param msg:
     :param conn_info_map:
     :return:
     """
     if ret == RET_OK:
         self._async_conn_id = conn_info_map['conn_id']
         self._async_ctx.set_conn_id(self._async_conn_id)
         FutuConnMng.add_conn(conn_info_map)
     logger.debug("async init connect ret={}, msg={}, conn_info={}".format(
         ret, msg, conn_info_map))
 def get_login_user_id(self):
     """
     get login user id
     :return: user id(int64)
     """
     with self._lock:
         return FutuConnMng.get_conn_user_id(self._sync_conn_id)
Exemple #5
0
    def _handle_init_connect(self, conn_id, proto_id, ret, msg, rsp_pb):
        data = None
        if ret == RET_OK:
            ret, msg, data = InitConnect.unpack_rsp(rsp_pb)

        with self._lock:
            self._sync_req_ret = _SyncReqRet(ret, msg)
            if ret == RET_OK:
                conn_info = copy(data)
                self._sync_conn_id = conn_info['conn_id']
                self._keep_alive_interval = conn_info['keep_alive_interval'] * 4 / 5
                self._net_mgr.set_conn_info(conn_id, conn_info)
                self._last_keep_alive_time = datetime.now()
                FutuConnMng.add_conn(conn_info)
                logger.info("sync socket init_connect ok: {}".format(conn_info))
            else:
                logger.error("sync socket init_connect error: {}".format(msg))
    def _handle_init_connect(self, conn_id, proto_info, ret, msg, rsp_pb):
        data = None
        if ret == RET_OK:
            ret, msg, data = InitConnect.unpack_rsp(rsp_pb)

        with self._lock:
            self._sync_req_ret = _SyncReqRet(ret, msg)
            if ret == RET_OK:
                conn_info = copy(data)
                self._sync_conn_id = conn_info['conn_id']
                self._keep_alive_interval = conn_info['keep_alive_interval'] * 4 / 5
                self._net_mgr.set_conn_info(conn_id, conn_info)
                self._last_keep_alive_time = datetime.now()
                FutuConnMng.add_conn(conn_info)
                logger.info(FTLog.make_log_msg("InitConnect ok", conn_id=conn_id, info=conn_info))
            else:
                logger.warning(FTLog.make_log_msg("InitConnect error", msg=msg))
                self._wait_reconnect()