public void SetCloseArgument(ArbitrageCloseArgument closeArg) { if (closeArg == null) { ClearView(); return; } this.lblBuyInstrument.Text = closeArg.BuyInstrument.InstrumentCode; this.lblSellInstrument.Text = closeArg.SellInstrument.InstrumentCode; this.lblBuyOrderPriceType.Text = closeArg.BuyInstrumentOrderPriceType.ToDescription(); this.lblSellOrderPriceType.Text = closeArg.SellInstrumentOrderPriceType.ToDescription(); switch (closeArg.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 (closeArg.CloseCondition.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 = closeArg.CloseCondition.PriceSpreadThreshold.ToString(); this.lblOrderQtyUint.Text = closeArg.OrderQtyUint.ToString(); this.lblDifferentialUnit.Text = closeArg.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 ArbitrageCloseArgument CreateCloseArg() { //ArbiOrder平仓参数 ArbitrageCloseArgument arg = new ArbitrageCloseArgument(); 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.CloseCondition = new PriceSpreadCondition() { PriceSpreadSide = PriceSpreadSide.LessOrEqual, PriceSpreadThreshold = 200 }; arg.OrderQtyUint = 10; arg.DifferentialUnit = 3; return(arg); }
/// <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); }
/// <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); }
public void SetCloseArgument(ArbitrageCloseArgument closeArg) { InitializeInstument(string.Empty); if (closeArg == null) { return; } this.cbxBuyInstrument.Items.Clear(); this.cbxBuyInstrument.Items.Add(closeArg.BuyInstrument); this.cbxBuyInstrument.SelectedIndex = 0; this.cbxSellInstrument.Items.Clear(); this.cbxSellInstrument.Items.Add(closeArg.SellInstrument); this.cbxSellInstrument.SelectedIndex = 0; switch (closeArg.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 (closeArg.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 (closeArg.PreferentialSide) { case USeOrderSide.Buy: this.rbnPreferentialSide_Buy.Checked = true; break; case USeOrderSide.Sell: this.rbnPreferentialSide_Sell.Checked = true; break; } switch (closeArg.CloseCondition.PriceSpreadSide) { case PriceSpreadSide.GreaterOrEqual: this.rbnPriceSpreadSide_Greater.Checked = true; break; case PriceSpreadSide.LessOrEqual: this.rbnPriceSpreadSide_Less.Checked = true; break; } this.nudPriceSpreadThreshold.Value = closeArg.CloseCondition.PriceSpreadThreshold; this.nudOrderQtyUint.Value = closeArg.OrderQtyUint; this.nudDifferentialUnit.Value = closeArg.DifferentialUnit; }
public ArbitrageCloseArgument GetCloseArgument(out string errorMessage) { if (VerifyCloseArgument(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); } ArbitrageCloseArgument closeArg = new ArbitrageCloseArgument(); closeArg.BuyInstrument = buyInstrument; closeArg.BuyInstrumentOrderPriceType = buyOrderPriceType; closeArg.SellInstrument = sellInstrument; closeArg.SellInstrumentOrderPriceType = sellOrderPriceType; closeArg.PreferentialSide = preferentialSide; closeArg.CloseCondition = new PriceSpreadCondition() { PriceSpreadSide = priceSpreadSide, PriceSpreadThreshold = this.nudPriceSpreadThreshold.Value }; closeArg.OrderQtyUint = (int)this.nudOrderQtyUint.Value; closeArg.DifferentialUnit = (int)this.nudDifferentialUnit.Value; return(closeArg); }