/// <summary> /// Parse raw historical price data into list /// </summary> /// <param name="csvData"></param> /// <returns>List of historical price</returns> private static async Task <List <HistoryPrice> > ParsePriceAsync(string csvData) { return(await Task.Run(() => { var lst = new List <HistoryPrice>(); try { var rows = csvData.Split(Convert.ToChar(10)); //row(0) was ignored because is column names //data is read from oldest to latest for (var i = 1; i <= rows.Length - 1; i++) { var row = rows[i]; if (string.IsNullOrEmpty(row)) { continue; } var cols = row.Split(','); if (cols[1] == "null") { continue; } var x = cols[1]; var itm = new HistoryPrice { Date = DateTime.Parse(cols[0]), Open = double.Parse(cols[1], NumberFormatInfo.InvariantInfo), High = double.Parse(cols[2], NumberFormatInfo.InvariantInfo), Low = double.Parse(cols[3], NumberFormatInfo.InvariantInfo), Close = double.Parse(cols[4], NumberFormatInfo.InvariantInfo), AdjClose = double.Parse(cols[5], NumberFormatInfo.InvariantInfo) }; //fixed issue in some currencies quote (e.g: SGDAUD=X) if (cols[6] != "null") { itm.Volume = Convert.ToDouble(cols[6]); } lst.Add(itm); } } catch (Exception ex) { Debug.Print(ex.Message); throw; } return lst; }).ConfigureAwait(false)); }
/// <summary> /// Parse raw historical price data into list /// </summary> /// <param name="csvData"></param> /// <returns></returns> private static List <HistoryPrice> Parse(string csvData) { List <HistoryPrice> hps = new List <HistoryPrice>(); try { string[] rows = csvData.Split(Convert.ToChar(10)); //row(0) was ignored because is column names //data is read from oldest to latest for (int i = 1; i <= rows.Length - 1; i++) { string row = rows[i]; if (string.IsNullOrEmpty(row)) { continue; } string[] cols = row.Split(','); if (cols[1] == "null") { continue; } HistoryPrice hp = new HistoryPrice(); hp.Date = DateTime.Parse(cols[0]); hp.Open = Convert.ToDouble(cols[1]); hp.High = Convert.ToDouble(cols[2]); hp.Low = Convert.ToDouble(cols[3]); hp.Close = Convert.ToDouble(cols[4]); hp.AdjClose = Convert.ToDouble(cols[5]); //fixed issue in some currencies quote (e.g: SGDAUD=X) if (cols[6] != "null") { hp.Volume = Convert.ToDouble(cols[6]); } hps.Add(hp); } } catch (Exception ex) { Debug.Print(ex.Message); } return(hps); }