public static async Task <bool> Run() { var symbols = SqlExecutor.GetSymbols(); var pathToScriptFile = @"DBScripts\StockDataTables\SelectStockBySymbol.sql"; var sqlScript = File.ReadAllText(Common.GetScriptPath(pathToScriptFile)); DataTable dt; foreach (var symbol in symbols) { var paramCollection = new List <KeyValuePair <string, string> >(); paramCollection.Add(new KeyValuePair <string, string>(Common.SymbolIdColumn, symbol.Id.ToString())); sqlScript = sqlScript.Replace(Common.TableNameOld, symbol.Symbol[0].ToString() + Common.TableNameSuffix); dt = StockDataLoader.MakeStockTable(symbol.Symbol[0].ToString() + Common.TableNameSuffix); SqlExecutor.ExecuteQueryFillDataTable(sqlScript, paramCollection, dt); Console.WriteLine(string.Format("Calculate SMA for Symbol:{0}", symbol.Symbol)); ////for (int i = 0; i < dt.Rows.Count; i++) ////{ //// CalculateSMA(5, i, dt); //// CalculateSMA(10, i, dt); //// CalculateSMA(30, i, dt); //// CalculateSMA(60, i, dt); ////} dt.AcceptChanges(); var ret = await SqlExecutor.BulkCopy(dt); } return(true); }
static void Main(string[] args) { DateTime now = DateTime.Now; Console.WriteLine(string.Format("Start at: {0}", now.ToString())); var options = new Options(); var parser = new Parser(); var updatePeriod = Convert.ToInt32(ConfigurationManager.AppSettings["UpdatePeriod"]); if (parser.ParseArguments(args, options)) { if (options.Verbose) { Common.Verbose = true; } if (options.ReRun) { //re run everything DBInitializer.DropAllTables(); DBInitializer.CreateAllTables(); SymbolLoader.LoadSymbols(); var ret = StockDataLoader.LoadStockPrice(0).Result; AnalyzerCoordinator.RunAnalysis(); } else if (options.Update) { DBInitializer.InitialzeForUpdate(); SymbolLoader.LoadSymbols(); var ret = StockDataLoader.LoadStockPrice(updatePeriod).Result; AnalyzerCoordinator.RunAnalysis(updatePeriod); } else if (options.LoadStockData) { DBInitializer.InitialzeForLoadOnly(); var ret = StockDataLoader.LoadStockPrice(0).Result; } else if (options.Analysis) { DBInitializer.InitialzeForAnalysisOnly(); AnalyzerCoordinator.RunAnalysis(); } else if (options.Alert) { } } double totalMins = DateTime.Now.Subtract(now).TotalMinutes; Console.WriteLine(string.Format("End at: {0}. Total Minutes {1}", DateTime.Now.ToString(), totalMins.ToString())); Console.ReadKey(); }
private static DataTable GetPrices(int symbolId, string symbol, int updatePeriod) { var date = Convert.ToDateTime(ConfigurationManager.AppSettings["StartTime"]); if (updatePeriod > 0) { date = DateTime.Now.Subtract(TimeSpan.FromDays(updatePeriod + 1)); } var paramCollection = new List <KeyValuePair <string, string> >(); paramCollection.Add(new KeyValuePair <string, string>(Common.SymbolIdColumn, symbolId.ToString())); paramCollection.Add(new KeyValuePair <string, string>(Common.DateColumn, date.ToString())); var newSqlScript = selectStockBySymbolSqlScript.Replace(Common.TableNameOld, symbol[0].ToString() + Common.TableNameSuffix); var dt = StockDataLoader.MakeStockTable(symbol[0].ToString() + Common.TableNameSuffix); SqlExecutor.ExecuteQueryFillDataTable(newSqlScript, paramCollection, dt); return(dt); }