コード例 #1
0
        /// <summary>
        /// 修改-下单参数
        /// </summary>
        /// <param name="argument"></param>
        public ArbitrageOrderCreateForm(ArbitrageArgument argument, USeProduct product)
        {
            InitializeComponent();

            m_product           = product;
            m_arbitrageArgument = argument;
        }
コード例 #2
0
        /// <summary>
        /// 更新套利单信息。
        /// </summary>
        private void ShowArbitrageOrderView()
        {
            if (m_arbitrageOrder == null)
            {
                ClearView();
                return;
            }

            ArbitrageArgument argument = m_arbitrageOrder.Argument;

            if (argument != null && argument.OpenArg != null)
            {
                this.lblOpenPriceSpread.Text = argument.OpenArg.OpenCondition.ToString();
            }
            else
            {
                this.lblOpenPriceSpread.Text = "----";
            }
            if (argument != null && argument.CloseArg != null)
            {
                this.lblClosePriceSpread.Text = argument.CloseArg.CloseCondition.ToString();
            }
            else
            {
                this.lblClosePriceSpread.Text = "----";
            }
            if (argument != null && argument.StopLossArg != null)
            {
                this.lblStopLossPriceSpread.Text = argument.StopLossArg.StopLossCondition.ToString();
            }
            else
            {
                this.lblStopLossPriceSpread.Text = "----";
            }


            switch (m_arbitrageOrder.State)
            {
            case ArbitrageOrderState.None:
            case ArbitrageOrderState.Opening:
            case ArbitrageOrderState.Opened:
                ShowOpenInfo(m_arbitrageOrder);
                break;

            case ArbitrageOrderState.Closeing:
            case ArbitrageOrderState.Closed:
            case ArbitrageOrderState.Finish:
                ShowCloseInfo(m_arbitrageOrder);
                break;

            default:
                Debug.Assert(false);
                break;
            }

            this.lblArbitrageOrderState.Text = m_arbitrageOrder.State.ToDescription();
        }
コード例 #3
0
        private void SetArbitrageArgument()
        {
            ArbitrageArgument argument = m_autoTrader.GetArgument();

            Debug.Assert(argument != null);

            USeProduct product = USeManager.Instance.OrderDriver.QueryProduct(argument.ProductID);

            Debug.Assert(product != null);

            ArbitrageOrderCreateForm form = new ArbitrageOrderCreateForm(argument, product);

            form.ShowDialog();
        }
コード例 #4
0
        /// <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));
                }
            }
        }
コード例 #5
0
        /// <summary>
        /// 创建新的套利订单。
        /// </summary>
        /// <param name="argument">套利单参数。</param>
        /// <param name="currentInvestor">当前投资者帐号。</param>
        public AutoTrader CreateNewAutoTrader(ArbitrageArgument argument, InvestorAccount currentInvestor)
        {
            Guid traderIdentify = CreateNewAutoTraderIdentify();
            int  aliasNum       = CreateNewAutoTraderAliasNum();

            USeArbitrageOrder arbitrageOrder = new USeArbitrageOrder();

            arbitrageOrder.TraderIdentify = traderIdentify;
            arbitrageOrder.AliasNum       = aliasNum;
            arbitrageOrder.State          = ArbitrageOrderState.None;
            arbitrageOrder.BrokerId       = currentInvestor.BrokerId;
            arbitrageOrder.Account        = currentInvestor.Account;
            arbitrageOrder.Argument       = argument.Clone();
            arbitrageOrder.CreateTime     = DateTime.Now;

            TaskOrderSetting taskOrderSetting = m_systemConfigManager.GetTaskOrderSetting();
            //任务组待开仓或者平仓时在创建
            AutoTrader trader = new AutoTrader();

            trader.SetRecordLogger(USeManager.Instance.CommandLogger);
            trader.SetTryOrderCondition(taskOrderSetting.TaskMaxTryCount, taskOrderSetting.TryOrderMinInterval);
            trader.Initialize(arbitrageOrder, m_orderDriver, m_quoteDriver, m_alarmManager);

            trader.OnNotify += AutoTrader_OnNotify;
            trader.OnAlarm  += AutoTrader_OnAlarm;
            trader.OnArbitrageOrderChanged += AutoTrader_OnArbitrageOrderChanged;
            trader.OnStateChanged          += AutoTrader_OnStateChanged;

            lock (m_syncObj)
            {
                m_autoTraderDic.Add(traderIdentify, trader);
            }

            SafeFireAddAutoTrader(traderIdentify);
            string           text   = "创建套利单成功";
            AutoTraderNotice notice = new AutoTraderNotice(trader.TraderIdentify, trader.Alias, AutoTraderNoticeType.Infomation, text);

            SafeFireAutoTraderNotice(notice);
            trader.WriteTraderNoticeLog(notice);

            return(trader);
        }
