Beispiel #1
0
        private int sendpacker(OptionFunction function, CT2Packer packer, bool IsAsync = true)
        {
            try
            {
                CT2BizMessage BizMessage = new CT2BizMessage();     //构造消息
                BizMessage.SetFunction((int)function);              //设置功能号
                BizMessage.SetPacketType(0);                        //设置消息类型为请求

                unsafe
                {
                    BizMessage.SetContent(packer.GetPackBuf(), packer.GetPackLen());
                }

                /************************************************************************/

                /* 此处使用异步发送 同步发送可以参考下面注释代码
                 * connection.SendBizMsg(BizMessage, 0);
                 * 1=异步,0=同步
                 * /************************************************************************/
                int iRet = this.connMain.SendBizMsg(BizMessage, (IsAsync) ? 1 : 0);
                if (iRet < 0)
                {
                    MessageManager.GetInstance().Add(MessageType.Error, string.Format("发送错误:{0}", connMain.GetErrorMsg(iRet)));
                }
                packer.Dispose();
                BizMessage.Dispose();

                return(iRet);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Beispiel #2
0
        //发送packer
        private int sendpacker(OptionFunctionCode functioncode, CT2Packer packer, bool IsAsync = true)
        {
            CT2BizMessage BizMessage = new CT2BizMessage();     //构造消息

            BizMessage.SetFunction((int)functioncode);          //设置功能号
            BizMessage.SetPacketType(0);                        //设置消息类型为请求

            unsafe
            {
                BizMessage.SetContent(packer.GetPackBuf(), packer.GetPackLen());
            }

            /************************************************************************/

            /* 此处使用异步发送 同步发送可以参考下面注释代码
             * connection.SendBizMsg(BizMessage, 0);
             * 1=异步,0=同步
             * /************************************************************************/
            int iRet = this.connMain.SendBizMsg(BizMessage, (IsAsync) ? 1 : 0);

            if (iRet < 0)
            {
                Debug.Print(string.Format("发送错误 错误码 {0} 错误信息 {1}", iRet, connMain.GetErrorMsg(iRet)));
            }
            packer.Dispose();
            BizMessage.Dispose();

            return(iRet);
        }
Beispiel #3
0
        public ConnectionCode HeartBeat()
        {
            FunctionItem functionItem = ConfigManager.Instance.GetFunctionConfig().GetFunctionItem(FunctionCode.HeartBeat);

            if (functionItem == null || functionItem.RequestFields == null || functionItem.RequestFields.Count == 0)
            {
                return(ConnectionCode.ErrorLogin);
            }

            CT2BizMessage bizMessage = new CT2BizMessage();

            //初始化
            bizMessage.SetFunction((int)FunctionCode.HeartBeat);
            bizMessage.SetPacketType(CT2tag_def.REQUEST_PACKET);

            //业务包
            CT2Packer packer = new CT2Packer(2);

            packer.BeginPack();
            foreach (FieldItem item in functionItem.RequestFields)
            {
                packer.AddField(item.Name, item.Type, item.Width, item.Scale);
            }

            foreach (FieldItem item in functionItem.RequestFields)
            {
                switch (item.Name)
                {
                case "user_token":
                    packer.AddStr(LoginManager.Instance.LoginUser.Token);
                    break;

                default:
                    break;
                }
            }

            packer.EndPack();

            unsafe
            {
                bizMessage.SetContent(packer.GetPackBuf(), packer.GetPackLen());
            }

            int retCode = _t2SDKWrap.SendSync(bizMessage);

            packer.Dispose();
            bizMessage.Dispose();

            if (retCode < 0)
            {
                logger.Error("心跳检测失败");

                return(ConnectionCode.ErrorConn);
            }

            return(ConnectionCode.Success);
        }
Beispiel #4
0
        public ConnectionCode Login(LoginUser user)
        {
            UFXFunctionCode functionCode = UFXFunctionCode.Login;
            FunctionItem    functionItem = ConfigManager.Instance.GetFunctionConfig().GetFunctionItem(functionCode);

            if (functionItem == null || functionItem.RequestFields == null || functionItem.RequestFields.Count == 0)
            {
                return(ConnectionCode.ErrorLogin);
            }

            LoginManager.Instance.LoginUser = user;
            CT2BizMessage bizMessage = new CT2BizMessage();

            //初始化
            bizMessage.SetFunction((int)functionCode);
            bizMessage.SetPacketType(CT2tag_def.REQUEST_PACKET);

            //业务包
            CT2Packer packer = new CT2Packer(2);

            packer.BeginPack();
            foreach (FieldItem item in functionItem.RequestFields)
            {
                packer.AddField(item.Name, item.Type, item.Width, item.Scale);
            }

            foreach (FieldItem item in functionItem.RequestFields)
            {
                switch (item.Name)
                {
                case "operator_no":
                    packer.AddStr(user.Operator);
                    break;

                case "password":
                    packer.AddStr(user.Password);
                    break;

                case "mac_address":
                {
                    packer.AddStr(ConfigManager.Instance.GetTerminalConfig().MacAddress);
                }
                break;

                case "op_station":
                {
                    packer.AddStr("www.htsec.com");
                }
                break;

                case "ip_address":
                {
                    packer.AddStr(ConfigManager.Instance.GetTerminalConfig().IPAddress);
                }
                break;

                case "hd_volserial":
                {
                    packer.AddStr("");
                }
                break;

                case "authorization_id":
                {
                    //TODO:
                    packer.AddStr("authorization_id");
                }
                break;

                default:
                    if (item.Type == UFXPackFieldType.IntType)
                    {
                        packer.AddInt(-1);
                    }
                    else if (item.Type == UFXPackFieldType.StringType || item.Type == UFXPackFieldType.CharType)
                    {
                        packer.AddStr(item.Name);
                    }
                    else
                    {
                        packer.AddStr(item.Name);
                    }
                    break;
                }
            }
            packer.EndPack();

            unsafe
            {
                bizMessage.SetContent(packer.GetPackBuf(), packer.GetPackLen());
            }

            var parser = _t2SDKWrap.SendSync2(bizMessage);

            packer.Dispose();
            bizMessage.Dispose();

            var ret = parser.ErrorCode;

            if (ret == ConnectionCode.Success)
            {
                string token    = string.Empty;
                string version  = string.Empty;
                var    response = T2ErrorHandler.Handle(parser);
                if (T2ErrorHandler.Success(response.ErrorCode))
                {
                    if (parser.DataSets[1].Rows[0].Columns.ContainsKey("user_token"))
                    {
                        token = parser.DataSets[1].Rows[0].Columns["user_token"].GetStr();
                    }

                    if (parser.DataSets[1].Rows[0].Columns.ContainsKey("version_no"))
                    {
                        version = parser.DataSets[1].Rows[0].Columns["version_no"].GetStr();
                    }

                    string msg = string.Format("Login success - token: [{0}], version: [{1}]", token, version);
                    UFXLogger.Info(logger, functionCode, msg);
                }
                else
                {
                    UFXLogger.Error(logger, functionCode, response);
                }

                if (!string.IsNullOrEmpty(token))
                {
                    LoginManager.Instance.LoginUser.Token = token;
                    ret = ConnectionCode.Success;
                }
                else
                {
                    ret = ConnectionCode.ErrorLogin;
                }
            }

            return(ret);
        }
Beispiel #5
0
        public ConnectionCode Logout()
        {
            UFXFunctionCode functionCode = UFXFunctionCode.Logout;
            FunctionItem    functionItem = ConfigManager.Instance.GetFunctionConfig().GetFunctionItem(functionCode);

            if (functionItem == null || functionItem.RequestFields == null || functionItem.RequestFields.Count == 0)
            {
                return(ConnectionCode.ErrorLogin);
            }

            CT2BizMessage bizMessage = new CT2BizMessage();

            //初始化
            bizMessage.SetFunction((int)functionCode);
            bizMessage.SetPacketType(CT2tag_def.REQUEST_PACKET);

            //业务包
            CT2Packer packer = new CT2Packer(2);

            packer.BeginPack();
            foreach (FieldItem item in functionItem.RequestFields)
            {
                packer.AddField(item.Name, item.Type, item.Width, item.Scale);
            }

            foreach (FieldItem item in functionItem.RequestFields)
            {
                switch (item.Name)
                {
                case "user_token":
                    packer.AddStr(LoginManager.Instance.LoginUser.Token);
                    break;

                default:
                    break;
                }
            }

            packer.EndPack();

            unsafe
            {
                bizMessage.SetContent(packer.GetPackBuf(), packer.GetPackLen());
            }

            var parser = _t2SDKWrap.SendSync2(bizMessage);

            packer.Dispose();
            bizMessage.Dispose();

            var ret = parser.ErrorCode;

            if (ret == ConnectionCode.Success)
            {
                var response = T2ErrorHandler.Handle(parser);
                if (!T2ErrorHandler.Success(response.ErrorCode))
                {
                    UFXLogger.Error(logger, functionCode, response);
                    return(ConnectionCode.ErrorFailContent);
                }
            }
            else
            {
                UFXLogger.Error(logger, functionCode, "退出登录失败!");
            }

            return(ret);
        }
Beispiel #6
0
        public ConnectionCode Login(User user)
        {
            if (!IsInit)
            {
                var retCon = Init();
                if (retCon != ConnectionCode.Success)
                {
                    return(retCon);
                }
            }

            FunctionItem functionItem = ConfigManager.Instance.GetFunctionConfig().GetFunctionItem(FunctionCode.Login);

            if (functionItem == null || functionItem.RequestFields == null || functionItem.RequestFields.Count == 0)
            {
                return(ConnectionCode.ErrorLogin);
            }
            CT2BizMessage bizMessage = new CT2BizMessage();

            //初始化
            bizMessage.SetFunction((int)FunctionCode.Login);
            bizMessage.SetPacketType(CT2tag_def.REQUEST_PACKET);

            //业务包
            CT2Packer packer = new CT2Packer(2);

            packer.BeginPack();
            foreach (FieldItem item in functionItem.RequestFields)
            {
                packer.AddField(item.Name, item.Type, item.Width, item.Scale);
            }

            foreach (FieldItem item in functionItem.RequestFields)
            {
                switch (item.Name)
                {
                case "operator_no":
                    packer.AddStr(user.Operator);
                    break;

                case "password":
                    packer.AddStr(user.Password);
                    break;

                case "mac_address":
                {
                    packer.AddStr(ConfigManager.Instance.GetTerminalConfig().MacAddress);
                }
                break;

                case "op_station":
                {
                    packer.AddStr("www.htsec.com");
                }
                break;

                case "ip_address":
                {
                    packer.AddStr(ConfigManager.Instance.GetTerminalConfig().IPAddress);
                }
                break;

                case "hd_volserial":
                {
                    packer.AddStr("");
                }
                break;

                case "authorization_id":
                {
                    //TODO:
                    packer.AddStr("authorization_id");
                }
                break;

                default:
                    if (item.Type == PackFieldType.IntType)
                    {
                        packer.AddInt(-1);
                    }
                    else if (item.Type == PackFieldType.StringType || item.Type == PackFieldType.CharType)
                    {
                        packer.AddStr(item.Name);
                    }
                    else
                    {
                        packer.AddStr(item.Name);
                    }
                    break;
                }
            }
            packer.EndPack();

            unsafe
            {
                bizMessage.SetContent(packer.GetPackBuf(), packer.GetPackLen());
            }

            int retCode = SendSync(bizMessage);

            packer.Dispose();
            bizMessage.Dispose();

            if (retCode < 0)
            {
                logger.Error("登录失败:" + _conn.GetErrorMsg(retCode));
                return(ConnectionCode.ErrorConn);
            }

            return(ReceivedBizMsg(retCode, FunctionCode.Login));
        }
Beispiel #7
0
        public ConnectionCode Logout()
        {
            if (!IsInit)
            {
                var retCon = Init();
                if (retCon != ConnectionCode.Success)
                {
                    return(retCon);
                }
            }

            FunctionItem functionItem = ConfigManager.Instance.GetFunctionConfig().GetFunctionItem(FunctionCode.Logout);

            if (functionItem == null || functionItem.RequestFields == null || functionItem.RequestFields.Count == 0)
            {
                return(ConnectionCode.ErrorLogin);
            }

            CT2BizMessage bizMessage = new CT2BizMessage();

            //初始化
            bizMessage.SetFunction((int)FunctionCode.Logout);
            bizMessage.SetPacketType(CT2tag_def.REQUEST_PACKET);

            //业务包
            CT2Packer packer = new CT2Packer(2);

            packer.BeginPack();
            foreach (FieldItem item in functionItem.RequestFields)
            {
                packer.AddField(item.Name, item.Type, item.Width, item.Scale);
            }

            foreach (FieldItem item in functionItem.RequestFields)
            {
                switch (item.Name)
                {
                case "user_token":
                    packer.AddStr(LoginManager.Instance.LoginUser.Token);
                    break;

                default:
                    break;
                }
            }


            unsafe
            {
                bizMessage.SetContent(packer.GetPackBuf(), packer.GetPackLen());
            }

            int retCode = SendSync(bizMessage);

            packer.Dispose();
            bizMessage.Dispose();

            if (retCode < 0)
            {
                logger.Error("退出登录失败:" + _conn.GetErrorMsg(retCode));
                return(ConnectionCode.ErrorConn);
            }

            var retConnCode = ReceivedBizMsg(retCode, FunctionCode.Logout);


            return(retConnCode);
        }
Beispiel #8
0
        public ConnectionCode QueryHolder()
        {
            UFXFunctionCode functionCode = UFXFunctionCode.QueryHolder;
            FunctionItem    functionItem = ConfigManager.Instance.GetFunctionConfig().GetFunctionItem(functionCode);

            if (functionItem == null || functionItem.RequestFields == null || functionItem.RequestFields.Count == 0)
            {
                return(ConnectionCode.ErrorLogin);
            }

            CT2BizMessage bizMessage = new CT2BizMessage();

            //初始化
            bizMessage.SetFunction((int)functionCode);
            bizMessage.SetPacketType(CT2tag_def.REQUEST_PACKET);

            //业务包
            CT2Packer packer = new CT2Packer(2);

            packer.BeginPack();
            foreach (FieldItem item in functionItem.RequestFields)
            {
                packer.AddField(item.Name, item.Type, item.Width, item.Scale);
            }

            foreach (FieldItem item in functionItem.RequestFields)
            {
                switch (item.Name)
                {
                case "user_token":
                    packer.AddStr(LoginManager.Instance.LoginUser.Token);
                    break;

                case "account_code":
                    packer.AddStr("");
                    break;

                case "asset_no":
                    packer.AddStr("");
                    break;

                case "combi_no":
                    packer.AddStr("");
                    break;

                case "market_no":
                    packer.AddStr("");
                    break;

                default:
                    break;
                }
            }

            packer.EndPack();

            unsafe
            {
                bizMessage.SetContent(packer.GetPackBuf(), packer.GetPackLen());
            }

            var parser = _t2SDKWrap.SendSync2(bizMessage);

            packer.Dispose();
            bizMessage.Dispose();

            if (parser.ErrorCode != ConnectionCode.Success)
            {
                UFXLogger.Error(logger, functionCode, "交易股东查询失败");
                return(parser.ErrorCode);
            }

            var response = T2ErrorHandler.Handle(parser);

            if (T2ErrorHandler.Success(response.ErrorCode))
            {
                if (parser.DataSets.Count > 1)
                {
                    var dataSet = parser.DataSets[1];
                    foreach (var dataRow in dataSet.Rows)
                    {
                        HolderItem p = new HolderItem();
                        p.AccountCode   = dataRow.Columns["account_code"].GetStr();
                        p.AssetNo       = dataRow.Columns["asset_no"].GetStr();
                        p.CombiNo       = dataRow.Columns["combi_no"].GetStr();
                        p.StockHolderId = dataRow.Columns["stockholder_id"].GetStr();
                        p.MarketNo      = dataRow.Columns["market_no"].GetStr();

                        LoginManager.Instance.AddHolder(p);
                    }
                }

                return(ConnectionCode.Success);
            }
            else
            {
                UFXLogger.Error(logger, functionCode, response);
                return(ConnectionCode.ErrorFailContent);
            }
        }
Beispiel #9
0
        public ConnectionCode QueryAccount()
        {
            UFXFunctionCode functionCode = UFXFunctionCode.QueryAccount;
            FunctionItem    functionItem = ConfigManager.Instance.GetFunctionConfig().GetFunctionItem(functionCode);

            if (functionItem == null || functionItem.RequestFields == null || functionItem.RequestFields.Count == 0)
            {
                return(ConnectionCode.ErrorLogin);
            }

            CT2BizMessage bizMessage = new CT2BizMessage();

            //初始化
            bizMessage.SetFunction((int)functionCode);
            bizMessage.SetPacketType(CT2tag_def.REQUEST_PACKET);

            //业务包
            CT2Packer packer = new CT2Packer(2);

            packer.BeginPack();
            foreach (FieldItem item in functionItem.RequestFields)
            {
                packer.AddField(item.Name, item.Type, item.Width, item.Scale);
            }

            foreach (FieldItem item in functionItem.RequestFields)
            {
                switch (item.Name)
                {
                case "user_token":
                    packer.AddStr(LoginManager.Instance.LoginUser.Token);
                    break;

                case "account_code":
                    packer.AddStr("");
                    break;

                default:
                    break;
                }
            }

            packer.EndPack();

            unsafe
            {
                bizMessage.SetContent(packer.GetPackBuf(), packer.GetPackLen());
            }

            var parser = _t2SDKWrap.SendSync2(bizMessage);

            packer.Dispose();
            bizMessage.Dispose();

            if (parser.ErrorCode != ConnectionCode.Success)
            {
                UFXLogger.Error(logger, functionCode, "账户查询失败");
                return(ConnectionCode.ErrorConn);
            }

            var response = T2ErrorHandler.Handle(parser);

            if (T2ErrorHandler.Success(response.ErrorCode))
            {
                if (parser.DataSets.Count > 1)
                {
                    var dataSet = parser.DataSets[1];
                    foreach (var dataRow in dataSet.Rows)
                    {
                        AccountItem acc = new AccountItem();
                        acc.AccountCode = dataRow.Columns["account_code"].GetStr();
                        acc.AccountName = dataRow.Columns["account_name"].GetStr();

                        string accType = dataRow.Columns["account_type"].GetStr();
                        int    temp;
                        if (int.TryParse(accType, out temp))
                        {
                            acc.AccountType = (FundAccountType)temp;
                        }

                        LoginManager.Instance.AddAccount(acc);
                    }
                }

                return(ConnectionCode.Success);
            }
            else
            {
                UFXLogger.Error(logger, functionCode, response);
                return(ConnectionCode.ErrorFailContent);
            }
        }
Beispiel #10
0
        /// <summary>
        /// 异步调用UFX接口,完成调用之后,如果不出错,则注册回调信息
        /// </summary>
        /// <typeparam name="T">A generic type defines the UFX request parameters.</typeparam>
        /// <param name="functionCode">An enum type defines the UFX interface number.</param>
        /// <param name="requests">A generic request list. NOTE: the caller MUST control the request count if the
        /// interface does not support many requests at a time.
        /// </param>
        /// <param name="callbacker">It is used to store the callback information.</param>
        /// <returns>It is used to define the call result.</returns>
        public ConnectionCode SubmitAsync <T>(UFXFunctionCode functionCode, List <T> requests, Callbacker callbacker)
        {
            FunctionItem functionItem = ConfigManager.Instance.GetFunctionConfig().GetFunctionItem(functionCode);

            if (functionItem == null || functionItem.RequestFields == null || functionItem.RequestFields.Count == 0)
            {
                string msg = string.Format("提交UFX请求号[{0}]未定义!", functionCode);
                logger.Error(msg);
                return(ConnectionCode.ErrorNoFunctionCode);
            }

            string userToken = LoginManager.Instance.LoginUser.Token;

            if (string.IsNullOrEmpty(userToken))
            {
                string msg = string.Format("提交UFX请求[{0}]令牌失效!", functionCode);
                logger.Error(msg);
                return(ConnectionCode.ErrorLogin);
            }

            CT2BizMessage bizMessage = new CT2BizMessage();

            //初始化
            bizMessage.SetFunction((int)functionCode);
            bizMessage.SetPacketType(CT2tag_def.REQUEST_PACKET);

            //业务包
            CT2Packer packer = new CT2Packer(2);

            packer.BeginPack();

            foreach (FieldItem item in functionItem.RequestFields)
            {
                packer.AddField(item.Name, item.Type, item.Width, item.Scale);
            }

            var dataFieldMap = UFXDataBindingHelper.GetProperty <T>();

            foreach (var request in requests)
            {
                foreach (FieldItem item in functionItem.RequestFields)
                {
                    if (dataFieldMap.ContainsKey(item.Name))
                    {
                        SetRequestField <T>(ref packer, request, item, dataFieldMap);
                    }
                    else
                    {
                        SetRequestDefaultField(ref packer, item, userToken);
                    }
                }
            }
            packer.EndPack();

#if DEBUG
            OutputParam <T>(functionCode, requests);
#endif
            unsafe
            {
                bizMessage.SetContent(packer.GetPackBuf(), packer.GetPackLen());
            }

            ConnectionCode retCode = ConnectionCode.Success;
            int            hSend   = _t2SDKWrap.SendAsync(bizMessage);
            if (hSend < 0)
            {
                string msg = string.Format("提交UFX请求[{0}]失败, 返回值:[{1}]!", functionCode, hSend);
                logger.Error(msg);
                retCode = ConnectionCode.ErrorConn;
            }
            else
            {
                //注册UFX返回数据后,需要调用的回调
                //此处存在假设,异步提交返回之前,不会触发回调
                AddDataHandler(functionCode, hSend, callbacker);
                retCode = ConnectionCode.Success;
            }

            packer.Dispose();
            bizMessage.Dispose();

            return(retCode);
        }
Beispiel #11
0
        public ConnectionCode WithdrawBasket()
        {
            FunctionItem functionItem = ConfigManager.Instance.GetFunctionConfig().GetFunctionItem(FunctionCode.WithdrawBasket);

            if (functionItem == null || functionItem.RequestFields == null || functionItem.RequestFields.Count == 0)
            {
                return(ConnectionCode.ErrorNoFunctionCode);
            }

            string userToken = LoginManager.Instance.LoginUser.Token;

            if (string.IsNullOrEmpty(userToken))
            {
                return(ConnectionCode.ErrorLogin);
            }

            CT2BizMessage bizMessage = new CT2BizMessage();

            //初始化
            bizMessage.SetFunction((int)FunctionCode.WithdrawBasket);
            bizMessage.SetPacketType(CT2tag_def.REQUEST_PACKET);

            //业务包
            CT2Packer packer = new CT2Packer(2);

            packer.BeginPack();
            foreach (FieldItem item in functionItem.RequestFields)
            {
                packer.AddField(item.Name, item.Type, item.Width, item.Scale);
            }

            foreach (FieldItem item in functionItem.RequestFields)
            {
                switch (item.Name)
                {
                case "user_token":
                {
                    packer.AddStr(userToken);
                }
                break;

                case "batch_no":
                {
                    packer.AddInt(-1);
                }
                break;

                default:
                    if (item.Type == PackFieldType.IntType)
                    {
                        packer.AddInt(-1);
                    }
                    else if (item.Type == PackFieldType.StringType || item.Type == PackFieldType.CharType)
                    {
                        packer.AddStr(item.Name);
                    }
                    else
                    {
                        packer.AddStr(item.Name);
                    }
                    break;
                }
            }
            packer.EndPack();

            unsafe
            {
                bizMessage.SetContent(packer.GetPackBuf(), packer.GetPackLen());
            }

            int retCode = _t2SDKWrap.SendAsync(bizMessage);

            packer.Dispose();
            bizMessage.Dispose();

            if (retCode < 0)
            {
                logger.Error("撤销委托实例失败!");
                return(ConnectionCode.ErrorConn);
            }

            return(ConnectionCode.Success);
        }
Beispiel #12
0
        public ConnectionCode EntrustBasket()
        {
            FunctionItem functionItem = ConfigManager.Instance.GetFunctionConfig().GetFunctionItem(FunctionCode.EntrustBasket);

            if (functionItem == null || functionItem.RequestFields == null || functionItem.RequestFields.Count == 0)
            {
                return(ConnectionCode.ErrorNoFunctionCode);
            }

            string userToken = LoginManager.Instance.LoginUser.Token;

            if (string.IsNullOrEmpty(userToken))
            {
                return(ConnectionCode.ErrorLogin);
            }

            CT2BizMessage bizMessage = new CT2BizMessage();

            //初始化
            bizMessage.SetFunction((int)FunctionCode.EntrustBasket);
            bizMessage.SetPacketType(CT2tag_def.REQUEST_PACKET);

            //业务包
            CT2Packer packer = new CT2Packer(2);

            packer.BeginPack();
            foreach (FieldItem item in functionItem.RequestFields)
            {
                packer.AddField(item.Name, item.Type, item.Width, item.Scale);
            }

            foreach (FieldItem item in functionItem.RequestFields)
            {
                switch (item.Name)
                {
                case "user_token":
                {
                    packer.AddStr(userToken);
                }
                break;

                case "account_code":
                {
                    packer.AddStr("");
                }
                break;

                case "asset_no":
                {
                    packer.AddStr("");
                }
                break;

                case "combi_no":
                {
                    packer.AddStr("");
                }
                break;

                case "instance_no":
                {
                    packer.AddStr("");
                }
                break;

                case "stockholder_id":
                {
                    packer.AddStr("");
                }
                break;

                case "report_seat":
                {
                    packer.AddStr("");
                }
                break;

                case "market_no":
                {
                    packer.AddStr("");
                }
                break;

                case "stock_code":
                {
                    packer.AddStr("");
                }
                break;

                case "entrust_direction":
                {
                    packer.AddStr("");
                }
                break;

                case "futures_direction":
                {
                    packer.AddStr("");
                }
                break;

                case "price_type":
                {
                    packer.AddDouble(0.0f);
                }
                break;

                case "entrust_price":
                {
                    packer.AddDouble(0.0f);
                }
                break;

                case "entrust_amount":
                {
                    packer.AddInt(0);
                }
                break;

                case "limit_entrust_ratio":
                {
                    packer.AddDouble(0.0f);
                }
                break;

                case "max_cancel_ratio":
                {
                    packer.AddDouble(0.0f);
                }
                break;

                case "invest_type":
                {
                    packer.AddStr("");
                }
                break;

                case "extsystem_id":
                {
                    packer.AddStr("");
                }
                break;

                case "third_reff":
                {
                    packer.AddStr("");
                }
                break;

                default:
                    if (item.Type == PackFieldType.IntType)
                    {
                        packer.AddInt(-1);
                    }
                    else if (item.Type == PackFieldType.StringType || item.Type == PackFieldType.CharType)
                    {
                        packer.AddStr(item.Name);
                    }
                    else
                    {
                        packer.AddStr(item.Name);
                    }
                    break;
                }
            }
            packer.EndPack();

            unsafe
            {
                bizMessage.SetContent(packer.GetPackBuf(), packer.GetPackLen());
            }

            int retCode = _t2SDKWrap.SendAsync(bizMessage);

            packer.Dispose();
            bizMessage.Dispose();

            if (retCode < 0)
            {
                logger.Error("证券篮子委托失败!");
                return(ConnectionCode.ErrorConn);
            }

            return(ConnectionCode.Success);
        }
Beispiel #13
0
        public ConnectionCode QueryTrading()
        {
            FunctionItem functionItem = ConfigManager.Instance.GetFunctionConfig().GetFunctionItem(FunctionCode.QueryTradingInstance);

            if (functionItem == null || functionItem.RequestFields == null || functionItem.RequestFields.Count == 0)
            {
                return(ConnectionCode.ErrorNoFunctionCode);
            }

            string userToken = LoginManager.Instance.LoginUser.Token;

            if (string.IsNullOrEmpty(userToken))
            {
                return(ConnectionCode.ErrorLogin);
            }

            CT2BizMessage bizMessage = new CT2BizMessage();

            //初始化
            bizMessage.SetFunction((int)FunctionCode.QueryTradingInstance);
            bizMessage.SetPacketType(CT2tag_def.REQUEST_PACKET);

            //业务包
            CT2Packer packer = new CT2Packer(2);

            packer.BeginPack();
            foreach (FieldItem item in functionItem.RequestFields)
            {
                packer.AddField(item.Name, item.Type, item.Width, item.Scale);
            }

            //string[] account_code = new string[3] { "850010", "S54638", "SF0007" };

            //foreach (string s in account_code)
            //{
            foreach (FieldItem item in functionItem.RequestFields)
            {
                switch (item.Name)
                {
                case "user_token":
                {
                    packer.AddStr(userToken);
                }
                break;

                case "account_group_code":
                {
                    packer.AddStr("");
                }
                break;

                case "instance_no":
                {
                    packer.AddStr("");
                }
                break;

                case "instance_type":
                {
                    packer.AddStr("");
                }
                break;

                case "ext_invest_plan_no_list":
                {
                    packer.AddStr("");
                }
                break;

                default:
                    if (item.Type == PackFieldType.IntType)
                    {
                        packer.AddInt(-1);
                    }
                    else if (item.Type == PackFieldType.StringType || item.Type == PackFieldType.CharType)
                    {
                        packer.AddStr(item.Name);
                    }
                    else
                    {
                        packer.AddStr(item.Name);
                    }
                    break;
                }
            }
            //}
            packer.EndPack();

            unsafe
            {
                bizMessage.SetContent(packer.GetPackBuf(), packer.GetPackLen());
            }

            int retCode = _t2SDKWrap.SendAsync(bizMessage);

            packer.Dispose();
            bizMessage.Dispose();

            if (retCode < 0)
            {
                logger.Error("查询交易实例失败!");
                return(ConnectionCode.ErrorConn);
            }

            return(ConnectionCode.Success);
        }
Beispiel #14
0
        public DataParser SubmitSync <T>(UFXFunctionCode functionCode, List <T> requests)
        {
            DataParser parser = new DataParser();

            FunctionItem functionItem = ConfigManager.Instance.GetFunctionConfig().GetFunctionItem(functionCode);

            if (functionItem == null || functionItem.RequestFields == null || functionItem.RequestFields.Count == 0)
            {
                string msg = string.Format("提交UFX请求号[{0}]未定义!", functionCode);
                logger.Error(msg);
                parser.ErrorCode = ConnectionCode.ErrorNoFunctionCode;

                return(parser);
            }

            string userToken = LoginManager.Instance.LoginUser.Token;

            if (string.IsNullOrEmpty(userToken))
            {
                string msg = string.Format("提交UFX请求[{0}]令牌失效!", functionCode);
                logger.Error(msg);
                parser.ErrorCode = ConnectionCode.ErrorLogin;

                return(parser);
            }

            CT2BizMessage bizMessage = new CT2BizMessage();

            //初始化
            bizMessage.SetFunction((int)functionCode);
            bizMessage.SetPacketType(CT2tag_def.REQUEST_PACKET);

            //业务包
            CT2Packer packer = new CT2Packer(2);

            packer.BeginPack();

            foreach (FieldItem item in functionItem.RequestFields)
            {
                packer.AddField(item.Name, item.Type, item.Width, item.Scale);
            }

            var dataFieldMap = UFXDataBindingHelper.GetProperty <T>();

            foreach (var request in requests)
            {
                foreach (FieldItem item in functionItem.RequestFields)
                {
                    if (dataFieldMap.ContainsKey(item.Name))
                    {
                        SetRequestField <T>(ref packer, request, item, dataFieldMap);
                    }
                    else
                    {
                        SetRequestDefaultField(ref packer, item, userToken);
                    }
                }
            }
            packer.EndPack();

#if DEBUG
            OutputParam <T>(functionCode, requests);
#endif
            unsafe
            {
                bizMessage.SetContent(packer.GetPackBuf(), packer.GetPackLen());
            }

            parser = _t2SDKWrap.SendSync2(bizMessage);
            return(parser);
        }
Beispiel #15
0
        public ConnectionCode QueryEntrust()
        {
            FunctionItem functionItem = ConfigManager.Instance.GetFunctionConfig().GetFunctionItem(FunctionCode.QuerySecurityEntrust);

            if (functionItem == null || functionItem.RequestFields == null || functionItem.RequestFields.Count == 0)
            {
                return(ConnectionCode.ErrorNoFunctionCode);
            }

            string userToken = LoginManager.Instance.LoginUser.Token;

            if (string.IsNullOrEmpty(userToken))
            {
                return(ConnectionCode.ErrorLogin);
            }

            CT2BizMessage bizMessage = new CT2BizMessage();

            //初始化
            bizMessage.SetFunction((int)FunctionCode.QuerySecurityEntrust);
            bizMessage.SetPacketType(CT2tag_def.REQUEST_PACKET);

            //业务包
            CT2Packer packer = new CT2Packer(2);

            packer.BeginPack();
            foreach (FieldItem item in functionItem.RequestFields)
            {
                packer.AddField(item.Name, item.Type, item.Width, item.Scale);
            }

            foreach (FieldItem item in functionItem.RequestFields)
            {
                switch (item.Name)
                {
                case "user_token":
                {
                    packer.AddStr(userToken);
                }
                break;

                case "batch_no":
                {
                    packer.AddInt(2317379);
                }
                break;

                case "entrust_no":
                {
                    packer.AddInt(-1);
                }
                break;

                case "account_code":
                {
                    packer.AddStr("");
                }
                break;

                case "asset_no":
                {
                    packer.AddStr("");
                }
                break;

                case "combi_no":
                {
                    packer.AddStr("");
                }
                break;

                case "stockholder_id":
                {
                    packer.AddStr("");
                }
                break;

                case "market_no":
                {
                    packer.AddStr("");
                }
                break;

                case "stock_code":
                {
                    packer.AddStr("");
                }
                break;

                case "entrust_direction":
                {
                    packer.AddStr("");
                }
                break;

                case "entrust_state_list":
                {
                    packer.AddStr("");
                }
                break;

                case "extsystem_id":
                {
                    packer.AddInt(-1);
                }
                break;

                case "third_reff":
                {
                    packer.AddStr("");
                }
                break;

                case "position_str":
                {
                    packer.AddStr("");
                }
                break;

                case "request_num":
                {
                    packer.AddInt(1000);
                }
                break;

                default:
                    if (item.Type == PackFieldType.IntType)
                    {
                        packer.AddInt(-1);
                    }
                    else if (item.Type == PackFieldType.StringType || item.Type == PackFieldType.CharType)
                    {
                        packer.AddStr(item.Name);
                    }
                    else
                    {
                        packer.AddStr(item.Name);
                    }
                    break;
                }
            }
            packer.EndPack();

            unsafe
            {
                bizMessage.SetContent(packer.GetPackBuf(), packer.GetPackLen());
            }

            int retCode = _t2SDKWrap.SendAsync(bizMessage);

            packer.Dispose();
            bizMessage.Dispose();

            if (retCode < 0)
            {
                logger.Error("撤销委托实例失败!");
                return(ConnectionCode.ErrorConn);
            }

            return(ConnectionCode.Success);
        }
Beispiel #16
0
        public ConnectionCode QueryTradingInstance(string userToken)
        {
            FunctionItem functionItem = ConfigManager.Instance.GetFunctionConfig().GetFunctionItem(FunctionCode.QueryTradingInstance);

            if (functionItem == null || functionItem.RequestFields == null || functionItem.RequestFields.Count == 0)
            {
                return(ConnectionCode.ErrorLogin);
            }
            CT2BizMessage bizMessage = new CT2BizMessage();

            //初始化
            bizMessage.SetFunction((int)FunctionCode.QueryTradingInstance);
            bizMessage.SetPacketType(CT2tag_def.REQUEST_PACKET);

            //业务包
            CT2Packer packer = new CT2Packer(2);

            packer.BeginPack();
            foreach (FieldItem item in functionItem.RequestFields)
            {
                packer.AddField(item.Name, item.Type, item.Width, item.Scale);
            }

            foreach (FieldItem item in functionItem.RequestFields)
            {
                switch (item.Name)
                {
                case "user_token":
                    packer.AddStr(userToken);
                    break;

                case "account_group_code":
                    packer.AddStr("");
                    break;

                case "instance_no":
                    packer.AddInt(0);
                    break;

                case "instance_type":
                    packer.AddStr("");
                    break;

                case "ext_invest_plan_no_list":
                    packer.AddStr("");
                    break;

                default:
                    break;
                }
            }
            unsafe
            {
                bizMessage.SetContent(packer.GetPackBuf(), packer.GetPackLen());
            }

            int retCode = SendAsync(bizMessage);

            packer.Dispose();
            bizMessage.Dispose();

            if (retCode < 0)
            {
                logger.Error("查询交易实例失败:" + _conn.GetErrorMsg(retCode));
                return(ConnectionCode.ErrorConn);
            }

            return(ConnectionCode.Success);
        }
Beispiel #17
0
        public ConnectionCode QueryInstance(AccountItem account)
        {
            FunctionItem functionItem = ConfigManager.Instance.GetFunctionConfig().GetFunctionItem(FunctionCode.QueryTradingInstance1);

            if (functionItem == null || functionItem.RequestFields == null || functionItem.RequestFields.Count == 0)
            {
                return(ConnectionCode.ErrorNoFunctionCode);
            }

            string userToken = LoginManager.Instance.LoginUser.Token;

            if (string.IsNullOrEmpty(userToken))
            {
                return(ConnectionCode.ErrorLogin);
            }

            CT2BizMessage bizMessage = new CT2BizMessage();

            //初始化
            bizMessage.SetFunction((int)FunctionCode.QueryTradingInstance1);
            bizMessage.SetPacketType(CT2tag_def.REQUEST_PACKET);

            //业务包
            CT2Packer packer = new CT2Packer(2);

            packer.BeginPack();
            foreach (FieldItem item in functionItem.RequestFields)
            {
                packer.AddField(item.Name, item.Type, item.Width, item.Scale);
            }

            //var accounts = LoginManager.Instance.Accounts;
            //foreach (var account in accounts)
            //{
            Console.WriteLine("Account: " + account.AccountCode + " " + account.AccountName);
            foreach (FieldItem item in functionItem.RequestFields)
            {
                switch (item.Name)
                {
                case "user_token":
                {
                    packer.AddStr(userToken);
                }
                break;

                case "account_code":
                {
                    packer.AddStr(account.AccountCode);
                }
                break;

                case "combi_no":
                {
                    packer.AddStr("");
                }
                break;

                case "instance_no":
                {
                    packer.AddStr("");
                }
                break;

                case "instance_type":
                {
                    packer.AddStr("");
                }
                break;

                case "template_no":
                {
                    packer.AddInt(0);
                }
                break;

                case "long_market_no":
                {
                    packer.AddStr("");
                }
                break;

                case "long_report_code":
                {
                    packer.AddStr("");
                }
                break;

                case "short_market_no":
                {
                    packer.AddStr("");
                }
                break;

                case "short_report_code":
                {
                    packer.AddStr("");
                }
                break;

                case "invest_plan_no":
                {
                    packer.AddStr("");
                }
                break;

                default:
                    if (item.Type == PackFieldType.IntType)
                    {
                        packer.AddInt(-1);
                    }
                    else if (item.Type == PackFieldType.StringType || item.Type == PackFieldType.CharType)
                    {
                        packer.AddStr(item.Name);
                    }
                    else
                    {
                        packer.AddStr(item.Name);
                    }
                    break;
                }
            }
            //}
            packer.EndPack();

            unsafe
            {
                bizMessage.SetContent(packer.GetPackBuf(), packer.GetPackLen());
            }

            int retCode = _t2SDKWrap.SendAsync(bizMessage);

            packer.Dispose();
            bizMessage.Dispose();

            if (retCode < 0)
            {
                logger.Error("查询交易实例失败!");
                return(ConnectionCode.ErrorConn);
            }

            return(ConnectionCode.Success);
        }