/// <summary>
        /// 期权行情
        /// </summary>
        /// <param name="realDataDict"></param>
        private void UpdateOptionDataCollection(Dictionary <Contract, RealData> realDataDict)
        {
            MainWindow mainWindow = TradeDataClient.GetClientInstance().getMainWindow();//CtpDataServer.GetUserInstance().getMainWindow();

            if (mainWindow != null)
            {
                foreach (var item in mainWindow.OptionRealDataCollection)
                {
                    foreach (Contract contract in realDataDict.Keys)
                    {
                        RealData tempData = realDataDict[contract];
                        mainWindow.updateOptionDataByDisplayRealData(tempData);
                        if (item.Code_C == tempData.CodeInfo.Code || item.Code_P == tempData.CodeInfo.Code)
                        {
                            item.UpdateProperties(tempData);
                            OptionCalculator.Enqueue(item);
                        }
                    }
                }
            }
            else
            {
                Util.Log("Warning!: mainWindow in BackgroundDataServer is NULL! ");
            }
        }
Exemple #2
0
 public void CopyProperties(RealData realData)
 {
     this.Position = realData.Position;
     this.BidHand  = realData.BidHand;
     this.BidPrice = realData.BidPrice;
     this.AskHand  = realData.AskHand;
     this.AskPrice = realData.AskPrice;
     this.MinPrice = realData.MinPrice;
     //this.HYCS = realData.HYCS;
     this.Sum = realData.Sum;
     //this.ICurrentSum = realData.ICurrentSum;
     this.SettlmentPrice      = realData.SettlmentPrice;
     this.PrevSettlementPrice = realData.PrevSettlementPrice;
     this.MaxPrice            = realData.MaxPrice;
     this.CodeInfo            = realData.CodeInfo;
     this.Hand = realData.Hand;
     //this.I64Outside = realData.I64Outside;
     this.ClosePrice = realData.ClosePrice;
     //this.IDealNumber = realData.IDealNumber;
     this.UpperLimitPrice = realData.UpperLimitPrice;
     this.LowerLimitPrice = realData.LowerLimitPrice;
     this.NewPrice        = realData.NewPrice;
     //this.IsFirstData = realData.IsFirstData;
     //this.LogMessage = realData.LogMessage;
     //this.Name = realData.Name;
     this.OpenPrice = realData.OpenPrice;
     //this.NTime = realData.NTime;
     this.PrevClose = realData.PrevClose;
     //this.UiTime = realData.UiTime;
     //this.UsUpdateNumber = realData.UsUpdateNumber;
     this.Volumn = realData.Volumn;
 }
        /// <summary>
        /// 期权行情
        /// </summary>
        /// <param name="m_realData"></param>
        private void UpdateOptionDataCollection(RealData m_realData)
        {
            MainWindow mainWindow = TradeDataClient.GetClientInstance().getMainWindow();//CtpDataServer.GetUserInstance().getMainWindow();

            if (mainWindow != null)
            {
                mainWindow.updateOptionDataByDisplayRealData(m_realData);
                foreach (var item in mainWindow.OptionRealDataCollection)
                {
                    if (item.Code_C == m_realData.CodeInfo.Code || item.Code_P == m_realData.CodeInfo.Code)
                    {
                        //lock (_Locker)
                        //{
                        //    DataContainer.AddRealDataToContainer(m_realData);
                        //}
                        item.UpdateProperties(m_realData);
                        OptionCalculator.Enqueue(item);
                        break;
                    }
                }
            }
            else
            {
                Util.Log("Warning!: mainWindow in BackgroundDataServer is NULL! ");
            }
        }
        public void UpdateProperties(RealData realData)
        {
            if (realData.CodeInfo.Code == this.Code)
            {
                this.ChiCangLiang  = realData.Position;
                this.StBuyCount    = realData.BidHand[0];
                this.StBuyPrice    = realData.BidPrice[0];
                this.StSellCount   = realData.AskHand[0];
                this.StSellPrice   = realData.AskPrice[0];
                this.DownStopPrice = realData.LowerLimitPrice;
                this.I64Sum        = (UInt64)realData.Sum;
                //this.ICurrentSum = realData.ICurrentSum ;
                this.ISettlementPrice = realData.SettlmentPrice;
                this.PrevSettleMent   = realData.PrevSettlementPrice;
                this.UpStopPrice      = realData.UpperLimitPrice;
                this.CurrentHand      = realData.Hand;
                //this.I64Outside = realData.I64Outside;
                this.IClose = realData.ClosePrice;
                //this.IDealNumber = realData.IDealNumber;
                this.IMaxPrice = realData.MaxPrice;
                this.IMinPrice = realData.MinPrice;
                this.INewPrice = realData.NewPrice;

                this.Open = realData.OpenPrice;
                //this.NTime = realData.NTime;
                this.PrevClose = realData.PrevClose;
                //this.UsUpdateNumber = realData.UsUpdateNumber;
                this.Volumn     = realData.Volumn;
                this.Market     = CodeSetManager.CtpToExName(realData.CodeInfo.ExchCode);
                this.PreChicang = realData.PrevPosition;
                this.PrevClose  = realData.PrevClose;
                this.UpdateTime = realData.UpdateTime;
            }
        }
        private void SetDisplayRealDataValueByRealTimeData(RealData realTimeDataArr, double newPrice, RealData tempData)
        {
            tempData.CodeInfo = realTimeDataArr.CodeInfo;//合约

            //double fluct = 0;
            //CodeSet.GetHycsAndFluct(tempData.Code, out tempData.m_hycs, out fluct);
            //tempData.HYCS = tempData.m_hycs;
            tempData.NewPrice            = newPrice;
            tempData.UpperLimitPrice     = realTimeDataArr.UpperLimitPrice;
            tempData.LowerLimitPrice     = realTimeDataArr.LowerLimitPrice;
            tempData.BidPrice            = realTimeDataArr.BidPrice;
            tempData.BidHand             = realTimeDataArr.BidHand;             //买量
            tempData.AskPrice            = realTimeDataArr.AskPrice;
            tempData.AskHand             = realTimeDataArr.AskHand;             //卖量
            tempData.Position            = realTimeDataArr.Position;            //持仓量
            tempData.Volumn              = realTimeDataArr.Volumn;              //成交量
            tempData.Sum                 = realTimeDataArr.Sum;                 //成交额
            tempData.Hand                = realTimeDataArr.Hand;                //现手
            tempData.AvgPrice            = realTimeDataArr.AvgPrice;            //均价
            tempData.OpenPrice           = realTimeDataArr.OpenPrice;           //开盘价
            tempData.PrevSettlementPrice = realTimeDataArr.PrevSettlementPrice; //昨结算
            tempData.SettlmentPrice      = realTimeDataArr.SettlmentPrice;      //现结算
            tempData.PrevClose           = realTimeDataArr.PrevClose;           //昨收
            tempData.PrevPosition        = realTimeDataArr.PrevPosition;
            tempData.ClosePrice          = realTimeDataArr.ClosePrice;
            //tempData.Market = CodeSet.GetMarketName(tempData.Code);
            tempData.UpdateTime      = realTimeDataArr.UpdateTime;
            tempData.MaxPrice        = realTimeDataArr.MaxPrice;
            tempData.MinPrice        = realTimeDataArr.MinPrice;
            tempData.UpperLimitPrice = realTimeDataArr.UpperLimitPrice;
            tempData.LowerLimitPrice = realTimeDataArr.LowerLimitPrice;
        }
        public void UpdateProperties(RealData realData)
        {
            this.ExchCode = realData.CodeInfo.ExchCode;
            if (realData.CodeInfo.Code == this.Code_C)
            {
                this.ChiCangLiang_C  = realData.Position;
                this.StBuyCount_C    = realData.BidHand[0];
                this.StBuyPrice_C    = realData.BidPrice[0];
                this.StSellCount_C   = realData.AskHand[0];
                this.StSellPrice_C   = realData.AskPrice[0];
                this.DownStopPrice_C = realData.LowerLimitPrice;
                this.I64Sum_C        = (UInt64)realData.Sum;
                //this.ICurrentSu_C = realData.ICurrentSum ;
                this.ISettlementPrice_C = realData.SettlmentPrice;
                this.PrevSettleMent_C   = realData.PrevSettlementPrice;
                this.UpStopPrice_C      = realData.UpperLimitPrice;
                this.CurrentHand_C      = realData.Hand;
                //this.I64Outside_C = realData.I64Outside;
                this.IClose_C = realData.ClosePrice;
                //this.IDealNumber_C = realData.IDealNumber;
                this.IMaxPrice_C = realData.MaxPrice;
                this.IMinPrice_C = realData.MinPrice;
                this.INewPrice_C = realData.NewPrice;

                this.Open_C = realData.OpenPrice;
                //this.NTime_C = realData.NTime;
                this.PrevClose_C = realData.PrevClose;
                //this.UsUpdateNumber_C = realData.UsUpdateNumber;
                this.Volumn_C = realData.Volumn;
            }
            else if (realData.CodeInfo.Code == this.Code_P)
            {
                this.ChiCangLiang_P  = realData.Position;
                this.StBuyCount_P    = realData.BidHand[0];
                this.StBuyPrice_P    = realData.BidPrice[0];
                this.StSellCount_P   = realData.AskHand[0];
                this.StSellPrice_P   = realData.AskPrice[0];
                this.DownStopPrice_P = realData.LowerLimitPrice;
                this.I64Sum_P        = (UInt64)realData.Sum;
                //this.ICurrentSu_P = realData.ICurrentSum;
                this.ISettlementPrice_P = realData.SettlmentPrice;
                this.PrevSettleMent_P   = realData.PrevSettlementPrice;
                this.UpStopPrice_P      = realData.UpperLimitPrice;
                this.CurrentHand_P      = realData.Hand;
                //this.I64Outside_P = realData.I64Outside;
                this.IClose_P = realData.ClosePrice;
                //this.IDealNumber_P = realData.IDealNumber;
                this.IMaxPrice_P = realData.MaxPrice;
                this.IMinPrice_P = realData.MinPrice;
                this.INewPrice_P = realData.NewPrice;
                //this.LastINewPrice_P = this.INewPrice_P + r.Next(-2, 1);

                this.Open_P = realData.OpenPrice;
                //this.NTime_P = realData.NTime;
                this.PrevClose_P = realData.PrevClose;
                //this.UsUpdateNumber_P = realData.UsUpdateNumber;
                this.Volumn_P = realData.Volumn;
            }
        }
 public void SavedDataInit(RealData savedData)
 {
     if (Application.Current != null)
     {
         Application.Current.Dispatcher.Invoke((Action) delegate
         {
             UpdateOptionDataCollection(savedData);
         });
     }
     //else if (this.commObj.RequestingCodes.Contains(tempData.codeInfo.Code))//只操作正在推送的合约
 }
 /// <summary>
 /// 处理持仓行情
 /// </summary>
 /// <param name="m_displayRealData"></param>
 public void SetPositionInfo(object realObj)
 {
     if (realObj is RealData)
     {
         RealData realData = realObj as RealData;
         Dictionary <Contract, RealData> realDataDict = new Dictionary <Contract, RealData>();
         realDataDict.Add(realData.CodeInfo, realData);
         UpdateFDYKForPositions(realDataDict);
     }
     else if (realObj is Dictionary <Contract, RealData> )
     {
         UpdateFDYKForPositions(realObj as Dictionary <Contract, RealData>);
     }
 }
        public RealData GetRealDataByCode(string code)
        {
            RealData realData = null;

            foreach (var item in RealDataList)
            {
                if (item.CodeInfo.Code == code)
                {
                    realData = item;
                    break;
                }
            }
            return(realData);
        }
        public void UpdateLevelsQuotes(RealData realData)
        {
            MainWindow mainWindow = TradeDataClient.GetClientInstance().getMainWindow();//CtpDataServer.GetUserInstance().getMainWindow();

            if (mainWindow != null)
            {
                if (mainWindow.uscHangqing != null)
                {
                    mainWindow.uscHangqing.LvQuotesPanel.SetLevelsQuotesByRealData(realData);
                }
                if (mainWindow.uscOptionHangqing != null)
                {
                    mainWindow.uscOptionHangqing.LvOptQuotesPanel.SetLevelsQuotesByRealData(realData);
                }
            }
        }
        /// <summary>
        /// 处理分档行情
        /// </summary>
        /// <param name="m_displayRealData"></param>
        private void SetNewOrderPanelInfo(RealData realData)
        {
            MainWindow mainWindow = TradeDataClient.GetClientInstance().getMainWindow();//CtpDataServer.GetUserInstance().getMainWindow();

            if (mainWindow != null && mainWindow.uscNewOrderPanel.txtCode.Text.Trim() == realData.CodeInfo.Code)
            {
                mainWindow.uscNewOrderPanel.SetExtendsInfo(realData);

                //将行情显示到报价表中
                //mainWindow.uscOptionHangqing.AddExternalHqingData(m_displayRealData);

                //if (mainWindow.uscOptionHangqing.fendanghangqing.lblCode.Content.ToString() == m_displayRealData.Code)
                //{
                //    mainWindow.uscOptionHangqing.SetFendanghangqingByDisplayRealData(m_displayRealData);
                //}
            }
        }
        public RealData GetOptRealData_C()
        {
            RealData realData = new RealData();

            realData.CodeInfo.Code   = this.Code_C;
            realData.CodeInfo.Name   = this.Name;
            realData.Position        = this.ChiCangLiang_C;
            realData.BidHand[0]      = this.StBuyCount_C;
            realData.BidPrice[0]     = this.StBuyPrice_C;
            realData.AskHand[0]      = this.StSellCount_C;
            realData.AskPrice[0]     = this.StSellPrice_C;
            realData.LowerLimitPrice = this.DownStopPrice_C;
            //realData.HYCS = this.HYCS;
            realData.Sum = this.I64Sum_C;
            //realData.ICurrentSum = this.ICurrentSu_C;
            realData.SettlmentPrice      = this.ISettlementPrice_C;
            realData.PrevSettlementPrice = this.PrevSettleMent_C;
            realData.UpperLimitPrice     = this.UpStopPrice_C;
            realData.CodeInfo.Code       = this.Code_C;//??
            realData.Hand = this.CurrentHand_C;
            //realData.I64Outside = this.I64Outside_C;
            realData.ClosePrice = this.IClose_C;
            //realData.IDealNumber = this.IDealNumber_C;
            realData.MaxPrice = this.IMaxPrice_C;
            realData.MinPrice = this.IMinPrice_C;
            realData.NewPrice = this.INewPrice_C;
            //Todo
            //realData.LastINewPrice = this.LastINewPrice_C + r.Next(-2, 1);
            //realData.IsFirstData = this.IsFirstData;
            //realData.LogMessage = this.LogMessage;
            //realData.Name = this.Name;
            realData.OpenPrice = this.Open_C;
            //realData.NTime = this.NTime_C;
            realData.PrevClose = this.PrevClose_C;
            //realData.UiTime = this.UiTime;
            //realData.UsUpdateNumber = this.UsUpdateNumber_C;
            realData.Volumn            = this.Volumn_C;
            realData.CodeInfo.ExchCode = CodeSetManager.ExNameToCtp(this.Market);
            realData.PrevPosition      = this.PreChicang_C;
            realData.PrevClose         = this.PrevClose_C;
            realData.UpdateTime        = this.UpdateTime_C;
            return(realData);
        }
        /// <summary>
        /// 期货行情
        /// </summary>
        /// <param name="realData"></param>
        private void UpdateFuturesDataCollection(Dictionary <Contract, RealData> realDataDict)
        {
            MainWindow mainWindow = TradeDataClient.GetClientInstance().getMainWindow();//CtpDataServer.GetUserInstance().getMainWindow();

            if (mainWindow != null)
            {
                foreach (var item in mainWindow.RealDataCollection)
                {
                    foreach (Contract contract in realDataDict.Keys)
                    {
                        RealData realData = realDataDict[contract];
                        if (item.Code == contract.Code)
                        {
                            item.UpdateProperties(realData);
                        }
                    }
                }
            }
            else
            {
                Util.Log("Warning!: mainWindow in BackgroundDataServer is NULL! ");
            }
        }
        /// <summary>
        /// 根据实时主推更新资金的盈亏数据和持仓的浮动盈亏数据
        /// </summary>
        /// <param name="commRealTimeDatas"></param>
        private void UpdateFDYK(Dictionary <Contract, RealData> realDataDict)
        {
            MainWindow mainWindow = TradeDataClient.GetClientInstance().getMainWindow();//CtpDataServer.GetUserInstance().getMainWindow();

            foreach (Contract contract in realDataDict.Keys)
            {
                RealData realData            = realDataDict[contract];
                double   newPrice            = realData.NewPrice;            //最新价
                double   prevSettlementPrice = realData.PrevSettlementPrice; //昨结算
                double   settlementPrice     = realData.SettlmentPrice;      //现结算
                double   bidPrice            = realData.BidPrice[0];
                double   askPrice            = realData.AskPrice[0];

                if (newPrice == 0 || realData.Volumn == 0)
                {
                    if (prevSettlementPrice > 0)
                    {
                        newPrice = prevSettlementPrice;
                    }
                    else if (newPrice == 0)
                    {
                        newPrice = realData.PrevClose;
                    }
                }
                if (bidPrice == 0)
                {
                    bidPrice = newPrice;
                }
                if (askPrice == 0)
                {
                    askPrice = newPrice;
                }

                double  hycs  = realData.CodeInfo.Hycs;
                decimal fluct = realData.CodeInfo.Fluct;

                if (mainWindow != null)
                {
                    foreach (PosInfoDetail detail in mainWindow.PositionDetailCollection)
                    {
                        if (detail.Code == contract.Code)
                        {
                            detail.PrevSettleMent = prevSettlementPrice;
                            if (newPrice == 0)
                            {
                                detail.Fdyk = detail.Ccyk = 0;
                            }

                            //更新Detail的数据
                            if (detail.BuySell.Contains("买"))
                            {
                                detail.INewPrice = bidPrice;
                                if (CodeSetManager.GetContractInfo(detail.Code, CodeSetManager.ExNameToCtp(detail.Exchange)).ProductType != null &&
                                    CodeSetManager.GetContractInfo(detail.Code, CodeSetManager.ExNameToCtp(detail.Exchange)).ProductType.Contains("Option"))
                                {
                                    detail.OptionMarketCap = bidPrice * detail.TradeHandCount * hycs;
                                    if (detail.PositionType.Contains("今"))
                                    {
                                        detail.Premium = -detail.AvgPx * detail.TradeHandCount * hycs;
                                        //detail.OptionProfit = (newPrice - detail.AvgPx) * detail.TradeHandCount * hycs;
                                    }
                                    else
                                    {
                                        //detail.OptionProfit = (newPrice - detail.PrevSettleMent) * detail.TradeHandCount * hycs;
                                    }
                                }

                                if (detail.PositionType == "今仓")
                                {
                                    detail.Ccyk = (bidPrice - detail.AvgPx) * detail.TradeHandCount * hycs;
                                    detail.Fdyk = detail.Ccyk;
                                }
                                else
                                {
                                    detail.Ccyk = (bidPrice - prevSettlementPrice) * detail.TradeHandCount * hycs;
                                    detail.Fdyk = (bidPrice - detail.AvgPx) * detail.TradeHandCount * hycs;
                                }
                            }
                            else
                            {
                                detail.INewPrice = askPrice;
                                if (CodeSetManager.GetContractInfo(detail.Code, CodeSetManager.ExNameToCtp(detail.Exchange)).ProductType != null &&
                                    CodeSetManager.GetContractInfo(detail.Code, CodeSetManager.ExNameToCtp(detail.Exchange)).ProductType.Contains("Option"))
                                {
                                    detail.OptionMarketCap = -askPrice * detail.TradeHandCount * hycs;
                                    if (detail.PositionType.Contains("今"))
                                    {
                                        detail.Premium = detail.AvgPx * detail.TradeHandCount * hycs;
                                        //detail.OptionProfit = -(newPrice - detail.AvgPx) * detail.TradeHandCount * hycs;
                                    }
                                    else
                                    {
                                        //detail.OptionProfit = -(newPrice - detail.PrevSettleMent) * detail.TradeHandCount * hycs;
                                    }
                                }

                                if (detail.PositionType == "今仓")
                                {
                                    detail.Ccyk = (detail.AvgPx - askPrice) * detail.TradeHandCount * hycs;
                                    detail.Fdyk = detail.Ccyk;
                                }
                                else
                                {
                                    detail.Ccyk = (prevSettlementPrice - askPrice) * detail.TradeHandCount * hycs;
                                    detail.Fdyk = (detail.AvgPx - askPrice) * detail.TradeHandCount * hycs;
                                }
                            }
                        }
                    }

                    foreach (PosInfoTotal posTotal in mainWindow.PositionCollection_Total)
                    {
                        if (posTotal.Code == realData.CodeInfo.Code)
                        {
                            double yesterdayDsyk     = 0;
                            double todayDsyk         = 0;
                            double yesterdayFdyk     = 0;
                            double todayFdyk         = 0;
                            double todayOpProfit     = 0;
                            double yesterdayOpProfit = 0;

                            if (newPrice != 0)
                            {
                                if (CodeSetManager.GetContractInfo(posTotal.Code, CodeSetManager.ExNameToCtp(posTotal.Exchange)).ProductType != null &&
                                    CodeSetManager.GetContractInfo(posTotal.Code, CodeSetManager.ExNameToCtp(posTotal.Exchange)).ProductType.Contains("Option"))
                                {
                                    if (posTotal.BuySell.Contains("买"))
                                    {
                                        posTotal.OptionMarketCap = bidPrice * posTotal.TotalPosition * hycs;
                                        posTotal.Premium         = -posTotal.TodayOpenAvgPx * posTotal.TodayPosition * hycs; //TODO: TradeHandCount
                                        //yesterdayOpProfit = (newPrice - posTotal.YesterdayOpenAvgPx) * posTotal.YesterdayPosition * hycs;//yesterdayOpProfit
                                        //todayOpProfit = (newPrice - posTotal.TodayOpenAvgPx) * posTotal.TodayPosition * hycs;//todayOpProfit
                                    }
                                    else
                                    {
                                        posTotal.OptionMarketCap = -askPrice * posTotal.TotalPosition * hycs;
                                        posTotal.Premium         = posTotal.TodayOpenAvgPx * posTotal.TodayPosition * hycs; //TODO: TradeHandCount
                                        //yesterdayOpProfit = (posTotal.YesterdayOpenAvgPx - newPrice) * posTotal.YesterdayPosition * hycs;//yesterdayOpProfit
                                        //todayOpProfit = (posTotal.TodayOpenAvgPx - newPrice) * posTotal.TodayPosition * hycs;//todayOpProfit
                                    }
                                }

                                //更新Detail的数据
                                if (posTotal.BuySell.Contains("买"))
                                {
                                    yesterdayDsyk = (bidPrice - prevSettlementPrice) * posTotal.YesterdayPosition * hycs;
                                    todayDsyk     = (bidPrice - posTotal.TodayOpenAvgPx) * posTotal.TodayPosition * hycs;

                                    yesterdayFdyk = (bidPrice - posTotal.YesterdayOpenAvgPx) * posTotal.YesterdayPosition * hycs;
                                    todayFdyk     = todayDsyk;//(newPrice - detail.OpenAvgPx) * detail.TodayOpen * hycs;
                                }
                                else
                                {
                                    if (CodeSetManager.GetContractInfo(posTotal.Code, CodeSetManager.ExNameToCtp(posTotal.Exchange)).ProductType != null &&
                                        CodeSetManager.GetContractInfo(posTotal.Code, CodeSetManager.ExNameToCtp(posTotal.Exchange)).ProductType.Contains("Option"))
                                    {
                                        posTotal.OptionMarketCap = -askPrice * posTotal.TotalPosition * hycs;
                                        posTotal.Premium         = posTotal.TodayOpenAvgPx * posTotal.TodayPosition * hycs; //TODO: TradeHandCount
                                    }

                                    yesterdayDsyk = (prevSettlementPrice - askPrice) * posTotal.YesterdayPosition * hycs;
                                    todayDsyk     = (posTotal.TodayOpenAvgPx - askPrice) * posTotal.TodayPosition * hycs;

                                    yesterdayFdyk = (posTotal.YesterdayOpenAvgPx - askPrice) * posTotal.YesterdayPosition * hycs;
                                    todayFdyk     = todayDsyk;//((newPrice - detail.OpenAvgPx) * detail.TodayOpen * hycs);
                                }
                            }

                            posTotal.Ccyk         = yesterdayDsyk + todayDsyk;
                            posTotal.Fdyk         = yesterdayFdyk + todayFdyk;
                            posTotal.OptionProfit = yesterdayOpProfit + todayOpProfit;

                            posTotal.AvgPositionPrice = (posTotal.TodayPosition * posTotal.TodayOpenAvgPx + posTotal.YesterdayPosition * prevSettlementPrice) / posTotal.TotalPosition;
                        }
                    }

                    //更新资金数据
                    double totalDSFY         = 0;
                    double totalFdyk         = 0;
                    double totalPremium      = 0;
                    double totalOptionCap    = 0;
                    double totalOptionProfit = 0;
                    foreach (PosInfoTotal detail in mainWindow.PositionCollection_Total)
                    {
                        if (CodeSetManager.GetContractInfo(detail.Code, CodeSetManager.ExNameToCtp(detail.Exchange)).ProductType == "Futures")
                        {
                            totalDSFY += detail.Ccyk;
                            totalFdyk += detail.Fdyk;
                        }
                        else if (CodeSetManager.GetContractInfo(detail.Code, CodeSetManager.ExNameToCtp(detail.Exchange)).ProductType != null &&
                                 CodeSetManager.GetContractInfo(detail.Code, CodeSetManager.ExNameToCtp(detail.Exchange)).ProductType.Contains("Option"))
                        {
                            totalOptionProfit += detail.Ccyk;
                        }
                        totalPremium      += detail.Premium;
                        totalOptionCap    += detail.OptionMarketCap;
                        totalOptionProfit += detail.OptionProfit;
                    }

                    if (mainWindow.CapitalDataCollection != null)
                    {
                        mainWindow.CapitalDataCollection.Dsfy        = totalDSFY;
                        mainWindow.CapitalDataCollection.FloatProfit = totalFdyk;
                        //mainWindow.CapitalDataCollection.Premium = totalPremium;
                        mainWindow.CapitalDataCollection.OptionMarketCap = totalOptionCap;
                        mainWindow.CapitalDataCollection.OptionProfit    = totalOptionProfit;
                        mainWindow.CapitalDataCollection.AccountCap      = totalOptionCap + mainWindow.CapitalDataCollection.DynamicEquity;
                    }
                }
            }
        }
        public void ChangeType(Dictionary <Contract, RealData> tempDataDict)
        {
            Dictionary <Contract, RealData> futuresDataDict     = new Dictionary <Contract, RealData>();
            Dictionary <Contract, RealData> combinationDataDict = new Dictionary <Contract, RealData>();

            foreach (Contract contract in tempDataDict.Keys)
            {
                RealData tempData = tempDataDict[contract];
                if (tempData == null || tempData.CodeInfo == null)
                {
                    return;
                }
                string tempCodeInfoKey = tempData.CodeInfo.Code + "_" + tempData.CodeInfo.ExchCode;
                double newPrice        = 0;

                newPrice = Math.Round(tempData.NewPrice, 4);//最新价
                if (_CodeDic.ContainsKey(tempCodeInfoKey))
                {
                    RealData DicData = _CodeDic[tempCodeInfoKey];
                    SetDisplayRealDataValueByRealTimeData(tempData, newPrice, DicData);
                }
                else //if (this._CommObj.RequestingCodes.Contains(tempData.CodeInfo.Code))//只操作正在推送的合约
                {
                    RealData reqRealData = new RealData();
                    SetDisplayRealDataValueByRealTimeData(tempData, newPrice, reqRealData);

                    _CodeDic.Add(tempCodeInfoKey, reqRealData);
                    RealDataList.Add(reqRealData);
                }

                if (tempData.CodeInfo.ProductType == "Futures" || tempData.CodeInfo.ProductType == "Combination" || tempData.CodeInfo.ProductType.Contains("Stock") || tempData.CodeInfo.ProductType.Contains("ETF"))
                {
                    if (futuresDataDict.ContainsKey(contract))
                    {
                        futuresDataDict[contract] = tempData;
                    }
                    else
                    {
                        futuresDataDict.Add(contract, tempData);
                    }
                }

                if (tempData.CodeInfo.ProductType == "Combination")
                {
                    if (combinationDataDict.ContainsKey(contract))
                    {
                        combinationDataDict[contract] = tempData;
                    }
                    else
                    {
                        combinationDataDict.Add(contract, tempData);
                    }
                }

                if (Application.Current != null)
                {
                    Application.Current.Dispatcher.Invoke((Action) delegate
                    {
                        SetNewOrderPanelInfo(tempData);
                        UpdateLevelsQuotes(tempData);
                    });
                }
            }

            if (Application.Current != null)
            {
                Application.Current.Dispatcher.Invoke((Action) delegate
                {
                    UpdateFuturesDataCollection(futuresDataDict);
                    UpdateCombinationDataCollection(combinationDataDict);
                    UpdateOptionDataCollection(tempDataDict);
                    SetPositionInfo(tempDataDict);
                });
            }
        }