public static List <InstrumentStats> AddInstrumentStats(string name, List <TradeRecord> trades) { var instrumentName = trades.Where(x => x.Cmd == TradeCommand.Buy || x.Cmd == TradeCommand.Sell).Select(x => x.Symbol).Distinct().ToList(); var AccountStatsList = new List <InstrumentStats>(); foreach (TimeLineEnum timeline in Enum.GetValues(typeof(TimeLineEnum))) { foreach (var item in instrumentName.Select((Value, Index) => new { Value, Index })) { InstrumentStats instrumentStats = new InstrumentStats(); instrumentStats.TimeLineId = (int)timeline; instrumentStats.AccountStatsId = timeline; instrumentStats.BuyRate = MathCalculations.GenerateRandomNo(3); instrumentStats.CreatedBy = name; //accountStats.CreatedOn = GenerateRandomDate(); instrumentStats.InstrumentId = item.Index + 1; instrumentStats.InstrumentName = item.Value; instrumentStats.Volume = InstrumentsCalculations.GetVolumeOfInstrumentByTimelineId((int)timeline, trades, item.Value); instrumentStats.WINRate = MathCalculations.GenerateRandomNo(2); instrumentStats.NAV = MathCalculations.GenerateRandomNo(2); instrumentStats.ROI = MathCalculations.GenerateRandomNo(2); instrumentStats.Profit = InstrumentsCalculations.GetProfitOfInstrumentByTimelineId((int)timeline, trades, item.Value); instrumentStats.Loss = InstrumentsCalculations.GetLossOfInstrumentByTimelineId((int)timeline, trades, item.Value); instrumentStats.Status = true; if (instrumentStats.Volume > 0) { AccountStatsList.Add(instrumentStats); } } } return(AccountStatsList); }
private static List <InstrumentStats> AddInstrumentStatsForExistingUsers(string name, List <TradeRecord> trades, List <InstrumentStats> Instruments) { try { var instrumentName = trades.Where(x => x.Cmd == TradeCommand.Buy || x.Cmd == TradeCommand.Sell).Select(x => x.Symbol).Distinct().ToList(); var existingInstruments = Instruments.Select(x => x.InstrumentName).Distinct().ToList(); var newInstruments = trades.Where(x => (x.Cmd == TradeCommand.Buy || x.Cmd == TradeCommand.Sell) && !existingInstruments.Contains(x.Symbol)).Select(x => x.Symbol).Distinct().ToList(); var timelineIds = GetTimelinesForExistingUser(); foreach (var timeline in timelineIds) { foreach (var item in existingInstruments.Select((Value, Index) => new { Value, Index })) { InstrumentStats existinInstrument = Instruments.Where(x => x.InstrumentName == item.Value && x.TimeLineId == (int)timeline).FirstOrDefault(); if (existinInstrument != null) { existinInstrument.Volume = InstrumentsCalculations.GetVolumeOfInstrumentByTimelineId((int)timeline, trades, item.Value); existinInstrument.Profit = InstrumentsCalculations.GetProfitOfInstrumentByTimelineId((int)timeline, trades, item.Value); existinInstrument.Loss = InstrumentsCalculations.GetLossOfInstrumentByTimelineId((int)timeline, trades, item.Value); } } } if (newInstruments.Count > 0) { foreach (TimeLineEnum timeline in Enum.GetValues(typeof(TimeLineEnum))) { foreach (var item in newInstruments.Select((Value, Index) => new { Value, Index })) { InstrumentStats instrumentStats = new InstrumentStats(); instrumentStats.TimeLineId = (int)timeline; instrumentStats.AccountStatsId = timeline; instrumentStats.BuyRate = MathCalculations.GenerateRandomNo(3); instrumentStats.CreatedBy = name; //accountStats.CreatedOn = GenerateRandomDate(); instrumentStats.InstrumentId = item.Index + 1; instrumentStats.InstrumentName = item.Value; instrumentStats.Volume = InstrumentsCalculations.GetVolumeOfInstrumentByTimelineId((int)timeline, trades, item.Value); instrumentStats.WINRate = MathCalculations.GenerateRandomNo(2); instrumentStats.NAV = MathCalculations.GenerateRandomNo(2); instrumentStats.ROI = MathCalculations.GenerateRandomNo(2); instrumentStats.Profit = InstrumentsCalculations.GetProfitOfInstrumentByTimelineId((int)timeline, trades, item.Value); instrumentStats.Loss = InstrumentsCalculations.GetLossOfInstrumentByTimelineId((int)timeline, trades, item.Value); instrumentStats.Status = true; if (instrumentStats.Volume > 0) { Instruments.Add(instrumentStats); } } } } return(Instruments); } catch (Exception ex) { throw; } }
public List <InstrumentStats> AddInstrumentStats(string name) { var instrumentName = new List <string> { "EUR/USD", "GBP/SGD", "SGD/AUD" }.ToList(); var timeLine = new List <int> { 1, 2, 3 }.ToList(); var AccountStatsList = new List <InstrumentStats>(); int count = 11; for (int i = 1; i <= 45; i++) { foreach (var item in instrumentName.Select((Value, Index) => new { Value, Index })) { InstrumentStats accountStats = new InstrumentStats(); accountStats.AccountStatsId = i.ToString(); accountStats.BuyRate = MathCalculations.GenerateRandomNo(3); accountStats.CreatedBy = name; accountStats.CreatedOn = GenerateRandomDate(); accountStats.InstrumentId = item.Index + 1; //InstrumentMasterEnum.EURUSD.ToString(); accountStats.Volume = MathCalculations.GenerateRandomNo(2); accountStats.WINRate = MathCalculations.GenerateRandomNo(2); accountStats.NAV = MathCalculations.GenerateRandomNo(2); accountStats.ROI = MathCalculations.GenerateRandomNo(2); accountStats.Status = false; accountStats.TimeLineId = i; accountStats.UpdatedBy = name; accountStats.UpdatedOn = GenerateRandomDate(); AccountStatsList.Add(accountStats); ++count; } } return(AccountStatsList); }