예제 #1
0
    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)
                conn_info['is_encrypt'] = self.is_encrypt()
                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._connect_err = msg
                self.close()
예제 #2
0
    def _send_init_connect_sync(self):
        kargs = {
            'client_ver': int(SysConfig.get_client_ver()),
            'client_id': str(SysConfig.get_client_id()),
            'recv_notify': True,
            'is_encrypt': self.is_encrypt(),
            'push_proto_fmt': SysConfig.get_proto_fmt()
        }

        ret, msg, req_str = InitConnect.pack_req(**kargs)
        if ret == RET_OK:
            _, send_result = self._net_mgr.send(self._conn_id, req_str, True)
        else:
            logger.error('Fail to pack InitConnect')
            return ret

        send_result.wait()
        if send_result.err is PacketErr.Ok:
            ret, msg, conn_info = self._handle_init_connect_rsp(
                send_result.rsp)
            if ret == RET_OK:
                # logger.info('InitConnect ok: {}'.format(conn_info))
                logger.info(
                    'InitConnect ok: conn_id={}, host={}, port={}, user_id={}'.
                    format(self._conn_id, self.__host, self.__port,
                           conn_info['login_user_id']))
                return RET_OK

        if msg == '':
            msg = send_result.msg if send_result.msg != '' else str(
                send_result.err)
        logger.warning('InitConnect fail: {}'.format(msg))
        return RET_ERROR
예제 #3
0
    def _handle_init_connect_rsp(self, rsp):
        ret, msg, data = InitConnect.unpack_rsp(rsp)
        if ret != RET_OK:
            return ret, msg, None

        with self._lock:
            conn_info = copy(data)
            conn_info['is_encrypt'] = self.is_encrypt()
            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(self._conn_id, conn_info)
            now = datetime.now()
            self._last_keep_alive_time = now
            self._last_recv_time = now
            self._status = ContextStatus.READY
            FutuConnMng.add_conn(conn_info)
        return ret, '', conn_info
예제 #4
0
    def on_connected(self, conn_id):
        logger.info('Connected : conn_id={0}; '.format(conn_id))
        kargs = {
            'client_ver': int(SysConfig.get_client_ver()),
            'client_id': str(SysConfig.get_client_id()),
            'recv_notify': True,
        }

        ret, msg, req_str = InitConnect.pack_req(**kargs)
        if ret == RET_OK:
            ret, msg = self._net_mgr.send(conn_id, req_str)
        else:
            logger.warning(FTLog.make_log_msg('InitConnect.pack_req fail', msg=msg))

        if ret != RET_OK:
            with self._lock:
                self._sync_req_ret = _SyncReqRet(ret, msg)
예제 #5
0
    def on_connected(self, conn_id):
        logger.info('Connected : conn_id={0}; '.format(conn_id))
        kargs = {
            'client_ver': int(SysConfig.get_client_ver()),
            'client_id': str(SysConfig.get_client_id()),
            'recv_notify': True,
            'is_encrypt': self.is_encrypt(),
            'push_proto_fmt': SysConfig.get_proto_fmt()
        }

        ret, msg, req_str = InitConnect.pack_req(**kargs)
        if ret == RET_OK:
            ret, msg = self._net_mgr.send(conn_id, req_str)
        else:
            logger.warning(FTLog.make_log_msg('InitConnect.pack_req fail', msg=msg))

        if ret != RET_OK:
            with self._lock:
                self._sync_req_ret = _SyncReqRet(RET_ERROR, msg)
                self._connect_err = Err.RsaErr
            self.close()