private void xamDataTreeAccount_NodeDragEnd(object sender, Infragistics.DragDrop.DragDropEventArgs e) { if (e.OperationType != null && e.OperationType == OperationType.Copy) { XamDataTreeNode origNode = e.Data as XamDataTreeNode; if (origNode == null) { return; } PortfolioVM porfVm = origNode.Data as PortfolioVM; if (porfVm == null) { return; } XamDataTreeNodeControl treeNodeCtrl = e.DropTarget as XamDataTreeNodeControl; if (treeNodeCtrl == null) { return; } AccountVM acctVm = treeNodeCtrl.Node.Data as AccountVM; if (acctVm == null) { return; } XElement portfElem = porfVm.Persist(); var cloned = PortfolioVM.Load(acctVm, portfElem); acctVm.AddPorfolio(cloned); ViewModel.Persist(); } }
private void OnRemovePortfolio(XamDataGrid dataGrid) { if (dataGrid == null) { return; } DataRecord dr = dataGrid.ActiveRecord as DataRecord; if (dr != null) { PortfolioVM portfVm = dr.DataItem as PortfolioVM; if (portfVm != null) { MessageBoxResult res = MessageBox.Show(Application.Current.MainWindow, string.Format("删除帐户[{0}]的组合 {1}", portfVm.AccountId, portfVm.DisplayText), "删除确认", MessageBoxButton.YesNo, MessageBoxImage.Question); if (res == MessageBoxResult.Yes) { RemovePortfolio(portfVm); if (_client.IsConnected) { _client.RemovePortf(portfVm.Id); } PublishChanged(); } } } }
public void AddPorfolio(PortfolioVM porfVm) { lock (_acctPortfolios) { _acctPortfolios.Add(porfVm); } }
public void From(PortfolioVM portf) { PortfId = portf.Id; Quantity = portf.Quantity; MaxQuantity = portf.MaxPosition; int legIdx = 0; foreach (var leg in portf.Legs) { ++legIdx; if (legIdx == 1) { Leg1 = true; Symbol1 = leg.Symbol; Side1 = leg.Side; Ratio1 = leg.Ratio; } else { Leg2 = true; Symbol2 = leg.Symbol; Side2 = leg.Side; Ratio2 = leg.Ratio; } } if (portf.StrategySetting != null) { StrategyName = portf.StrategySetting.Name; } }
private void OnAddPortfolio(AccountVM acct) { PortfolioVM portf = new PortfolioVM(this); portf.Id = NextPortfId(); EditPortfolioDlg dlg = new EditPortfolioDlg(); dlg.Owner = System.Windows.Application.Current.MainWindow; dlg.Portfolio = portf; bool?res = dlg.ShowDialog(); if (res ?? false) { portf.SetHedgeFlag(HedgeFlag); PTEntity.PortfolioItem portfolioItem = dlg.Portfolio.GetEntity(); AddPorfolio(portf); if (_client.IsConnected) { _client.AddPortfolio(portfolioItem); } PublishChanged(); } }
public void From(PortfolioVM portf) { PortfId = portf.Id; Quantity = portf.Quantity; MaxOpenPerStart = portf.MaxOpenPerStart; MaxCancelVol = portf.MaxCancel; TotalOpenLimit = portf.TotalOpenLimit; EndTimePointsExpr = portf.EndTimePointsExpr; int legIdx = 0; foreach (var leg in portf.Legs) { ++legIdx; if (legIdx == 1) { Leg1 = true; Symbol1 = leg.Symbol; Side1 = leg.Side; Ratio1 = leg.Ratio; } else { Leg2 = true; Symbol2 = leg.Symbol; Side2 = leg.Side; Ratio2 = leg.Ratio; } } if (portf.StrategySetting != null) { StrategyName = portf.StrategySetting.Name; } }
public void RemovePortfolio(PortfolioVM portfVm) { lock (_acctPortfolios) { int idx = _acctPortfolios.IndexOf(portfVm); if (idx >= 0 && idx < _acctPortfolios.Count) { _acctPortfolios.RemoveAt(idx); } } }
public void RemovePortfolio(PortfolioVM portfVm) { lock (_acctPortfolios) { int idx = _acctPortfolios.IndexOf(portfVm); if (idx >= 0 && idx < _acctPortfolios.Count) { _acctPortfolios.RemoveAt(idx); EventAggregator.GetEvent <PortfolioSelectedEvent>().Publish(null); } } }
public static AccountVM Load(XElement xmlElement) { AccountVM acct = new AccountVM(); XAttribute attrBrokerId = xmlElement.Attribute("brokerId"); if (attrBrokerId != null) { acct.BrokerId = attrBrokerId.Value; } XAttribute attrInvestorId = xmlElement.Attribute("investorId"); if (attrInvestorId != null) { acct.InvestorId = attrInvestorId.Value; } XAttribute attrPwd = xmlElement.Attribute("password"); if (attrPwd != null) { acct.Password = attrPwd.Value; } XAttribute attrMaxSubmit = xmlElement.Attribute("maxSubmit"); if (attrMaxSubmit != null) { acct.MaxSubmit = int.Parse(attrMaxSubmit.Value); } XAttribute attrMaxCancel = xmlElement.Attribute("maxCancel"); if (attrMaxCancel != null) { acct.MaxCancel = int.Parse(attrMaxCancel.Value); } foreach (var portfElem in xmlElement.Element("portfolios").Elements("portfolio")) { PortfolioVM porfVm = PortfolioVM.Load(acct, portfElem); acct.AddPorfolio(porfVm); } return(acct); }
public void To(PortfolioVM portf) { portf.Quantity = this.Quantity; portf.MaxPosition = this.MaxQuantity; if (Leg1) { LegVM leg; if (portf.LegCount < 1) { leg = new LegVM(); portf.AddLeg(leg); } else { leg = portf.GetLeg(0); } leg.Symbol = Symbol1; leg.Side = Side1; leg.Ratio = Ratio1; leg.SetIsPreferred(PreferLeg1); } if (Leg2 || StrategyName == StrategySetting.ChangePositionStrategyName) { LegVM leg; if (portf.LegCount < 2) { leg = new LegVM(); portf.AddLeg(leg); } else { leg = portf.GetLeg(1); } leg.Symbol = Symbol2; leg.Side = Side2; leg.Ratio = Ratio2; leg.IsPreferred = PreferLeg2; } portf.StrategySetting = StrategySetting.Create(StrategyName); if (StrategyName == StrategySetting.ChangePositionStrategyName) { portf.AutoOpen = true; portf.AutoStopGain = false; portf.AutoStopLoss = false; portf.EnablePrefer = true; portf.AutoTracking = true; ChangePositionSetting setting = (ChangePositionSetting)portf.StrategySetting; setting.CloseLeg = Symbol1; setting.CloseLegSide = Side1; } else if (StrategyName == StrategySetting.ScalperStrategyName) { if (!string.IsNullOrEmpty(Symbol1)) { ScalperSetting setting = (ScalperSetting)portf.StrategySetting; setting.PriceTick = this.PriceTick; setting.Threshold = this.Threshold; } } }
public static PortfolioVM Load(AccountVM acct, XElement xmlElement) { PortfolioVM portf = new PortfolioVM(acct); portf.IsLoading = true; XAttribute attr = xmlElement.Attribute("id"); if (attr != null) { portf.Id = attr.Value; } attr = xmlElement.Attribute("quantity"); if (attr != null) { portf.Quantity = int.Parse(attr.Value); } attr = xmlElement.Attribute("currentPosition"); if (attr != null) { int currPos = int.Parse(attr.Value); portf.Position = currPos; portf.OpenTimes = currPos; } attr = xmlElement.Attribute("avgCost"); if (attr != null) { double avgCost = double.Parse(attr.Value); portf.AvgCost = avgCost; } attr = xmlElement.Attribute("maxPosition"); if (attr != null) { portf.MaxPosition = int.Parse(attr.Value); } attr = xmlElement.Attribute("autoOpen"); if (attr != null) { portf.AutoOpen = attr.Value == bool.TrueString; } attr = xmlElement.Attribute("autoStopGain"); if (attr != null) { portf.AutoStopGain = attr.Value == bool.TrueString; } attr = xmlElement.Attribute("autoStopLoss"); if (attr != null) { portf.AutoStopLoss = attr.Value == bool.TrueString; } attr = xmlElement.Attribute("autoTracking"); if (attr != null) { portf.AutoTracking = attr.Value == bool.TrueString; } attr = xmlElement.Attribute("enablePrefer"); if (attr != null) { portf.EnablePrefer = attr.Value == bool.TrueString; } foreach (var legElem in xmlElement.Element("legs").Elements("leg")) { LegVM legVm = LegVM.Load(legElem); portf.AddLeg(legVm); } XElement xmlSetting = xmlElement.Element("setting"); string strategyName = xmlSetting.Attribute("name").Value; string strategyXmlText = xmlSetting.Value; portf.StrategySetting = StrategySetting.Load(strategyName, strategyXmlText); portf.IsLoading = false; return(portf); }
public void To(PortfolioVM portf) { portf.Quantity = this.Quantity; portf.TotalOpenLimit = this.TotalOpenLimit; portf.MaxCancel = this.MaxCancelVol; portf.MaxOpenPerStart = this.MaxOpenPerStart; portf.EndTimePointsExpr = this.EndTimePointsExpr; if (Leg1) { LegVM leg; if (portf.LegCount < 1) { leg = new LegVM(); portf.AddLeg(leg); } else { leg = portf.GetLeg(0); } leg.Symbol = Symbol1; leg.Side = Side1; leg.Ratio = Ratio1; leg.SetIsPreferred(PreferLeg1); } if (Leg2 || StrategyName == StrategySetting.ChangePositionStrategyName) { LegVM leg; if (portf.LegCount < 2) { leg = new LegVM(); portf.AddLeg(leg); } else { leg = portf.GetLeg(1); } leg.Symbol = Symbol2; leg.Side = Side2; leg.Ratio = Ratio2; leg.IsPreferred = PreferLeg2; } portf.StrategySetting = StrategySetting.Create(StrategyName); if (StrategyName == StrategySetting.ArbitrageStrategyName) { ArbitrageStrategySetting setting = (ArbitrageStrategySetting)portf.StrategySetting; setting.BollPeriod = AR_BollPeriod; setting.StdDevMultiplier = AR_StdDevMultiplier; setting.TimeFrame = 60; setting.FirstLegSymbol = Symbol1; setting.SecondLegSymbol = Symbol2; foreach (var l in portf.Legs) { l.MinPriceChange = PriceTick; } } else if (StrategyName == StrategySetting.ChangePositionStrategyName) { portf.AutoOpen = true; portf.AutoStopGain = false; portf.AutoStopLoss = false; portf.EnablePrefer = true; portf.AutoTracking = true; ChangePositionSetting setting = (ChangePositionSetting)portf.StrategySetting; setting.CloseLeg = Symbol1; setting.CloseLegSide = Side1; } else if (StrategyName == StrategySetting.ScalperStrategyName) { if (!string.IsNullOrEmpty(Symbol1)) { ScalperSetting setting = (ScalperSetting)portf.StrategySetting; setting.PriceTick = this.PriceTick; setting.Threshold = this.Threshold; } } else if (StrategyName == StrategySetting.MACDHistSlopeStrategyName) { if (!string.IsNullOrEmpty(Symbol1)) { MACDHistSlopeStrategySetting setting = (MACDHistSlopeStrategySetting)portf.StrategySetting; setting.Symbol = Symbol1; setting.MACD_Short = 12; setting.MACD_Long = 26; setting.MACD_M = 9; setting.FastPeriod = this.FastPeriod; setting.SlowPeriod = this.SlowPeriod; setting.FastStdDiff = this.FastStdDiff; setting.SlowStdDiff = this.SlowStdDiff; setting.FastAngleThreshold = 45; setting.SlowAngleThreshold = 30; setting.TrailingStopValue = this.TrailingStop; } } else if (StrategyName == StrategySetting.WMATrendStrategyName) { if (!string.IsNullOrEmpty(Symbol1)) { WMATrendStrategySettings setting = (WMATrendStrategySettings)portf.StrategySetting; setting.Symbol = Symbol1; setting.Period = WT_Period; setting.WMA_Param = WMA_Param; setting.MA_N = MA_N; //setting.TrailingStopValue = this.TrailingStop; } } else if (StrategyName == StrategySetting.LinerRegressionStrategyName) { if (!string.IsNullOrEmpty(Symbol1)) { LinerRegStrategySettings setting = (LinerRegStrategySettings)portf.StrategySetting; setting.Symbol = Symbol1; setting.Period = LR_Period; setting.Number = LR_Number; setting.OpenThreshold = LR_OpenThreshold; setting.CloseThreshold = LR_CloseThreshold; } } else if (StrategyName == StrategySetting.ASCTrendStrategyName) { if (!string.IsNullOrEmpty(Symbol1)) { ASCTrendStrategySettings setting = (ASCTrendStrategySettings)portf.StrategySetting; setting.Symbol = Symbol1; setting.Period = AS_Period; setting.Risk = AS_Risk; setting.AvergatePeriod = AS_AveragePeriod; setting.BreakoutLength = AS_BreakoutLength; } } else if (StrategyName == StrategySetting.RangeTrendStrategyName) { if (!string.IsNullOrEmpty(Symbol1)) { RangeTrendStrategySettings setting = (RangeTrendStrategySettings)portf.StrategySetting; setting.Symbol = Symbol1; setting.Period = RT_TimeFrame; setting.OpenPeriod = RT_OpenPeriod; setting.ClosePeriod = RT_ClosePeriod; setting.StopLossFactor = RT_StopLossFactor; setting.TrendFactor = RT_TrendFactor; } } else if (StrategyName == StrategySetting.ManualStrategyName) { if (!string.IsNullOrEmpty(Symbol1)) { ManualStrategySetting setting = (ManualStrategySetting)portf.StrategySetting; setting.RetryTimes = RetryTimes; } } }