public static void loadStock(string symbol) { ticker = symbol; //get stock market data through alpha vantage string rawDataPath = @"C:\Users\Public\Documents\RawData\"; if (!getData(symbol, rawDataPath)) { return; } //get rid of previous data chart.Series[0].Points.Clear(); //clearing previous data foreach (var series in chart.Series) { series.Points.Clear(); } //reading the output file: using (var reader = new StreamReader(rawDataPath + symbol)) { bool isFirstLine = true; while (!reader.EndOfStream) { //to get rid of the first line of gaff that alpha-vantage gives if (isFirstLine) { reader.ReadLine(); isFirstLine = false; } var line = reader.ReadLine(); var values = line.Split(','); //date stuff var stringDateArr = values[0].Split('-'); int[] dateInfo = new int[3]; dateInfo[0] = Convert.ToInt32(stringDateArr[0]); dateInfo[1] = Convert.ToInt32(stringDateArr[1]); dateInfo[2] = Convert.ToInt32(stringDateArr[2]); chart.Series[0].XValueType = ChartValueType.DateTime; DateTime x = new DateTime(dateInfo[0], dateInfo[1], dateInfo[2]); //candle stick data double open = Convert.ToDouble(values[1]); double high = Convert.ToDouble(values[2]); double low = Convert.ToDouble(values[3]); double close = Convert.ToDouble(values[4]); double[] data = { high, low, open, close }; DataPoint candleStick = new DataPoint(x.ToOADate(), data); chart.Series[0].Points.Add(candleStick); } } //so that the user can use the actual data that is being shown on the graph in the strategies scriping Strategies.updateData(); }
public static async void loadStock(string symbol) { //MessageBox.Show(symbol); ticker = symbol; //get stock market data through worldtradingdata api string rawDataPath = @"C:\Users\Public\Documents\RawData\"; if (!await getDataAsync(symbol, rawDataPath)) { return; } //get rid of previous data chart.Series[0].Points.Clear(); foreach (var series in chart.Series) { series.Points.Clear(); } JObject jsonData = JObject.Parse(File.ReadAllText(rawDataPath + symbol + ".csv")); foreach (JProperty intraday in jsonData["history"]) { DateTime date = DateTime.Parse(intraday.Name); double[] data = { (double)intraday.Value["high"], (double)intraday.Value["low"], (double)intraday.Value["open"], (double)intraday.Value["close"] }; DataPoint candleStick = new DataPoint(date.ToOADate(), data); chart.Series[0].XValueType = ChartValueType.DateTime; chart.Series[0].Points.Add(candleStick); } return; // old stuff here...: //reading the output file: using (var reader = new StreamReader(rawDataPath + symbol + ".csv")) { bool isFirstLine = true; while (!reader.EndOfStream) { //to get rid of the first line of gaff that alpha-vantage gives if (isFirstLine) { reader.ReadLine(); isFirstLine = false; } var line = reader.ReadLine(); var values = line.Split(','); //date stuff var stringDateArr = values[0].Split('-'); int[] dateInfo = new int[3]; dateInfo[0] = Convert.ToInt32(stringDateArr[0]); dateInfo[1] = Convert.ToInt32(stringDateArr[1]); dateInfo[2] = Convert.ToInt32(stringDateArr[2]); chart.Series[0].XValueType = ChartValueType.DateTime; DateTime x = new DateTime(dateInfo[0], dateInfo[1], dateInfo[2]); //candle stick data double open = Convert.ToDouble(values[1]); double high = Convert.ToDouble(values[2]); double low = Convert.ToDouble(values[3]); double close = Convert.ToDouble(values[4]); double[] data = { high, low, open, close }; DataPoint candleStick = new DataPoint(x.ToOADate(), data); chart.Series[0].Points.Add(candleStick); } } //so that the user can use the actual data that is being shown on the graph in the strategies scriping Strategies.updateData(); }