diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 8138dd6..d99d9d1 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -7,7 +7,7 @@ "type": "process", "args": [ "build", - "${workspaceFolder}/MarketData/MarketData.sln", + "${workspaceFolder}/MarketData.sln", "/property:GenerateFullPaths=true", "/consoleloggerparameters:NoSummary;ForceNoAlign" ], @@ -19,7 +19,7 @@ "type": "process", "args": [ "publish", - "${workspaceFolder}/MarketData/MarketData.sln", + "${workspaceFolder}/MarketData.sln", "/property:GenerateFullPaths=true", "/consoleloggerparameters:NoSummary;ForceNoAlign" ], @@ -33,9 +33,14 @@ "watch", "run", "--project", - "${workspaceFolder}/MarketData/MarketData.sln" + "${workspaceFolder}/MarketData.sln" ], "problemMatcher": "$msCompile" + }, + { + "label": "echo", + "type": "shell", + "command": "echo ${workspaceFolder}" } ] } \ No newline at end of file diff --git a/MarketData/MarketDataLib/Cache/LocalPriceCache.cs b/MarketData/MarketDataLib/Cache/LocalPriceCache.cs index ce81e89..0517037 100755 --- a/MarketData/MarketDataLib/Cache/LocalPriceCache.cs +++ b/MarketData/MarketDataLib/Cache/LocalPriceCache.cs @@ -3,14 +3,15 @@ using MarketData.Utils; using MarketData.DataAccess; // This cache is mainly used by gainloss generator. This cache is intended to be front loaded and then used. -// This cache will not attempt to load an item that is not found. It does have a Refresh() that will reload only the most recent pricing data from the database in order to -// maintain the most updated pricing. +// This cache will not attempt to load an item that is not found. It does have a Refresh() that will reload only the most recent +// pricing data from the database in order to maintain the most updated pricing. namespace MarketData.Cache { public class LocalPriceCache { private Dictionary priceCache=new Dictionary(); private static LocalPriceCache instance=null; + private DateTime latestDate = Utility.Epoch; private Thread cacheMonitorThread=null; private volatile bool threadRun=true; private int cacheCycle=300000; @@ -26,7 +27,8 @@ namespace MarketData.Cache { lock(thisLock) { - priceCache=new Dictionary(); + priceCache=new Dictionary(); + RefreshLatestDate(); } } @@ -51,18 +53,38 @@ namespace MarketData.Cache { lock(typeof(LocalPriceCache)) { - if(null==instance)instance=new LocalPriceCache(); + if(null==instance) + { + instance=new LocalPriceCache(); + instance.RefreshLatestDate(); + } return instance; } } + public void RefreshLatestDate() + { + lock(typeof(LocalPriceCache)) + { + latestDate=PricingDA.GetLatestDate(); + } + } + + public DateTime GetLatestDate() + { + lock(typeof(LocalPriceCache)) + { + return latestDate; + } + } + public void Refresh() { lock(typeof(LocalPriceCache)) { List symbols=new List(priceCache.Keys); Dictionary maxDbDates = PricingDA.GetLatestDates(symbols); - + RefreshLatestDate(); foreach(String symbol in symbols) { PricesByDate symbolPrices=priceCache[symbol]; diff --git a/MarketData/MarketDataLib/DataAccess/PricingDA.cs b/MarketData/MarketDataLib/DataAccess/PricingDA.cs index b83fa77..9138cc5 100755 --- a/MarketData/MarketDataLib/DataAccess/PricingDA.cs +++ b/MarketData/MarketDataLib/DataAccess/PricingDA.cs @@ -682,6 +682,7 @@ namespace MarketData.DataAccess try { + if(null == symbols || 0==symbols.Count)return dictionary; StringBuilder sb = new StringBuilder(); sqlConnection = SqlUtils.CreateMySqlConnection(MainDataSource.Instance.LocateDataSource("market_data")); sb.Append("select symbol, company from securitymaster where symbol in "); diff --git a/MarketData/MarketDataLib/Generator/GainLoss/ActiveGainLossGenerator.cs b/MarketData/MarketDataLib/Generator/GainLoss/ActiveGainLossGenerator.cs index cfa3ecf..b6ceb35 100755 --- a/MarketData/MarketDataLib/Generator/GainLoss/ActiveGainLossGenerator.cs +++ b/MarketData/MarketDataLib/Generator/GainLoss/ActiveGainLossGenerator.cs @@ -16,10 +16,6 @@ namespace MarketData.Generator.GainLoss public ActiveGainLossGenerator() { } - //public void RefreshPriceCache() - //{ - // LocalPriceCache.GetInstance().Refresh(); - //} // ***************************************************************************************************************************************************************** // ************************************************ G E N E R A T E A C T I V E G A I N L O S S / G A I N L O S S P E R C E N T ***************************** // ***************************************************************************************************************************************************************** @@ -28,7 +24,8 @@ namespace MarketData.Generator.GainLoss if (null == portfolioTrades || 0 == portfolioTrades.Count) return null; LocalPriceCache.GetInstance().Add(portfolioTrades); DateTime minTradeDate = portfolioTrades.GetMinTradeDate(); - DateTime maxDate = PricingDA.GetLatestDate(); +// DateTime maxDate = PricingDA.GetLatestDate(); + DateTime maxDate=LocalPriceCache.GetInstance().GetLatestDate(); if(null!=maxDateRef)maxDate=maxDateRef.Value; Dictionary gainLoss = new Dictionary(); DateGenerator dateGenerator = new DateGenerator(); diff --git a/MarketData/MarketDataLib/Generator/GainLoss/GainLossGenerator.cs b/MarketData/MarketDataLib/Generator/GainLoss/GainLossGenerator.cs index de5c20e..4f705b2 100755 --- a/MarketData/MarketDataLib/Generator/GainLoss/GainLossGenerator.cs +++ b/MarketData/MarketDataLib/Generator/GainLoss/GainLossGenerator.cs @@ -24,7 +24,8 @@ namespace MarketData.Generator.GainLoss if (null == portfolioTrades || 0 == portfolioTrades.Count) return null; LocalPriceCache.GetInstance().Add(portfolioTrades); DateTime minTradeDate = portfolioTrades.GetMinTradeDate(); - DateTime maxDate = PricingDA.GetLatestDate(); +// DateTime maxDate = PricingDA.GetLatestDate(); + DateTime maxDate=LocalPriceCache.GetInstance().GetLatestDate(); if(null!=maxDateRef)maxDate=maxDateRef.Value; Dictionary gainLossCollection = new Dictionary(); DateGenerator dateGenerator = new DateGenerator(); diff --git a/MarketData/MarketDataLib/MarketDataModel/GainLoss/GainLossSummaryItemCollection.cs b/MarketData/MarketDataLib/MarketDataModel/GainLoss/GainLossSummaryItemCollection.cs index 4f34039..2e2440c 100755 --- a/MarketData/MarketDataLib/MarketDataModel/GainLoss/GainLossSummaryItemCollection.cs +++ b/MarketData/MarketDataLib/MarketDataModel/GainLoss/GainLossSummaryItemCollection.cs @@ -99,8 +99,8 @@ namespace MarketData.MarketDataModel.GainLoss public GainLossSummaryItemCollection(PortfolioTrades portfolioTrades,DateTime? maxDateRef=null) { List symbols=portfolioTrades.Symbols; - Dictionary stopLimits = PortfolioDA.HasStopLimit(symbols); + Dictionary namesDictionary = PricingDA.GetNamesForSymbols(symbols); foreach(String symbol in symbols) { @@ -114,7 +114,8 @@ namespace MarketData.MarketDataModel.GainLoss GainLossSummaryItem gainLossSummaryItem=new GainLossSummaryItem(); gainLossSummaryItem.Date=gainLossCompoundModelCollection[gainLossCompoundModelCollection.Count-1].Date; gainLossSummaryItem.Symbol=symbol; - gainLossSummaryItem.CompanyName=PricingDA.GetNameForSymbol(symbol); +// gainLossSummaryItem.CompanyName=PricingDA.GetNameForSymbol(symbol); + gainLossSummaryItem.CompanyName=namesDictionary.ContainsKey(symbol)?namesDictionary[symbol]:""; gainLossSummaryItem.CurrentGainLoss=gainLossCompoundModelCollection[gainLossCompoundModelCollection.Count-1].ActiveGainLoss; double previousGainLoss=1==gainLossCompoundModelCollection.Count?0.00:gainLossCompoundModelCollection[gainLossCompoundModelCollection.Count-2].ActiveGainLoss; gainLossSummaryItem.PreviousGainLoss=previousGainLoss; diff --git a/MarketData/MarketDataLib/MarketDataModel/PricesByDate.cs b/MarketData/MarketDataLib/MarketDataModel/PricesByDate.cs index 9877dd3..0d68c4e 100755 --- a/MarketData/MarketDataLib/MarketDataModel/PricesByDate.cs +++ b/MarketData/MarketDataLib/MarketDataModel/PricesByDate.cs @@ -21,11 +21,8 @@ namespace MarketData.MarketDataModel if(Utility.IsEpoch(key))return; base.Add(key,price); if(key>maxDate) maxDate=key; -// if(!Utility.IsEpoch(minDate) && key