private List <StockPrice01M> CreateStockValues1MFromJson(string data) { var result = new List <StockPrice01M>(); var jsonString = data; // TODO. Esta linea deberia sobrar. Pendiente de comprobacion jsonString = jsonString.Substring(0, jsonString.Length - 1); try { JsonTextReader reader = new JsonTextReader(new StringReader(jsonString)); while (reader.Read()) { if (reader.Value != null) { if (reader.TokenType == JsonToken.PropertyName) { var cad = reader.Value; var regex = @"^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$"; Match match = Regex.Match(reader.Value.ToString(), regex, RegexOptions.IgnoreCase); if (match.Success) { var strDate = reader.Value.ToString(); // ATENCION: Vamoa a leer los siguientes registros por orden reader.Read(); reader.Read(); reader.Read(); var strOpen = reader.Value.ToString(); reader.Read(); reader.Read(); var strHigh = reader.Value.ToString(); reader.Read(); reader.Read(); var strLow = reader.Value.ToString(); reader.Read(); reader.Read(); var strClose = reader.Value.ToString(); reader.Read(); reader.Read(); var strVolume = reader.Value.ToString(); result.Add(new StockPrice01M() { Date = Convert.ToDateTime(strDate), Open = Double.Parse(strOpen, CultureInfo.InvariantCulture), Max = Double.Parse(strHigh, CultureInfo.InvariantCulture), Min = Double.Parse(strLow, CultureInfo.InvariantCulture), Close = Double.Parse(strClose, CultureInfo.InvariantCulture), Volume = Double.Parse(strVolume, CultureInfo.InvariantCulture), }); } } } } } catch (Exception error) { LoggerHelper.LogException(true, error); } return(result); }
public StatusMessage DeleteStockValue(string stockCode) { StatusMessage result = new StatusMessage(); if (_stockContext != null) { try { var savedStock = _stockContext.Stocks.FirstOrDefault(x => x.Code.Equals(stockCode, StringComparison.InvariantCultureIgnoreCase)); var savedOverview = _stockContext.Overviews.FirstOrDefault(x => x.Code.Equals(stockCode, StringComparison.InvariantCultureIgnoreCase)); var savedPrices01 = _stockContext.OneMinuteValues.Where(x => x.Code.Equals(stockCode, StringComparison.InvariantCultureIgnoreCase)); var savedPrices05 = _stockContext.FiveMinuteValues.Where(x => x.Code.Equals(stockCode, StringComparison.InvariantCultureIgnoreCase)); var savedPrices15 = _stockContext.FifteenMinuteValues.Where(x => x.Code.Equals(stockCode, StringComparison.InvariantCultureIgnoreCase)); var savedPrices60 = _stockContext.SixtyMinuteValues.Where(x => x.Code.Equals(stockCode, StringComparison.InvariantCultureIgnoreCase)); var savedDailys = _stockContext.Dailys.Where(x => x.Code.Equals(stockCode, StringComparison.InvariantCultureIgnoreCase)); if (savedStock != null) { _stockContext.Stocks.Remove(savedStock); } if (savedOverview != null) { _stockContext.Overviews.Remove(savedOverview); } if (savedDailys != null) { _stockContext.Dailys.RemoveRange(savedDailys); } if (savedPrices01 != null) { _stockContext.OneMinuteValues.RemoveRange(savedPrices01); } if (savedPrices05 != null) { _stockContext.FiveMinuteValues.RemoveRange(savedPrices05); } if (savedPrices15 != null) { _stockContext.FifteenMinuteValues.RemoveRange(savedPrices15); } if (savedPrices60 != null) { _stockContext.SixtyMinuteValues.RemoveRange(savedPrices60); } _stockContext.SaveChanges(); result = new StatusMessage(MSG_TYPE.SUCCESS, "Datos eliminados correctamente"); } catch (Exception error) { LoggerHelper.LogException(true, error); result = GetErrorMessage(error); } } return(result); }
private List <StockPriceDaily> CreateDailyStockValuesFromJson(string data) { var result = new List <StockPriceDaily>(); var jsonString = data; jsonString = jsonString.Replace("Meta Data", "Metadata"); jsonString = jsonString.Replace("Time Series (Daily)", "Timeseries"); jsonString = jsonString.Replace("1. open", "Open"); jsonString = jsonString.Replace("2. high", "High"); jsonString = jsonString.Replace("3. low", "Low"); jsonString = jsonString.Replace("4. close", "Close"); jsonString = jsonString.Replace("5. volume", "Volume"); jsonString = jsonString.Substring(0, jsonString.Length - 1); try { JsonTextReader reader = new JsonTextReader(new StringReader(jsonString)); while (reader.Read()) { if (reader.Value != null) { if (reader.TokenType == JsonToken.PropertyName) { var cad = reader.Value; var regex = @"^\d{4}-\d{2}-\d{2}$"; Match match = Regex.Match(reader.Value.ToString(), regex, RegexOptions.IgnoreCase); if (match.Success) { var strDate = reader.Value.ToString(); // ATENCION: Vamoa a leer los siguientes registros por orden reader.Read(); reader.Read(); reader.Read(); var strOpen = reader.Value.ToString(); reader.Read(); reader.Read(); var strHigh = reader.Value.ToString(); reader.Read(); reader.Read(); var strLow = reader.Value.ToString(); reader.Read(); reader.Read(); var strClose = reader.Value.ToString(); reader.Read(); reader.Read(); var strVolume = reader.Value.ToString(); result.Add(new StockPriceDaily() { Date = Convert.ToDateTime(strDate), Open = Double.Parse(strOpen, CultureInfo.InvariantCulture), Max = Double.Parse(strHigh, CultureInfo.InvariantCulture), Min = Double.Parse(strLow, CultureInfo.InvariantCulture), Close = Double.Parse(strClose, CultureInfo.InvariantCulture), Volume = Double.Parse(strVolume, CultureInfo.InvariantCulture), }); } } } } } catch (Exception error) { LoggerHelper.LogException(true, error); } return(result); }