/// <summary> /// 初始化。 /// </summary> public override void Initialize() { Debug.Assert(m_autoTrader != null); m_autoTrader.OnStateChanged += M_autoTrader_OnStateChanged; m_autoTrader.OnArbitrageOrderChanged += M_autoTrader_OnArbitrageOrderChanged; m_autoTrader.OnAlarm += M_autoTrader_OnAlarm; m_arbitrageOrder = m_autoTrader.GetArbitrageOrder(); ResetContextMenu(); SetChartViewData(m_arbitrageOrder); ShowArbitrageOrderView(); ShowAlarmIcon(); ShowChartView(); ShowTaskGrid(); ShowRunButton(); m_porfitCalcTimer.Change(500, Timeout.Infinite); }
private void ModifyArbitrageOpenArgumentForm_Load(object sender, EventArgs e) { if (m_autoTrader != null) { m_arbitrageOrder = m_autoTrader.GetArbitrageOrder(); } if (m_arbitrageOrder != null) { this.Text = string.Format("套利单[{0}]开仓参数", m_arbitrageOrder.Alias); this.arbitrageOrderOpenArgumentViewControl1.SetOpenArgument(m_arbitrageOrder.OpenArgument); } }
private void M_autoTraderManager_OnArbitrageOrderChanged(Guid tradeIdentify) { try { AutoTrader trader = m_autoTraderManager.GetAutoTrader(tradeIdentify); USeArbitrageOrder arbitrageOrder = trader.GetArbitrageOrder(); m_dataSaver.AddSaveTask(arbitrageOrder); } catch (Exception ex) { Debug.Assert(false, ex.Message); } }
private void btnRefresh_Click(object sender, EventArgs e) { if (m_arbitrageOrder == null) { return; } try { AutoTrader trader = USeManager.Instance.AutoTraderManager.GetAutoTrader(m_arbitrageOrder.TraderIdentify); USeArbitrageOrder arbitrageOrder = trader.GetArbitrageOrder(); Debug.Assert(arbitrageOrder != null); m_arbitrageOrder = arbitrageOrder; BindData(); } catch (Exception ex) { Debug.Assert(false, ex.Message); } }
/// <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); }