コード例 #1
0
ファイル: EntrustHunsun.cs プロジェクト: svn2014/MMO
        public override void OnReceivedBizMsg(CT2Connection lpConnection, int hSend, CT2BizMessage lpMsg)
        {
            int iRetCode   = lpMsg.GetErrorNo();    //获取返回码
            int iErrorCode = lpMsg.GetReturnCode(); //获取错误码
            int iFunction  = lpMsg.GetFunction();

            if (iRetCode != 0)
            {
                Debug.Print("异步接收出错:" + lpMsg.GetErrorNo().ToString() + lpMsg.GetErrorInfo());
            }
            else
            {
                if (iFunction == 620000)//1.0消息中心心跳
                {
                    Debug.Print("收到心跳!==>" + iFunction);
                    lpMsg.ChangeReq2AnsMessage();
                    connMain.SendBizMsg(lpMsg, 1);
                    return;
                }
                else if (iFunction == 620003 || iFunction == 620025) //收到发布过来的行情
                {
                    Debug.Print("收到主推消息!==>" + iFunction);
                    int         iKeyInfo  = 0;
                    void *      lpKeyInfo = lpMsg.GetKeyInfo(&iKeyInfo);
                    CT2UnPacker unPacker  = new CT2UnPacker(lpKeyInfo, (uint)iKeyInfo);
                    //this.ShowUnPacker(unPacker);
                    unPacker.Dispose();
                }
                else if (iFunction == 620001)
                {
                    Debug.Print("收到订阅应答!==>");
                    return;
                }
                else if (iFunction == 620002)
                {
                    Debug.Print("收到取消订阅应答!==>");
                    return;
                }

                CT2UnPacker unpacker = null;
                unsafe
                {
                    int   iLen   = 0;
                    void *lpdata = lpMsg.GetContent(&iLen);
                    unpacker = new CT2UnPacker(lpdata, (uint)iLen);
                }
                if (iFunction == 10001)
                {
                    int code = unpacker.GetInt("ErrCode");
                    if (code == 0)
                    {
                        unpacker.SetCurrentDatasetByIndex(1);
                        token = unpacker.GetStr("user_token");
                    }
                }
                //this.ShowUnPacker(unpacker);
            }
        }
コード例 #2
0
        public override void OnReceivedBizMsg(CT2Connection lpConnection, int hSend, CT2BizMessage lpMsg)
        {
            logger.Info("OnReceivedBizMsg: 接收业务数据!");

            //获取返回码
            int iRetCode = lpMsg.GetReturnCode();

            //获取错误码
            int iErrorCode = lpMsg.GetErrorNo();

            int iFunction = lpMsg.GetFunction();

            if (iRetCode != 0)
            {
                logger.Error("异步接收数据出错:" + lpMsg.GetErrorNo().ToString() + lpMsg.GetErrorInfo());
            }
            else
            {
                CT2UnPacker unpacker = null;
                unsafe
                {
                    int   iLen   = 0;
                    void *lpdata = lpMsg.GetContent(&iLen);
                    unpacker = new CT2UnPacker(lpdata, (uint)iLen);
                }

                switch (iFunction)
                {
                case (int)FunctionCode.QueryTradingInstance:
                {
                }
                break;

                case (int)FunctionCode.EntrustInstanceBasket:
                    break;

                case (int)FunctionCode.QueryEntrustInstance:
                    break;

                case (int)FunctionCode.QueryDealInstance:
                    break;

                default:
                    break;
                }

                unpacker.Dispose();
            }

            lpMsg.Dispose();
        }
コード例 #3
0
        public override void OnReceivedBizMsg(CT2Connection lpConnection, int hSend, CT2BizMessage lpMsg)
        {
            logger.Info("OnReceivedBizMsg: 接收业务数据!");

            //获取返回码
            int iRetCode = lpMsg.GetReturnCode();

            //获取错误码
            int iErrorCode = lpMsg.GetErrorNo();

            int iFunction = lpMsg.GetFunction();

            if (iRetCode != 0)
            {
                logger.Error("异步接收数据出错:" + lpMsg.GetErrorNo().ToString() + lpMsg.GetErrorInfo());
            }
            else
            {
                CT2UnPacker unpacker = null;
                unsafe
                {
                    int   iLen   = 0;
                    void *lpdata = lpMsg.GetContent(&iLen);
                    unpacker = new CT2UnPacker(lpdata, (uint)iLen);
                }

                switch (iFunction)
                {
                case (int)FunctionCode.Login:
                {
                    var token = unpacker.GetStr("user_token");
                    if (string.IsNullOrEmpty(token))
                    {
                        LoginManager.Instance.LoginUser.Token = token;
                    }
                }
                break;

                case (int)FunctionCode.Logout:
                    break;

                default:
                    break;
                }

                PrintUnPack(unpacker);
                unpacker.Dispose();
            }

            lpMsg.Dispose();
        }
