public static string GetOrderUniqueKey(object field)
        {
            //委托单
            //if (field is CZQThostFtdcInputOrderField)
            //{
            //  CZQThostFtdcInputOrderField ctpOrder = (CZQThostFtdcInputOrderField)field;
            //  return string.Format("{0}_{1}_{2}_{3}", ctpOrder.BrokerID, ctpOrder.InvestorID, ctpOrder.InstrumentID, ctpOrder.OrderRef);
            //}

            //撤单
            if (field is CZQThostFtdcOrderActionField)
            {
                CZQThostFtdcOrderActionField ctpOrder = (CZQThostFtdcOrderActionField)field;
                return(string.Format("{0:X}_{1:X}_{2}", ctpOrder.FrontID, ctpOrder.SessionID, ctpOrder.OrderRef.Trim()));
            }

            //订单
            if (field is CZQThostFtdcOrderField)
            {
                CZQThostFtdcOrderField ctpOrder = (CZQThostFtdcOrderField)field;
                return(string.Format("{0:X}_{1:X}_{2}", ctpOrder.FrontID, ctpOrder.SessionID, ctpOrder.OrderRef.Trim()));
            }

            //预埋单
            if (field is CZQThostFtdcParkedOrderField)
            {
                CZQThostFtdcParkedOrderField ctpOrder = (CZQThostFtdcParkedOrderField)field;
                return(string.Format("{0}_{1}_{2}", ctpOrder.BrokerID, ctpOrder.InvestorID, ctpOrder.ParkedOrderID));
            }

            //删除预埋单
            if (field is CZQThostFtdcRemoveParkedOrderField)
            {
                CZQThostFtdcRemoveParkedOrderField ctpOrder = (CZQThostFtdcRemoveParkedOrderField)field;
                return(string.Format("{0}_{1}_{2}", ctpOrder.BrokerID, ctpOrder.InvestorID, ctpOrder.ParkedOrderID));
            }


            //成交单
            if (field is CZQThostFtdcTradeField)
            {
                CZQThostFtdcTradeField ctpData = (CZQThostFtdcTradeField)field;
                return(string.Format("{0}_{1}_{2}_{3}", ctpData.BrokerID, ctpData.InvestorID, ctpData.TradingDay, ctpData.TradeID));
            }

            //持仓
            if (field is CZQThostFtdcInvestorPositionField)
            {
                CZQThostFtdcInvestorPositionField ctpData = (CZQThostFtdcInvestorPositionField)field;
                return(string.Format("{0}_{1}_{2}_{3}_{4}", ctpData.BrokerID, ctpData.InvestorID, ctpData.TradingDay, ctpData.InstrumentID, ctpData.PosiDirection));
            }

            //持仓明细
            if (field is CZQThostFtdcInvestorPositionDetailField)
            {
                //注意!!成交单ID可能重复
                CZQThostFtdcInvestorPositionDetailField ctpData = (CZQThostFtdcInvestorPositionDetailField)field;
                return(string.Format("{0}_{1}_{2}_{3}", ctpData.BrokerID, ctpData.InvestorID, ctpData.TradingDay, ctpData.TradeID));
            }

            throw new Exception("Unknow type : " + field.GetType().ToString());
        }
        public static string GetUserKey(object field)
        {
            //委托单
            if (field is CZQThostFtdcInputOrderField)
            {
                CZQThostFtdcInputOrderField ctpOrder = (CZQThostFtdcInputOrderField)field;
                return(GetUserKey(ctpOrder.InvestorID, ctpOrder.BrokerID));
            }

            //撤单
            if (field is CZQThostFtdcOrderActionField)
            {
                CZQThostFtdcOrderActionField ctpOrder = (CZQThostFtdcOrderActionField)field;
                return(GetUserKey(ctpOrder.InvestorID, ctpOrder.BrokerID));
            }

            //预埋单
            if (field is CZQThostFtdcParkedOrderField)
            {
                CZQThostFtdcParkedOrderField ctpOrder = (CZQThostFtdcParkedOrderField)field;
                return(GetUserKey(ctpOrder.InvestorID, ctpOrder.BrokerID));
            }

            //删除预埋单
            if (field is CZQThostFtdcRemoveParkedOrderField)
            {
                CZQThostFtdcRemoveParkedOrderField ctpOrder = (CZQThostFtdcRemoveParkedOrderField)field;
                return(GetUserKey(ctpOrder.InvestorID, ctpOrder.BrokerID));
            }

            //预埋撤单
            if (field is CZQThostFtdcParkedOrderActionField)
            {
                CZQThostFtdcRemoveParkedOrderField ctpOrder = (CZQThostFtdcRemoveParkedOrderField)field;
                return(GetUserKey(ctpOrder.InvestorID, ctpOrder.BrokerID));
            }

            //删除预埋撤单
            if (field is CZQThostFtdcRemoveParkedOrderActionField)
            {
                CZQThostFtdcRemoveParkedOrderActionField ctpOrder = (CZQThostFtdcRemoveParkedOrderActionField)field;
                return(GetUserKey(ctpOrder.InvestorID, ctpOrder.BrokerID));
            }

            //订单
            if (field is CZQThostFtdcOrderField)
            {
                CZQThostFtdcOrderField ctpOrder = (CZQThostFtdcOrderField)field;
                return(GetUserKey(ctpOrder.InvestorID, ctpOrder.BrokerID));
            }

            //成交单
            if (field is CZQThostFtdcTradeField)
            {
                CZQThostFtdcTradeField ctpData = (CZQThostFtdcTradeField)field;
                return(GetUserKey(ctpData.InvestorID, ctpData.BrokerID));
            }

            //持仓
            if (field is CZQThostFtdcInvestorPositionField)
            {
                CZQThostFtdcInvestorPositionField ctpData = (CZQThostFtdcInvestorPositionField)field;
                return(GetUserKey(ctpData.InvestorID, ctpData.BrokerID));
            }

            //持仓明细
            if (field is CZQThostFtdcInvestorPositionDetailField)
            {
                CZQThostFtdcInvestorPositionDetailField ctpData = (CZQThostFtdcInvestorPositionDetailField)field;
                return(GetUserKey(ctpData.InvestorID, ctpData.BrokerID));
            }

            //持仓明细
            if (field is CZQThostFtdcInvestorPositionCombineDetailField)
            {
                CZQThostFtdcInvestorPositionCombineDetailField ctpData = (CZQThostFtdcInvestorPositionCombineDetailField)field;
                return(GetUserKey(ctpData.InvestorID, ctpData.BrokerID));
            }

            //资金账户
            if (field is CZQThostFtdcTradingAccountField)
            {
                CZQThostFtdcTradingAccountField ctpData = (CZQThostFtdcTradingAccountField)field;
                return(GetUserKey(ctpData.AccountID, ctpData.BrokerID));
            }

            throw new Exception("unknow type : " + field.GetType().FullName);
        }