private void txtCode_TextChanged(object sender, TextChangedEventArgs e)
        {
            //Util.Log("txtCode_TextChanged starts.");
            txtCode.SelectionStart = txtCode.Text.Length;
            int    firstNumberIndiex = txtCode.Text.IndexOfAny("0123456789".ToCharArray());
            string SpeciesName       = txtCode.Text;
            string SpeciesDate       = string.Empty;

            if (firstNumberIndiex >= 0)
            {
                SpeciesName = txtCode.Text.Substring(0, firstNumberIndiex);
                SpeciesDate = txtCode.Text.Substring(firstNumberIndiex, txtCode.Text.Length - firstNumberIndiex);
                //}

                //用户可能不区分大小写输入合约
                string validSpeciesName = CodeSetManager.GetValidSpeciesName(SpeciesName);
                if (validSpeciesName != null && validSpeciesName != SpeciesName)
                {
                    txtCode.Text = validSpeciesName + SpeciesDate;
                    return;
                }
            }
            if (CommonUtil.IsValidCode(txtCode.Text.Trim()))
            {
                Contract newCode = CodeSetManager.GetContractInfo(txtCode.Text.Trim());
                txtCodeName.Text = newCode.Name;

                //iudNum.Value = DefaultCodeHandInstance.GetDefaultCodeHand(txtCode.Text);
            }
        }
        /// <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)
                        }));
                    }
                }
            }
        }
        public void AddSingleRealData(string strCode)
        {
            if (_CommObj.RequestingCodes.Contains(strCode))
            {
                return;
            }
            Contract searchCodeInfo = CodeSetManager.GetContractInfo(strCode);

            this.AddContract(new Contract[] { searchCodeInfo });
            this.GetRealData();
            this.Request();
        }
 public void RefreshAutoPushMarketData()
 {
     foreach (string code in _CommObj.RequestingCodes)
     {
         Contract item = CodeSetManager.GetContractInfo(code);
         if (item != null)
         {
             _CodesList.Add(item);
         }
     }
     _CommObj.RequestingCodes.Clear();
     Request();
 }
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (value == null)
            {
                return("");
            }
            string code = value.ToString();

            if (CodeSetManager.GetContractInfo(code) != null)
            {
                return(CodeSetManager.GetContractInfo(code).Name);
            }
            return("");
        }
예제 #6
0
        private void bt_add_Click(object sender, RoutedEventArgs e)
        {
            if (CommonUtil.IsValidCode(txtCode.Text))
            {
                Contract orderCodeIndo = CodeSetManager.GetContractInfo(txtCode.Text);
                if (!_ChooseSet.Contains(orderCodeIndo))
                {
                    _ChooseSet.Add(orderCodeIndo);
                }
                txtCode.Text = string.Empty;
                return;
            }

            AddContractFromChooseSet();
        }