コード例 #4
0
        public override void OnReceivedBizMsg(CT2Connection lpConnection, int hSend, CT2BizMessage lpMsg)
        {
            UFXLogger.Info(logger, "OnReceivedBizMsg: 成功触发回调接收数据!");
            //获取返回码
            int iRetCode = lpMsg.GetReturnCode();

            //获取错误码
            int iErrorCode = lpMsg.GetErrorNo();

            int iFunction = lpMsg.GetFunction();

            if (iRetCode != 0)
            {
                logger.Error("异步接收数据出错:" + lpMsg.GetErrorNo().ToString() + lpMsg.GetErrorInfo());
            }
            else
            {
                //Console.WriteLine("主推业务订阅 - 返回码:{0}, 错误码: {1}, 功能号: {2}", iRetCode, iErrorCode, iFunction);
                if (Enum.IsDefined(typeof(UFXFunctionCode), iFunction))
                {
                    UFXFunctionCode functionCode = (UFXFunctionCode)Enum.ToObject(typeof(UFXFunctionCode), iFunction);
                    switch (functionCode)
                    {
                    case UFXFunctionCode.MCHeartBeat:
                        break;

                    case UFXFunctionCode.MCRecvSubscribe:
                        break;

                    case UFXFunctionCode.MCRecvUnsubscribe:
                        break;

                    default:
                        break;
                    }
                }
                else
                {
                    string msg = string.Format("为支持的功能号:{0}", iFunction);
                    logger.Error(msg);
                }
            }
        }
コード例 #5
0
ファイル: T2SDKWrap.cs プロジェクト: pinke/winformapplayout
        public override void OnReceivedBizMsg(CT2Connection lpConnection, int hSend, CT2BizMessage lpMsg)
        {
            UFXLogger.Info(logger, "OnReceivedBizMsg: 成功触发回调接收数据!");
            //获取返回码
            int iRetCode = lpMsg.GetReturnCode();

            //获取错误码
            int iErrorCode = lpMsg.GetErrorNo();

            int iFunction = lpMsg.GetFunction();

            if (iRetCode != 0)
            {
                logger.Error("异步接收数据出错:" + lpMsg.GetErrorNo().ToString() + lpMsg.GetErrorInfo());
            }
            else
            {
                HandleReceivedBizMsg(SendType.Async, (UFXFunctionCode)iFunction, hSend, lpMsg);
            }
        }
コード例 #6
0
        public override void OnReceivedBizMsg(CT2Connection lpConnection, int hSend, CT2BizMessage lpMsg)
        {
            logger.Info("OnReceivedBizMsg: 成功建立安全连接!");
            //获取返回码
            int iRetCode = lpMsg.GetReturnCode();

            //获取错误码
            int iErrorCode = lpMsg.GetErrorNo();

            int iFunction = lpMsg.GetFunction();

            if (iRetCode != 0)
            {
                logger.Error("异步接收数据出错:" + lpMsg.GetErrorNo().ToString() + lpMsg.GetErrorInfo());
            }
            else
            {
                if (Enum.IsDefined(typeof(FunctionCode), iFunction))
                {
                    FunctionCode functionCode = (FunctionCode)Enum.ToObject(typeof(FunctionCode), iFunction);
                    if (_bizCallbackMap.ContainsKey(functionCode) && _bizCallbackMap[functionCode] != null)
                    {
                        _bizCallbackMap[functionCode](lpMsg);
                    }
                    else
                    {
                        string msg = string.Format("异步接收数据回调函数找不到 - 功能号:{0}", iFunction);
                        logger.Error(msg);
                    }
                }
                else
                {
                    string msg = string.Format("为支持的功能号:{0}", iFunction);
                    logger.Error(msg);
                    //throw new NotSupportedException(msg);
                }
            }
        }