コード例 #6
0
ファイル: AutoTrader.cs プロジェクト: handayu/TFS-WebKit
        /// <summary>
        /// 设定平仓参数。
        /// </summary>
        /// <param name="closeArg">平仓参数。</param>
        public void ModifyArbitrageArgument(ArbitrageArgument argument)
        {
            CheckBackgroundWorker("修改套利单参数");

            lock (m_syncObj)
            {
                if (m_arbitrageOrder.State >= ArbitrageOrderState.Closeing)
                {
                    throw new Exception(string.Format("{0}为{1}状态,不能修改套利单参数", this, this.ArbitrageOrderState.ToDescription()));
                }
                string errorMessage = string.Empty;
                if (VerfiyArbitrageArgument(argument, out errorMessage) == false)
                {
                    string text = string.Format("{0}修改套利单参数失败,{1}", this, errorMessage);
                    throw new ArgumentException(text);
                }

                //[yangming]更新能修改的参数
                m_arbitrageOrder.Argument = argument.Clone();
                //m_arbitrageOrder.CloseArgument = closeArg.Clone();
            }
        }
コード例 #7
0
        /// <summary>
        /// 校验平仓运行参数。
        /// </summary>
        /// <param name="errorMessage">错误信息。</param>
        /// <returns></returns>
        private bool VerfiyArbitrageArgument(ArbitrageArgument argument, out string errorMessage)
        {
            //[yangming]待补充
            Debug.Assert(argument != null);
            errorMessage = string.Empty;
            //if (argument.BuyInstrument == null)
            //{
            //    errorMessage = "买入合约不能为空";
            //    return false;
            //}
            //if (argument.SellInstrument == null)
            //{
            //    errorMessage = "卖出合约不能为空";
            //    return false;
            //}

            //if (argument.OrderQtyUint <= 0)
            //{
            //    errorMessage = "下单单位不能为空";
            //    return false;
            //}
            return(true);
        }
