using MarketData.Utils; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace MarketData.Generator.Model { public class StopLimits:List { public StopLimits() { } public StopLimits(List stopLimits) { foreach(StopLimit stopLimit in stopLimits)Add(stopLimit); } public NVPCollections ToNVPCollections() { NVPCollections nvpCollections=new NVPCollections(); foreach(StopLimit stopLimit in this) { nvpCollections.Add(stopLimit.ToNVPCollection()); } return nvpCollections; } public static StopLimits FromNVPCollections(NVPCollections nvpCollections) { StopLimits stopLimits=new StopLimits(); foreach(NVPCollection nvpCollection in nvpCollections) { stopLimits.Add(StopLimit.FromNVPCollection(nvpCollection)); } return stopLimits; } public void AddFromNVPCollection(NVPCollection nvpCollection) { Add(StopLimit.FromNVPCollection(nvpCollection)); } } public class StopLimit { public StopLimit() { } public StopLimit(StopLimit stopLimit) { this.Symbol=stopLimit.Symbol; this.AnalysisDate=stopLimit.AnalysisDate; this.PreviousStop=stopLimit.PreviousStop; this.NewStop=stopLimit.NewStop; this.CurrentPriceLow=stopLimit.CurrentPriceLow; this.CurrentPriceClose=stopLimit.CurrentPriceClose; this.PriceTrendIndicatorSlope=stopLimit.PriceTrendIndicatorSlope; } public StopLimit(String symbol,DateTime analysisDate,double previousStop,double newStop,double currentPriceLow,double currentPriceClose,double priceTrendIndicatorSlope) { this.Symbol=symbol; this.AnalysisDate=analysisDate; this.PreviousStop=previousStop; this.NewStop=newStop; this.CurrentPriceLow=currentPriceLow; this.CurrentPriceClose=currentPriceClose; this.PriceTrendIndicatorSlope=priceTrendIndicatorSlope; } public String Symbol { get; set; } public DateTime AnalysisDate{get;set;} public double PreviousStop{get;set;} public double NewStop{get;set;} public double CurrentPriceLow{get;set;} public double CurrentPriceClose{get;set;} public double PriceTrendIndicatorSlope{get;set;} public static String Header() { StringBuilder sb=new StringBuilder(); sb.Append("Symbol,AnalysisDate,PreviousStop,NewStop,CurrentPriceLow,CurrentPriceClose,PriceTrendIndicatorSlope"); return sb.ToString(); } public override String ToString() { StringBuilder sb=new StringBuilder(); sb.Append(Symbol).Append(","); sb.Append(AnalysisDate.ToShortDateString()).Append(","); sb.Append(Utility.FormatCurrency(PreviousStop)).Append(","); sb.Append(Utility.FormatCurrency(NewStop)).Append(","); sb.Append(Utility.FormatCurrency(CurrentPriceLow)).Append(","); sb.Append(Utility.FormatCurrency(CurrentPriceClose)).Append(","); sb.Append(Utility.FormatNumber(PriceTrendIndicatorSlope,4,false)); return sb.ToString(); } public virtual NVPCollection ToNVPCollection() { NVPCollection nvpCollection=new NVPCollection(); nvpCollection.Add(new NVP("Symbol",Symbol.ToString())); nvpCollection.Add(new NVP("AnalysisDate",AnalysisDate.ToString())); nvpCollection.Add(new NVP("PreviousStop",PreviousStop.ToString())); nvpCollection.Add(new NVP("NewStop",NewStop.ToString())); nvpCollection.Add(new NVP("CurrentPriceLow",CurrentPriceLow.ToString())); nvpCollection.Add(new NVP("CurrentPriceClose",CurrentPriceClose.ToString())); nvpCollection.Add(new NVP("PriceTrendIndicatorSlope",PriceTrendIndicatorSlope.ToString())); return nvpCollection; } public static StopLimit FromNVPCollection(NVPCollection nvpCollection) { StopLimit stopLimit=new StopLimit(); NVPDictionary nvpDictionary=nvpCollection.ToDictionary(); stopLimit.Symbol=nvpDictionary["Symbol"].Get(); stopLimit.AnalysisDate=nvpDictionary["AnalysisDate"].Get(); stopLimit.PreviousStop=nvpDictionary["PreviousStop"].Get(); stopLimit.NewStop=nvpDictionary["NewStop"].Get(); stopLimit.CurrentPriceLow=nvpDictionary["CurrentPriceLow"].Get(); stopLimit.CurrentPriceClose=nvpDictionary["CurrentPriceClose"].Get(); stopLimit.PriceTrendIndicatorSlope=nvpDictionary["PriceTrendIndicatorSlope"].Get(); return stopLimit; } } }