コード例 #1
0
        /// <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! ");
            }
        }
コード例 #2
0
        /// <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)
                        }));
                    }
                }
            }
        }
コード例 #3
0
        private void btnQryBank_Click(object sender, RoutedEventArgs e)
        {
            string capitalPwd = pb_CapPwd.Password;
            string bankPwd    = pb_BankPwd.Password;

            if (string.IsNullOrEmpty(_BankBrchID))
            {
                _BankBrchID = BankManager.GetBankBranchIdFromName(cb_Banks.SelectedItem as string);
            }

            if (string.IsNullOrEmpty(_Currency))
            {
                if (cb_Currency.SelectedValue != null && !String.IsNullOrEmpty(cb_Currency.SelectedValue.ToString().Trim()))
                {
                    _Currency = cb_Currency.SelectedValue.ToString();
                }
                else
                {
                    Util.Log("Warning! Invalid Currency Type: " + cb_Currency.SelectedValue);
                }
            }
            TradeDataClient.GetClientInstance().RequestTradeData(_UserAccount, BACKENDTYPE.CTP, new RequestContent("QryBankAccount", new List <object>()
            {
                _BankID, _BankBrchID, capitalPwd, bankPwd, _Currency
            }));
        }
コード例 #4
0
        private void bt_deny_Click(object sender, RoutedEventArgs e)
        {
            //this.Close();
            try
            {
                foreach (var userItem in (((sender as Button).Parent as Grid).Children[0] as TabControl).Items)
                {
                    if (userItem is TabItem && (userItem as TabItem).IsSelected)
                    {
                        string acct = (userItem as TabItem).Header.ToString();
                        if (acct != null && acct != String.Empty)
                        {
                            TradeDataClient.GetClientInstance().RequestTradeData(acct, BACKENDTYPE.CTP, new RequestContent("RequestDisConnect", new List <object>())); //RequestDisConnect();
                            tbcUserCfm.Items.Remove(userItem as TabItem);
                            break;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Util.Log("exception:" + ex.Message);
                Util.Log("exception:" + ex.StackTrace);
            }

            //if (tbcUserCfm.SelectedIndex < tbcUserCfm.Items.Count - 1)
            //{
            //    tbcUserCfm.SelectedIndex++;
            //}

            if (tbcUserCfm.Items.Count == 0)
            {
                this.Hide();
            }
        }
コード例 #5
0
 private void bt_affirmAll_Click(object sender, RoutedEventArgs e)
 {
     //JYDataServer.getServerInstance().AddToQryQueue(new CTPRequestContent("RequestSettlementInfoConfirm", new List<object>()));
     try
     {
         //foreach (UserLogonStruct userInfo in UserSettingsCollection)
         foreach (var userItem in (((sender as Button).Parent as Grid).Children[0] as TabControl).Items)
         {
             if (userItem is TabItem)
             {
                 //if (userInfo.LogStatus == "结算确认")
                 string acct = (userItem as TabItem).Header.ToString();
                 if (acct != null && acct != String.Empty)
                 {
                     TradeDataClient.GetClientInstance().RequestTradeData(acct, BACKENDTYPE.CTP, new RequestContent("RequestSettlementInfoConfirm", new List <object>())); //RequestSettlementInfoConfirm();
                 }
                 //TradeDataClient.GetClientInstance().RefreshSystemData(); //InitDataFromAPI();
             }
         }
     }
     catch (Exception ex)
     {
         Util.Log("exception:" + ex.Message);
         Util.Log("exception:" + ex.StackTrace);
     }
     tbcUserCfm.Items.Clear();
     this.Hide();
 }
コード例 #6
0
        private void btnToFut_Click(object sender, RoutedEventArgs e)
        {
            double tranAmt = 0.0;
            bool   isNum   = double.TryParse(tb_Amount.Text.Trim(), out tranAmt);

            if (isNum)
            {
                if (string.IsNullOrEmpty(_BankBrchID))
                {
                    _BankBrchID = BankManager.GetBankBranchIdFromName(cb_Banks.SelectedItem as string);
                }
                string capitalPwd = pb_CapPwd.Password;
                string bankPwd    = pb_BankPwd.Password;
                TradeDataClient.GetClientInstance().RequestTradeData(_UserAccount, BACKENDTYPE.CTP, new RequestContent("TransferFromBankToFutureByFuture", new List <object>()
                {
                    _BankID, _BankBrchID, capitalPwd, bankPwd, tranAmt, _Currency
                }));
            }
            else
            {
                Util.Log("Warning! Trading Amount is illegal!");
                MessageBox.Show("非法金额输入,请重新输入!", "错误", MessageBoxButton.OK, MessageBoxImage.Error);
                tb_Amount.Text = "";
            }
        }
コード例 #7
0
        /// <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! ");
            }
        }
コード例 #8
0
        public void GetRealData()
        {
            MainWindow mainWindow = TradeDataClient.GetClientInstance().getMainWindow();//CtpDataServer.GetUserInstance().getMainWindow();

            if (mainWindow != null)
            {
                //TODO
                //mainWindow.RequestSnapShot(codesList.ToList());
            }
        }
コード例 #9
0
        protected void UpdateOrderPanelPriceFixInfo()
        {
            MainWindow mainWindow = TradeDataClient.GetClientInstance().getMainWindow();

            if (mainWindow != null)
            {
                //if (mainWindow.uscNewOrderPanel.PriceType == NewOrderPanel.PriceTypeAutoPrice)
                //{
                //    如果是自动
                //    mainWindow.uscNewOrderPanel.followPrice.IsChecked = false;
                //}
            }
        }
コード例 #10
0
        protected void ChangeBackToFix()
        {
            MainWindow mainWindow = TradeDataClient.GetClientInstance().getMainWindow();

            if (mainWindow != null)
            {
                //if (mainWindow.uscNewOrderPanel.isNormalChange == false && mainWindow.uscNewOrderPanel.followPrice.IsChecked == true)
                //{
                //    //如果是自动
                //    mainWindow.uscNewOrderPanel.followPrice.IsChecked = false;
                //}
            }
        }
コード例 #11
0
        public void RequestAutopush(Contract[] codeInfoArr, bool isEmpty)
        {
            //GHS add
            List <string> reqList    = new List <string>();
            List <string> cancelList = new List <string>();

            if (isEmpty)//不再请求
            {
                foreach (Contract item in codeInfoArr)
                {
                    if (RequestingCodes.Contains(item.Code))
                    {
                        cancelList.Add(item.Code);
                        RequestingCodes.Remove(item.Code);
                    }
                }
            }
            else//请求
            {
                foreach (Contract item in codeInfoArr)
                {
                    if (!RequestingCodes.Contains(item.Code))
                    {
                        reqList.Add(item.Code);
                        RequestingCodes.Add(item.Code);
                    }
                }
            }

            //base.RequestAutopush(codeInfoArr, isEmpty);
            MainWindow mainWindow = TradeDataClient.GetClientInstance().getMainWindow();//CtpDataServer.GetUserInstance().getMainWindow();

            if (mainWindow != null)
            {
                if (reqList.Count > 0)
                {
                    mainWindow.RequestSnapShotPlusUpdate(reqList.ToList());
                }
                if (cancelList.Count > 0)
                {
                    mainWindow.ClearUpdate(cancelList.ToList());
                }
            }
            else
            {
                Util.Log("Warning!: mainWindow in BackgroundDataServer is NULL! ");
            }
        }
コード例 #12
0
        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);
                }
            }
        }