コード例 #8
0
        /// <summary>
        /// 创建平仓任务组。
        /// </summary>
        /// <param name="openTaskGroup">开仓任务组。</param>
        /// <param name="closeArg">平仓参数。</param>
        /// <returns></returns>
        private ArbitrageTaskGroup CreateCloseTaskGroup(ArbitrageTaskGroup openTaskGroup, ArbitrageArgument argument)
        {
            ArbitrageCloseArgument closeArg = argument.CloseArg;

            Debug.Assert(openTaskGroup.BuyInstrument == closeArg.SellInstrument);
            Debug.Assert(openTaskGroup.SellInstrument == closeArg.BuyInstrument);

            int buyPosition  = openTaskGroup.SellSubTaskTradeQty; // 平仓买入量 = 开仓卖出量
            int sellPosition = openTaskGroup.BuySubTaskTradeQty;  // 平仓卖出量 = 开仓买入量

            USeInstrument           firstInstrument      = null;
            USeInstrument           secondInstrument     = null;
            USeOrderSide            firstOrderSide       = USeOrderSide.Buy;
            USeOrderSide            secondOrderSide      = USeOrderSide.Sell;
            ArbitrageOrderPriceType firstOrderPriceType  = ArbitrageOrderPriceType.Unknown;
            ArbitrageOrderPriceType secondOrderPriceType = ArbitrageOrderPriceType.Unknown;
            int firstPosition  = 0;
            int secondPosition = 0;

            if (closeArg.PreferentialSide == USeOrderSide.Buy)
            {
                //优先买入
                firstInstrument      = closeArg.BuyInstrument;
                firstOrderSide       = USeOrderSide.Buy;
                firstOrderPriceType  = closeArg.BuyInstrumentOrderPriceType;
                secondInstrument     = closeArg.SellInstrument;
                secondOrderSide      = USeOrderSide.Sell;
                secondOrderPriceType = closeArg.SellInstrumentOrderPriceType;
                firstPosition        = buyPosition;
                secondPosition       = sellPosition;
            }
            else if (closeArg.PreferentialSide == USeOrderSide.Sell)
            {
                //优先卖出
                firstInstrument      = closeArg.SellInstrument;
                firstOrderSide       = USeOrderSide.Sell;
                firstOrderPriceType  = closeArg.SellInstrumentOrderPriceType;
                secondInstrument     = closeArg.BuyInstrument;
                secondOrderSide      = USeOrderSide.Buy;
                secondOrderPriceType = closeArg.BuyInstrumentOrderPriceType;
                firstPosition        = sellPosition;
                secondPosition       = buyPosition;
            }
            else
            {
                Debug.Assert(false);
            }


            Debug.Assert(closeArg.OrderQtyUint > 0);

            int maxPositon = Math.Max(buyPosition, sellPosition);
            int taskCount  = maxPositon / closeArg.OrderQtyUint;

            if ((maxPositon % closeArg.OrderQtyUint) > 0)
            {
                taskCount += 1;
            }

            #region 构造任务组
            ArbitrageTaskGroup taskGroup = new ArbitrageTaskGroup();
            taskGroup.OpenCloseType  = OpenCloseType.Close;
            taskGroup.BuyInstrument  = closeArg.BuyInstrument;
            taskGroup.SellInstrument = closeArg.SellInstrument;
            taskGroup.BuyInstrumentOrderPriceType  = closeArg.BuyInstrumentOrderPriceType;
            taskGroup.SellInstrumentOrderPriceType = closeArg.SellInstrumentOrderPriceType;

            taskGroup.OperationSide    = argument.OperationSide.GetOppositeSide();
            taskGroup.PreferentialSide = closeArg.PreferentialSide;

            List <ArbitrageTask> taskList = new List <ArbitrageTask>();
            int remainFirstPlanQty        = firstPosition;
            int remainSecondPlanQty       = secondPosition;
            for (int i = 1; i <= taskCount; i++)
            {
                int firstPlanOrderQty = Math.Min(closeArg.OrderQtyUint, remainFirstPlanQty);
                remainFirstPlanQty -= firstPlanOrderQty;
                int secondPlanOrderQty = Math.Min(closeArg.OrderQtyUint, remainSecondPlanQty);
                remainSecondPlanQty -= secondPlanOrderQty;

                ArbitrageTask task = new ArbitrageTask();
                task.TaskId    = i;
                task.TaskState = ArbitrageTaskState.None;
                ArbitrageSubTask firstSubTask = new ArbitrageSubTask()
                {
                    Instrument     = firstInstrument,
                    OrderPriceType = firstOrderPriceType,
                    OrderSide      = firstOrderSide,
                    PlanOrderQty   = firstPlanOrderQty,
                    OffsetType     = USeOffsetType.Close,
                };
                ArbitrageSubTask secondSubTask = new ArbitrageSubTask()
                {
                    Instrument     = secondInstrument,
                    OrderPriceType = secondOrderPriceType,
                    OrderSide      = secondOrderSide,
                    PlanOrderQty   = secondPlanOrderQty,
                    OffsetType     = USeOffsetType.Close
                };

                task.FirstSubTask  = firstSubTask;
                task.SecondSubTask = secondSubTask;

                taskList.Add(task);
            }
            Debug.Assert(remainFirstPlanQty == 0);
            Debug.Assert(remainSecondPlanQty == 0);
            taskGroup.TaskList = taskList;
            #endregion

            return(taskGroup);
        }
