private void btnOK_Click(object sender, EventArgs e) { MessageBox.Show("开仓参数不允许修改"); return; string errorMessage = string.Empty; ArbitrageOpenArgument openArg = this.arbitrageOrderOpenArgumentViewControl1.GetOpenArgument(out errorMessage); if (openArg == null) { USeFuturesSpiritUtility.ShowWarningMessageBox(this, errorMessage); return; } try { m_autoTrader.SetOpenArgument(openArg); } catch (Exception ex) { MessageBox.Show(ex.Message); } this.DialogResult = DialogResult.Yes; this.Close(); }
/// <summary> /// 校验开仓运行参数。 /// </summary> /// <param name="errorMessage">错误信息。</param> /// <returns></returns> private bool VerfiyOpenArgument(ArbitrageOpenArgument argument, out string errorMessage) { Debug.Assert(argument != null); errorMessage = string.Empty; if (argument.BuyInstrument == null) { errorMessage = "买入合约不能为空"; return(false); } if (argument.SellInstrument == null) { errorMessage = "卖出合约不能为空"; return(false); } if (argument.TotalOrderQty <= 0) { errorMessage = "下单口数不能为空"; return(false); } if (argument.OrderQtyUint <= 0) { errorMessage = "下单单位不能为空"; return(false); } return(true); }
/// <summary> /// 评估创建套利单需要保证金。 /// </summary> /// <param name="openArg"></param> /// <returns></returns> public decimal EvaluateMargin(ArbitrageOpenArgument openArg) { USeOrderDriver orderDriver = USeManager.Instance.OrderDriver; USeQuoteDriver quoteDriver = USeManager.Instance.QuoteDriver; USeInstrumentDetail buyInstrumentDetail = orderDriver.QueryInstrumentDetail(openArg.BuyInstrument); USeInstrumentDetail sellInstrumentDetail = orderDriver.QueryInstrumentDetail(openArg.SellInstrument); USeMarketData buyMarketData = quoteDriver.Query(openArg.BuyInstrument); USeMarketData sellMarketData = quoteDriver.Query(openArg.SellInstrument); USeMargin buyMarginRate = orderDriver.QueryInstrumentMargin(openArg.BuyInstrument); USeMargin sellMarginRate = orderDriver.QueryInstrumentMargin(openArg.SellInstrument); decimal buyMargin = (openArg.TotalOrderQty * buyMarginRate.BrokerLongMarginRatioByVolume) + (buyMarketData.LastPrice * openArg.TotalOrderQty * buyInstrumentDetail.VolumeMultiple * buyMarginRate.BrokerLongMarginRatioByMoney); decimal sellMargin = (openArg.TotalOrderQty * sellMarginRate.BrokerShortMarginRatioByVolume) + (sellMarketData.LastPrice * openArg.TotalOrderQty * sellInstrumentDetail.VolumeMultiple * sellMarginRate.BrokerShortMarginRatioByMoney); if (openArg.BuyInstrument.Market == USeMarket.SHFE && openArg.SellInstrument.Market == USeMarket.SHFE) { return(Math.Max(buyMargin, sellMargin)); } else { return(buyMargin + sellMargin); } }
public void SetOpenArgument(ArbitrageOpenArgument openArg) { if (openArg == null) { ClearView(); return; } this.lblBuyInstrument.Text = openArg.BuyInstrument.InstrumentCode; this.lblSellInstrument.Text = openArg.SellInstrument.InstrumentCode; this.lblBuyOrderPriceType.Text = openArg.BuyInstrumentOrderPriceType.ToDescription(); this.lblSellOrderPriceType.Text = openArg.SellInstrumentOrderPriceType.ToDescription(); switch (openArg.PreferentialSide) { case USeOrderSide.Buy: this.lblPreferentialSide_Buy.Text = "优先买入"; this.lblPreferentialSide_Buy.Font = new System.Drawing.Font("Microsoft Sans Serif", 7.8F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134))); this.lblPreferentialSide_Buy.ForeColor = Color.Red; this.lblPreferentialSide_Sell.Text = "卖出"; this.lblPreferentialSide_Sell.Font = new System.Drawing.Font("Microsoft Sans Serif", 7.8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); this.lblPreferentialSide_Sell.ForeColor = SystemColors.ControlText; break; case USeOrderSide.Sell: this.lblPreferentialSide_Buy.Text = "买入"; this.lblPreferentialSide_Buy.Font = new System.Drawing.Font("Microsoft Sans Serif", 7.8F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134))); this.lblPreferentialSide_Buy.ForeColor = Color.Red; this.lblPreferentialSide_Sell.Text = "优先卖出"; this.lblPreferentialSide_Sell.Font = this.lblPreferentialSide_Sell.Font = new System.Drawing.Font("Microsoft Sans Serif", 7.8F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134))); this.lblPreferentialSide_Sell.ForeColor = SystemColors.ControlText; break; } switch (openArg.OpenCondition.PriceSpreadSide) { case PriceSpreadSide.GreaterOrEqual: this.lblPriceSpreadSide.Text = "大于等于"; this.lblPriceSpreadSide.ForeColor = Color.Red; break; case PriceSpreadSide.LessOrEqual: this.lblPriceSpreadSide.Text = "小于等于"; this.lblPriceSpreadSide.ForeColor = Color.Blue; break; } this.lblPriceSpreadThreshold.Text = openArg.OpenCondition.PriceSpreadThreshold.ToString(); this.lblTotalOrderQty.Text = openArg.TotalOrderQty.ToString(); this.lblOrderQtyUint.Text = openArg.OrderQtyUint.ToString(); this.lblDifferentialUnit.Text = openArg.DifferentialUnit.ToString(); }
/// <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)); } } }
private static ArbitrageOpenArgument CreateOpenArg() { //ArbiOrder开仓仓参数 ArbitrageOpenArgument arg = new ArbitrageOpenArgument(); arg.BuyInstrument = new USeInstrument("CF1701", "CF1701", USeMarket.CFFEX); arg.SellInstrument = new USeInstrument("CF1701", "CF1701", USeMarket.CFFEX); arg.BuyInstrumentOrderPriceType = ArbitrageOrderPriceType.OpponentPrice; arg.SellInstrumentOrderPriceType = ArbitrageOrderPriceType.LastPrice; arg.PreferentialSide = USeOrderSide.Buy; arg.OpenCondition = new PriceSpreadCondition() { PriceSpreadSide = PriceSpreadSide.LessOrEqual, PriceSpreadThreshold = 200 }; arg.TotalOrderQty = 100; arg.OrderQtyUint = 10; arg.DifferentialUnit = 3; return(arg); }
/// <summary> /// 校验保证金。 /// </summary> /// <param name="errorMessage"></param> /// <returns></returns> private bool VerifyMargin(ArbitrageOpenArgument openArg, out string errorMessage) { errorMessage = string.Empty; USeOrderDriver orderDriver = USeManager.Instance.OrderDriver; try { OrderMarginSetting marginSetting = USeManager.Instance.SystemConfigManager.GetOrderMarginSetting(); USeFundDetail fundDetail = orderDriver.QueryFundDetailInfo(); if (fundDetail == null) { errorMessage = "查询资金信息失败"; return(false); } decimal evaluateMargin = EvaluateMargin(openArg); // 评估当前开仓参数可能占用保证金 decimal investorMaxUse = fundDetail.DynamicBenefit * marginSetting.MaxUseRate; // 账户最大占用保证金 decimal usedMargin = USeManager.Instance.AutoTraderManager.CalculatUseMargin(); // 当前套利单占用保证金 if (investorMaxUse < usedMargin + evaluateMargin) { errorMessage = string.Format("套利单预计占用{0}保证金,当前账户占用保证金超出设定预警阀值", evaluateMargin.ToString("#,0")); return(false); } if (fundDetail.Available < evaluateMargin) { errorMessage = string.Format("套利单预计占用{0}保证金,当前账户可用余额不足", evaluateMargin.ToString("#,0")); return(false); } return(true); } catch (Exception ex) { Debug.Assert(false, ex.Message); errorMessage = "校验保证金失败"; return(false); } }
/// <summary> /// 计算当前套利单占用的保证金。 /// </summary> /// <returns></returns> public decimal CalculatUseMargin() { ArbitrageOpenArgument openArg = null; lock (m_syncObj) { if (m_arbitrageOrder.State == ArbitrageOrderState.Finish || m_arbitrageOrder.State == ArbitrageOrderState.Closed) { //平仓完成套利单不占用保证金 return(0m); } openArg = m_arbitrageOrder.OpenArgument.Clone(); } USeOrderDriver orderDriver = USeManager.Instance.OrderDriver; USeQuoteDriver quoteDriver = USeManager.Instance.QuoteDriver; USeInstrumentDetail buyInstrumentDetail = orderDriver.QueryInstrumentDetail(openArg.BuyInstrument); USeInstrumentDetail sellInstrumentDetail = orderDriver.QueryInstrumentDetail(openArg.SellInstrument); USeMarketData buyMarketData = quoteDriver.Query(openArg.BuyInstrument); USeMarketData sellMarketData = quoteDriver.Query(openArg.SellInstrument); USeMargin buyMarginRate = orderDriver.QueryInstrumentMargin(openArg.BuyInstrument); USeMargin sellMarginRate = orderDriver.QueryInstrumentMargin(openArg.SellInstrument); decimal buyMargin = (openArg.TotalOrderQty * buyMarginRate.BrokerLongMarginRatioByVolume) + (buyMarketData.LastPrice * openArg.TotalOrderQty * buyInstrumentDetail.VolumeMultiple * buyMarginRate.BrokerLongMarginRatioByMoney); decimal sellMargin = (openArg.TotalOrderQty * sellMarginRate.BrokerShortMarginRatioByVolume) + (sellMarketData.LastPrice * openArg.TotalOrderQty * sellInstrumentDetail.VolumeMultiple * sellMarginRate.BrokerShortMarginRatioByMoney); if (openArg.BuyInstrument.Market == USeMarket.SHFE && openArg.SellInstrument.Market == USeMarket.SHFE) { return(Math.Max(buyMargin, sellMargin)); } else { return(buyMargin + sellMargin); } }
public void SetOpenArgument(ArbitrageOpenArgument openArg) { InitializeInstument(string.Empty); if (openArg == null) { return; } for (int i = 0; i < this.cbxBuyInstrument.Items.Count; i++) { if ((this.cbxBuyInstrument.Items[i] as USeInstrument).InstrumentCode == openArg.BuyInstrument.InstrumentCode) { this.cbxBuyInstrument.SelectedIndex = i; break; } } for (int i = 0; i < this.cbxSellInstrument.Items.Count; i++) { if ((this.cbxSellInstrument.Items[i] as USeInstrument).InstrumentCode == openArg.SellInstrument.InstrumentCode) { this.cbxSellInstrument.SelectedIndex = i; break; } } switch (openArg.BuyInstrumentOrderPriceType) { case ArbitrageOrderPriceType.LastPrice: this.rbnBuyOrderPriceType_LastPrice.Checked = true; break; case ArbitrageOrderPriceType.OpponentPrice: this.rbnBuyOrderPriceType_OpponentPrice.Checked = true; break; case ArbitrageOrderPriceType.QueuePrice: this.rbnBuyOrderPriceType_QueuePrice.Checked = true; break; } switch (openArg.SellInstrumentOrderPriceType) { case ArbitrageOrderPriceType.LastPrice: this.rbnSellOrderPriceType_LastPrice.Checked = true; break; case ArbitrageOrderPriceType.OpponentPrice: this.rbnSellOrderPriceType_OpponentPrice.Checked = true; break; case ArbitrageOrderPriceType.QueuePrice: this.rbnSellOrderPriceType_QueuePrice.Checked = true; break; } switch (openArg.PreferentialSide) { case USeOrderSide.Buy: this.rbnPreferentialSide_Buy.Checked = true; break; case USeOrderSide.Sell: this.rbnPreferentialSide_Sell.Checked = true; break; } switch (openArg.OpenCondition.PriceSpreadSide) { case PriceSpreadSide.GreaterOrEqual: this.rbnPriceSpreadSide_Greater.Checked = true; break; case PriceSpreadSide.LessOrEqual: this.rbnPriceSpreadSide_Less.Checked = true; break; } this.nudPriceSpreadThreshold.Value = openArg.OpenCondition.PriceSpreadThreshold; this.nudTotalOrderQty.Value = openArg.TotalOrderQty; this.nudOrderQtyUint.Value = openArg.OrderQtyUint; this.nudDifferentialUnit.Value = openArg.DifferentialUnit; }
public ArbitrageOpenArgument GetOpenArgument(out string errorMessage) { if (VerifyOpenArgument(out errorMessage) == false) { return(null); } USeInstrument buyInstrument = this.cbxBuyInstrument.SelectedItem as USeInstrument; USeInstrument sellInstrument = this.cbxSellInstrument.SelectedItem as USeInstrument; ArbitrageOrderPriceType buyOrderPriceType = ArbitrageOrderPriceType.Unknown; if (this.rbnBuyOrderPriceType_LastPrice.Checked) { buyOrderPriceType = ArbitrageOrderPriceType.LastPrice; } else if (this.rbnBuyOrderPriceType_OpponentPrice.Checked) { buyOrderPriceType = ArbitrageOrderPriceType.OpponentPrice; } else if (this.rbnBuyOrderPriceType_QueuePrice.Checked) { buyOrderPriceType = ArbitrageOrderPriceType.QueuePrice; } else { Debug.Assert(false); } ArbitrageOrderPriceType sellOrderPriceType = ArbitrageOrderPriceType.Unknown; if (this.rbnSellOrderPriceType_LastPrice.Checked) { sellOrderPriceType = ArbitrageOrderPriceType.LastPrice; } else if (this.rbnSellOrderPriceType_OpponentPrice.Checked) { sellOrderPriceType = ArbitrageOrderPriceType.OpponentPrice; } else if (this.rbnSellOrderPriceType_QueuePrice.Checked) { sellOrderPriceType = ArbitrageOrderPriceType.QueuePrice; } else { Debug.Assert(false); } USeOrderSide preferentialSide = USeOrderSide.Buy; if (this.rbnPreferentialSide_Buy.Checked) { preferentialSide = USeOrderSide.Buy; } else if (this.rbnPreferentialSide_Sell.Checked) { preferentialSide = USeOrderSide.Sell; } else { Debug.Assert(false); } PriceSpreadSide priceSpreadSide = PriceSpreadSide.Unknown; if (this.rbnPriceSpreadSide_Greater.Checked) { priceSpreadSide = PriceSpreadSide.GreaterOrEqual; } else if (this.rbnPriceSpreadSide_Less.Checked) { priceSpreadSide = PriceSpreadSide.LessOrEqual; } else { Debug.Assert(false); } ArbitrageOpenArgument openArg = new ArbitrageOpenArgument(); openArg.BuyInstrument = buyInstrument; openArg.BuyInstrumentOrderPriceType = buyOrderPriceType; openArg.SellInstrument = sellInstrument; openArg.SellInstrumentOrderPriceType = sellOrderPriceType; openArg.PreferentialSide = preferentialSide; openArg.OpenCondition = new PriceSpreadCondition() { PriceSpreadSide = priceSpreadSide, PriceSpreadThreshold = this.nudPriceSpreadThreshold.Value }; openArg.TotalOrderQty = (int)this.nudTotalOrderQty.Value; openArg.OrderQtyUint = (int)this.nudOrderQtyUint.Value; openArg.DifferentialUnit = (int)this.nudDifferentialUnit.Value; return(openArg); }
/// <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); }
/// <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); }
/// <summary> /// 设定开仓参数。 /// </summary> /// <param name="openArg">开仓参数。</param> public void SetOpenArgument(ArbitrageOpenArgument openArg) { throw new NotSupportedException("不支持开仓参数设定"); }
private void btnOpenArbitrageOrder_Click(object sender, EventArgs e) { string errorMessage = string.Empty; if (VerifyOpenArgument(out errorMessage) == false) { USeFuturesSpiritUtility.ShowWarningMessageBox(this, errorMessage); return; } USeInstrument buyInstrument = this.cbxBuyInstrument.SelectedItem as USeInstrument; USeInstrument sellInstrument = this.cbxSellInstrument.SelectedItem as USeInstrument; ArbitrageOrderPriceType buyOrderPriceType = GetBuyOrderPriceTypeFromUI(); ArbitrageOrderPriceType sellOrderPriceType = GetSellOrderPriceTypeFromUI(); USeOrderSide preferentialSide = GetPreferentialSideFromUI(); PriceSpreadSide priceSpreadSide = GetPriceSpreadSideFromUI(); ArbitrageOpenArgument openArg = new ArbitrageOpenArgument(); openArg.BuyInstrument = buyInstrument; openArg.BuyInstrumentOrderPriceType = buyOrderPriceType; openArg.SellInstrument = sellInstrument; openArg.SellInstrumentOrderPriceType = sellOrderPriceType; openArg.PreferentialSide = preferentialSide; openArg.OpenCondition = new PriceSpreadCondition() { PriceSpreadSide = priceSpreadSide, PriceSpreadThreshold = this.nudPriceSpreadThreshold.Value }; openArg.TotalOrderQty = (int)this.nudTotalOrderQty.Value; openArg.OrderQtyUint = (int)this.nudOrderQtyUint.Value; openArg.DifferentialUnit = (int)this.nudDifferentialUnit.Value; if (VerifyMargin(openArg, out errorMessage) == false) { USeFuturesSpiritUtility.ShowWarningMessageBox(this, errorMessage); return; } decimal evaluateMargin = EvaluateMargin(openArg); string text = string.Format("套利单预计占用保证金 {0},确定跟单么?", evaluateMargin.ToString("#,0")); if (DialogResult.Yes != USeFuturesSpiritUtility.ShowYesNoMessageBox(this, text)) { return; } //try //{ // AutoTraderManager traderManager = USeManager.Instance.AutoTraderManager; // Debug.Assert(traderManager != null); // AutoTrader trader = traderManager.CreateNewAutoTrader(openArg, USeManager.Instance.LoginUser); // trader.BeginOpen(); // //[yangming]创建后应该启动跟单 // trader.StartOpenOrCloseMonitor(); // USeManager.Instance.DataSaver.AddSaveTask(trader.GetArbitrageOrder()); //} //catch (Exception ex) //{ // USeFuturesSpiritUtility.ShowWarningMessageBox(this, ex.Message); // return; //} }