private void syncRates()
        {
            using (var context = new InvestingContext())
            {
                var balancesDates = context.Balances.Select(o => o.DateTimeStamp).ToArray();
                var fromDate      = context.Flows.Min(o => o.DateTimeStamp).AddMonths(-1);
                var toDate        = DateTime.Now;

                foreach (var type in Enum.GetValues(typeof(RateType)))
                {
                    var rateType = (RateType)type;
                    var data     = RatesDownloader.GetValues(rateType, fromDate, toDate);

                    var existingRateDates = context.Rates.Where(o => o.Type == rateType)
                                            .Select(o => o.DateTimeStamp);
                    var datesToAdd = balancesDates.Except(existingRateDates);

                    foreach (var d in datesToAdd.Where(o => data.Keys.Contains(o)))
                    {
                        context.Rates.Add(new Rate()
                        {
                            Type          = rateType,
                            DateTimeStamp = d,
                            Value         = data[d]
                        });
                    }
                    context.SaveChanges();
                }
            }
        }
Beispiel #2
0
        public void TestRatesForUSDollar()
        {
            var values = RatesDownloader.GetValues(RateType.USDollar,
                                                   new DateTime(2018, 1, 1), new DateTime(2018, 3, 1));

            Assert.AreEqual(37, values.Count());
            Assert.AreEqual(56.4334, values.Last().Value);
        }