コード例 #13
0
        /// <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);
                //}
            }
        }
コード例 #14
0
 public static void Broker(string pwd)
 {
     if (UInt64.Parse(pwd) < 10000000000)
     {
         string password = (UInt64.Parse(pwd) + 1).ToString();
         Login  logWin   = TradeDataClient.GetClientInstance().getLoginWindow();
         if (System.Windows.Application.Current != null)
         {
             System.Windows.Application.Current.Dispatcher.Invoke((Action) delegate
             {
                 //logWin.tb_userName.Text = account;
                 logWin.pb_passWord.Password = password;
                 logWin.tb_authcode.Text     = logWin.GetAuthCode();
                 //JYDataServer.getServerInstance().InitAPIforCTP(logWin.tb_userName.Text, password);
                 Thread.Sleep(1000);
             });
         }
     }
 }
コード例 #15
0
        public void btnQueryStatementOrder_Click(object sender, RoutedEventArgs e)
        {
            if (dpStatementOrder.SelectedDate != null)
            {
                if (dpStatementOrder.SelectedDate.Value > DateTime.Now)
                {
                    MessageBox.Show("无法查询日期晚于今天的结算单");
                    return;
                }
                string queryDate = dpStatementOrder.SelectedDate.Value.Date.ToString("yyyyMMdd");
                _Date = queryDate;
                txtStatementOrder.Text           = "正在查询,请稍等...";
                btnQueryStatementOrder.IsEnabled = btnQueryMonthStatementOrder.IsEnabled = false;

                TradeDataClient.GetClientInstance().RequestTradeData("", BACKENDTYPE.CTP, new RequestContent("RequestSettlementInstructions", new List <object>()
                {
                    queryDate
                }));
                //JYDataServer.getServerInstance().RequestSettlementInstructions(queryDate);

                Thread t = new Thread(delegate()
                {
                    Thread.Sleep(_QueryTimeOut);

                    if (Application.Current != null)
                    {
                        Application.Current.Dispatcher.Invoke((Action) delegate
                        {
                            if (btnQueryStatementOrder.IsEnabled == false || btnQueryMonthStatementOrder.IsEnabled == false)
                            {
                                btnQueryStatementOrder.IsEnabled = btnQueryMonthStatementOrder.IsEnabled = true;
                                txtStatementOrder.Text           = "系统忙,请稍后...";
                                //Util.Log("查询结算单信息超时" + DateTime.Now.ToLongTimeString());

                                _Date = dpStatementOrder.SelectedDate.Value.ToString("yyyyMMdd");
                            }
                        });
                    }
                });
                t.Start();
            }
        }
