Ejemplo n.º 1
0
        private void SetRequestField <T>(ref CT2Packer packer, T request, FieldItem fieldItem, Dictionary <string, UFXDataField> dataFieldMap)
        {
            var    dataField = dataFieldMap[fieldItem.Name];
            Type   type      = request.GetType();
            object obj       = type.GetProperty(dataField.Name).GetValue(request);

            if (fieldItem.Name.Equals("entrust_amount"))
            {
                //TODO: 委托数量字段跟文档定义不一样,文档定义是N12(整型),但测试时传入整型出错。
                //恒生确认: 该字段将会被更新为:N16.2
                if (obj != null)
                {
                    packer.AddDouble((double)(int)obj);
                    //packer.AddInt((int)obj);
                }
                else
                {
                    packer.AddDouble(0f);
                    //packer.AddInt(0);
                }
            }
            else if (fieldItem.Type == UFXPackFieldType.IntType)
            {
                if (obj != null)
                {
                    packer.AddInt((int)obj);
                }
                else
                {
                    packer.AddInt(-1);
                }
            }
            else if (fieldItem.Type == UFXPackFieldType.FloatType)
            {
                if (obj != null)
                {
                    packer.AddDouble((double)obj);
                }
                else
                {
                    packer.AddDouble(0f);
                }
            }
            else if (fieldItem.Type == UFXPackFieldType.StringType)
            {
                if (obj != null)
                {
                    packer.AddStr(obj.ToString());
                }
                else
                {
                    packer.AddStr("");
                }
            }
            else
            {
                packer.AddStr("");
            }
        }
Ejemplo n.º 2
0
        private void SetRequestDefaultField(ref CT2Packer packer, FieldItem fieldItem, string userToken)
        {
            switch (fieldItem.Name)
            {
            case "user_token":
            {
                packer.AddStr(userToken);
            }
            break;

            default:
                if (fieldItem.Type == UFXPackFieldType.IntType)
                {
                    packer.AddInt(-1);
                }
                else if (fieldItem.Type == UFXPackFieldType.StringType || fieldItem.Type == UFXPackFieldType.CharType)
                {
                    packer.AddStr(fieldItem.Name);
                }
                else
                {
                    packer.AddStr(fieldItem.Name);
                }
                break;
            }
        }
Ejemplo n.º 3
0
        private void button1_Click(object sender, EventArgs e)
        {
            //初始化t2连接
            if (!InitT2())
            {
                return;
            }

            //打包请求报文
            CT2Packer packer  = new CT2Packer(2);
            sbyte     strType = Convert.ToSByte('S');
            sbyte     intType = Convert.ToSByte('I');

            packer.BeginPack();
            //插件编号
            packer.AddField("plugin_id", strType, 255, 4);
            //管理功能号
            packer.AddField("function_id", intType, 255, 4);
            packer.AddStr("com.hundsun.fbase.f2core");
            packer.AddInt(100);
            packer.EndPack();
            //功能号,业务包
            int iRet = conn.SendBiz(8, packer, 0, 0, 1);

            if (iRet < 0)
            {
                DisplayText(conn.GetErrorMsg(iRet));
            }
            else
            {
                string      error    = null;
                CT2UnPacker unpacker = null;
                iRet = conn.RecvBiz(iRet, out error, out unpacker, 4000, 0);
                if (iRet == 0 || iRet == 1)
                {
                    while (unpacker.IsEOF() != 1)
                    {
                        for (int i = 0; i < unpacker.GetColCount(); i++)
                        {
                            textBox1.Text += unpacker.GetStrByIndex(i) + " ";
                        }
                        textBox1.Text += "\r\n";
                        unpacker.Next();
                    }
                }
                else if (iRet < 0)
                {
                    DisplayText(conn.GetErrorMsg(iRet));
                }
                else if (iRet == 2)
                {
                    DisplayText("解包失败");
                }
            }

            packer.Dispose();
        }
Ejemplo n.º 4
0
        public void Withdraw(int enrtustno)
        {
            Debug.Print(string.Format("正在撤单:no={0}", enrtustno));
            CT2Packer packer = new CT2Packer(2);

            packer.BeginPack();
            packer.AddField("user_token", Convert.ToSByte('S'), 512, 4);
            packer.AddField("entrust_no", Convert.ToSByte('I'), 8, 4);

            packer.AddStr(token);
            packer.AddInt(enrtustno);
            packer.EndPack();

            this.sendpacker(OptionFunctionCode.Withdraw, packer);
        }
Ejemplo n.º 5
0
        private void button2_Click(object sender, EventArgs e)
        {
            //打包请求报文
            CT2Packer packer  = new CT2Packer(2);
            sbyte     strType = Convert.ToSByte('S');
            sbyte     intType = Convert.ToSByte('I');

            packer.BeginPack();
            //插件编号
            packer.AddField("plugin_id", strType, 255, 4);
            //管理功能号
            packer.AddField("function_id", intType, 255, 4);
            packer.AddStr("com.hundsun.fbase.f2core");
            packer.AddInt(100);
            packer.EndPack();

            int iRet = conn.SendBiz(8, packer, 1, 0, 1);

            packer.Dispose();
        }