コード例 #7
0
        public ConnectionCode ReceivedBizMsg(int hSend, FunctionCode functionCode)
        {
            CT2BizMessage bizMessage = null;
            int           retCode    = _conn.RecvBizMsg(hSend, out bizMessage, (int)_timeOut, 1);

            if (retCode < 0)
            {
                logger.Error("同步接收出错: " + _conn.GetErrorMsg(retCode));
                return(ConnectionCode.ErrorConn);
            }

            int iRetCode   = bizMessage.GetReturnCode();
            int iErrorCode = bizMessage.GetErrorNo();

            if (iRetCode != 0)
            {
                string msg = string.Format("同步接收数据出错: {0}, {1}", iErrorCode, bizMessage.GetErrorInfo());

                return(ConnectionCode.ErrorConn);
            }

            CT2UnPacker unpacker = null;

            unsafe
            {
                int   iLen   = 0;
                void *lpdata = bizMessage.GetContent(&iLen);
                unpacker = new CT2UnPacker(lpdata, (uint)iLen);
            }

            if (unpacker != null)
            {
                PrintUnPack(unpacker);
                switch (functionCode)
                {
                case FunctionCode.Login:
                {
                    var token = unpacker.GetStr("user_token");
                    if (!string.IsNullOrEmpty(token))
                    {
                        LoginManager.Instance.LoginUser.Token = token;
                    }
                    else
                    {
                        return(ConnectionCode.ErrorLogin);
                    }
                }
                break;

                case FunctionCode.Logout:
                    break;

                case FunctionCode.HeartBeat:
                    break;

                default:
                    break;
                }

                unpacker.Dispose();
            }
            //bizMessage.Dispose();

            return(ConnectionCode.Success);
        }
コード例 #8
0
        public int OnReceivedBizMsg(CT2BizMessage bizMessage)
        {
            int iRetCode   = bizMessage.GetReturnCode();
            int iErrorCode = bizMessage.GetErrorNo();
            int iFunction  = bizMessage.GetFunction();

            if (iRetCode != 0)
            {
                string msg = string.Format("异步接收数据出错: {0}, {1}", iErrorCode, bizMessage.GetErrorInfo());

                return(iRetCode);
            }

            CT2UnPacker unpacker = null;

            unsafe
            {
                int   iLen   = 0;
                void *lpdata = bizMessage.GetContent(&iLen);
                unpacker = new CT2UnPacker(lpdata, (uint)iLen);
            }

            if (unpacker != null)
            {
                Console.WriteLine("功能号:" + iFunction);
                _t2SDKWrap.PrintUnPack(unpacker);

                switch ((FunctionCode)iFunction)
                {
                case FunctionCode.Entrust:
                {
                }
                break;

                case FunctionCode.Withdraw:
                {
                }
                break;

                case FunctionCode.EntrustBasket:
                {
                }
                break;

                case FunctionCode.WithdrawBasket:
                {
                }
                break;

                case FunctionCode.QuerySecurityEntrust:
                {
                }
                break;

                default:
                    break;
                }

                unpacker.Dispose();
            }
            //bizMessage.Dispose();

            return((int)ConnectionCode.Success);
        }
コード例 #9
0
ファイル: T2SDKWrap.cs プロジェクト: pinke/winformapplayout
        private int HandleReceivedBizMsg(SendType sendType, UFXFunctionCode functionCode, int hSend, CT2BizMessage bizMessage)
        {
            int iRetCode   = bizMessage.GetReturnCode();
            int iErrorCode = bizMessage.GetErrorNo();
            int iFunction  = bizMessage.GetFunction();

            //FunctionCode functionCode = (FunctionCode)iFunction;
            if (iRetCode != 0)
            {
                string msg = string.Format("同步接收数据出错: {0}, {1}", iErrorCode, bizMessage.GetErrorInfo());
                logger.Error(msg);
                return(iRetCode);
            }

            CT2UnPacker unpacker = null;

            unsafe
            {
                int   iLen   = 0;
                void *lpdata = bizMessage.GetContent(&iLen);
                unpacker = new CT2UnPacker(lpdata, (uint)iLen);
            }

            int ret = (int)ConnectionCode.ErrorConn;

            if (unpacker == null)
            {
                ret = (int)ConnectionCode.ErrorFailContent;
                string msg = string.Format("提交UFX请求回调中,功能号[{0}]数据获取失败!", iFunction);
                logger.Error(msg);

                return(ret);
            }

            DataParser parser = new DataParser();

            parser.FunctionCode = functionCode;
            parser.Parse(unpacker);
            unpacker.Dispose();

            //parser.Output();
            if (!_dataHandlerMap.ContainsKey(functionCode))
            {
                ret = (int)ConnectionCode.ErrorNoCallback;
                string msg = string.Format("提交UFX请求时,未注册功能号[{0}]的回调方法!", iFunction);
                logger.Error(msg);

                return(ret);
            }

            var dataHandler = _dataHandlerMap[functionCode];

            if (dataHandler == null)
            {
                ret = (int)ConnectionCode.ErrorNoCallback;
                string msg = string.Format("提交UFX请求时,未注册功能号[{0}]的回调方法!", iFunction);
                logger.Error(msg);

                return(ret);
            }

            if (sendType == SendType.Sync)
            {
                return(dataHandler(functionCode, hSend, parser));
            }
            else
            {
                //TODO: control the maximum number of the thread?
                //Task task = new Task(() => dataHandler(parser));
                //task.Start();

                //use the TaskScheduler to limit the maximum thread number
                TaskFactory taskFactory = new TaskFactory(_taskScheduler);
                taskFactory.StartNew(() => dataHandler(functionCode, hSend, parser));

                return((int)ConnectionCode.Success);
            }
        }
