private void MainForm_FormClosing(object sender, FormClosingEventArgs e) { if (USeManager.Instance.AutoTraderManager.HasUnfinishOrderBook()) { string text = "当前有挂单中的委托单,退出后可能不能正常处理套利单状态"; if (DialogResult.Yes != USeFuturesSpiritUtility.ShowYesNoMessageBox(this, text)) { e.Cancel = true; return; } } this.investorFundControl1.Stop(); this.arbitrageOrderListControl1.Stop(); }
/// <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); }
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; //} }