Example #1
0
 /// <summary>
 /// 创建自动下单机管理类。
 /// </summary>
 private void CreateAutoTraderManager()
 {
     try
     {
         AutoTraderManager traderManager = new AutoTraderManager();
         m_autoTraderManager = traderManager;
         m_autoTraderManager.OnArbitrageOrderChanged += M_autoTraderManager_OnArbitrageOrderChanged;
         string text = String.Format("{0} Create {1} OK.", this, traderManager);
         m_eventLogger.WriteInformation(text);
     }
     catch (Exception ex)
     {
         string text = "Create AutoTraderManager object failed, " + ex.Message;
         throw new ApplicationException(text, ex);
     }
 }
Example #2
0
        /// <summary>
        /// 初始化。
        /// </summary>
        public override void Initialize()
        {
            this.panelOrderContainer.Controls.Clear();

            AutoTraderManager traderManager = USeManager.Instance.AutoTraderManager;

            traderManager.OnAddAutoTrader    += TraderManager_OnAddAutoTrader;
            traderManager.OnRemoveAutoTrader += TraderManager_OnRemoveAutoTrader;
            List <AutoTrader> autoTraderList = traderManager.GetAllAutoTrader();

            if (autoTraderList != null && autoTraderList.Count > 0)
            {
                foreach (AutoTrader autoTrader in autoTraderList)
                {
                    AddArbitrageOrderControl(autoTrader);
                }
            }
        }
        /// <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);
        }