public Task <IReadOnlyList <IStockPriceHistory> > GetStockPriceHistoryAsync(CountryKind country, string stockID, DateTime dateBefore, int recordNumber)
 {
     return(Task.FromResult <IReadOnlyList <IStockPriceHistory> >(StockPriceHistoryTable.Where(a => a.Country == country &&
                                                                                               string.Equals(a.StockId, stockID, StringComparison.OrdinalIgnoreCase) &&
                                                                                               a.TradeDateTime < dateBefore)
                                                                  .OrderByDescending(a => a.TradeDateTime)
                                                                  .Take(recordNumber)
                                                                  .ToList()));
 }
        public Task DeleteStockPriceHistoryAsync(CountryKind country, string stockId)
        {
            IEnumerable <IStockPriceHistory> entries = StockPriceHistoryTable.Where(a => a.Country == country &&
                                                                                    string.Equals(a.StockId, stockId, StringComparison.OrdinalIgnoreCase));

            foreach (IStockPriceHistory item in entries)
            {
                StockPriceHistoryTable.Remove(item);
            }

            return(Task.CompletedTask);
        }
        public Task <IReadOnlyList <IAllPricesEntry> > GetTheLatestStockPriceAsync(CountryKind country, DateTime date)
        {
            IReadOnlyList <IStockPriceHistory> priceHistories = StockPriceHistoryTable.Where(a => a.Country == country && a.TradeDateTime < date)
                                                                .OrderByDescending(a => a.TradeDateTime)
                                                                .ToList();

            if (priceHistories.Count == 0)
            {
                return(Task.FromResult <IReadOnlyList <IAllPricesEntry> >(null));
            }

            List <IAllPricesEntry> list = priceHistories.Select(history => new AllPricesEntry(country,
                                                                                              history.StockId,
                                                                                              history.LowPrice,
                                                                                              history.HighPrice,
                                                                                              history.ClosePrice,
                                                                                              history.OpenPrice,
                                                                                              history.TradeDateTime,
                                                                                              history.YearRange,
                                                                                              history.Volume,
                                                                                              history.ATR,
                                                                                              history.N20,
                                                                                              history.HighIn20,
                                                                                              history.LowIn10,
                                                                                              history.N40,
                                                                                              history.HighIn40,
                                                                                              history.LowIn15,
                                                                                              history.N60,
                                                                                              history.HighIn60,
                                                                                              history.LowIn20,
                                                                                              history.MA20,
                                                                                              history.MA40,
                                                                                              history.MA60,
                                                                                              history.MA120,
                                                                                              history.MA240))
                                          .Cast <IAllPricesEntry>()
                                          .ToList();

            return(Task.FromResult <IReadOnlyList <IAllPricesEntry> >(list));
        }
 public Task <IReadOnlyList <IStockPriceHistory> > GetStockPriceHistoryAsync(CountryKind country, string stockID, DateTime start, DateTime end)
 {
     return(Task.FromResult <IReadOnlyList <IStockPriceHistory> >(StockPriceHistoryTable.Where(a => a.Country == country &&
                                                                                               string.Equals(a.StockId, stockID, StringComparison.OrdinalIgnoreCase) &&
                                                                                               a.TradeDateTime >= start && a.TradeDateTime <= end).ToList()));
 }