Code enhancements
This commit is contained in:
@@ -13,6 +13,8 @@ namespace MarketData.Services
|
||||
{
|
||||
public class MainService : IMainService
|
||||
{
|
||||
private Dictionary<String, Func<CommandArgs,Task>> tasks = new Dictionary<String,Func<CommandArgs,Task>>();
|
||||
|
||||
/// <summary>
|
||||
/// This is the main entry point
|
||||
/// </summary>
|
||||
@@ -21,84 +23,49 @@ namespace MarketData.Services
|
||||
public void RunService(String[] args,IConfiguration configuration)
|
||||
{
|
||||
Profiler profiler = new Profiler();
|
||||
MDTrace.LogLevel = LogLevel.DEBUG;
|
||||
String strLogFile = "marketdata.log";
|
||||
Utility.DeleteFile(strLogFile);
|
||||
Trace.Listeners.Add(new TextWriterTraceListener(strLogFile));
|
||||
DateTime currentDate=DateTime.Now;
|
||||
|
||||
MDTrace.WriteLine(LogLevel.DEBUG,$"[RunService] Started @ {Utility.DateTimeToStringYYYYHMMHDDHHMMSSTT(currentDate)}");
|
||||
Trace.Listeners.Remove("Default");
|
||||
|
||||
tasks.Add("LOADHEADLINESWATCHLIST",TaskLoadHeadlinesWatchList);
|
||||
tasks.Add("LOADPREMARKETDATA",TaskLoadPremarketData);
|
||||
tasks.Add("UPDATEDAILY2",TaskUpdateDaily2);
|
||||
tasks.Add("UPDATELATESTPRICEOPENPOSITIONS",TaskUpdateLatestPriceOpenPositions);
|
||||
tasks.Add("UPDATELATESTPRICEWATCHLIST",TaskUpdateLatestPriceWatchList);
|
||||
tasks.Add("UPDATELATESTANALYSTRATINGS",TaskUpdateLatestAnalystRatings);
|
||||
tasks.Add("UPDATEANALYSTRATINGS",TaskUpdateAnalystRatings);
|
||||
tasks.Add("ECHO",TaskEcho);
|
||||
|
||||
GlobalConfig.Instance.Configuration = configuration; // This call sets up configuration stuff so it needs to be first.
|
||||
if (args.Length < 1 || String.IsNullOrEmpty(args[0]))
|
||||
{
|
||||
DisplayUsage();
|
||||
return;
|
||||
}
|
||||
|
||||
string arg = args[0].ToUpper();
|
||||
|
||||
CreateLogging(arg); // log files are now of the form market_data+task.log. Also log files will expire daily
|
||||
|
||||
MDTrace.WriteLine(LogLevel.DEBUG,$"[RunService] Started @ {Utility.DateTimeToStringYYYYHMMHDDHHMMSSTT(currentDate)}");
|
||||
MDTrace.WriteLine(LogLevel.DEBUG,$"[RunService] Argument {arg}");
|
||||
|
||||
DateTime maxHolidayDate =HolidayDA.GetMaxHolidayDate();
|
||||
if(currentDate>maxHolidayDate)
|
||||
{
|
||||
Console.WriteLine(String.Format("There are no holidays defined in the system. Add holidays for year {0} into marketholidays table",currentDate.Year));
|
||||
MDTrace.WriteLine(LogLevel.DEBUG,String.Format("There are no holidays defined in the system. Add holidays for year {0} into marketholidays table",currentDate.Year));
|
||||
return;
|
||||
}
|
||||
|
||||
if (args.Length < 1)
|
||||
if(!tasks.ContainsKey(arg))
|
||||
{
|
||||
DisplayUsage();
|
||||
DisplayUsage();
|
||||
return;
|
||||
}
|
||||
|
||||
string arg = args[0].ToUpper();
|
||||
MDTrace.WriteLine(LogLevel.DEBUG,$"[RunService] Argument {arg}");
|
||||
|
||||
try
|
||||
{
|
||||
if(arg.Equals("LOADHEADLINESWATCHLIST"))
|
||||
{
|
||||
CommandArgs commandArgs=new CommandArgs(args);
|
||||
if(!commandArgs.Has("WATCHLIST")){Console.WriteLine("LOADHEADLINESWATCHLIST REQUIRES WATCHLIST");return;}
|
||||
else LoadHeadlinesWatchList(commandArgs.Coalesce<String>("WATCHLIST"));
|
||||
}
|
||||
else if(arg.Equals("LOADPREMARKETDATA"))
|
||||
{
|
||||
LoadPremarketData();
|
||||
}
|
||||
else if (arg.Equals("UPDATEDAILY2"))
|
||||
{
|
||||
CommandArgs commandArgs=new CommandArgs(args);
|
||||
if(!commandArgs.Has("DATE")){Console.WriteLine("UPDATEDAILY2 MISSING DATE");return;}
|
||||
UpdateDaily2(commandArgs.Coalesce<DateTime>("DATE"));
|
||||
}
|
||||
else if (arg.Equals("UPDATELATESTPRICEOPENPOSITIONS"))
|
||||
{
|
||||
UpdateLatestPriceOpenPositions();
|
||||
}
|
||||
else if (arg.Equals("UPDATELATESTPRICEWATCHLIST"))
|
||||
{
|
||||
CommandArgs commandArgs=new CommandArgs(args);
|
||||
if(!commandArgs.Has("WATCHLIST")){Console.WriteLine("UPDATELATESTPRICEWATCHLIST MISSING WATCHLIST");return;}
|
||||
UpdateLatestPriceWatchList(commandArgs.Coalesce<String>("WATCHLIST"));
|
||||
}
|
||||
else if (arg.Equals("UPDATELATESTANALYSTRATINGS"))
|
||||
{
|
||||
CommandArgs commandArgs = new CommandArgs(args);
|
||||
if (commandArgs.Has("UPDATESECURITYMASTER")) UpdateLatestAnalystRatings(commandArgs.Coalesce<Boolean>("UPDATESECURITYMASTER"));
|
||||
else UpdateLatestAnalystRatings();
|
||||
}
|
||||
else if (arg.Equals("UPDATEANALYSTRATINGS"))
|
||||
{
|
||||
CommandArgs commandArgs = new CommandArgs(args);
|
||||
if (commandArgs.Has("SYMBOL") && commandArgs.Has("MINDATE")) UpdateAnalystRatings(commandArgs.Coalesce<String>("SYMBOL"), commandArgs.Coalesce<DateTime>("MINDATE"));
|
||||
else if (commandArgs.Has("SYMBOL") ) UpdateAnalystRatings(commandArgs.Coalesce<String>("SYMBOL"));
|
||||
else if (commandArgs.Has("MINDATE")) UpdateAnalystRatings(null,commandArgs.Coalesce<DateTime>("MINDATE"));
|
||||
else UpdateAnalystRatings();
|
||||
}
|
||||
else if(arg.Equals("ECHO"))
|
||||
{
|
||||
MDTrace.WriteLine(LogLevel.DEBUG,$"ECHO");
|
||||
for(int index =0; index<args.Length;index++)
|
||||
{
|
||||
MDTrace.WriteLine(LogLevel.DEBUG,$"ARG[{index}]:{args[index]}");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
DisplayUsage();
|
||||
}
|
||||
tasks[arg](new CommandArgs(args));
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
@@ -110,9 +77,85 @@ namespace MarketData.Services
|
||||
LocalPriceCache.GetInstance().Dispose();
|
||||
GBPriceCache.GetInstance().Dispose();
|
||||
}
|
||||
|
||||
MDTrace.WriteLine(LogLevel.DEBUG,$"[RunService] Done, total took {profiler.End()}(ms)");
|
||||
}
|
||||
|
||||
public async Task TaskLoadHeadlinesWatchList(CommandArgs commandArgs)
|
||||
{
|
||||
if(!commandArgs.Has("WATCHLIST")){Console.WriteLine("LOADHEADLINESWATCHLIST REQUIRES WATCHLIST");return;}
|
||||
else LoadHeadlinesWatchList(commandArgs.Coalesce<String>("WATCHLIST"));
|
||||
await Task.FromResult(true);
|
||||
}
|
||||
|
||||
public async Task TaskLoadPremarketData(CommandArgs commandArgs)
|
||||
{
|
||||
LoadPremarketData();
|
||||
await Task.FromResult(true);
|
||||
}
|
||||
|
||||
public async Task TaskUpdateDaily2(CommandArgs commandArgs)
|
||||
{
|
||||
if(!commandArgs.Has("DATE")){Console.WriteLine("UPDATEDAILY2 MISSING DATE");return;}
|
||||
UpdateDaily2(commandArgs.Coalesce<DateTime>("DATE"));
|
||||
await Task.FromResult(true);
|
||||
}
|
||||
|
||||
public async Task TaskUpdateLatestPriceOpenPositions(CommandArgs commandArgs)
|
||||
{
|
||||
UpdateLatestPriceOpenPositions();
|
||||
await Task.FromResult(true);
|
||||
}
|
||||
|
||||
public async Task TaskUpdateLatestPriceWatchList(CommandArgs commandArgs)
|
||||
{
|
||||
if(!commandArgs.Has("WATCHLIST")){Console.WriteLine("UPDATELATESTPRICEWATCHLIST MISSING WATCHLIST");return;}
|
||||
UpdateLatestPriceWatchList(commandArgs.Coalesce<String>("WATCHLIST"));
|
||||
await Task.FromResult(true);
|
||||
}
|
||||
|
||||
public async Task TaskUpdateLatestAnalystRatings(CommandArgs commandArgs)
|
||||
{
|
||||
if (commandArgs.Has("UPDATESECURITYMASTER")) UpdateLatestAnalystRatings(commandArgs.Coalesce<Boolean>("UPDATESECURITYMASTER"));
|
||||
else UpdateLatestAnalystRatings();
|
||||
await Task.FromResult(true);
|
||||
}
|
||||
|
||||
public async Task TaskUpdateAnalystRatings(CommandArgs commandArgs)
|
||||
{
|
||||
if (commandArgs.Has("SYMBOL") && commandArgs.Has("MINDATE")) UpdateAnalystRatings(commandArgs.Coalesce<String>("SYMBOL"), commandArgs.Coalesce<DateTime>("MINDATE"));
|
||||
else if (commandArgs.Has("SYMBOL") ) UpdateAnalystRatings(commandArgs.Coalesce<String>("SYMBOL"));
|
||||
else if (commandArgs.Has("MINDATE")) UpdateAnalystRatings(null,commandArgs.Coalesce<DateTime>("MINDATE"));
|
||||
else UpdateAnalystRatings();
|
||||
await Task.FromResult(true);
|
||||
}
|
||||
|
||||
public async Task TaskEcho(CommandArgs commandArgs)
|
||||
{
|
||||
String[] args = commandArgs.GetArguments();
|
||||
MDTrace.WriteLine(LogLevel.DEBUG,$"ECHO");
|
||||
for(int index =0; index<args.Count();index++)
|
||||
{
|
||||
MDTrace.WriteLine(LogLevel.DEBUG,$"ARG[{index}]:{args[index]}");
|
||||
}
|
||||
await Task.FromResult(true);
|
||||
}
|
||||
|
||||
private static void CreateLogging(String task)
|
||||
{
|
||||
if(null == task) return;
|
||||
task=task.ToLower();
|
||||
MDTrace.LogLevel = LogLevel.DEBUG;
|
||||
String logFolder = "/logs";
|
||||
DateTime currentDate=DateTime.Now;
|
||||
String strLogFile = "marketdata_" + task + ".log";
|
||||
String currentWorkingDirectory = Directory.GetCurrentDirectory();
|
||||
Console.WriteLine($"Current directory is {currentWorkingDirectory}");
|
||||
Utility.EnsureLogFolder(currentWorkingDirectory+logFolder);
|
||||
Utility.ExpireLogs(currentWorkingDirectory+logFolder,1);
|
||||
Trace.Listeners.Add(new TextWriterTraceListener(currentWorkingDirectory+logFolder+"/"+strLogFile));
|
||||
}
|
||||
|
||||
// *********************************************************************************************************************************
|
||||
// *********************************************************************************************************************************
|
||||
// *********************************************************************************************************************************
|
||||
@@ -124,9 +167,9 @@ namespace MarketData.Services
|
||||
MDTrace.WriteLine(LogLevel.DEBUG,$"LOADPREMARKETDATA");
|
||||
MDTrace.WriteLine(LogLevel.DEBUG,"UPDATEDAILY2 /DATE: - updates prices, yields, and ratings");
|
||||
MDTrace.WriteLine(LogLevel.DEBUG,"UPDATEANALYSTRATINGS");
|
||||
MDTrace.WriteLine(LogLevel.DEBUG,"UPDATELATESTANALYSTRATINGS");
|
||||
MDTrace.WriteLine(LogLevel.DEBUG,"UPDATELATESTPRICEWATCHLIST /WATCHLIST:");
|
||||
MDTrace.WriteLine(LogLevel.DEBUG,"UPDATELATESTPRICEOPENPOSITIONS");
|
||||
MDTrace.WriteLine(LogLevel.DEBUG,"UPDATELATESTPRICEOPENPOSITIONS");
|
||||
}
|
||||
|
||||
// **********************************************************************************************************************************************
|
||||
@@ -166,7 +209,6 @@ namespace MarketData.Services
|
||||
if(null==result||!(result.ToUpper().Equals("Y")||result.ToUpper().Equals("YES")))return;
|
||||
}
|
||||
MDTrace.WriteLine(LogLevel.DEBUG,$"UPDATEDAILY2 DATE:{startDate.ToShortDateString()}");
|
||||
Utility.RemoveLogFilesExcept("marketdata.log"); // don't remove the current log file
|
||||
int STAGE_1=0,STAGE_2=1,STAGE_3=2,STAGE_4=3,STAGE_5=4,STAGE_6=5,STAGE_7=6,STAGE_8=7,STAGE_9=8,STAGE_10=9,STAGE_11=10,STAGE_12=11,STAGE_FINAL=12;
|
||||
DeletePriceWatchList("valuations",startDate.ToShortDateString());
|
||||
DeletePriceWatchList("Momentum",startDate.ToShortDateString());
|
||||
|
||||
Reference in New Issue
Block a user