protected void feedGetSeriesFromFileCallback(IWrite iWrite, string cmdName, object[] cmdArguments) { int argsNum = cmdArguments.Length; string[] args = (string[])cmdArguments; // string filename = "yahoo_feed_data.csv"; string filename = "yahoo_feed_data_5y.csv"; switch (argsNum) { case 2: filename = args[1]; break; default: break; } if (filename == null) { iWrite.WriteLine("Filename is not specified"); } else { IDataFeed dataFeed = new FeedYahoo(); bool result = dataFeed.GetSeries(filename, out FeedSeries); TA.PriceVolumeSeries series = FeedSeries; if (result) { iWrite.WriteLine("Parsed " + series.Data.Count + " entries"); } else { iWrite.WriteLine("Failed to read data from server"); } } }
protected void feedGetSeriesCallback(IWrite iWrite, string cmdName, object[] cmdArguments, bool outputToFile) { int argsNum = cmdArguments.Length; string symbol = null; DateTime from = DateTime.Today - TimeSpan.FromDays(30); DateTime to = DateTime.Now; DateTime tmp; bool result = true; string[] args = (string[])cmdArguments; string filename = null; switch (argsNum) { case 1: result = false; break; case 2: if (outputToFile) { result = false; } else { symbol = args[1]; } break; case 3: if (outputToFile) { symbol = args[1]; filename = args[2]; } else { symbol = args[1]; result = DateTime.TryParse(args[2], out tmp); if (result) from = tmp; } break; case 4: if (outputToFile) { symbol = args[1]; filename = args[2]; result = DateTime.TryParse(args[3], out tmp); if (result) from = tmp; } else { symbol = args[1]; result = DateTime.TryParse(args[2], out tmp); if (result) from = tmp; result = DateTime.TryParse(args[3], out tmp); if (result) to = tmp; } break; case 5: default: if (outputToFile) { symbol = args[1]; filename = args[2]; result = DateTime.TryParse(args[3], out tmp); if (result) from = tmp; result = DateTime.TryParse(args[4], out tmp); if (result) to = tmp; } else { symbol = args[1]; result = DateTime.TryParse(args[2], out tmp); if (result) from = tmp; result = DateTime.TryParse(args[3], out tmp); if (result) to = tmp; } break; } if (!result) { iWrite.WriteLine("Please, specify symbol, from and to date"); return; } IDataFeed dataFeed = new FeedYahoo(); result = dataFeed.GetSeries(from, to, new Equity(symbol), DataFeed.DataType.Daily, out FeedSeries); TA.PriceVolumeSeries series = FeedSeries; if (result) { System.IO.FileStream fileStream = null; iWrite.WriteLine("Parsed " + series.Data.Count + " entries"); if (outputToFile) { bool shouldClose = false; try { fileStream = new System.IO.FileStream(filename, FileMode.CreateNew, FileAccess.Write, FileShare.Read); shouldClose = true; StreamWriter streamWriter = new StreamWriter(fileStream); streamWriter.Write(series.ToString(TA.PriceVolumeSeries.Format.Table)); streamWriter.Flush(); fileStream.Close(); shouldClose = false; } catch (IOException e) { iWrite.WriteLine(e.ToString()); } if (shouldClose) { fileStream.Close(); } } else { iWrite.WriteLine(series.ToString(TA.PriceVolumeSeries.Format.Table)); } } else { iWrite.WriteLine("Failed to read data from server"); } }
protected void feedGetSeriesCallback(IWrite iWrite, string cmdName, object[] cmdArguments, bool outputToFile) { int argsNum = cmdArguments.Length; string symbol = null; DateTime from = DateTime.Today - TimeSpan.FromDays(30); DateTime to = DateTime.Now; DateTime tmp; bool result = true; string[] args = (string[])cmdArguments; string filename = null; switch (argsNum) { case 1: result = false; break; case 2: if (outputToFile) { result = false; } else { symbol = args[1]; } break; case 3: if (outputToFile) { symbol = args[1]; filename = args[2]; } else { symbol = args[1]; result = DateTime.TryParse(args[2], out tmp); if (result) { from = tmp; } } break; case 4: if (outputToFile) { symbol = args[1]; filename = args[2]; result = DateTime.TryParse(args[3], out tmp); if (result) { from = tmp; } } else { symbol = args[1]; result = DateTime.TryParse(args[2], out tmp); if (result) { from = tmp; } result = DateTime.TryParse(args[3], out tmp); if (result) { to = tmp; } } break; case 5: default: if (outputToFile) { symbol = args[1]; filename = args[2]; result = DateTime.TryParse(args[3], out tmp); if (result) { from = tmp; } result = DateTime.TryParse(args[4], out tmp); if (result) { to = tmp; } } else { symbol = args[1]; result = DateTime.TryParse(args[2], out tmp); if (result) { from = tmp; } result = DateTime.TryParse(args[3], out tmp); if (result) { to = tmp; } } break; } if (!result) { iWrite.WriteLine("Please, specify symbol, from and to date"); return; } IDataFeed dataFeed = new FeedYahoo(); result = dataFeed.GetSeries(from, to, new Equity(symbol), DataFeed.DataType.Daily, out FeedSeries); TA.PriceVolumeSeries series = FeedSeries; if (result) { System.IO.FileStream fileStream = null; iWrite.WriteLine("Parsed " + series.Data.Count + " entries"); if (outputToFile) { bool shouldClose = false; try { fileStream = new System.IO.FileStream(filename, FileMode.CreateNew, FileAccess.Write, FileShare.Read); shouldClose = true; StreamWriter streamWriter = new StreamWriter(fileStream); streamWriter.Write(series.ToString(TA.PriceVolumeSeries.Format.Table)); streamWriter.Flush(); fileStream.Close(); shouldClose = false; } catch (IOException e) { iWrite.WriteLine(e.ToString()); } if (shouldClose) { fileStream.Close(); } } else { iWrite.WriteLine(series.ToString(TA.PriceVolumeSeries.Format.Table)); } } else { iWrite.WriteLine("Failed to read data from server"); } }