public override bool Equals(object obj)
            {
                if (obj == null)
                {
                    return(false);
                }

                ArbitrageAlarmArgumentViewModel model = obj as ArbitrageAlarmArgumentViewModel;

                if (model == null)
                {
                    return(false);
                }

                if (this.MonitorType == model.MonitorType &&
                    this.PriceSpreadSide == model.PriceSpreadSide &&
                    this.PriceSpreadThreshold == model.PriceSpreadThreshold)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
        /// <summary>
        /// 添加预警
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button_AddNotify_Click(object sender, EventArgs e)
        {
            ArbitragePriceSpreadAlarmType monitorType = this.arbitragePriceSpreadMonitorTypeControl.MonitorType;
            PriceSpreadSide priceSpreadSide           = this.priceSpreadSideControl_Alarm.PriceSpreadSide;
            decimal         threshold = this.nudPriceSpreadThreshold_Alarm.Value;

            ArbitrageAlarmArgument args = new ArbitrageAlarmArgument();

            args.MonitorType          = monitorType;
            args.PriceSpreadSide      = priceSpreadSide;
            args.PriceSpreadThreshold = threshold;

            ArbitrageAlarmArgumentViewModel model    = ArbitrageAlarmArgumentViewModel.CreatViewModel(args);
            ArbitrageAlarmArgumentViewModel hasModel = (from m in m_dataSourceAlarm
                                                        where m.Equals(model)
                                                        select m).FirstOrDefault();

            if (hasModel != null)
            {
                USeFuturesSpiritUtility.ShowWarningMessageBox(this, "不能添加重复的预警");
                return;
            }

            m_dataSourceAlarm.Add(ArbitrageAlarmArgumentViewModel.CreatViewModel(args));
        }
            public static ArbitrageAlarmArgument CreatAlarmData(ArbitrageAlarmArgumentViewModel model)
            {
                ArbitrageAlarmArgument args = new ArbitrageAlarmArgument();

                args.MonitorType          = model.MonitorType;
                args.PriceSpreadSide      = model.PriceSpreadSide;
                args.PriceSpreadThreshold = model.PriceSpreadThreshold;

                return(args);
            }
            public static ArbitrageAlarmArgumentViewModel CreatViewModel(ArbitrageAlarmArgument args)
            {
                ArbitrageAlarmArgumentViewModel model = new ArbitrageAlarmArgumentViewModel();

                model.MonitorType          = args.MonitorType;
                model.PriceSpreadSide      = args.PriceSpreadSide;
                model.PriceSpreadThreshold = args.PriceSpreadThreshold;

                return(model);
            }
        /// <summary>
        /// 初始化预警列表。
        /// </summary>
        private void InitializeAlarmList()
        {
            m_dataSourceAlarm = new BindingList <ArbitrageAlarmArgumentViewModel>();
            this.gridAlarmCondition.AutoGenerateColumns = false;
            this.gridAlarmCondition.DataSource          = m_dataSourceAlarm;

            if (m_arbitrageArgument != null && m_arbitrageArgument.AlarmArgs != null)
            {
                foreach (ArbitrageAlarmArgument alarmArg in m_arbitrageArgument.AlarmArgs)
                {
                    ArbitrageAlarmArgumentViewModel model = ArbitrageAlarmArgumentViewModel.CreatViewModel(alarmArg);
                }
            }
        }
        /// <summary>
        /// 设置前套利参数用于修改
        /// </summary>
        private void SetArbitrageArgument(ArbitrageArgument arg)
        {
            this.arbitrageOperationSideControl.OperationSide = arg.OperationSide;

            //开仓参数参数
            if (arg.OpenArg != null)
            {
                ArbitrageOpenArgument openArg = arg.OpenArg;

                this.preferentialSideControl_OpenArg.PreferentialSide     = openArg.PreferentialSide;
                this.orderPriceTypeControl_OpenNearArg.OrderPriceType     = openArg.NearOrderPriceType;
                this.orderPriceTypeControl_OpenFarArg.OrderPriceType      = openArg.FarOrderPriceType;
                this.priceSpreadSideControl_OpenSpreadArg.PriceSpreadSide = openArg.OpenCondition.PriceSpreadSide;
                this.nudPriceSpreadThreshold_OpenArg.Value = openArg.OpenCondition.PriceSpreadThreshold;
                this.nudDifferentialUnit_OpenArg.Value     = openArg.DifferentialUnit;
                this.nudOrderQtyUint_OpenArg.Value         = openArg.OrderQtyUint;
                this.nudTotalOrderQty_OpenArg.Value        = openArg.TotalOrderQty;
            }

            //平仓参数
            if (arg.CloseArg != null)
            {
                ArbitrageCloseArgument closeArg = arg.CloseArg;

                this.orderPriceTypeControl_CloseNearArg.OrderPriceType     = closeArg.NearOrderPriceType;
                this.orderPriceTypeControl_CloseFarArg.OrderPriceType      = closeArg.FarOrderPriceType;
                this.preferentialSideControl_CloseArg.PreferentialSide     = closeArg.PreferentialSide;
                this.priceSpreadSideControl_CloseSpreadArg.PriceSpreadSide = closeArg.CloseCondition.PriceSpreadSide;
                this.nudPriceSpreadThreshold_CloseArg.Value = closeArg.CloseCondition.PriceSpreadThreshold;
                this.nudDifferentialUnit_CloseArg.Value     = closeArg.DifferentialUnit;
                this.nudOrderQtyUint_CloseArg.Value         = closeArg.OrderQtyUint;
            }

            //止损参数
            if (arg.StopLossArg != null)
            {
                this.priceSpreadSideControl_StopLossArg.PriceSpreadSide = arg.StopLossArg.StopLossCondition.PriceSpreadSide;
                this.nudPriceSpreadThreshold_StopLossArg.Value          = arg.StopLossArg.StopLossCondition.PriceSpreadThreshold;
            }

            //预警参数
            if (arg.AlarmArgs != null)
            {
                foreach (ArbitrageAlarmArgument alarmArg in arg.AlarmArgs)
                {
                    m_dataSourceAlarm.Add(ArbitrageAlarmArgumentViewModel.CreatViewModel(alarmArg));
                }
            }
        }
        /// <summary>
        /// 移除预警
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button_CancelNotify_Click(object sender, EventArgs e)
        {
            DataGridViewSelectedRowCollection selectRows = this.gridAlarmCondition.SelectedRows;

            if (selectRows == null || selectRows.Count == 0)
            {
                USeFuturesSpiritUtility.ShowWarningMessageBox(this, "请选择要移除的预警");
                return;
            }
            ;

            foreach (DataGridViewRow row in selectRows)
            {
                ArbitrageAlarmArgumentViewModel model = row.DataBoundItem as ArbitrageAlarmArgumentViewModel;
                m_dataSourceAlarm.Remove(model);
            }
        }
        /// <summary>
        /// 创建组合套利单下单参数
        /// </summary>
        private bool CreateNewArbitrageOrder()
        {
            USeInstrument          nearInstrument = this.cbxNearInstrument.SelectedItem as USeInstrument;
            USeInstrument          farInstrument  = this.cbxFarInstrument.SelectedItem as USeInstrument;
            ArbitrageOperationSide operationSide  = this.arbitrageOperationSideControl.OperationSide;

            ArbitrageOpenArgument openArg = new ArbitrageOpenArgument();

            if (operationSide == ArbitrageOperationSide.BuyNearSellFar)
            {
                openArg.BuyInstrument  = nearInstrument;
                openArg.SellInstrument = farInstrument;
                openArg.BuyInstrumentOrderPriceType  = this.orderPriceTypeControl_OpenNearArg.OrderPriceType;
                openArg.SellInstrumentOrderPriceType = this.orderPriceTypeControl_OpenFarArg.OrderPriceType;
            }
            else if (operationSide == ArbitrageOperationSide.SellNearBuyFar)
            {
                openArg.BuyInstrument  = farInstrument;
                openArg.SellInstrument = nearInstrument;
                openArg.BuyInstrumentOrderPriceType  = this.orderPriceTypeControl_OpenFarArg.OrderPriceType;
                openArg.SellInstrumentOrderPriceType = this.orderPriceTypeControl_OpenNearArg.OrderPriceType;
            }
            else
            {
                Debug.Assert(false);
            }
            openArg.NearOrderPriceType = this.orderPriceTypeControl_OpenNearArg.OrderPriceType;
            openArg.FarOrderPriceType  = this.orderPriceTypeControl_OpenFarArg.OrderPriceType;

            openArg.PreferentialSide = this.preferentialSideControl_OpenArg.PreferentialSide;
            openArg.OpenCondition    = new PriceSpreadCondition()
            {
                PriceSpreadSide      = this.priceSpreadSideControl_OpenSpreadArg.PriceSpreadSide,
                PriceSpreadThreshold = this.nudPriceSpreadThreshold_OpenArg.Value
            };
            openArg.TotalOrderQty    = (int)this.nudTotalOrderQty_OpenArg.Value;
            openArg.OrderQtyUint     = (int)this.nudOrderQtyUint_OpenArg.Value;
            openArg.DifferentialUnit = (int)this.nudDifferentialUnit_OpenArg.Value;


            ArbitrageCloseArgument closeArg = new ArbitrageCloseArgument();

            if (operationSide == ArbitrageOperationSide.BuyNearSellFar)
            {
                closeArg.BuyInstrument  = farInstrument;
                closeArg.SellInstrument = nearInstrument;
                closeArg.BuyInstrumentOrderPriceType  = this.orderPriceTypeControl_CloseFarArg.OrderPriceType;
                closeArg.SellInstrumentOrderPriceType = this.orderPriceTypeControl_CloseNearArg.OrderPriceType;
            }
            else if (operationSide == ArbitrageOperationSide.SellNearBuyFar)
            {
                closeArg.BuyInstrument  = nearInstrument;
                closeArg.SellInstrument = farInstrument;
                closeArg.BuyInstrumentOrderPriceType  = this.orderPriceTypeControl_CloseNearArg.OrderPriceType;
                closeArg.SellInstrumentOrderPriceType = this.orderPriceTypeControl_CloseFarArg.OrderPriceType;
            }
            closeArg.NearOrderPriceType = this.orderPriceTypeControl_CloseNearArg.OrderPriceType;
            closeArg.FarOrderPriceType  = this.orderPriceTypeControl_CloseFarArg.OrderPriceType;

            closeArg.PreferentialSide = this.preferentialSideControl_CloseArg.PreferentialSide;
            closeArg.CloseCondition   = new PriceSpreadCondition()
            {
                PriceSpreadSide      = this.priceSpreadSideControl_CloseSpreadArg.PriceSpreadSide,
                PriceSpreadThreshold = this.nudPriceSpreadThreshold_CloseArg.Value
            };
            closeArg.OrderQtyUint     = (int)this.nudOrderQtyUint_CloseArg.Value;
            closeArg.DifferentialUnit = (int)this.nudDifferentialUnit_CloseArg.Value;

            ArbitrageStopLossArgument stopLossArg = null;

            if (this.cbxStopLossFlag.Checked)
            {
                stopLossArg = new ArbitrageStopLossArgument();
                stopLossArg.StopLossCondition = new PriceSpreadCondition()
                {
                    PriceSpreadSide      = this.priceSpreadSideControl_StopLossArg.PriceSpreadSide,
                    PriceSpreadThreshold = this.nudPriceSpreadThreshold_StopLossArg.Value
                };
            }


            List <ArbitrageAlarmArgument> alarmArgList = new List <ArbitrageAlarmArgument>();

            if (m_dataSourceAlarm != null && m_dataSourceAlarm.Count > 0)
            {
                foreach (ArbitrageAlarmArgumentViewModel alarmView in m_dataSourceAlarm)
                {
                    alarmArgList.Add(ArbitrageAlarmArgumentViewModel.CreatAlarmData(alarmView));
                }
            }

            ArbitrageArgument argument = new ArbitrageArgument();

            argument.ProductID      = m_product.ProductCode;
            argument.NearInstrument = nearInstrument;
            argument.FarInstrument  = farInstrument;
            argument.OperationSide  = operationSide;

            argument.OpenArg     = openArg;
            argument.CloseArg    = closeArg;
            argument.StopLossArg = stopLossArg;
            argument.AlarmArgs   = alarmArgList;

            string errorMessage = string.Empty;

            if (VerifyMargin(argument.OpenArg, out errorMessage) == false)
            {
                USeFuturesSpiritUtility.ShowWarningMessageBox(this, errorMessage);
                return(false);
            }

            decimal evaluateMargin = EvaluateMargin(argument.OpenArg);
            string  text           = string.Format("套利单预计占用保证金 {0},确定跟单么?", evaluateMargin.ToString("#,0"));

            if (DialogResult.Yes != USeFuturesSpiritUtility.ShowYesNoMessageBox(this, text))
            {
                return(false);
            }

            try
            {
                AutoTraderManager traderManager = USeManager.Instance.AutoTraderManager;
                Debug.Assert(traderManager != null);

                AutoTrader trader = traderManager.CreateNewAutoTrader(argument, USeManager.Instance.LoginUser);
                trader.BeginOpen();
                //[yangming]创建后应该启动跟单
                trader.StartOpenOrCloseMonitor();

                USeManager.Instance.DataSaver.AddSaveTask(trader.GetArbitrageOrder());

                //同时保存所有的ArbitrageArgument便于下次修改
            }
            catch (Exception ex)
            {
                USeFuturesSpiritUtility.ShowWarningMessageBox(this, ex.Message);
                return(false);
            }

            return(true);
        }