public static void CacheData() { Logger.Info("Caching MarketPrices"); if (Mock) { _all = Utils.GetFile <Dictionary <string, MarketPrice> >("all_marketprices"); } var sql = $@"select business_date, symbol, MAX(price) from FundAccounting..market_prices group by business_date, symbol"; var list = new Dictionary <string, MarketPrice>(); using (var con = new SqlConnection(connectionString)) { con.Open(); var query = new SqlCommand(sql, con); var reader = query.ExecuteReader(System.Data.CommandBehavior.SingleResult); while (reader.Read()) { var businessDate = reader.GetFieldValue <DateTime>(0); var symbol = reader.GetFieldValue <string>(1); var price = reader.GetFieldValue <decimal>(2); var element = new MarketPrice { BusinessDate = businessDate, Symbol = symbol, Price = Convert.ToDouble(price), }; list.Add(element.Key, element); } reader.Close(); con.Close(); } Utils.Save(list, "all_marketprices"); _all = list; }
private static MarketPrice Find(DateTime busDate, Transaction element) { var mp = new MarketPrice { Price = 1 }; if (element.Symbol.Equals("MSUXX")) { return(mp); } var price = Find(busDate, element.Symbol); mp = new MarketPrice { Price = price.Price, Valid = price.Valid, Error = price.Error, }; var baseCurrency = element.TradeCurrency; if (element.SecurityType.Equals("FORWARD")) { var split = element.Symbol.Split(new char[] { '/', ' ' }); baseCurrency = split[0]; } if (baseCurrency.ToLowerInvariant().Equals("gbx") || baseCurrency.Equals("GBp")) { mp.Price = mp.Price / 100.0; } return(mp); }