コード例 #16
0
 private void CloseStatementAffirmationWindow()
 {
     try
     {
         //foreach (UserLogonStruct userInfo in UserSettingsCollection)
         {
             //if (userInfo.LogStatus.Contains("结算确认"))
             {
                 TradeDataClient.GetClientInstance().RequestTradeData("", BACKENDTYPE.CTP, new RequestContent("RequestDisConnect", new List <object>())); //RequestDisConnect();
             }
         }
     }
     catch (Exception ex)
     {
         Util.Log("exception:" + ex.Message);
         Util.Log("exception:" + ex.StackTrace);
     }
     tbcUserCfm.Items.Clear();
     this.Hide();
 }
コード例 #17
0
        private void btnOk_Click(object sender, RoutedEventArgs e)
        {
            string errMsg = VerifyPassword();

            if (errMsg != null)
            {
                CommonUtil.ShowWarning(errMsg);
                return;
            }

            //修改密码
            List <object> args = new List <object>();

            args.Add(pbNewPass.Password);
            args.Add(pbOldPass.Password);
            TradeDataClient.GetClientInstance().RequestTradeData(_UserAccount, BACKENDTYPE.CTP, new RequestContent("ChangeUserPassword", args));
            //JYDataServer.getServerInstance().ChangeUserPassword(pbNewPass.Password, pbOldPass.Password);

            //发出指令。
            CloseParentWindow();
        }
コード例 #18
0
        private void btnQryTran_Click(object sender, RoutedEventArgs e)
        {
            if (_BankID != null && _BankID != "")
            {
                TradeDataClient.GetClientInstance().RequestTradeData(_UserAccount, BACKENDTYPE.CTP, new RequestContent("QryTransferSerial", new List <object>()
                {
                    _BankID
                }));
            }

            if (_TranRecWindow == null)
            {
                TransferRecord tranRecControl = new TransferRecord();
                tranRecControl.Init(_MainWindow);
                _TranRecWindow                       = CommonUtil.GetWindow("银期转账记录", tranRecControl, this._MainWindow);
                _TranRecWindow.Closing              += new CancelEventHandler(TranRecWindow_Closing);
                _TranRecWindow.ResizeMode            = ResizeMode.NoResize;
                _TranRecWindow.WindowStartupLocation = WindowStartupLocation.CenterScreen;
            }
            _TranRecWindow.Show();
        }
コード例 #19
0
 public bool Save()
 {
     try
     {
         UserCodeSetInstance.SaveStyleToFile();
         UserCodeSet userCodeSet   = cbUserCodeSet.SelectedItem as UserCodeSet;
         string      userCodeSetId = null;
         if (userCodeSet != null)
         {
             userCodeSetId = userCodeSet.Id;
         }
         TradeDataClient.GetClientInstance().getMainWindow().uscHangqing.ResetBlockButtons();
         //JYDataServer.getServerInstance().getMainWindow().userCodeSetBar.ResetUserCodeSetButtons(userCodeSetId);
         IsUpdated = true;
         return(true);
     }
     catch (Exception ex)
     {
         Util.Log(ex.ToString());
         return(false);
     }
 }