コード例 #9
0
        /// <summary>
        /// 创建开仓任务组。
        /// </summary>
        /// <param name="openArg">开仓参数。</param>
        /// <returns></returns>
        private static ArbitrageTaskGroup CreateOpenTaskGroup(ArbitrageArgument argument)
        {
            ArbitrageOpenArgument openArg = argument.OpenArg;

            USeInstrument           firstInstrument      = null;
            USeInstrument           secondInstrument     = null;
            USeOrderSide            firstOrderSide       = USeOrderSide.Buy;
            USeOrderSide            secondOrderSide      = USeOrderSide.Sell;
            ArbitrageOrderPriceType firstOrderPriceType  = ArbitrageOrderPriceType.Unknown;
            ArbitrageOrderPriceType secondOrderPriceType = ArbitrageOrderPriceType.Unknown;

            if (openArg.PreferentialSide == USeOrderSide.Buy)
            {
                //优先买入
                firstInstrument     = openArg.BuyInstrument;
                firstOrderSide      = USeOrderSide.Buy;
                firstOrderPriceType = openArg.BuyInstrumentOrderPriceType;

                secondInstrument     = openArg.SellInstrument;
                secondOrderSide      = USeOrderSide.Sell;
                secondOrderPriceType = openArg.SellInstrumentOrderPriceType;
            }
            else if (openArg.PreferentialSide == USeOrderSide.Sell)
            {
                //优先卖出
                firstInstrument     = openArg.SellInstrument;
                firstOrderSide      = USeOrderSide.Sell;
                firstOrderPriceType = openArg.SellInstrumentOrderPriceType;

                secondInstrument     = openArg.BuyInstrument;
                secondOrderSide      = USeOrderSide.Buy;
                secondOrderPriceType = openArg.BuyInstrumentOrderPriceType;
            }
            else
            {
                Debug.Assert(false);
            }

            Debug.Assert(openArg.OrderQtyUint > 0);
            int taskCount = openArg.TotalOrderQty / openArg.OrderQtyUint;

            if ((openArg.TotalOrderQty % openArg.OrderQtyUint) > 0)
            {
                taskCount += 1;
            }

            #region 构造任务组
            ArbitrageTaskGroup taskGroup = new ArbitrageTaskGroup();
            taskGroup.OpenCloseType  = OpenCloseType.Open;
            taskGroup.BuyInstrument  = openArg.BuyInstrument;
            taskGroup.SellInstrument = openArg.SellInstrument;
            taskGroup.BuyInstrumentOrderPriceType  = openArg.BuyInstrumentOrderPriceType;
            taskGroup.SellInstrumentOrderPriceType = openArg.SellInstrumentOrderPriceType;

            taskGroup.OperationSide    = argument.OperationSide;
            taskGroup.PreferentialSide = openArg.PreferentialSide;

            List <ArbitrageTask> taskList = new List <ArbitrageTask>();
            int remainPlanQty             = openArg.TotalOrderQty;
            for (int i = 1; i <= taskCount; i++)
            {
                int planOrderQty = Math.Min(openArg.OrderQtyUint, remainPlanQty);
                Debug.Assert(planOrderQty > 0 && planOrderQty <= openArg.OrderQtyUint);
                remainPlanQty -= planOrderQty;

                ArbitrageTask task = new ArbitrageTask();
                task.TaskId    = i;
                task.TaskState = ArbitrageTaskState.None;
                ArbitrageSubTask firstSubTask = new ArbitrageSubTask()
                {
                    Instrument     = firstInstrument,
                    OrderPriceType = firstOrderPriceType,
                    OrderSide      = firstOrderSide,
                    PlanOrderQty   = planOrderQty,
                    OffsetType     = USeOffsetType.Open,
                };
                ArbitrageSubTask secondSubTask = new ArbitrageSubTask()
                {
                    Instrument     = secondInstrument,
                    OrderPriceType = secondOrderPriceType,
                    OrderSide      = secondOrderSide,
                    PlanOrderQty   = planOrderQty,
                    OffsetType     = USeOffsetType.Open
                };

                task.FirstSubTask  = firstSubTask;
                task.SecondSubTask = secondSubTask;

                taskList.Add(task);
            }
            Debug.Assert(remainPlanQty == 0);
            taskGroup.TaskList = taskList;
            #endregion

            return(taskGroup);
        }
