Add LatestPricingDate to LocalPriceCache and optimize company name retrieval
This commit is contained in:
11
.vscode/tasks.json
vendored
11
.vscode/tasks.json
vendored
@@ -7,7 +7,7 @@
|
|||||||
"type": "process",
|
"type": "process",
|
||||||
"args": [
|
"args": [
|
||||||
"build",
|
"build",
|
||||||
"${workspaceFolder}/MarketData/MarketData.sln",
|
"${workspaceFolder}/MarketData.sln",
|
||||||
"/property:GenerateFullPaths=true",
|
"/property:GenerateFullPaths=true",
|
||||||
"/consoleloggerparameters:NoSummary;ForceNoAlign"
|
"/consoleloggerparameters:NoSummary;ForceNoAlign"
|
||||||
],
|
],
|
||||||
@@ -19,7 +19,7 @@
|
|||||||
"type": "process",
|
"type": "process",
|
||||||
"args": [
|
"args": [
|
||||||
"publish",
|
"publish",
|
||||||
"${workspaceFolder}/MarketData/MarketData.sln",
|
"${workspaceFolder}/MarketData.sln",
|
||||||
"/property:GenerateFullPaths=true",
|
"/property:GenerateFullPaths=true",
|
||||||
"/consoleloggerparameters:NoSummary;ForceNoAlign"
|
"/consoleloggerparameters:NoSummary;ForceNoAlign"
|
||||||
],
|
],
|
||||||
@@ -33,9 +33,14 @@
|
|||||||
"watch",
|
"watch",
|
||||||
"run",
|
"run",
|
||||||
"--project",
|
"--project",
|
||||||
"${workspaceFolder}/MarketData/MarketData.sln"
|
"${workspaceFolder}/MarketData.sln"
|
||||||
],
|
],
|
||||||
"problemMatcher": "$msCompile"
|
"problemMatcher": "$msCompile"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "echo",
|
||||||
|
"type": "shell",
|
||||||
|
"command": "echo ${workspaceFolder}"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
@@ -3,14 +3,15 @@ using MarketData.Utils;
|
|||||||
using MarketData.DataAccess;
|
using MarketData.DataAccess;
|
||||||
|
|
||||||
// This cache is mainly used by gainloss generator. This cache is intended to be front loaded and then used.
|
// 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
|
// 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
|
||||||
// maintain the most updated pricing.
|
// pricing data from the database in order to maintain the most updated pricing.
|
||||||
namespace MarketData.Cache
|
namespace MarketData.Cache
|
||||||
{
|
{
|
||||||
public class LocalPriceCache
|
public class LocalPriceCache
|
||||||
{
|
{
|
||||||
private Dictionary<String,PricesByDate> priceCache=new Dictionary<String,PricesByDate>();
|
private Dictionary<String,PricesByDate> priceCache=new Dictionary<String,PricesByDate>();
|
||||||
private static LocalPriceCache instance=null;
|
private static LocalPriceCache instance=null;
|
||||||
|
private DateTime latestDate = Utility.Epoch;
|
||||||
private Thread cacheMonitorThread=null;
|
private Thread cacheMonitorThread=null;
|
||||||
private volatile bool threadRun=true;
|
private volatile bool threadRun=true;
|
||||||
private int cacheCycle=300000;
|
private int cacheCycle=300000;
|
||||||
@@ -27,6 +28,7 @@ namespace MarketData.Cache
|
|||||||
lock(thisLock)
|
lock(thisLock)
|
||||||
{
|
{
|
||||||
priceCache=new Dictionary<String,PricesByDate>();
|
priceCache=new Dictionary<String,PricesByDate>();
|
||||||
|
RefreshLatestDate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -51,18 +53,38 @@ namespace MarketData.Cache
|
|||||||
{
|
{
|
||||||
lock(typeof(LocalPriceCache))
|
lock(typeof(LocalPriceCache))
|
||||||
{
|
{
|
||||||
if(null==instance)instance=new LocalPriceCache();
|
if(null==instance)
|
||||||
|
{
|
||||||
|
instance=new LocalPriceCache();
|
||||||
|
instance.RefreshLatestDate();
|
||||||
|
}
|
||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void RefreshLatestDate()
|
||||||
|
{
|
||||||
|
lock(typeof(LocalPriceCache))
|
||||||
|
{
|
||||||
|
latestDate=PricingDA.GetLatestDate();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public DateTime GetLatestDate()
|
||||||
|
{
|
||||||
|
lock(typeof(LocalPriceCache))
|
||||||
|
{
|
||||||
|
return latestDate;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void Refresh()
|
public void Refresh()
|
||||||
{
|
{
|
||||||
lock(typeof(LocalPriceCache))
|
lock(typeof(LocalPriceCache))
|
||||||
{
|
{
|
||||||
List<String> symbols=new List<String>(priceCache.Keys);
|
List<String> symbols=new List<String>(priceCache.Keys);
|
||||||
Dictionary<String, DateTime> maxDbDates = PricingDA.GetLatestDates(symbols);
|
Dictionary<String, DateTime> maxDbDates = PricingDA.GetLatestDates(symbols);
|
||||||
|
RefreshLatestDate();
|
||||||
foreach(String symbol in symbols)
|
foreach(String symbol in symbols)
|
||||||
{
|
{
|
||||||
PricesByDate symbolPrices=priceCache[symbol];
|
PricesByDate symbolPrices=priceCache[symbol];
|
||||||
|
|||||||
@@ -682,6 +682,7 @@ namespace MarketData.DataAccess
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
if(null == symbols || 0==symbols.Count)return dictionary;
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
sqlConnection = SqlUtils.CreateMySqlConnection(MainDataSource.Instance.LocateDataSource("market_data"));
|
sqlConnection = SqlUtils.CreateMySqlConnection(MainDataSource.Instance.LocateDataSource("market_data"));
|
||||||
sb.Append("select symbol, company from securitymaster where symbol in ");
|
sb.Append("select symbol, company from securitymaster where symbol in ");
|
||||||
|
|||||||
@@ -16,10 +16,6 @@ namespace MarketData.Generator.GainLoss
|
|||||||
public ActiveGainLossGenerator()
|
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 *****************************
|
// ************************************************ 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;
|
if (null == portfolioTrades || 0 == portfolioTrades.Count) return null;
|
||||||
LocalPriceCache.GetInstance().Add(portfolioTrades);
|
LocalPriceCache.GetInstance().Add(portfolioTrades);
|
||||||
DateTime minTradeDate = portfolioTrades.GetMinTradeDate();
|
DateTime minTradeDate = portfolioTrades.GetMinTradeDate();
|
||||||
DateTime maxDate = PricingDA.GetLatestDate();
|
// DateTime maxDate = PricingDA.GetLatestDate();
|
||||||
|
DateTime maxDate=LocalPriceCache.GetInstance().GetLatestDate();
|
||||||
if(null!=maxDateRef)maxDate=maxDateRef.Value;
|
if(null!=maxDateRef)maxDate=maxDateRef.Value;
|
||||||
Dictionary<DateTime,GainLossItem> gainLoss = new Dictionary<DateTime, GainLossItem>();
|
Dictionary<DateTime,GainLossItem> gainLoss = new Dictionary<DateTime, GainLossItem>();
|
||||||
DateGenerator dateGenerator = new DateGenerator();
|
DateGenerator dateGenerator = new DateGenerator();
|
||||||
|
|||||||
@@ -24,7 +24,8 @@ namespace MarketData.Generator.GainLoss
|
|||||||
if (null == portfolioTrades || 0 == portfolioTrades.Count) return null;
|
if (null == portfolioTrades || 0 == portfolioTrades.Count) return null;
|
||||||
LocalPriceCache.GetInstance().Add(portfolioTrades);
|
LocalPriceCache.GetInstance().Add(portfolioTrades);
|
||||||
DateTime minTradeDate = portfolioTrades.GetMinTradeDate();
|
DateTime minTradeDate = portfolioTrades.GetMinTradeDate();
|
||||||
DateTime maxDate = PricingDA.GetLatestDate();
|
// DateTime maxDate = PricingDA.GetLatestDate();
|
||||||
|
DateTime maxDate=LocalPriceCache.GetInstance().GetLatestDate();
|
||||||
if(null!=maxDateRef)maxDate=maxDateRef.Value;
|
if(null!=maxDateRef)maxDate=maxDateRef.Value;
|
||||||
Dictionary<DateTime,TotalGainLossItem> gainLossCollection = new Dictionary<DateTime, TotalGainLossItem>();
|
Dictionary<DateTime,TotalGainLossItem> gainLossCollection = new Dictionary<DateTime, TotalGainLossItem>();
|
||||||
DateGenerator dateGenerator = new DateGenerator();
|
DateGenerator dateGenerator = new DateGenerator();
|
||||||
|
|||||||
@@ -99,8 +99,8 @@ namespace MarketData.MarketDataModel.GainLoss
|
|||||||
public GainLossSummaryItemCollection(PortfolioTrades portfolioTrades,DateTime? maxDateRef=null)
|
public GainLossSummaryItemCollection(PortfolioTrades portfolioTrades,DateTime? maxDateRef=null)
|
||||||
{
|
{
|
||||||
List<String> symbols=portfolioTrades.Symbols;
|
List<String> symbols=portfolioTrades.Symbols;
|
||||||
|
|
||||||
Dictionary<String,bool> stopLimits = PortfolioDA.HasStopLimit(symbols);
|
Dictionary<String,bool> stopLimits = PortfolioDA.HasStopLimit(symbols);
|
||||||
|
Dictionary<String,String> namesDictionary = PricingDA.GetNamesForSymbols(symbols);
|
||||||
|
|
||||||
foreach(String symbol in symbols)
|
foreach(String symbol in symbols)
|
||||||
{
|
{
|
||||||
@@ -114,7 +114,8 @@ namespace MarketData.MarketDataModel.GainLoss
|
|||||||
GainLossSummaryItem gainLossSummaryItem=new GainLossSummaryItem();
|
GainLossSummaryItem gainLossSummaryItem=new GainLossSummaryItem();
|
||||||
gainLossSummaryItem.Date=gainLossCompoundModelCollection[gainLossCompoundModelCollection.Count-1].Date;
|
gainLossSummaryItem.Date=gainLossCompoundModelCollection[gainLossCompoundModelCollection.Count-1].Date;
|
||||||
gainLossSummaryItem.Symbol=symbol;
|
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;
|
gainLossSummaryItem.CurrentGainLoss=gainLossCompoundModelCollection[gainLossCompoundModelCollection.Count-1].ActiveGainLoss;
|
||||||
double previousGainLoss=1==gainLossCompoundModelCollection.Count?0.00:gainLossCompoundModelCollection[gainLossCompoundModelCollection.Count-2].ActiveGainLoss;
|
double previousGainLoss=1==gainLossCompoundModelCollection.Count?0.00:gainLossCompoundModelCollection[gainLossCompoundModelCollection.Count-2].ActiveGainLoss;
|
||||||
gainLossSummaryItem.PreviousGainLoss=previousGainLoss;
|
gainLossSummaryItem.PreviousGainLoss=previousGainLoss;
|
||||||
|
|||||||
@@ -21,11 +21,8 @@ namespace MarketData.MarketDataModel
|
|||||||
if(Utility.IsEpoch(key))return;
|
if(Utility.IsEpoch(key))return;
|
||||||
base.Add(key,price);
|
base.Add(key,price);
|
||||||
if(key>maxDate) maxDate=key;
|
if(key>maxDate) maxDate=key;
|
||||||
// if(!Utility.IsEpoch(minDate) && key<minDate)minDate=key;
|
|
||||||
if(Utility.IsEpoch(minDate))minDate=key;
|
if(Utility.IsEpoch(minDate))minDate=key;
|
||||||
else if(key<minDate)minDate=key;
|
else if(key<minDate)minDate=key;
|
||||||
//else if(Utility.IsEpoch(minDate)) minDate=key;
|
|
||||||
//else if(key<minDate && !Utility.IsEpoch(key)) minDate=key;
|
|
||||||
}
|
}
|
||||||
public DateTime MaxDate
|
public DateTime MaxDate
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user