コード例 #20
0
        private void cb_Banks_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            _BankID = BankManager.GetBankIdFromName(cb_Banks.SelectedItem as string);
            if (string.IsNullOrEmpty(_BankID))
            {
                Util.Log("Warning! Invalid Bank ID.");
                return;
            }
            else
            {
                TradeDataClient.GetClientInstance().RequestTradeData(_UserAccount, BACKENDTYPE.CTP, new RequestContent("QryTransferSerial", new List <object>()
                {
                    _BankID
                }));
            }

            _BankBrchID = BankManager.GetBankBranchIdFromName(cb_Banks.SelectedItem as string);
            if (string.IsNullOrEmpty(_BankBrchID))
            {
                Util.Log("Warning! Invalid Bank ID.");
                return;
            }
        }
コード例 #21
0
        /// <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! ");
            }
        }
コード例 #22
0
        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
                        }));
                    }
                }
            }
        }
コード例 #23
0
        /// <summary>
        /// 买量
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Grid_MouseEnter_Close_Buy(object sender, MouseEventArgs e)
        {
            Grid grid = sender as Grid;

            if (grid == null)
            {
                return;
            }
            TextBlock       tp = grid.ToolTip as TextBlock;
            DisplayRealData displayRealData = grid.DataContext as DisplayRealData;
            //卖出平仓
            TradeDataClient jyDataServer = TradeDataClient.GetClientInstance();
            int             todayPosCount;
            int             lastPosCount;
            string          code = displayRealData.Code;

            //查找多头的单子
            if (jyDataServer.GetPositionCount(code, true, out todayPosCount, out lastPosCount) == false)
            {
                grid.ToolTip = null;
                return;
            }
            if (todayPosCount == 0 && lastPosCount == 0)
            {
                grid.ToolTip = null;
                return;
            }
            if (tp == null)
            {
                grid.ToolTip = new TextBlock();
                tp           = grid.ToolTip as TextBlock;
            }
            tp.Inlines.Clear();
            Run run = new Run();

            run.Text = "双击 ";
            tp.Inlines.Add(run);

            run = new Run();
            Binding binding1 = new Binding();

            binding1.Source = grid.DataContext;
            binding1.Mode   = BindingMode.OneWay;
            binding1.Path   = new PropertyPath("StBuyPrice");
            run.SetBinding(Run.TextProperty, binding1);
            tp.Inlines.Add(run);

            run            = new Run();
            run.Text       = " 卖出";
            run.Foreground = new SolidColorBrush(Color.FromRgb(0x13, 0xaf, 0x13));
            tp.Inlines.Add(run);

            Boolean bHasComma = false;

            if (CodeSetManager.IsCloseTodaySupport(code) && todayPosCount != 0)
            {
                //如果支持平今
                run            = new Run();
                run.Text       = "平今";
                run.FontSize   = 13;
                run.Foreground = new SolidColorBrush(Color.FromRgb(0xff, 0x00, 0xff));
                tp.Inlines.Add(run);

                run            = new Run();
                run.Text       = " " + todayPosCount.ToString() + " ";
                run.Foreground = new SolidColorBrush(Color.FromRgb(0x13, 0xaf, 0x13));
                tp.Inlines.Add(run);

                bHasComma = true;
            }
            else
            {
                lastPosCount += todayPosCount;
            }
            if (lastPosCount != 0)
            {
                if (bHasComma)
                {
                    run      = new Run();
                    run.Text = ",";
                    tp.Inlines.Add(run);
                }

                run            = new Run();
                run.Text       = " 平仓";
                run.FontSize   = 13;
                run.Foreground = new SolidColorBrush(Color.FromRgb(0xff, 0x00, 0xff));
                tp.Inlines.Add(run);

                run            = new Run();
                run.Text       = " " + lastPosCount.ToString() + " ";
                run.Foreground = new SolidColorBrush(Color.FromRgb(0x13, 0xaf, 0x13));
                tp.Inlines.Add(run);
            }

            run           = new Run();
            run.Text      = "手" + code;
            tp.FontWeight = FontWeights.Bold;
            tp.Inlines.Add(run);
        }
コード例 #24
0
 private void btnFresh_Click(object sender, RoutedEventArgs e)
 {
     //CtpDataServer.getServerInstance().InitDataFromAPI();
     TradeDataClient.GetClientInstance().RefreshSystemData();
 }
コード例 #25
0
        /// <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;
                    }
                }
            }
        }
コード例 #26
0
        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();
            }
        }