コード例 #10
0
ファイル: T2SDKWrap.cs プロジェクト: pinke/winformapplayout
        /// <summary>
        /// 通过调用UFX接口同步发送请求,并将结果封装在DataParser对象中返回。
        /// </summary>
        /// <param name="message">CT2BizMessage对象的实例,包含用户信息,功能号,请求参数等信息</param>
        /// <returns>DataParser对象实例,包含错误代码和最终数据。</returns>
        public DataParser SendSync2(CT2BizMessage message)
        {
            DataParser dataParser = new DataParser();

            int iRet = _conn.SendBizMsg(message, (int)SendType.Sync);

            if (iRet < 0)
            {
                string msg = string.Format("一般交易业务同步发送数据失败! 错误码:{0}, 错误消息:{1}", iRet, _conn.GetErrorMsg(iRet));
                logger.Error(msg);
                dataParser.ErrorCode = ConnectionCode.ErrorSendMsg;

                return(dataParser);
            }

            CT2BizMessage bizMessage = null;
            int           retCode    = _conn.RecvBizMsg(iRet, out bizMessage, (int)_timeOut, 1);

            if (retCode < 0)
            {
                string msg = "一般交易业务同步接收出错: " + _conn.GetErrorMsg(retCode);
                logger.Error(msg);
                dataParser.ErrorCode = ConnectionCode.ErrorRecvMsg;

                return(dataParser);
            }

            int iFunction = bizMessage.GetFunction();

            if (!Enum.IsDefined(typeof(UFXFunctionCode), iFunction))
            {
                dataParser.ErrorCode = ConnectionCode.ErrorNoFunctionCode;

                return(dataParser);
            }

            dataParser.FunctionCode = (UFXFunctionCode)iFunction;

            int             iRetCode     = bizMessage.GetReturnCode();
            int             iErrorCode   = bizMessage.GetErrorNo();
            UFXFunctionCode functionCode = (UFXFunctionCode)iFunction;

            if (iRetCode != 0)
            {
                string msg = string.Format("同步接收数据出错: {0}, {1}", iErrorCode, bizMessage.GetErrorInfo());
                //Console.WriteLine(msg);
                logger.Error(msg);

                dataParser.ErrorCode = ConnectionCode.ErrorRecvMsg;
                return(dataParser);
            }

            CT2UnPacker unpacker = null;

            unsafe
            {
                int   iLen   = 0;
                void *lpdata = bizMessage.GetContent(&iLen);
                unpacker = new CT2UnPacker(lpdata, (uint)iLen);
            }

            if (unpacker == null)
            {
                string msg = string.Format("提交UFX请求回调中,功能号[{0}]数据获取失败!", iFunction);
                logger.Error(msg);

                dataParser.ErrorCode = ConnectionCode.ErrorFailContent;
            }
            else
            {
                dataParser.Parse(unpacker);
                unpacker.Dispose();

                dataParser.ErrorCode = ConnectionCode.Success;
            }

            return(dataParser);
        }
