コード例 #1
0
        private void InternalRun()
        {
            DateTime latestUpdated;
            var      currencyList = GetCurrencyListFromWeb(out latestUpdated);

            Log.Info(string.Format("Currency list contains {0} items", currencyList.Count()));
            if (!DatabaseHasStoredCurrencyList)
            {
                Log.Info("Currency list store to DB started...");
                StoreToDatabaseCurrencyList(currencyList);
                Log.Info("Currency list store to DB successfully completed!");
            }

            var now = DateTime.Now.Date;

            var history = RetriveCurrencyHistoriesFromWeb(currencyList, now.AddYears(-1), now);

            CurrencyRateRepository.EnsureTransaction(() =>
            {
                Log.Info(string.Format("Currency list with history data {0} items", history.Count()));
                if (history != null)
                {
                    Log.Info("Store currency historical price started");
                    StoreToDatabaseCurrencyHistory(history);
                    Log.Info("Store currency historical price successfully completed!");
                }

                var latestData = _LastCurrencyRates.Select(pair =>
                {
                    var currencyName = pair.Key;
                    var price        = pair.Value;
                    var data         = new CurrencyHistoryData(currencyName);

                    data.History.Add(new CurrencyHistoryItemData(latestUpdated, price));

                    return(data);
                }
                                                           );

                Log.Info("Store latest currency rates started");
                StoreToDatabaseCurrencyHistory(latestData);
                Log.Info("Store latest currency rates successfully completed!");
            });
        }
コード例 #2
0
        public void TestParceHistory()
        {
            string symbolName = "KWL";
            string response   =
                @"Date,Open,High,Low,Close,Volume,Adj Close
2012-04-26,1843.71,1845.31,1831.23,1837.21,000,1837.21
2012-04-25,1841.64,1845.24,1832.59,1841.15,000,1841.15
2012-04-24,1837.06,1844.62,1834.58,1837.15,000,1837.15
2011-05-31,1782.95,1785.86,1771.70,1775.49,000,1775.49
2011-05-30,1784.99,1785.53,1777.27,1778.36,000,1778.36
2011-05-27,1785.26,1789.38,1772.51,1785.25,000,1785.25
";
            var list = response.Split(new[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries).ToList();

            Assert.IsTrue(list[0].Contains("Open"));
            Assert.AreEqual(list.Count, 7);

            list.RemoveAt(0);

            Assert.IsFalse(list[0].Contains("Open"));
            Assert.AreEqual(list.Count, 6);

            var data = new CurrencyHistoryData(symbolName);

            data.History = list.Select(i =>
            {
                var dataList = i.Split(new[] { ',' });
                Assert.AreEqual(dataList.Length, 7);
                var dateStr   = dataList[0];
                DateTime date = DateTime.Parse(dateStr);

                var priceStr = dataList[4];
                var price    = decimal.Parse(priceStr);
                return(new CurrencyHistoryItemData
                {
                    Date = date,
                    Price = price
                });
            }).ToList();

            Assert.AreEqual(symbolName, data.CurrencyName);
            Assert.AreEqual(data.History.Count, list.Count);
        }
コード例 #3
0
        internal CurrencyHistoryData RetriveCurrencyHistoryFromWeb(string currencyName, DateTime startDate, DateTime endDate)
        {
            Log.Info(string.Format("Retrieve historical price data started for Currency {0}...", currencyName));
            var data = new CurrencyHistoryData(currencyName);

            if (currencyName.Equals(CurrencyRateProviderYahoo.GbpLabel, StringComparison.InvariantCultureIgnoreCase))
            {
                data.History.Add(new CurrencyHistoryItemData(startDate, 1));
                return(data);
            }

            var yahooService = new CurrencyRateProviderYahoo();
            var yahooData    = yahooService.RetriveData(currencyName, startDate, endDate);

            data.AddHistory(new CurrencyRateHistoryContainer(yahooData));

            Log.Info(string.Format("Retrieve historical price data successfully completed for Currency {0}!", currencyName));
            return(data);
        }