예제 #7
0
        public static void SetRealDataToContainer(RealData realData)
        {
            Contract codeKey = CodeSetManager.GetContractInfo(realData.CodeInfo.Code, realData.CodeInfo.ExchCode);

            if (codeKey != null)
            {
                if (RealDataContainer.ContainsKey(codeKey))
                {
                    RealDataContainer[codeKey] = realData;
                }
                else
                {
                    RealDataContainer.Add(codeKey, realData);
                }
            }
            else
            {
                Util.Log("Warning!: codeKey is NULL! ");
            }
        }
        public void RemoveUselessRequest()
        {
            //去除不必要的请求
            List <Contract> lstDelCodes = new List <Contract>();
            MainWindow      mainWindow  = TradeDataClient.GetClientInstance().getMainWindow();//CtpDataServer.GetUserInstance().getMainWindow();

            if (mainWindow != null)
            {
                foreach (var item in _CommObj.RequestingCodes)
                {
                    bool isUsed = false;
                    foreach (var positionItem in mainWindow.PositionDetailCollection)
                    {
                        if (item == positionItem.Code)
                        {
                            isUsed = true;
                            break;
                        }
                    }
                    foreach (var quoteItem in mainWindow.RealDataCollection)
                    {
                        if (item == quoteItem.Code)
                        {
                            isUsed = true;
                            break;
                        }
                    }
                    foreach (var quoteItem in mainWindow.RealDataArbitrageCollection)
                    {
                        if (item == quoteItem.Code)
                        {
                            isUsed = true;
                            break;
                        }
                    }
                    if (item == mainWindow.uscNewOrderPanel.txtCode.Text)
                    {
                        isUsed = true;
                    }

                    string fCode = mainWindow.uscOptionHangqing.titleCode.Content.ToString();
                    if (fCode != null && fCode != String.Empty)
                    {
                        if (fCode == item)
                        {
                            isUsed = true;
                            break;
                        }
                        if (mainWindow.uscOptionHangqing.OptionCodeDict.ContainsKey(fCode))
                        {
                            foreach (string contract in mainWindow.uscOptionHangqing.OptionCodeDict[fCode])
                            {
                                if (contract == item)
                                {
                                    isUsed = true;
                                    break;
                                }
                            }
                        }
                    }

                    if (!isUsed)
                    {
                        Contract cCode = CodeSetManager.GetContractInfo(item);
                        //TODO :临时方案
                        if (cCode == null)
                        {
                            cCode = new Contract(item);
                        }
                        //
                        lstDelCodes.Add(cCode);
                    }
                }
            }

            if (lstDelCodes.Count > 0)
            {
                AddContract(lstDelCodes.ToArray());
                UnRequest();
            }
        }
        /// <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;
                    }
                }
            }
        }
        private void RequestRealData(BackgroundDataServer hqRealData)
        {
            ObservableCollection <UserCodeSet> lstUserCodeSet = UserCodeSetInstance.GetUserCodeSetList();
            //先删除合约
            bool bChanged = false;

            _DelCodeList.Clear();
            foreach (Contract temp in hqRealData.m_oldCodeArray)
            {
                if (!hqRealData.m_codeArray.Contains(temp))
                {
                    _DelCodeList.Add(temp);
                }
            }
            if (_DelCodeList.Count > 0)
            {
                bChanged = true;
                hqRealData.AddContract(_DelCodeList.ToArray());
                hqRealData.UnRequest();
                try
                {
                    RealData tempData = null;
                    foreach (Contract temp in _DelCodeList)
                    {
                        string tempKey = temp.Code + "_" + temp.ExchCode;
                        if (_BackupCodeDic.ContainsKey(tempKey))
                        {
                            tempData = _BackupCodeDic[tempKey];
                            if (tempData != null)
                            {
                                DisplayRealData tempDisplayData = UpdateDisplayProperties(tempData);
                                if (hqRealData == HQRealData)
                                {
                                    //Util.Log("<<:" + tempData.ToString());
                                    _MainWindow.RealDataCollection.Remove(tempDisplayData);
                                }
                                else if (hqRealData == GroupHQRealData)
                                {
                                    _MainWindow.RealDataArbitrageCollection.Remove(tempDisplayData);
                                }
                                _BackupCodeDic.Remove(tempKey);
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    Util.Log_Error("exception: " + ex.Message);
                    Util.Log_Error("exception: " + ex.StackTrace);
                }
            }
            //在请求新增的合约
            _AddCodeList.Clear();
            foreach (Contract temp in hqRealData.m_codeArray)
            {
                if (!hqRealData.m_oldCodeArray.Contains(temp))
                {
                    _AddCodeList.Add(temp);
                }
            }

            if (_AddCodeList.Count > 0)
            {
                foreach (Contract temp in _AddCodeList)
                {
                    if (temp == null)
                    {
                        continue;
                    }
                    string tempKey = temp.Code + "_" + temp.ExchCode;
                    if (_BackupCodeDic.ContainsKey(tempKey) == false)
                    {
                        RealData tempData2 = new RealData();
                        //Contract tempContract = CodeSetManager.GetContractInfo(temp.Code);
                        tempData2.CodeInfo = CodeSetManager.GetContractInfo(temp.Code, temp.ExchCode);
                        if (tempData2.CodeInfo == null)
                        {
                            tempData2.CodeInfo = new Contract(temp.Code);
                        }
                        //tempData2.Name = tempContract.Name;
                        //decimal fluct = 0.00M;
                        //CodeSetManager.GetHycsAndFluct(tempData2.codeInfo.Code, out (double)tempData2.m_hycs, out fluct);
                        _BackupCodeDic.Add(tempKey, tempData2);
                    }
                }
                bChanged = true;
                hqRealData.AddContract(_AddCodeList.ToArray());
                hqRealData.GetRealData();
                hqRealData.Request();
            }

            DeepCopyInfo(hqRealData.m_codeArray, hqRealData.m_oldCodeArray);

            if (bChanged == false)
            {
                RealData tempData2 = null;
                _MainWindow.RealDataCollection.Clear();
                _MainWindow.RealDataArbitrageCollection.Clear();
                foreach (Contract temp in hqRealData.m_oldCodeArray)
                {
                    //Util.Log(this.defaultButton.Content + " 添加内容 Old-----");
                    string tempKey = temp.Code + "_" + temp.ExchCode;
                    if (_BackupCodeDic.ContainsKey(tempKey))
                    {
                        tempData2 = _BackupCodeDic[tempKey];
                        if (tempData2 != null)
                        {
                            DisplayRealData tempDisplayData = UpdateDisplayProperties(tempData2);
                            if (hqRealData == HQRealData)
                            {
                                //Util.Log(">>:" + tempData2.ToString());
                                _MainWindow.RealDataCollection.Add(tempDisplayData);
                            }
                            else if (hqRealData == GroupHQRealData)
                            {
                                if (tempData2.CodeInfo.Code.Contains("&"))
                                {
                                    //string[] tempType = tempData2.codeInfo.Code.Split(' ');
                                    //string[] tempGroup = tempType[1].Split('&');
                                    //tempData2.Code = tempGroup[0];
                                    //tempData2.Code2 = tempGroup[1];
                                }
                                _MainWindow.RealDataArbitrageCollection.Add(UpdateDisplayProperties(tempData2));
                            }
                        }
                    }
                }
            }
            else
            {
                RealData tempData2 = null;
                _MainWindow.RealDataCollection.Clear();
                _MainWindow.RealDataArbitrageCollection.Clear();
                if (hqRealData == HQRealData)
                {
                    //Util.Log(this.defaultButton.Content + " 添加内容-----");
                    foreach (Contract temp in _CodeArray)
                    {
                        if (temp != null)
                        {
                            string tempKey = temp.Code + "_" + temp.ExchCode;
                            if (_BackupCodeDic.ContainsKey(tempKey) == false)
                            {
                                tempData2 = new RealData();
                                //Contract tempContract = CodeSetManager.GetContractInfo(temp.Code);
                                tempData2.CodeInfo = CodeSetManager.GetContractInfo(temp.Code, temp.ExchCode);
                                if (tempData2.CodeInfo == null)
                                {
                                    tempData2.CodeInfo = new Contract(temp.Code);
                                }
                                //tempData2.Name = tempContract.Name;
                                //double fluct = 0;
                                //CodeSetManager.GetHycsAndFluct(tempData2.Code, out tempData2.m_hycs, out fluct);
                                _BackupCodeDic.Add(tempKey, tempData2);
                            }
                            else
                            {
                                tempData2 = _BackupCodeDic[tempKey];
                            }
                            DisplayRealData tempDisplayData = UpdateDisplayProperties(tempData2);
                            //Util.Log(">>:"+tempData2.ToString());
                            _MainWindow.RealDataCollection.Add(tempDisplayData);
                            //Util.Log("mainWindow.RealDataCollection.count=" + mainWindow.RealDataCollection.Count);
                        }
                    }
                }

                else if (hqRealData == GroupHQRealData)
                {
                    foreach (Contract temp in _GroupCodeArray)
                    {
                        if (temp != null)
                        {
                            string tempKey = temp.Code + "_" + temp.ExchCode;
                            if (_BackupCodeDic.ContainsKey(tempKey) == false)
                            {
                                tempData2          = new RealData();
                                tempData2.CodeInfo = CodeSetManager.GetContractInfo(temp.Code, temp.ExchCode);
                                if (tempData2.CodeInfo == null)
                                {
                                    tempData2.CodeInfo = new Contract(tempKey);
                                }
                                //decimal fluct = 0;
                                //CodeSetManager.GetHycsAndFluct(temp.Code, out tempData2.m_hycs, out fluct);
                                _BackupCodeDic.Add(tempKey, tempData2);
                            }
                            else
                            {
                                tempData2 = _BackupCodeDic[tempKey];
                            }
                            if (tempData2.CodeInfo.Code.Contains("&"))
                            {
                                //string[] tempType = tempData2.Code.Split(' ');
                                //string[] tempGroup = tempType[1].Split('&');
                                //tempData2.Code1 = tempGroup[0];
                                //tempData2.Code2 = tempGroup[1];
                            }
                            _MainWindow.RealDataArbitrageCollection.Add(UpdateDisplayProperties(tempData2));
                        }
                    }
                }
            }
            hqRealData.UpdateRealDataList();
        }
        private void Exec_Click(object sender, RoutedEventArgs e)
        {
            string verifyMessage = execOrderDataVerification();

            if (verifyMessage == string.Empty)
            {
                Contract optContract = CodeSetManager.GetContractInfo(txtCode.Text.Trim());
                if (optContract == null)
                {
                    Util.Log("Warning! Cannot find contract info for " + txtCode.Text.Trim());
                    return;
                }
                bool   isExec    = rbExec.IsChecked == true ? true : false;
                string order     = rbExec.IsChecked == true ? "行权" : "弃权";
                string strCode   = optContract.Code;
                int    handCount = CommonUtil.GetIntValue(iudNum.Value.Value);
                EnumThostOffsetFlagType openClose = EnumThostOffsetFlagType.Close;
                string kp = "平仓";
                if (CodeSetManager.IsCloseTodaySupport(optContract.Code))
                {
                    if (rbPingjin.IsChecked == true)
                    {
                        openClose = EnumThostOffsetFlagType.CloseToday;
                        kp        = "平今";
                    }

                    else if (rbPingcang.IsChecked == true)
                    {
                        openClose = EnumThostOffsetFlagType.CloseYesterday;
                        kp        = "平仓";
                    }
                }
                else if (rbPingcang.IsChecked == true)
                {
                    openClose = EnumThostOffsetFlagType.Close;
                }

                if (TradingMaster.Properties.Settings.Default.ConfirmBeforeSendNewOrder == true)
                {
                    CheckableMessageBox messageBox = new CheckableMessageBox();
                    messageBox.tbMessage.Text = string.Format("{0}:{1} {2} {3}手", order, kp, strCode, handCount);
                    string windowTitle   = string.Format("确认{0}:{1} {2} {3}手", order, kp, strCode, handCount);
                    Window confirmWindow = CommonUtil.GetWindow(windowTitle, messageBox, _MainWindow);

                    if (confirmWindow.ShowDialog() == true)
                    {
                        if (handCount > 0)
                        {
                            TradeDataClient.GetClientInstance().RequestOrder("", BACKENDTYPE.CTP, new RequestContent("NewExecOrder", new List <object>()
                            {
                                strCode, handCount, optContract.ExchName, isExec, openClose
                            }));
                        }
                    }
                }
                else
                {
                    if (!CodeSetManager.IsCloseTodaySupport(strCode) && openClose == EnumThostOffsetFlagType.CloseToday)
                    {
                        openClose = EnumThostOffsetFlagType.Close;
                    }
                    if (handCount > 0)
                    {
                        TradeDataClient.GetClientInstance().RequestOrder("", BACKENDTYPE.CTP, new RequestContent("NewExecOrder", new List <object>()
                        {
                            strCode, handCount, optContract.ExchName, isExec, openClose
                        }));
                    }
                }
            }
        }