/// <summary>
        /// 埋单提交(选中)
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void MaiDanHandle(object sender, RoutedEventArgs e)
        {
            List <TradeOrderData> selectedOrder = new List <TradeOrderData>();

            foreach (var item in dgMaiConditionOrder.SelectedItems)
            {
                selectedOrder.Add((TradeOrderData)item);
            }

            foreach (var item in selectedOrder)
            {
                TradeOrderData o = (TradeOrderData)item;
                if (o != null)
                {
                    //对o撤单
                    if (IsMaiDanHandlable(o))
                    {
                        TradeDataClient.GetClientInstance().RequestOrder(o.InvestorID, BACKENDTYPE.CTP, new RequestContent("NewOrderSingle", new List <object>()
                        {
                            CodeSetManager.GetContractInfo(o.Code, CodeSetManager.ExNameToCtp(o.Exchange)), SIDETYPE.BUY, PosEffect.Close, 0, 0, 0, o.OrderID, CommonUtil.GetHedgeType(o.Hedge)
                        }));
                    }
                }
            }
        }
        void grdRealData_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            //将不需要的行情去除掉
            if (dgRealData.SelectedItem != null)
            {
                DisplayRealData selectedRecord = dgRealData.SelectedItem as DisplayRealData;
                LvQuotesPanel.lblCode.Content = selectedRecord.Code;

                //RealData selectedData = new RealData();
                string tempKey = selectedRecord.Code + "_" + CodeSetManager.ExNameToCtp(selectedRecord.Market);
                if (_BackupCodeDic.ContainsKey(tempKey))
                {
                    LvQuotesPanel.SetLevelsQuotesByRealData(_BackupCodeDic[tempKey]);
                }

                //List<DisplayRealData> uselessDatas = new List<DisplayRealData>();
                //foreach (var item in mainWindow.RealDataCollection)
                //{
                //    if (!HQRealData.commObj.RequestingCodes.Contains(item.Code)
                //        && item.Code != mainWindow.uscNewOrderPanel.txtCode.Text.Trim()
                //        && item != selectedRecord)
                //    {
                //        uselessDatas.Add(item);
                //    }
                //}
                //foreach (var item in uselessDatas)
                //{
                //    mainWindow.RealDataCollection.Remove(item);
                //}
            }
        }
Beispiel #3
0
        public bool UpdateRealProperties(DisplayRealData displayData)
        {
            try
            {
                this.CodeInfo.Code   = displayData.Code;
                this.CodeInfo.Name   = displayData.Name;
                this.Position        = displayData.ChiCangLiang;
                this.BidHand[0]      = displayData.StBuyCount;
                this.BidPrice[0]     = displayData.StBuyPrice;
                this.AskHand[0]      = displayData.StSellCount;
                this.AskPrice[0]     = displayData.StSellPrice;
                this.LowerLimitPrice = displayData.DownStopPrice;
                this.Sum             = displayData.I64Sum;

                this.SettlmentPrice      = displayData.ISettlementPrice;
                this.PrevSettlementPrice = displayData.PrevSettleMent;
                this.UpperLimitPrice     = displayData.UpStopPrice;
                this.Hand = displayData.CurrentHand;

                this.ClosePrice = displayData.IClose;

                this.MaxPrice = displayData.IMaxPrice;
                this.MinPrice = displayData.IMinPrice;
                this.NewPrice = displayData.INewPrice;

                this.OpenPrice = displayData.Open;

                this.PrevClose = displayData.PrevClose;

                this.Volumn            = displayData.Volumn;
                this.CodeInfo.ExchCode = CodeSetManager.ExNameToCtp(displayData.Market);
                this.PrevPosition      = displayData.PreChicang;
                this.PrevClose         = displayData.PrevClose;
                this.UpdateTime        = displayData.UpdateTime;
                return(true);
            }
            catch (Exception ex)
            {
                Util.Log_Error("exception: " + ex.Message);
                Util.Log_Error("exception: " + ex.StackTrace);
                return(false);
            }
        }
        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="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;
                    }
                }
            }
        }