public void AddStockData(List <string> scrapedData, IScrapeInfoRepository scrapeInfoRepo, ICompanyRepository companyRepo, string userId)
        {
            using (IDbConnection connection = new SqlConnection(config.GetConnectionString("ScraperData")))
            {
                var stocksData = new List <StockData>();
                int scrapeId   = scrapeInfoRepo.GetScrapeInfo(connection, userId).ScrapeId;

                foreach (var item in scrapedData)
                {
                    var data = item.Split('\t');

                    int symbolId = companyRepo.GetSymbolId(connection, data[0].Trim());

                    decimal?lastPrice     = ParseDecimalString(data[2].Trim());
                    decimal?change        = ParseDecimalString(data[3].Trim());
                    decimal?percentChange = ParseDecimalString(data[4].Trim().TrimEnd('%'));
                    decimal?prevClose     = ParseDecimalString(data[6].Trim());
                    decimal?openPrice     = ParseDecimalString(data[7].Trim());
                    int?    shares        = ParseIntString(data[8].Trim());
                    decimal?costBasics    = ParseDecimalString(data[9].Trim());

                    DateTime tradeDate1;
                    DateTime?tradeDate = DateTime.TryParse(data[10].Trim(), out tradeDate1) ? tradeDate1
                        : (DateTime?)null;

                    decimal?percentAnnualGain = ParseDecimalString(data[11].Trim().TrimEnd('%'));
                    decimal?fiftyTwoWeekHigh  = ParseDecimalString(data[12].Trim());
                    decimal?fiftyTwoWeekLow   = ParseDecimalString(data[13].Trim());
                    decimal?bid       = ParseDecimalString(data[14].Trim());
                    int?    bidSize   = ParseIntString(data[15].Trim());
                    decimal?ask       = ParseDecimalString(data[16].Trim());
                    int?    askSize   = ParseIntString(data[17].Trim());
                    decimal?marketCap = ParseMarketCap(data[18].Trim());

                    stocksData.Add(new StockData
                    {
                        ScrapeId          = scrapeId,
                        SymbolId          = symbolId,
                        LastPrice         = lastPrice,
                        Change            = change,
                        PercentChange     = percentChange,
                        PrevClose         = prevClose,
                        OpenPrice         = openPrice,
                        Shares            = shares,
                        CostBasics        = costBasics,
                        TradeDate         = tradeDate,
                        PercentAnnualGain = percentAnnualGain,
                        FiftyTwoWeekHigh  = fiftyTwoWeekHigh,
                        FiftyTwoWeekLow   = fiftyTwoWeekLow,
                        Bid       = bid,
                        BidSize   = bidSize,
                        Ask       = ask,
                        AskSize   = askSize,
                        MarketCap = marketCap
                    });
                }
                connection.Execute("dbo.uspStocksData_AddStockData @ScrapeId, @SymbolId, @LastPrice, @Change, @PercentChange, @PrevClose, @OpenPrice, @Shares, @CostBasics, @TradeDate, @PercentAnnualGain, @FiftyTwoWeekHigh, @FiftyTwoWeekLow, @Bid, @BidSize, @Ask, @AskSize, @MarketCap", stocksData);
            }
        }
Ejemplo n.º 2
0
        public List <CombinedStockDataVM> GetStocksDataByScrapeId(IScrapeInfoRepository scrapeInfoRepo, int scrapeId)
        {
            using (IDbConnection connection = new SqlConnection(config.GetConnectionString("ScraperData")))
            {
                ScrapeInfo scrapeInfo = scrapeInfoRepo.GetScrapeInfo(connection, scrapeId);

                List <CombinedStockDataVM> stocksData = connection.Query <Company, StockData, CombinedStockDataVM>
                                                            ("dbo.uspStocksData_Companies_GetByScrapeId @ScrapeId",
                                                            MapResults,
                                                            new { ScrapeId = scrapeId }, splitOn: "LastPrice").ToList();

                stocksData[0].ScrapeInfo = scrapeInfo;
                return(stocksData);
            }
        }