Example #1
0
        //private static List<SummaryStock> DailySummaryStock(List<Stock> stocks, List<SummaryStock> summaryStocks)
        //{
        //    if (stocks == null) throw new ArgumentNullException(nameof(stocks));

        //    var groupDate = stocks.GroupBy(x => x.Date.Date).Select(x => new { x.Key, StockItem = x }).ToList();
        //    SummaryStock summaryStock;
        //    foreach (var item in groupDate)
        //    {
        //        summaryStock = new SummaryStock
        //        {
        //            Date = item.Key.Date,
        //            Open = item.StockItem.OrderBy(x => x.Date).Select(x => x.Current).FirstOrDefault(),
        //            Close = item.StockItem.OrderByDescending(x => x.Date).Select(x => x.Current).FirstOrDefault(),
        //            Low = item.StockItem.Select(x => x.Current).Min(),
        //            Hight = item.StockItem.Select(x => x.Current).Max()
        //        };
        //        summaryStocks.Add(summaryStock);
        //    }
        //    return summaryStocks;
        //}

        //private static List<SummaryStock> HourlySummaryStock(List<Stock> stocks, List<SummaryStock> summaryStocks)
        //{
        //    if (stocks == null) throw new ArgumentNullException(nameof(stocks));

        //    var groupDate = stocks.GroupBy(x => x.Date.Date).Select(x => new { x.Key, StockItem = x }).ToList();
        //    SummaryStock summaryStock;
        //    foreach (var itemDate in groupDate)
        //    {
        //        var groupHour = itemDate.StockItem.GroupBy(x => x.Date.Hour).Select(x => new { x.Key, StockItem = x }).ToList();
        //        foreach (var itemHour in groupHour)
        //        {
        //            summaryStock = new SummaryStock
        //            {
        //                Date = itemDate.Key.Date,
        //                Hour = itemHour.Key,
        //                Open = itemHour.StockItem.OrderBy(x => x.Date).Select(x => x.Current).FirstOrDefault(),
        //                Close = itemHour.StockItem.OrderByDescending(x => x.Date).Select(x => x.Current).FirstOrDefault(),
        //                Low = itemHour.StockItem.Select(x => x.Current).Min(),
        //                Hight = itemHour.StockItem.Select(x => x.Current).Max()
        //            };
        //            summaryStocks.Add(summaryStock);
        //        }
        //    }
        //    return summaryStocks;
        //}

        private static void SetStockData(string[] strSplit, List <SummaryStock> summaryStocks)
        {
            SummaryStock summaryStock;

            if (strSplit[1].Trim() != "0")
            {
                summaryStock = new SummaryStock();
                if (summaryStocks.Count == 0)
                {
                    InitialNewStockRecord(strSplit, summaryStocks, summaryStock);
                }
                else
                {
                    for (int i = 0; i < summaryStocks.Count; i++)
                    {
                        i = summaryStocks.Count;
                        --i;
                        if (summaryStocks[i].Date.Date != DateTime.Parse(strSplit[0].Trim()).Date)
                        {
                            InitialNewStockRecord(strSplit, summaryStocks, summaryStock);
                        }
                        else
                        {
                            summaryStocks[i].Close = Double.Parse(strSplit[1].Trim());
                            if (summaryStocks[i].Low > Double.Parse(strSplit[1].Trim()))
                            {
                                summaryStocks[i].Low = Double.Parse(strSplit[1].Trim());
                            }
                            if (summaryStocks[i].Hight < Double.Parse(strSplit[1].Trim()))
                            {
                                summaryStocks[i].Hight = Double.Parse(strSplit[1].Trim());
                            }
                        }
                    }
                }
            }
        }
Example #2
0
 private static void InitialNewStockRecord(string[] strSplit, List <SummaryStock> summaryStocks, SummaryStock summaryStock)
 {
     summaryStock.Date  = DateTime.Parse(strSplit[0].Trim());
     summaryStock.Open  = Double.Parse(strSplit[1].Trim());
     summaryStock.Close = Double.Parse(strSplit[1].Trim());
     summaryStock.Low   = Double.Parse(strSplit[1].Trim());
     summaryStock.Hight = Double.Parse(strSplit[1].Trim());
     summaryStocks.Add(summaryStock);
 }