Пример #1
0
        public List <CumulativeDatedPAndL> GetCumulativePAndLByDate(PAndLRequestModel pAndLModel)
        {
            var startDate    = !string.IsNullOrWhiteSpace(pAndLModel.StartDate) ? (DateTime?)Convert.ToDateTime(pAndLModel.StartDate) : null;
            var queryRegions = (string.IsNullOrWhiteSpace(pAndLModel.Region))
                ? new List <string> {
                "AP", "EU", "US"
            }
                : new List <string> {
                pAndLModel.Region
            };

            var datedPAndLsForRegionAfterStartDateOrderedByDate =
                QueryDatedPAndLsForRegionAfterStartDateOrderedByDate(queryRegions, startDate);

            var cumulatedPandLs = new List <CumulativeDatedPAndL>();
            var previouslyRecordedCumulatedPAndLForRegion = new Dictionary <string, long>();

            foreach (var queryRegion in queryRegions)
            {
                previouslyRecordedCumulatedPAndLForRegion.Add(queryRegion, 0);
            }

            foreach (var datedPAndL in datedPAndLsForRegionAfterStartDateOrderedByDate)
            {
                previouslyRecordedCumulatedPAndLForRegion[datedPAndL.Region] += datedPAndL.Value;
                cumulatedPandLs.Add(new CumulativeDatedPAndL()
                {
                    Date   = datedPAndL.Date,
                    Region = datedPAndL.Region,
                    Value  = previouslyRecordedCumulatedPAndLForRegion[datedPAndL.Region]
                });
            }

            return(cumulatedPandLs);
        }
Пример #2
0
        public IActionResult GetCumulativePAndL([FromQuery] PAndLRequestModel pAndLModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var resultingCumulatedPandLs = _capitalService.GetCumulativePAndLByDate(pAndLModel)
                                           .Select(cumulatedPandL => new
            {
                region        = cumulatedPandL.Region,
                date          = cumulatedPandL.Date.ToString("yyyy-MM-dd"),
                cumulativePnl = cumulatedPandL.Value
            });

            return(Ok(resultingCumulatedPandLs));
        }