コード例 #10
0
        /// <summary>
        /// 检查是否满足任务组监控价差条件。
        /// </summary>
        /// <param name="taskGroup">任务组。</param>
        /// <returns></returns>
        private PriceSpreadCheckResult CheckPriceSpread(OpenCloseType openCloseType, ArbitrageArgument argument)
        {
            USeMarketData nearMarketData = m_quoteDriver.Query(argument.NearInstrument);
            USeMarketData farMarketData  = m_quoteDriver.Query(argument.FarInstrument);

            decimal nearPrice = 0m;
            decimal farPrice  = 0m;

            if (openCloseType == OpenCloseType.Open)
            {
                nearPrice = GetMarketPrice(nearMarketData, argument.OpenArg.NearOrderPriceType);
                farPrice  = GetMarketPrice(farMarketData, argument.OpenArg.FarOrderPriceType);
            }
            else if (openCloseType == OpenCloseType.Close)
            {
                nearPrice = GetMarketPrice(nearMarketData, argument.CloseArg.NearOrderPriceType);
                farPrice  = GetMarketPrice(farMarketData, argument.CloseArg.FarOrderPriceType);
            }
            else
            {
                Debug.Assert(false);
                return(PriceSpreadCheckResult.CreateNoOrderResult());
            }

            if (nearPrice <= 0 || farPrice <= 0)
            {
                return(PriceSpreadCheckResult.CreateNoOrderResult());
            }

            decimal priceSpread = nearPrice - farPrice;

            if (openCloseType == OpenCloseType.Open)
            {
                Debug.Assert(argument.OpenArg != null && argument.OpenArg.OpenCondition != null);
                if (IsInPriceSpread(argument.OpenArg.OpenCondition, priceSpread))
                {
                    PriceSpreadCheckResult result = new PriceSpreadCheckResult();
                    result.OrderReason          = TaskOrderReason.Open;
                    result.PriceSpreadThreshold = argument.OpenArg.OpenCondition.PriceSpreadThreshold;
                    return(result);
                }
            }
            else if (openCloseType == OpenCloseType.Close)
            {
                Debug.Assert(argument.CloseArg != null && argument.CloseArg.CloseCondition != null);
                if (argument.CloseArg != null && argument.CloseArg.CloseCondition != null)
                {
                    if (IsInPriceSpread(argument.CloseArg.CloseCondition, priceSpread))
                    {
                        PriceSpreadCheckResult result = new PriceSpreadCheckResult();
                        result.OrderReason          = TaskOrderReason.Close;
                        result.PriceSpreadThreshold = argument.CloseArg.CloseCondition.PriceSpreadThreshold;
                        return(result);
                    }
                }

                if (argument.StopLossArg != null && argument.StopLossArg.StopLossCondition != null)
                {
                    if (IsInPriceSpread(argument.StopLossArg.StopLossCondition, priceSpread))
                    {
                        PriceSpreadCheckResult result = new PriceSpreadCheckResult();
                        result.OrderReason          = TaskOrderReason.StopLoss;
                        result.PriceSpreadThreshold = argument.StopLossArg.StopLossCondition.PriceSpreadThreshold;
                        return(result);
                    }
                }
            }

            return(PriceSpreadCheckResult.CreateNoOrderResult());
        }
コード例 #11
0
        /// <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);
        }