コード例 #11
0
        //数据
        public override void OnReceivedBizMsg(CT2Connection lpConnection, int hSend, CT2BizMessage lpMsg)
        {
            int errcode  = lpMsg.GetErrorNo();     //获取错误代码
            int retcode  = lpMsg.GetReturnCode();  //获取返回码
            int function = lpMsg.GetFunction();

            if (errcode != 0)
            {
                MessageManager.GetInstance().Add(MessageType.Error, string.Format("异步接收出错:", lpMsg.GetErrorInfo()));
                return;
            }

            string      msg = "", entrustlist = "", batchno = "";
            uint        cnt      = 0;
            CT2UnPacker unpacker = null;

            unsafe
            {
                int   iLen   = 0;
                void *lpdata = lpMsg.GetContent(&iLen);
                unpacker = new CT2UnPacker(lpdata, (uint)iLen);
            }

            errcode = unpacker.GetInt("ErrorCode");
            if (errcode != 0)
            {
                msg = unpacker.GetStr("ErrorMsg");
                MessageManager.GetInstance().Add(MessageType.Error, string.Format("操作失败:{0}", msg));
                return;
            }

            //回报数据存于第1个数据集,第0个为错误消息
            unpacker.SetCurrentDatasetByIndex(1);
            cnt = unpacker.GetRowCount();
            while (unpacker.IsEOF() == 0)
            {
                entrustlist += unpacker.GetInt("entrust_no") + "|";
                batchno      = unpacker.GetInt("batch_no").ToString();
                unpacker.Next();
            }

            //返回消息
            switch (function)
            {
            case (int)EntrustHundsun.OptionFunction.SingleEntrust:
                MessageManager.GetInstance().Add(MessageType.TradeNotice, string.Format("单笔委托回报:成功,共1笔,|{0}", entrustlist));
                break;

            case (int)EntrustHundsun.OptionFunction.BasketEntrust:
                MessageManager.GetInstance().Add(MessageType.TradeNotice, string.Format("篮子委托回报:成功,批号={0}", batchno));
                break;

            case (int)EntrustHundsun.OptionFunction.Withdraw:
                MessageManager.GetInstance().Add(MessageType.TradeNotice, string.Format("委托撤单回报:成功,共{0}笔,|{1}", cnt, entrustlist));
                break;

            default:
                break;
            }
        }
コード例 #12
0
        public int OnReceivedBizMsg(CT2BizMessage bizMessage)
        {
            int iRetCode   = bizMessage.GetReturnCode();
            int iErrorCode = bizMessage.GetErrorNo();
            int iFunction  = bizMessage.GetFunction();

            if (iRetCode != 0)
            {
                string msg = string.Format("同步接收数据出错: {0}, {1}", iErrorCode, bizMessage.GetErrorInfo());
                Console.WriteLine(msg);
                return(iRetCode);
            }

            CT2UnPacker unpacker = null;

            unsafe
            {
                int   iLen   = 0;
                void *lpdata = bizMessage.GetContent(&iLen);
                unpacker = new CT2UnPacker(lpdata, (uint)iLen);
            }

            if (unpacker != null)
            {
                Console.WriteLine("功能号:" + iFunction);
                //_t2SDKWrap.PrintUnPack(unpacker);
                //_t2SDKWrap.PrintUnPack(unpacker);
                DataParser parser = new DataParser();
                parser.Parse(unpacker);
                parser.Output();
                switch ((FunctionCode)iFunction)
                {
                case FunctionCode.Login:
                {
                    var token = unpacker.GetStr("user_token");
                    if (!string.IsNullOrEmpty(token))
                    {
                        LoginManager.Instance.LoginUser.Token = token;
                    }
                    else
                    {
                        return((int)ConnectionCode.ErrorLogin);
                    }
                }
                break;

                case FunctionCode.Logout:
                    break;

                case FunctionCode.HeartBeat:
                    break;

                case FunctionCode.QuerymemoryData:
                    break;

                case FunctionCode.QueryAccount:
                {
                    if (_dataHandlerMap.ContainsKey(FunctionCode.QueryAccount))
                    {
                        _dataHandlerMap[FunctionCode.QueryAccount](parser);
                    }
                }
                break;

                case FunctionCode.QueryAssetUnit:
                    break;

                case FunctionCode.QueryPortfolio:
                    break;

                case FunctionCode.QueryHolder:
                    break;

                default:
                    break;
                }

                unpacker.Dispose();
            }
            //bizMessage.Dispose();

            return((int)ConnectionCode.Success);
        }