Ejemplo n.º 6
0
        public override void OptionWithdraw(List <int> entrustnolist)
        {
            try
            {
                if (!islogon())
                {
                    return;
                }

                if (entrustnolist == null || entrustnolist.Count == 0)
                {
                    return;
                }

                #region packer
                CT2Packer packer = new CT2Packer(2);
                packer.BeginPack();
                packer.AddField("user_token", Convert.ToSByte('S'), 512, 4);
                packer.AddField("entrust_no", Convert.ToSByte('I'), 8, 4);

                string entrustlist = "";
                foreach (int entrustno in entrustnolist)
                {
                    packer.AddStr(this.token);
                    packer.AddInt(entrustno);
                    entrustlist += entrustno + "|";
                }

                packer.EndPack();
                #endregion

                int retcode = this.sendpacker(OptionFunction.Withdraw, packer);

                MessageManager.GetInstance().Add(MessageType.TradeNotice, string.Format("委托撤单:共{0}笔,|{1}", entrustnolist.Count, entrustlist));
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Ejemplo n.º 7
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);
        }
Ejemplo n.º 8
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);
        }
Ejemplo n.º 9
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));
        }
Ejemplo n.º 10
0
        public void SendFunctionAction(int functionId, string functionIdGenerationStr, Action <ShowList> callback)
        {
            CT2Esbmsg t2Message = new CT2Esbmsg();                               //构造消息

            t2Message.GetItem(CT2tag_def.TAG_FUNCTION_ID).SetInt(functionId, 0); //设置功能号
            t2Message.GetItem(CT2tag_def.TAG_PACKET_TYPE).SetInt(0, 0);;         //设置消息类型为请求
            //打包请求报文
            CT2Packer packer   = new CT2Packer(3);
            sbyte     strType  = Convert.ToSByte('S');
            sbyte     intType  = Convert.ToSByte('I');
            sbyte     charType = Convert.ToSByte('C');

            packer.BeginPack();
            //插件编号
            //管理功能号

            foreach (var item in _sendFunctionDtoList)
            {
                if (item.Type == "int")
                {
                    packer.AddField(item.Name, intType, 255, 4);
                }
                else if (item.Type == "string")
                {
                    packer.AddField(item.Name, strType, 255, 4);
                }
            }

            foreach (var item in _sendFunctionDtoList)
            {
                if (item.Type == "int")
                {
                    packer.AddInt(Convert.ToInt32(item.Value));
                }
                else if (item.Type == "string")
                {
                    packer.AddStr(item.Value);
                }
            }

            packer.EndPack();

            unsafe
            {
                t2Message.GetItem(CT2tag_def.TAG_MESSAGE_BODY).SetRawData(packer.GetPackBuf(), packer.GetPackLen());
                int   iMsgLen = 0;
                void *lpData  = t2Message.GetBuffer(&iMsgLen);
                int   iRet    = Conn.Send(lpData, iMsgLen, 0);
                if (iRet < 0)
                {
                    MessageBox.Show(Conn.GetErrorMsg(iRet));
                }
                else
                {
                    void *lpRecvData = null;
                    int   iRecvLen   = 0;
                    iRet = Conn.Receive(iRet, &lpRecvData, &iRecvLen, 5000, 0);
                    if (iRet == 0)
                    {
                        CT2Esbmsg ansMessage  = new CT2Esbmsg();                            //构造消息
                        int       iParseError = ansMessage.SetBuffer(lpRecvData, iRecvLen); //解析消息
                        if (iParseError != 0)
                        {
                            MessageBox.Show("同步接收业务错误:解析消息失败\n");
                        }
                        else
                        {
                            int iRetCode   = ansMessage.GetItem(CT2tag_def.TAG_RETURN_CODE).GetInt(0); //获取返回码
                            int iErrorCode = ansMessage.GetItem(CT2tag_def.TAG_ERROR_NO).GetInt(0);    //获取错误码
                            if (iErrorCode != 0)
                            {
                                MessageBox.Show("同步接收出错:" + ansMessage.GetItem(CT2tag_def.TAG_ERROR_NO).GetString(0) +
                                                ansMessage.GetItem(CT2tag_def.TAG_ERROR_INFO).GetString(0));
                            }
                            else
                            {
                                CT2UnPacker unpacker = null;
                                unsafe
                                {
                                    int   iLen   = 0;
                                    void *lpdata = ansMessage.GetItem(CT2tag_def.TAG_MESSAGE_BODY).GetRawData(&iLen, 0);
                                    unpacker = new CT2UnPacker(lpdata, (uint)iLen);
                                }
                                //返回业务错误
                                if (iRetCode != 0)
                                {
                                    MessageBox.Show("同步接收业务出错:\n");
                                    UnPack(unpacker);
                                }
                                //正常业务返回
                                else
                                {
                                    UnPack(unpacker);
                                    callback?.Invoke(_showlist);
                                }

                                unpacker.Dispose();
                            }
                        }
                        ansMessage.Dispose();
                    }
                    else
                    {
                        Conn.GetErrorMsg(iRet);
                    }
                }
            }
            t2Message.Dispose();
            packer.Dispose();
        }
Ejemplo n.º 11
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);
        }
Ejemplo n.º 12
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);
        }
Ejemplo n.º 13
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);
        }
Ejemplo n.º 14
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);
        }
Ejemplo n.º 15
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);
        }