diff --git a/MarketData/MarketDataLib/Utility/SQLUtils.cs b/MarketData/MarketDataLib/Utility/SQLUtils.cs
index 6a0f16c..9c07492 100755
--- a/MarketData/MarketDataLib/Utility/SQLUtils.cs
+++ b/MarketData/MarketDataLib/Utility/SQLUtils.cs
@@ -12,7 +12,7 @@ namespace MarketData.Utils
/// SQlUtils - SQL utility class
public class SqlUtils
{
- private static readonly int MIN_POOL_SIZE=10;
+ private static readonly int MIN_POOL_SIZE=0; // this will allow the connection pool to shrink for better utilization
private static readonly int MAX_POOL_SIZE=100;
public static readonly int COMMAND_TIMEOUT=300; // seconds
private static readonly int CONNECTION_TIMEOUT=300; // seconds
diff --git a/MarketDataServer/Controllers/GainLossController.cs b/MarketDataServer/Controllers/GainLossController.cs
index e2cda49..bedc624 100755
--- a/MarketDataServer/Controllers/GainLossController.cs
+++ b/MarketDataServer/Controllers/GainLossController.cs
@@ -21,268 +21,308 @@ namespace MarketDataServer.Controllers
[HttpGet]
public IEnumerable GetGainLossByDate(String token,DateTime selectedDate)
{
- MDTrace.WriteLine(LogLevel.DEBUG,String.Format("[{0:G}][GainLossController::GetGainLoss](String token, DateTime selectedDate)", DateTime.Now));
- if (!Authorizations.GetInstance().IsAuthorized(token)) return null;
- LocalPriceCache.GetInstance().Refresh();
- PortfolioTrades portfolioTrades = PortfolioDA.GetTrades();
- PortfolioTrades tradesOnOrBefore = portfolioTrades.GetTradesOnOrBefore(selectedDate);
- GainLossSummaryItemCollection gainLossSummaryItems = new GainLossSummaryItemCollection(tradesOnOrBefore, selectedDate);
+ try
+ {
+ MDTrace.WriteLine(LogLevel.DEBUG,String.Format("[{0:G}][GainLossController::GetGainLoss](String token, DateTime selectedDate)", DateTime.Now));
+ if (!Authorizations.GetInstance().IsAuthorized(token)) return null;
+ LocalPriceCache.GetInstance().Refresh();
+ PortfolioTrades portfolioTrades = PortfolioDA.GetTrades();
+ PortfolioTrades tradesOnOrBefore = portfolioTrades.GetTradesOnOrBefore(selectedDate);
+ GainLossSummaryItemCollection gainLossSummaryItems = new GainLossSummaryItemCollection(tradesOnOrBefore, selectedDate);
-// **** Add an aggregate entry
- GainLossSummaryItem gainLossSummaryTotals=new GainLossSummaryItem();
- gainLossSummaryTotals.Symbol="";
- gainLossSummaryTotals.CompanyName="Account Summary";
- if(null!=gainLossSummaryItems&&gainLossSummaryItems.Count>0)
- {
- gainLossSummaryTotals.Date=gainLossSummaryItems.Min(x => x.Date);
- gainLossSummaryTotals.Change=gainLossSummaryItems.Sum(x=>x.Change);
- gainLossSummaryTotals.CurrentGainLoss=gainLossSummaryItems.Sum(x => x.CurrentGainLoss);
- gainLossSummaryTotals.PreviousGainLoss = gainLossSummaryItems.Sum(x => x.PreviousGainLoss);
- gainLossSummaryTotals.ChangePercent=((gainLossSummaryTotals.CurrentGainLoss-gainLossSummaryTotals.PreviousGainLoss)/Math.Abs(gainLossSummaryTotals.PreviousGainLoss))*100.00;
+ // **** Add an aggregate entry
+ GainLossSummaryItem gainLossSummaryTotals=new GainLossSummaryItem();
+ gainLossSummaryTotals.Symbol="";
+ gainLossSummaryTotals.CompanyName="Account Summary";
+ if(null!=gainLossSummaryItems&&gainLossSummaryItems.Count>0)
+ {
+ gainLossSummaryTotals.Date=gainLossSummaryItems.Min(x => x.Date);
+ gainLossSummaryTotals.Change=gainLossSummaryItems.Sum(x=>x.Change);
+ gainLossSummaryTotals.CurrentGainLoss=gainLossSummaryItems.Sum(x => x.CurrentGainLoss);
+ gainLossSummaryTotals.PreviousGainLoss = gainLossSummaryItems.Sum(x => x.PreviousGainLoss);
+ gainLossSummaryTotals.ChangePercent=((gainLossSummaryTotals.CurrentGainLoss-gainLossSummaryTotals.PreviousGainLoss)/Math.Abs(gainLossSummaryTotals.PreviousGainLoss))*100.00;
+ }
+ else
+ {
+ gainLossSummaryTotals.Date = selectedDate;
+ gainLossSummaryTotals.Change = 0.00;
+ gainLossSummaryTotals.CurrentGainLoss = 0.00;
+ gainLossSummaryTotals.PreviousGainLoss = 0.00;
+ gainLossSummaryTotals.ChangePercent = 0.00;
+ }
+ gainLossSummaryItems.Insert(0,gainLossSummaryTotals);
+ // ****
+ return gainLossSummaryItems;
}
- else
+ catch(Exception exception)
{
- gainLossSummaryTotals.Date = selectedDate;
- gainLossSummaryTotals.Change = 0.00;
- gainLossSummaryTotals.CurrentGainLoss = 0.00;
- gainLossSummaryTotals.PreviousGainLoss = 0.00;
- gainLossSummaryTotals.ChangePercent = 0.00;
+ MDTrace.WriteLine(LogLevel.DEBUG,$"Exception:{exception.ToString()}");
+ return null;
}
- gainLossSummaryItems.Insert(0,gainLossSummaryTotals);
-// ****
- return gainLossSummaryItems;
}
[HttpGet]
public IEnumerable GetGainLossByDateAndAccount(String token,DateTime selectedDate,String account)
{
- MDTrace.WriteLine(LogLevel.DEBUG,String.Format("[{0:G}][GainLossController::GetGainLoss](String token, DateTime selectedDate,String account)", DateTime.Now));
- LocalPriceCache.GetInstance().Refresh();
- if (!Authorizations.GetInstance().IsAuthorized(token)) return null;
- PortfolioTrades portfolioTrades = PortfolioDA.GetTrades();
- portfolioTrades=new PortfolioTrades(portfolioTrades.Where(x=>x.Account.Equals(account)).ToList());
- PortfolioTrades tradesOnOrBefore = portfolioTrades.GetTradesOnOrBefore(selectedDate);
- GainLossSummaryItemCollection gainLossSummaryItems = new GainLossSummaryItemCollection(tradesOnOrBefore, selectedDate);
+ try
+ {
+ MDTrace.WriteLine(LogLevel.DEBUG,String.Format("[{0:G}][GainLossController::GetGainLoss](String token, DateTime selectedDate,String account)", DateTime.Now));
+ LocalPriceCache.GetInstance().Refresh();
+ if (!Authorizations.GetInstance().IsAuthorized(token)) return null;
+ PortfolioTrades portfolioTrades = PortfolioDA.GetTrades();
+ portfolioTrades=new PortfolioTrades(portfolioTrades.Where(x=>x.Account.Equals(account)).ToList());
+ PortfolioTrades tradesOnOrBefore = portfolioTrades.GetTradesOnOrBefore(selectedDate);
+ GainLossSummaryItemCollection gainLossSummaryItems = new GainLossSummaryItemCollection(tradesOnOrBefore, selectedDate);
- // **** Add an aggregate entry
- GainLossSummaryItem gainLossSummaryTotals = new GainLossSummaryItem();
- gainLossSummaryTotals.Symbol = "";
- gainLossSummaryTotals.CompanyName="Account Summary";
- if (null != gainLossSummaryItems && gainLossSummaryItems.Count > 0)
- {
- gainLossSummaryTotals.Date = gainLossSummaryItems.Min(x => x.Date);
- gainLossSummaryTotals.Change = gainLossSummaryItems.Sum(x => x.Change);
- gainLossSummaryTotals.CurrentGainLoss = gainLossSummaryItems.Sum(x => x.CurrentGainLoss);
- gainLossSummaryTotals.PreviousGainLoss = gainLossSummaryItems.Sum(x => x.PreviousGainLoss);
- gainLossSummaryTotals.ChangePercent = ((gainLossSummaryTotals.CurrentGainLoss - gainLossSummaryTotals.PreviousGainLoss) / Math.Abs(gainLossSummaryTotals.PreviousGainLoss)) * 100.00;
+ // **** Add an aggregate entry
+ GainLossSummaryItem gainLossSummaryTotals = new GainLossSummaryItem();
+ gainLossSummaryTotals.Symbol = "";
+ gainLossSummaryTotals.CompanyName="Account Summary";
+ if (null != gainLossSummaryItems && gainLossSummaryItems.Count > 0)
+ {
+ gainLossSummaryTotals.Date = gainLossSummaryItems.Min(x => x.Date);
+ gainLossSummaryTotals.Change = gainLossSummaryItems.Sum(x => x.Change);
+ gainLossSummaryTotals.CurrentGainLoss = gainLossSummaryItems.Sum(x => x.CurrentGainLoss);
+ gainLossSummaryTotals.PreviousGainLoss = gainLossSummaryItems.Sum(x => x.PreviousGainLoss);
+ gainLossSummaryTotals.ChangePercent = ((gainLossSummaryTotals.CurrentGainLoss - gainLossSummaryTotals.PreviousGainLoss) / Math.Abs(gainLossSummaryTotals.PreviousGainLoss)) * 100.00;
+ }
+ else
+ {
+ gainLossSummaryTotals.Date = selectedDate;
+ gainLossSummaryTotals.Change = 0.00;
+ gainLossSummaryTotals.CurrentGainLoss = 0.00;
+ gainLossSummaryTotals.PreviousGainLoss = 0.00;
+ gainLossSummaryTotals.ChangePercent = 0.00;
+ }
+ gainLossSummaryItems.Insert(0, gainLossSummaryTotals);
+ // ****
+ return gainLossSummaryItems;
}
- else
+ catch(Exception exception)
{
- gainLossSummaryTotals.Date = selectedDate;
- gainLossSummaryTotals.Change = 0.00;
- gainLossSummaryTotals.CurrentGainLoss = 0.00;
- gainLossSummaryTotals.PreviousGainLoss = 0.00;
- gainLossSummaryTotals.ChangePercent = 0.00;
+ MDTrace.WriteLine(LogLevel.DEBUG,$"Exception:{exception.ToString()}");
+ return null;
}
- gainLossSummaryItems.Insert(0, gainLossSummaryTotals);
- // ****
- return gainLossSummaryItems;
}
[HttpGet]
public IEnumerable GetGainLossWithDetailByDate(String token,DateTime selectedDate)
{
- MDTrace.WriteLine(LogLevel.DEBUG,String.Format("[{0:G}][GainLossController::GetGainLossWithDetail](String token, DateTime selectedDate)", DateTime.Now));
- if (!Authorizations.GetInstance().IsAuthorized(token)) return null;
- LocalPriceCache.GetInstance().Refresh();
- PortfolioTrades portfolioTrades = PortfolioDA.GetTrades();
- PortfolioTrades tradesOnOrBefore = portfolioTrades.GetTradesOnOrBefore(selectedDate);
- GainLossSummaryItemCollection gainLossSummaryItems = new GainLossSummaryItemCollection(tradesOnOrBefore, selectedDate);
+ try
+ {
+ MDTrace.WriteLine(LogLevel.DEBUG,String.Format("[{0:G}][GainLossController::GetGainLossWithDetail](String token, DateTime selectedDate)", DateTime.Now));
+ if (!Authorizations.GetInstance().IsAuthorized(token)) return null;
+ LocalPriceCache.GetInstance().Refresh();
+ PortfolioTrades portfolioTrades = PortfolioDA.GetTrades();
+ PortfolioTrades tradesOnOrBefore = portfolioTrades.GetTradesOnOrBefore(selectedDate);
+ GainLossSummaryItemCollection gainLossSummaryItems = new GainLossSummaryItemCollection(tradesOnOrBefore, selectedDate);
- List gainLossSummaryItemDetailCollection = new List();
- foreach (GainLossSummaryItem gainLossSummaryItem in gainLossSummaryItems)
- {
- GainLossSummaryItemDetail gainLossSummaryItemDetail = new GainLossSummaryItemDetail(gainLossSummaryItem);
- portfolioTrades = PortfolioDA.GetOpenTradesSymbol(gainLossSummaryItem.Symbol);
- double weightAdjustedDividendYield = portfolioTrades.GetWeightAdjustedDividendYield();
- DateTime currentDate = PricingDA.GetLatestDate(gainLossSummaryItem.Symbol);
- if (null == portfolioTrades || 0 == portfolioTrades.Count) continue;
- double shares = (from PortfolioTrade portfolioTrade in portfolioTrades select portfolioTrade.Shares).Sum();
- double exposure = portfolioTrades.Sum(x => x.Exposure());
- if(null==gainLossGenerator) gainLossGenerator=new ActiveGainLossGenerator();
- GainLossCollection gainLoss=gainLossGenerator.GenerateGainLoss(portfolioTrades); // gainLoss contains the gain/loss from active positions. Never includes dividends .. just positions
- GainLossItem gainLossItem = gainLoss.OrderByDescending(x => x.GainLossPercent).FirstOrDefault();
- gainLossSummaryItemDetail.Lots = portfolioTrades.Count;
- gainLossSummaryItemDetail.Shares = shares;
- gainLossSummaryItemDetail.Exposure = exposure;
- if (!double.IsNaN(weightAdjustedDividendYield))
+ List gainLossSummaryItemDetailCollection = new List();
+ foreach (GainLossSummaryItem gainLossSummaryItem in gainLossSummaryItems)
{
- gainLossSummaryItemDetail.DividendYield = weightAdjustedDividendYield;
- gainLossSummaryItemDetail.AnnualDividend = exposure * weightAdjustedDividendYield;
+ GainLossSummaryItemDetail gainLossSummaryItemDetail = new GainLossSummaryItemDetail(gainLossSummaryItem);
+ portfolioTrades = PortfolioDA.GetOpenTradesSymbol(gainLossSummaryItem.Symbol);
+ double weightAdjustedDividendYield = portfolioTrades.GetWeightAdjustedDividendYield();
+ DateTime currentDate = PricingDA.GetLatestDate(gainLossSummaryItem.Symbol);
+ if (null == portfolioTrades || 0 == portfolioTrades.Count) continue;
+ double shares = (from PortfolioTrade portfolioTrade in portfolioTrades select portfolioTrade.Shares).Sum();
+ double exposure = portfolioTrades.Sum(x => x.Exposure());
+ if(null==gainLossGenerator) gainLossGenerator=new ActiveGainLossGenerator();
+ GainLossCollection gainLoss=gainLossGenerator.GenerateGainLoss(portfolioTrades); // gainLoss contains the gain/loss from active positions. Never includes dividends .. just positions
+ GainLossItem gainLossItem = gainLoss.OrderByDescending(x => x.GainLossPercent).FirstOrDefault();
+ gainLossSummaryItemDetail.Lots = portfolioTrades.Count;
+ gainLossSummaryItemDetail.Shares = shares;
+ gainLossSummaryItemDetail.Exposure = exposure;
+ if (!double.IsNaN(weightAdjustedDividendYield))
+ {
+ gainLossSummaryItemDetail.DividendYield = weightAdjustedDividendYield;
+ gainLossSummaryItemDetail.AnnualDividend = exposure * weightAdjustedDividendYield;
+ }
+ ParityElement parityElement = ParityGenerator.GenerateBreakEven(gainLossSummaryItem.Symbol);
+ gainLossSummaryItemDetail.ParityElement = parityElement;
+ if (null != parityElement)
+ {
+ gainLossSummaryItemDetail.AllTimeGainLossPercent = gainLossItem.GainLossPercent;
+ gainLossSummaryItemDetail.PercentDistanceFromAllTimeGainLossPercent = parityElement.ParityOffsetPercent - (gainLossItem.GainLossPercent / 100);
+ }
+ DateGenerator dateGenerator = new DateGenerator();
+ DateTime priorDate = dateGenerator.FindPrevBusinessDay(currentDate);
+ Price p1 = PricingDA.GetPrice(gainLossSummaryItem.Symbol, currentDate);
+ Price p2 = PricingDA.GetPrice(gainLossSummaryItem.Symbol, priorDate);
+ if (null == p2 && null != p1)
+ {
+ priorDate = dateGenerator.FindPrevBusinessDay(priorDate);
+ p2 = PricingDA.GetPrice(gainLossSummaryItem.Symbol, priorDate);
+ }
+ if (null != p1 && null != p2)
+ {
+ double change = (p1.Close - p2.Close) / p2.Close;
+ gainLossSummaryItemDetail.LatestPrice = p1;
+ gainLossSummaryItemDetail.PriceChange = change;
+ }
+ gainLossSummaryItemDetailCollection.Add(gainLossSummaryItemDetail);
}
- ParityElement parityElement = ParityGenerator.GenerateBreakEven(gainLossSummaryItem.Symbol);
- gainLossSummaryItemDetail.ParityElement = parityElement;
- if (null != parityElement)
- {
- gainLossSummaryItemDetail.AllTimeGainLossPercent = gainLossItem.GainLossPercent;
- gainLossSummaryItemDetail.PercentDistanceFromAllTimeGainLossPercent = parityElement.ParityOffsetPercent - (gainLossItem.GainLossPercent / 100);
- }
- DateGenerator dateGenerator = new DateGenerator();
- DateTime priorDate = dateGenerator.FindPrevBusinessDay(currentDate);
- Price p1 = PricingDA.GetPrice(gainLossSummaryItem.Symbol, currentDate);
- Price p2 = PricingDA.GetPrice(gainLossSummaryItem.Symbol, priorDate);
- if (null == p2 && null != p1)
- {
- priorDate = dateGenerator.FindPrevBusinessDay(priorDate);
- p2 = PricingDA.GetPrice(gainLossSummaryItem.Symbol, priorDate);
- }
- if (null != p1 && null != p2)
- {
- double change = (p1.Close - p2.Close) / p2.Close;
- gainLossSummaryItemDetail.LatestPrice = p1;
- gainLossSummaryItemDetail.PriceChange = change;
- }
- gainLossSummaryItemDetailCollection.Add(gainLossSummaryItemDetail);
- }
- // **** Add an aggregate entry
- GainLossSummaryItemDetail gainLossSummaryTotals = new GainLossSummaryItemDetail();
- gainLossSummaryTotals.Symbol = "";
- gainLossSummaryTotals.CompanyName = "Account Summary";
- if (null != gainLossSummaryItemDetailCollection && gainLossSummaryItemDetailCollection.Count > 0)
- {
- gainLossSummaryTotals.Date = gainLossSummaryItemDetailCollection.Min(x => x.Date);
- gainLossSummaryTotals.Exposure = gainLossSummaryItemDetailCollection.Sum(x => x.Exposure);
- gainLossSummaryTotals.Change = gainLossSummaryItemDetailCollection.Sum(x => x.Change);
- gainLossSummaryTotals.CurrentGainLoss = gainLossSummaryItemDetailCollection.Sum(x => x.CurrentGainLoss);
- gainLossSummaryTotals.PreviousGainLoss = gainLossSummaryItemDetailCollection.Sum(x => x.PreviousGainLoss);
- gainLossSummaryTotals.ChangePercent = ((gainLossSummaryTotals.CurrentGainLoss - gainLossSummaryTotals.PreviousGainLoss) / Math.Abs(gainLossSummaryTotals.PreviousGainLoss)) * 100.00;
- gainLossSummaryTotals.LatestPrice = new Price();
- gainLossSummaryTotals.PriceChange = 0;
+ // **** Add an aggregate entry
+ GainLossSummaryItemDetail gainLossSummaryTotals = new GainLossSummaryItemDetail();
+ gainLossSummaryTotals.Symbol = "";
+ gainLossSummaryTotals.CompanyName = "Account Summary";
+ if (null != gainLossSummaryItemDetailCollection && gainLossSummaryItemDetailCollection.Count > 0)
+ {
+ gainLossSummaryTotals.Date = gainLossSummaryItemDetailCollection.Min(x => x.Date);
+ gainLossSummaryTotals.Exposure = gainLossSummaryItemDetailCollection.Sum(x => x.Exposure);
+ gainLossSummaryTotals.Change = gainLossSummaryItemDetailCollection.Sum(x => x.Change);
+ gainLossSummaryTotals.CurrentGainLoss = gainLossSummaryItemDetailCollection.Sum(x => x.CurrentGainLoss);
+ gainLossSummaryTotals.PreviousGainLoss = gainLossSummaryItemDetailCollection.Sum(x => x.PreviousGainLoss);
+ gainLossSummaryTotals.ChangePercent = ((gainLossSummaryTotals.CurrentGainLoss - gainLossSummaryTotals.PreviousGainLoss) / Math.Abs(gainLossSummaryTotals.PreviousGainLoss)) * 100.00;
+ gainLossSummaryTotals.LatestPrice = new Price();
+ gainLossSummaryTotals.PriceChange = 0;
+ }
+ else
+ {
+ gainLossSummaryTotals.Date = selectedDate;
+ gainLossSummaryTotals.Change = 0.00;
+ gainLossSummaryTotals.CurrentGainLoss = 0.00;
+ gainLossSummaryTotals.PreviousGainLoss = 0.00;
+ gainLossSummaryTotals.ChangePercent = 0.00;
+ gainLossSummaryTotals.LatestPrice = new Price();
+ gainLossSummaryTotals.PriceChange = 0;
+ }
+ gainLossSummaryItemDetailCollection.Insert(0, gainLossSummaryTotals);
+ // ****
+ return gainLossSummaryItemDetailCollection;
}
- else
+ catch(Exception exception)
{
- gainLossSummaryTotals.Date = selectedDate;
- gainLossSummaryTotals.Change = 0.00;
- gainLossSummaryTotals.CurrentGainLoss = 0.00;
- gainLossSummaryTotals.PreviousGainLoss = 0.00;
- gainLossSummaryTotals.ChangePercent = 0.00;
- gainLossSummaryTotals.LatestPrice = new Price();
- gainLossSummaryTotals.PriceChange = 0;
+ MDTrace.WriteLine(LogLevel.DEBUG,$"Exception:{exception.ToString()}");
+ return null;
}
- gainLossSummaryItemDetailCollection.Insert(0, gainLossSummaryTotals);
- // ****
- return gainLossSummaryItemDetailCollection;
}
[HttpGet]
public IEnumerable GetGainLossWithDetailByDateAndAccount(String token, DateTime selectedDate, String account)
{
- MDTrace.WriteLine(LogLevel.DEBUG,String.Format("[{0:G}][GainLossController::GetGainLossWithDetail](String token, DateTime selectedDate,String account)", DateTime.Now));
- if (!Authorizations.GetInstance().IsAuthorized(token)) return null;
- LocalPriceCache.GetInstance().Refresh();
- PortfolioTrades portfolioTrades = PortfolioDA.GetTrades();
- portfolioTrades = new PortfolioTrades(portfolioTrades.Where(x => x.Account.Equals(account)).ToList());
- PortfolioTrades tradesOnOrBefore = portfolioTrades.GetTradesOnOrBefore(selectedDate);
- GainLossSummaryItemCollection gainLossSummaryItems = new GainLossSummaryItemCollection(tradesOnOrBefore, selectedDate);
+ try
+ {
+ MDTrace.WriteLine(LogLevel.DEBUG,String.Format("[{0:G}][GainLossController::GetGainLossWithDetail](String token, DateTime selectedDate,String account)", DateTime.Now));
+ if (!Authorizations.GetInstance().IsAuthorized(token)) return null;
+ LocalPriceCache.GetInstance().Refresh();
+ PortfolioTrades portfolioTrades = PortfolioDA.GetTrades();
+ portfolioTrades = new PortfolioTrades(portfolioTrades.Where(x => x.Account.Equals(account)).ToList());
+ PortfolioTrades tradesOnOrBefore = portfolioTrades.GetTradesOnOrBefore(selectedDate);
+ GainLossSummaryItemCollection gainLossSummaryItems = new GainLossSummaryItemCollection(tradesOnOrBefore, selectedDate);
- List gainLossSummaryItemDetailCollection=new List();
- foreach(GainLossSummaryItem gainLossSummaryItem in gainLossSummaryItems)
- {
- GainLossSummaryItemDetail gainLossSummaryItemDetail = new GainLossSummaryItemDetail(gainLossSummaryItem);
- portfolioTrades = PortfolioDA.GetOpenTradesSymbol(gainLossSummaryItem.Symbol);
- double weightAdjustedDividendYield = portfolioTrades.GetWeightAdjustedDividendYield();
- DateTime currentDate = PricingDA.GetLatestDate(gainLossSummaryItem.Symbol);
- if(null==portfolioTrades||0==portfolioTrades.Count)continue;
- double shares = (from PortfolioTrade portfolioTrade in portfolioTrades select portfolioTrade.Shares).Sum();
- double exposure = portfolioTrades.Sum(x => x.Exposure());
- if(null==gainLossGenerator) gainLossGenerator=new ActiveGainLossGenerator();
- GainLossCollection gainLoss = gainLossGenerator.GenerateGainLoss(portfolioTrades); // gainLoss contains the gain/loss from active positions. Never includes dividends .. just positions
- GainLossItem gainLossItem = gainLoss.OrderByDescending(x => x.GainLossPercent).FirstOrDefault();
- gainLossSummaryItemDetail.Lots=portfolioTrades.Count;
- gainLossSummaryItemDetail.Shares=shares;
- gainLossSummaryItemDetail.Exposure=exposure;
- if (!double.IsNaN(weightAdjustedDividendYield))
+ List gainLossSummaryItemDetailCollection=new List();
+ foreach(GainLossSummaryItem gainLossSummaryItem in gainLossSummaryItems)
{
- gainLossSummaryItemDetail.DividendYield=weightAdjustedDividendYield;
- gainLossSummaryItemDetail.AnnualDividend=exposure * weightAdjustedDividendYield;
+ GainLossSummaryItemDetail gainLossSummaryItemDetail = new GainLossSummaryItemDetail(gainLossSummaryItem);
+ portfolioTrades = PortfolioDA.GetOpenTradesSymbol(gainLossSummaryItem.Symbol);
+ double weightAdjustedDividendYield = portfolioTrades.GetWeightAdjustedDividendYield();
+ DateTime currentDate = PricingDA.GetLatestDate(gainLossSummaryItem.Symbol);
+ if(null==portfolioTrades||0==portfolioTrades.Count)continue;
+ double shares = (from PortfolioTrade portfolioTrade in portfolioTrades select portfolioTrade.Shares).Sum();
+ double exposure = portfolioTrades.Sum(x => x.Exposure());
+ if(null==gainLossGenerator) gainLossGenerator=new ActiveGainLossGenerator();
+ GainLossCollection gainLoss = gainLossGenerator.GenerateGainLoss(portfolioTrades); // gainLoss contains the gain/loss from active positions. Never includes dividends .. just positions
+ GainLossItem gainLossItem = gainLoss.OrderByDescending(x => x.GainLossPercent).FirstOrDefault();
+ gainLossSummaryItemDetail.Lots=portfolioTrades.Count;
+ gainLossSummaryItemDetail.Shares=shares;
+ gainLossSummaryItemDetail.Exposure=exposure;
+ if (!double.IsNaN(weightAdjustedDividendYield))
+ {
+ gainLossSummaryItemDetail.DividendYield=weightAdjustedDividendYield;
+ gainLossSummaryItemDetail.AnnualDividend=exposure * weightAdjustedDividendYield;
+ }
+ ParityElement parityElement = ParityGenerator.GenerateBreakEven(gainLossSummaryItem.Symbol);
+ gainLossSummaryItemDetail.ParityElement=parityElement;
+ if (null != parityElement)
+ {
+ gainLossSummaryItemDetail.AllTimeGainLossPercent=gainLossItem.GainLossPercent;
+ gainLossSummaryItemDetail.PercentDistanceFromAllTimeGainLossPercent=parityElement.ParityOffsetPercent - (gainLossItem.GainLossPercent / 100);
+ }
+ DateGenerator dateGenerator = new DateGenerator();
+ DateTime priorDate = dateGenerator.FindPrevBusinessDay(currentDate);
+ Price p1 = PricingDA.GetPrice(gainLossSummaryItem.Symbol, currentDate);
+ Price p2 = PricingDA.GetPrice(gainLossSummaryItem.Symbol, priorDate);
+ if (null == p2 && null != p1)
+ {
+ priorDate = dateGenerator.FindPrevBusinessDay(priorDate);
+ p2 = PricingDA.GetPrice(gainLossSummaryItem.Symbol, priorDate);
+ }
+ if(null!=p1&&null!=p2)
+ {
+ double change = (p1.Close - p2.Close) / p2.Close;
+ gainLossSummaryItemDetail.LatestPrice=p1;
+ gainLossSummaryItemDetail.PriceChange=change;
+ }
+ gainLossSummaryItemDetailCollection.Add(gainLossSummaryItemDetail);
}
- ParityElement parityElement = ParityGenerator.GenerateBreakEven(gainLossSummaryItem.Symbol);
- gainLossSummaryItemDetail.ParityElement=parityElement;
- if (null != parityElement)
- {
- gainLossSummaryItemDetail.AllTimeGainLossPercent=gainLossItem.GainLossPercent;
- gainLossSummaryItemDetail.PercentDistanceFromAllTimeGainLossPercent=parityElement.ParityOffsetPercent - (gainLossItem.GainLossPercent / 100);
- }
- DateGenerator dateGenerator = new DateGenerator();
- DateTime priorDate = dateGenerator.FindPrevBusinessDay(currentDate);
- Price p1 = PricingDA.GetPrice(gainLossSummaryItem.Symbol, currentDate);
- Price p2 = PricingDA.GetPrice(gainLossSummaryItem.Symbol, priorDate);
- if (null == p2 && null != p1)
- {
- priorDate = dateGenerator.FindPrevBusinessDay(priorDate);
- p2 = PricingDA.GetPrice(gainLossSummaryItem.Symbol, priorDate);
- }
- if(null!=p1&&null!=p2)
- {
- double change = (p1.Close - p2.Close) / p2.Close;
- gainLossSummaryItemDetail.LatestPrice=p1;
- gainLossSummaryItemDetail.PriceChange=change;
- }
- gainLossSummaryItemDetailCollection.Add(gainLossSummaryItemDetail);
- }
- // **** Add an aggregate entry
- GainLossSummaryItemDetail gainLossSummaryTotals = new GainLossSummaryItemDetail();
- gainLossSummaryTotals.Symbol = "";
- gainLossSummaryTotals.CompanyName = "Account Summary";
- if (null != gainLossSummaryItemDetailCollection && gainLossSummaryItemDetailCollection.Count > 0)
- {
- gainLossSummaryTotals.Date = gainLossSummaryItemDetailCollection.Min(x => x.Date);
- gainLossSummaryTotals.Exposure=gainLossSummaryItemDetailCollection.Sum(x=>x.Exposure);
- gainLossSummaryTotals.Change = gainLossSummaryItemDetailCollection.Sum(x => x.Change);
- gainLossSummaryTotals.CurrentGainLoss = gainLossSummaryItemDetailCollection.Sum(x => x.CurrentGainLoss);
- gainLossSummaryTotals.PreviousGainLoss = gainLossSummaryItemDetailCollection.Sum(x => x.PreviousGainLoss);
- gainLossSummaryTotals.ChangePercent = ((gainLossSummaryTotals.CurrentGainLoss - gainLossSummaryTotals.PreviousGainLoss) / Math.Abs(gainLossSummaryTotals.PreviousGainLoss)) * 100.00;
- gainLossSummaryTotals.LatestPrice=new Price();
- gainLossSummaryTotals.PriceChange=0;
+ // **** Add an aggregate entry
+ GainLossSummaryItemDetail gainLossSummaryTotals = new GainLossSummaryItemDetail();
+ gainLossSummaryTotals.Symbol = "";
+ gainLossSummaryTotals.CompanyName = "Account Summary";
+ if (null != gainLossSummaryItemDetailCollection && gainLossSummaryItemDetailCollection.Count > 0)
+ {
+ gainLossSummaryTotals.Date = gainLossSummaryItemDetailCollection.Min(x => x.Date);
+ gainLossSummaryTotals.Exposure=gainLossSummaryItemDetailCollection.Sum(x=>x.Exposure);
+ gainLossSummaryTotals.Change = gainLossSummaryItemDetailCollection.Sum(x => x.Change);
+ gainLossSummaryTotals.CurrentGainLoss = gainLossSummaryItemDetailCollection.Sum(x => x.CurrentGainLoss);
+ gainLossSummaryTotals.PreviousGainLoss = gainLossSummaryItemDetailCollection.Sum(x => x.PreviousGainLoss);
+ gainLossSummaryTotals.ChangePercent = ((gainLossSummaryTotals.CurrentGainLoss - gainLossSummaryTotals.PreviousGainLoss) / Math.Abs(gainLossSummaryTotals.PreviousGainLoss)) * 100.00;
+ gainLossSummaryTotals.LatestPrice=new Price();
+ gainLossSummaryTotals.PriceChange=0;
+ }
+ else
+ {
+ gainLossSummaryTotals.Date = selectedDate;
+ gainLossSummaryTotals.Change = 0.00;
+ gainLossSummaryTotals.CurrentGainLoss = 0.00;
+ gainLossSummaryTotals.PreviousGainLoss = 0.00;
+ gainLossSummaryTotals.ChangePercent = 0.00;
+ gainLossSummaryTotals.LatestPrice = new Price();
+ gainLossSummaryTotals.PriceChange = 0;
+ }
+ gainLossSummaryItemDetailCollection.Insert(0, gainLossSummaryTotals);
+ // ****
+ return gainLossSummaryItemDetailCollection;
}
- else
+ catch(Exception exception)
{
- gainLossSummaryTotals.Date = selectedDate;
- gainLossSummaryTotals.Change = 0.00;
- gainLossSummaryTotals.CurrentGainLoss = 0.00;
- gainLossSummaryTotals.PreviousGainLoss = 0.00;
- gainLossSummaryTotals.ChangePercent = 0.00;
- gainLossSummaryTotals.LatestPrice = new Price();
- gainLossSummaryTotals.PriceChange = 0;
+ MDTrace.WriteLine(LogLevel.DEBUG,$"Exception:{exception.ToString()}");
+ return null;
}
- gainLossSummaryItemDetailCollection.Insert(0, gainLossSummaryTotals);
- // ****
- return gainLossSummaryItemDetailCollection;
}
[HttpGet(Name = "GetCompoundGainLoss")]
public GainLossCompoundModelCollection GetCompoundGainLoss(String token, int selectedDays, bool includeDividends)
{
- MDTrace.WriteLine(LogLevel.DEBUG,String.Format("[{0:G}][GainLossController::GetCompundGainLoss](String token, int days)", DateTime.Now));
- if(!Authorizations.GetInstance().IsAuthorized(token)) return null;
- LocalPriceCache.GetInstance().Refresh();
- DividendPayments dividendPayments = null;
- PortfolioTrades portfolioTrades = PortfolioDA.GetTrades();
- GainLossGenerator gainLossGenerator=new GainLossGenerator();
- if(includeDividends)dividendPayments=DividendPaymentDA.GetDividendPayments();
- ActiveGainLossGenerator activeGainLossGenerator=new ActiveGainLossGenerator();
- GainLossCollection gainLoss=activeGainLossGenerator.GenerateGainLoss(portfolioTrades); // gainLoss contains the gain/loss from active positions. Never includes dividends .. just positions
- TotalGainLossCollection totalGainLoss=null;
- if(null!=dividendPayments)totalGainLoss=gainLossGenerator.GenerateTotalGainLossWithDividends(portfolioTrades,dividendPayments);
- else totalGainLoss=gainLossGenerator.GenerateTotalGainLoss(portfolioTrades);
- GainLossCompoundModelCollection gainLossModelCollection=null;
- gainLossModelCollection=new GainLossCompoundModelCollection(gainLoss,totalGainLoss);
- if(-1==selectedDays)return gainLossModelCollection;
- int skip=gainLossModelCollection.Count-selectedDays;
- if(skip<0)return gainLossModelCollection;
- return new GainLossCompoundModelCollection(gainLossModelCollection.Skip(skip).ToList());
+ try
+ {
+ MDTrace.WriteLine(LogLevel.DEBUG,String.Format("[{0:G}][GainLossController::GetCompundGainLoss](String token, int days)", DateTime.Now));
+ if(!Authorizations.GetInstance().IsAuthorized(token)) return null;
+ LocalPriceCache.GetInstance().Refresh();
+ DividendPayments dividendPayments = null;
+ PortfolioTrades portfolioTrades = PortfolioDA.GetTrades();
+ GainLossGenerator gainLossGenerator=new GainLossGenerator();
+ if(includeDividends)dividendPayments=DividendPaymentDA.GetDividendPayments();
+ ActiveGainLossGenerator activeGainLossGenerator=new ActiveGainLossGenerator();
+ GainLossCollection gainLoss=activeGainLossGenerator.GenerateGainLoss(portfolioTrades); // gainLoss contains the gain/loss from active positions. Never includes dividends .. just positions
+ TotalGainLossCollection totalGainLoss=null;
+ if(null!=dividendPayments)totalGainLoss=gainLossGenerator.GenerateTotalGainLossWithDividends(portfolioTrades,dividendPayments);
+ else totalGainLoss=gainLossGenerator.GenerateTotalGainLoss(portfolioTrades);
+ GainLossCompoundModelCollection gainLossModelCollection=null;
+ gainLossModelCollection=new GainLossCompoundModelCollection(gainLoss,totalGainLoss);
+ if(-1==selectedDays)return gainLossModelCollection;
+ int skip=gainLossModelCollection.Count-selectedDays;
+ if(skip<0)return gainLossModelCollection;
+ return new GainLossCompoundModelCollection(gainLossModelCollection.Skip(skip).ToList());
+ }
+ catch(Exception exception)
+ {
+ MDTrace.WriteLine(LogLevel.DEBUG,$"Exception:{exception.ToString()}");
+ return null;
+ }
}
}
}
diff --git a/MarketDataServer/Controllers/HeadlinesController.cs b/MarketDataServer/Controllers/HeadlinesController.cs
index 30d9a3c..97d9561 100755
--- a/MarketDataServer/Controllers/HeadlinesController.cs
+++ b/MarketDataServer/Controllers/HeadlinesController.cs
@@ -14,27 +14,51 @@ namespace MarketDataServer.Controllers
[HttpGet(Name = "GetLatestHeadlines")]
public IEnumerable GetLatestHeadlines(String token)
{
- MDTrace.WriteLine(LogLevel.DEBUG,String.Format("[{0:G}][HeadlinesController::GetLatestHeadlines]", DateTime.Now));
- if (!Authorizations.GetInstance().IsAuthorized(token)) return null;
- return HeadlinesDA.GetLatestHeadlines();
+ try
+ {
+ MDTrace.WriteLine(LogLevel.DEBUG,String.Format("[{0:G}][HeadlinesController::GetLatestHeadlines]", DateTime.Now));
+ if (!Authorizations.GetInstance().IsAuthorized(token)) return null;
+ return HeadlinesDA.GetLatestHeadlines();
+ }
+ catch(Exception exception)
+ {
+ MDTrace.WriteLine(LogLevel.DEBUG,$"Exception:{exception.ToString()}");
+ return null;
+ }
}
[HttpGet(Name = "GetHeadlineDates")]
public IEnumerable GetHeadlineDates(String token)
{
- MDTrace.WriteLine(LogLevel.DEBUG,String.Format("[{0:G}][HeadlinesController::GetHeadlineDates]", DateTime.Now));
- if (!Authorizations.GetInstance().IsAuthorized(token)) return null;
- List headlineDates = HeadlinesDA.GetHeadlineDates();
- if(headlineDates.Count>0)headlineDates=headlineDates.Take(252).ToList();
- return headlineDates;
+ try
+ {
+ MDTrace.WriteLine(LogLevel.DEBUG,String.Format("[{0:G}][HeadlinesController::GetHeadlineDates]", DateTime.Now));
+ if (!Authorizations.GetInstance().IsAuthorized(token)) return null;
+ List headlineDates = HeadlinesDA.GetHeadlineDates();
+ if(headlineDates.Count>0)headlineDates=headlineDates.Take(252).ToList();
+ return headlineDates;
+ }
+ catch(Exception exception)
+ {
+ MDTrace.WriteLine(LogLevel.DEBUG,$"Exception:{exception.ToString()}");
+ return null;
+ }
}
[HttpGet(Name = "GetHeadlines")]
public IEnumerable GetHeadlines(String token,DateTime headlineDate)
{
- MDTrace.WriteLine(LogLevel.DEBUG,String.Format("[{0:G}][HeadlinesController::GetHeadliness(DateTime headlineDate)]", DateTime.Now));
- if (!Authorizations.GetInstance().IsAuthorized(token)) return null;
- return HeadlinesDA.GetHeadlines(headlineDate);
+ try
+ {
+ MDTrace.WriteLine(LogLevel.DEBUG,String.Format("[{0:G}][HeadlinesController::GetHeadliness(DateTime headlineDate)]", DateTime.Now));
+ if (!Authorizations.GetInstance().IsAuthorized(token)) return null;
+ return HeadlinesDA.GetHeadlines(headlineDate);
+ }
+ catch(Exception exception)
+ {
+ MDTrace.WriteLine(LogLevel.DEBUG,$"Exception:{exception.ToString()}");
+ return null;
+ }
}
}
}
diff --git a/MarketDataServer/Controllers/LoginController.cs b/MarketDataServer/Controllers/LoginController.cs
index 2761f29..0804c99 100755
--- a/MarketDataServer/Controllers/LoginController.cs
+++ b/MarketDataServer/Controllers/LoginController.cs
@@ -12,19 +12,27 @@ namespace MarketDataServer.Controllers
[HttpGet(Name = "GetToken")]
public String GetToken(String user, String password)
{
- MDTrace.WriteLine(LogLevel.DEBUG,String.Format("[{0:G}][AuthorizationController::Authorize]",DateTime.Now));
- if(null==user)return null;
- user=Authorizations.Xor(user,5);
- password=Authorizations.Xor(password,5);
- MDTrace.WriteLine(LogLevel.DEBUG,String.Format("[{0:G}][Login requested for user '{1}']",DateTime.Now, user));
- if(!Authorizations.GetInstance().IsValidUser(user, password))
+ try
{
- MDTrace.WriteLine(LogLevel.DEBUG,String.Format("[{0:G}][User '{1}' is not authorized]", DateTime.Now,user));
+ MDTrace.WriteLine(LogLevel.DEBUG,String.Format("[{0:G}][AuthorizationController::Authorize]",DateTime.Now));
+ if(null==user)return null;
+ user=Authorizations.Xor(user,5);
+ password=Authorizations.Xor(password,5);
+ MDTrace.WriteLine(LogLevel.DEBUG,String.Format("[{0:G}][Login requested for user '{1}']",DateTime.Now, user));
+ if(!Authorizations.GetInstance().IsValidUser(user, password))
+ {
+ MDTrace.WriteLine(LogLevel.DEBUG,String.Format("[{0:G}][User '{1}' is not authorized]", DateTime.Now,user));
+ return null;
+ }
+ String accessToken= Authorizations.GetInstance().GetAuthenticationToken();
+ MDTrace.WriteLine(LogLevel.DEBUG,String.Format("[{0:G}][Access token granted for user {1} : {2}]",DateTime.Now ,user, accessToken));
+ return accessToken;
+ }
+ catch(Exception exception)
+ {
+ MDTrace.WriteLine(LogLevel.DEBUG,$"Exception:{exception.ToString()}");
return null;
}
- String accessToken= Authorizations.GetInstance().GetAuthenticationToken();
- MDTrace.WriteLine(LogLevel.DEBUG,String.Format("[{0:G}][Access token granted for user {1} : {2}]",DateTime.Now ,user, accessToken));
- return accessToken;
}
}
}
diff --git a/MarketDataServer/Controllers/PortfolioController.cs b/MarketDataServer/Controllers/PortfolioController.cs
index 60b0433..6463769 100755
--- a/MarketDataServer/Controllers/PortfolioController.cs
+++ b/MarketDataServer/Controllers/PortfolioController.cs
@@ -20,60 +20,100 @@ namespace MarketDataServer.Controllers
[HttpGet(Name = "GetOpenPositionsWithDescription")]
public IEnumerable GetOpenPositionsWithDescription(String token)
{
- MDTrace.WriteLine(LogLevel.DEBUG,String.Format("[{0:G}][PortfolioController::GetOpenPositionsWithDescriptionAsOf]",DateTime.Now));
- if (!Authorizations.GetInstance().IsAuthorized(token)) return null;
- List positionsWithDescription=new List();
- PortfolioTrades openTrades=PortfolioDA.GetOpenTrades();
- List positions=openTrades.GetPositions(DateTime.Now);
- foreach(Position position in positions)
- {
- CompanyProfile companyProfile=CompanyProfileDA.GetCompanyProfile(position.Symbol);
- if(null==companyProfile.Description)companyProfile.Description="Description unvailable";
- positionsWithDescription.Add(new PositionWithDescription(position,companyProfile.CompanyName, companyProfile.Description));
- }
- return positionsWithDescription;
- }
+ try
+ {
+ MDTrace.WriteLine(LogLevel.DEBUG,String.Format("[{0:G}][PortfolioController::GetOpenPositionsWithDescriptionAsOf]",DateTime.Now));
+ if (!Authorizations.GetInstance().IsAuthorized(token)) return null;
+ List positionsWithDescription=new List();
+ PortfolioTrades openTrades=PortfolioDA.GetOpenTrades();
+ List positions=openTrades.GetPositions(DateTime.Now);
+ foreach(Position position in positions)
+ {
+ CompanyProfile companyProfile=CompanyProfileDA.GetCompanyProfile(position.Symbol);
+ if(null==companyProfile.Description)companyProfile.Description="Description unvailable";
+ positionsWithDescription.Add(new PositionWithDescription(position,companyProfile.CompanyName, companyProfile.Description));
+ }
+ return positionsWithDescription;
+ }
+ catch(Exception exception)
+ {
+ MDTrace.WriteLine(LogLevel.DEBUG,$"Exception:{exception.ToString()}");
+ return null;
+ }
+ }
[HttpGet(Name = "GetAccounts")]
public IEnumerable GetAccounts(String token)
{
- MDTrace.WriteLine(LogLevel.DEBUG,String.Format("[{0:G}][PortfolioController::GetAccounts]",DateTime.Now));
- if (!Authorizations.GetInstance().IsAuthorized(token)) return null;
- return PortfolioDA.GetAccounts();
+ try
+ {
+ MDTrace.WriteLine(LogLevel.DEBUG,String.Format("[{0:G}][PortfolioController::GetAccounts]",DateTime.Now));
+ if (!Authorizations.GetInstance().IsAuthorized(token)) return null;
+ return PortfolioDA.GetAccounts();
+ }
+ catch(Exception exception)
+ {
+ MDTrace.WriteLine(LogLevel.DEBUG,$"Exception:{exception.ToString()}");
+ return null;
+ }
}
[HttpGet(Name = "GetAccountsWithOpenTrades")]
public IEnumerable GetAccountsWithOpenTrades(String token)
{
- MDTrace.WriteLine(LogLevel.DEBUG,String.Format("[{0:G}][PortfolioController::GetAccountsWithOpenTrades]", DateTime.Now));
- if (!Authorizations.GetInstance().IsAuthorized(token)) return null;
- return PortfolioDA.GetAccountsWithOpenTrades();
+ try
+ {
+ MDTrace.WriteLine(LogLevel.DEBUG,String.Format("[{0:G}][PortfolioController::GetAccountsWithOpenTrades]", DateTime.Now));
+ if (!Authorizations.GetInstance().IsAuthorized(token)) return null;
+ return PortfolioDA.GetAccountsWithOpenTrades();
+ }
+ catch(Exception exception)
+ {
+ MDTrace.WriteLine(LogLevel.DEBUG,$"Exception:{exception.ToString()}");
+ return null;
+ }
}
[HttpGet(Name = "GetStopLimit")]
public StopLimit GetStopLimit(String token,String symbol)
{
- MDTrace.WriteLine(LogLevel.DEBUG,String.Format("[{0:G}][PortfolioController::GetStopLimit]",DateTime.Now));
- if(!Authorizations.GetInstance().IsAuthorized(token)) return null;
- StopLimit stopLimit=PortfolioDA.GetStopLimit(symbol);
- return stopLimit;
+ try
+ {
+ MDTrace.WriteLine(LogLevel.DEBUG,String.Format("[{0:G}][PortfolioController::GetStopLimit]",DateTime.Now));
+ if(!Authorizations.GetInstance().IsAuthorized(token)) return null;
+ StopLimit stopLimit=PortfolioDA.GetStopLimit(symbol);
+ return stopLimit;
+ }
+ catch(Exception exception)
+ {
+ MDTrace.WriteLine(LogLevel.DEBUG,$"Exception:{exception.ToString()}");
+ return null;
+ }
}
[HttpGet(Name = "GetPortfolioTradesWithParityPrice")]
public PortfolioTradesWithParityPrice GetPortfolioTradesWithParityPrice(String token, String symbol)
{
- MDTrace.WriteLine(LogLevel.DEBUG,String.Format("[{0:G}][PortfolioController::GetPortfolioTradesWithParityPrice]", DateTime.Now));
- if (!Authorizations.GetInstance().IsAuthorized(token)) return null;
- Price zeroPrice=null;
- DateTime latestPricingDate=PricingDA.GetLatestDate(symbol);
- Price latestPrice = PricingDA.GetPrice(symbol, latestPricingDate);
- PortfolioTrades portfolioTrades = PortfolioDA.GetTradesSymbol(symbol);
- if (null == portfolioTrades) return null;
- portfolioTrades = portfolioTrades.GetOpenTrades();
- if (null == portfolioTrades) return null;
- PortfolioTrades portfolioTradesLots = LotAggregator.CombineLots(portfolioTrades);
- zeroPrice=ParityGenerator.GenerateGainLossValue(portfolioTrades,latestPrice);
- return new PortfolioTradesWithParityPrice(portfolioTradesLots,zeroPrice);
+ try
+ {
+ MDTrace.WriteLine(LogLevel.DEBUG,String.Format("[{0:G}][PortfolioController::GetPortfolioTradesWithParityPrice]", DateTime.Now));
+ if (!Authorizations.GetInstance().IsAuthorized(token)) return null;
+ Price zeroPrice=null;
+ DateTime latestPricingDate=PricingDA.GetLatestDate(symbol);
+ Price latestPrice = PricingDA.GetPrice(symbol, latestPricingDate);
+ PortfolioTrades portfolioTrades = PortfolioDA.GetTradesSymbol(symbol);
+ if (null == portfolioTrades) return null;
+ portfolioTrades = portfolioTrades.GetOpenTrades();
+ if (null == portfolioTrades) return null;
+ PortfolioTrades portfolioTradesLots = LotAggregator.CombineLots(portfolioTrades);
+ zeroPrice=ParityGenerator.GenerateGainLossValue(portfolioTrades,latestPrice);
+ return new PortfolioTradesWithParityPrice(portfolioTradesLots,zeroPrice);
+ }
+ catch(Exception exception)
+ {
+ MDTrace.WriteLine(LogLevel.DEBUG,$"Exception:{exception.ToString()}");
+ return null;
+ }
}
}
}
diff --git a/MarketDataServer/Controllers/PreMarketController.cs b/MarketDataServer/Controllers/PreMarketController.cs
index 7eca1bd..1e7ccde 100755
--- a/MarketDataServer/Controllers/PreMarketController.cs
+++ b/MarketDataServer/Controllers/PreMarketController.cs
@@ -15,25 +15,49 @@ namespace MarketDataServer.Controllers
[HttpGet(Name = "GetAvailableMarketDates")]
public IEnumerable GetAvailableMarketDates(String token,String market)
{
- MDTrace.WriteLine(LogLevel.DEBUG,String.Format("[{0:G}][PreMarketController::GetAvailableMarketDates]{1}",DateTime.Now,market));
- if(!Authorizations.GetInstance().IsAuthorized(token)) return null;
- return PremarketDA.GetAvailableMarketDates(market);
+ try
+ {
+ MDTrace.WriteLine(LogLevel.DEBUG,String.Format("[{0:G}][PreMarketController::GetAvailableMarketDates]{1}",DateTime.Now,market));
+ if(!Authorizations.GetInstance().IsAuthorized(token)) return null;
+ return PremarketDA.GetAvailableMarketDates(market);
+ }
+ catch(Exception exception)
+ {
+ MDTrace.WriteLine(LogLevel.DEBUG,$"Exception:{exception.ToString()}");
+ return null;
+ }
}
[HttpGet(Name = "GetAvailableMarkets")]
public IEnumerable GetAvailableMarkets(String token)
{
- MDTrace.WriteLine(LogLevel.DEBUG,String.Format("[{0:G}][PreMarketController::GetAvailableMarkets]",DateTime.Now));
- if(!Authorizations.GetInstance().IsAuthorized(token)) return null;
- return PremarketDA.GetDistinctMarkets();
+ try
+ {
+ MDTrace.WriteLine(LogLevel.DEBUG,String.Format("[{0:G}][PreMarketController::GetAvailableMarkets]",DateTime.Now));
+ if(!Authorizations.GetInstance().IsAuthorized(token)) return null;
+ return PremarketDA.GetDistinctMarkets();
+ }
+ catch(Exception exception)
+ {
+ MDTrace.WriteLine(LogLevel.DEBUG,$"Exception:{exception.ToString()}");
+ return null;
+ }
}
[HttpGet(Name = "GetLatestPremarketData")]
public IEnumerable GetLatestPremarketData(String token,String market,DateTime marketDate)
{
- MDTrace.WriteLine(LogLevel.DEBUG,String.Format("[{0:G}][PreMarketController::GetLatestPremarketData]{1},{2}",DateTime.Now,market,marketDate.ToShortDateString()));
- if(!Authorizations.GetInstance().IsAuthorized(token)) return null;
- return PremarketDA.GetLatestPremarketData(market,marketDate);
+ try
+ {
+ MDTrace.WriteLine(LogLevel.DEBUG,String.Format("[{0:G}][PreMarketController::GetLatestPremarketData]{1},{2}",DateTime.Now,market,marketDate.ToShortDateString()));
+ if(!Authorizations.GetInstance().IsAuthorized(token)) return null;
+ return PremarketDA.GetLatestPremarketData(market,marketDate);
+ }
+ catch(Exception exception)
+ {
+ MDTrace.WriteLine(LogLevel.DEBUG,$"Exception:{exception.ToString()}");
+ return null;
+ }
}
}
}
diff --git a/MarketDataServer/Controllers/PriceController.cs b/MarketDataServer/Controllers/PriceController.cs
index cde2179..83130b4 100755
--- a/MarketDataServer/Controllers/PriceController.cs
+++ b/MarketDataServer/Controllers/PriceController.cs
@@ -5,6 +5,7 @@ using MarketData.Generator;
using MarketData;
using LogLevel = MarketData.LogLevel;
using Microsoft.AspNetCore.Mvc;
+using MarketData.Utils;
namespace MarketDataServer.Controllers
{
@@ -19,37 +20,69 @@ namespace MarketDataServer.Controllers
[HttpGet(Name = "GetPrices")]
public IEnumerable GetPrices(String token, String symbol, int days)
{
- MDTrace.WriteLine(LogLevel.DEBUG,String.Format("[{0:G}][PriceController::GetPrices]", DateTime.Now));
- if (!Authorizations.GetInstance().IsAuthorized(token)) return null;
- return PricingDA.GetPrices(symbol, days);
+ try
+ {
+ MDTrace.WriteLine(LogLevel.DEBUG,String.Format("[{0:G}][PriceController::GetPrices]", DateTime.Now));
+ if (!Authorizations.GetInstance().IsAuthorized(token)) return null;
+ return PricingDA.GetPrices(symbol, days);
+ }
+ catch(Exception exception)
+ {
+ MDTrace.WriteLine(LogLevel.DEBUG,$"Exception:{exception.ToString()}");
+ return null;
+ }
}
[HttpGet(Name = "GetBollingerBands")]
public BollingerBands GetBollingerBands(String token,String symbol,int dayCount)
{
- MDTrace.WriteLine(LogLevel.DEBUG,String.Format("[{0:G}][PriceController::GetBollingerBands]", DateTime.Now));
- if (!Authorizations.GetInstance().IsAuthorized(token)) return null;
- Prices prices=PricingDA.GetPrices(symbol,dayCount);
- BollingerBands bollingerBands=BollingerBandGenerator.GenerateBollingerBands(prices);
- return bollingerBands;
+ try
+ {
+ MDTrace.WriteLine(LogLevel.DEBUG,String.Format("[{0:G}][PriceController::GetBollingerBands]", DateTime.Now));
+ if (!Authorizations.GetInstance().IsAuthorized(token)) return null;
+ Prices prices=PricingDA.GetPrices(symbol,dayCount);
+ BollingerBands bollingerBands=BollingerBandGenerator.GenerateBollingerBands(prices);
+ return bollingerBands;
+ }
+ catch(Exception exception)
+ {
+ MDTrace.WriteLine(LogLevel.DEBUG,$"Exception:{exception.ToString()}");
+ return null;
+ }
}
[HttpGet(Name = "GetLatestPricingDate")]
public DateTime GetLatestPricingDate(String token)
{
- MDTrace.WriteLine(LogLevel.DEBUG,String.Format("[{0:G}][PriceController::GetLatestPricingDate]", DateTime.Now));
- if (!Authorizations.GetInstance().IsAuthorized(token)) return DateTime.MinValue;
- DateTime latestPricingDate=PricingDA.GetLatestDate();
- return latestPricingDate;
+ try
+ {
+ MDTrace.WriteLine(LogLevel.DEBUG,String.Format("[{0:G}][PriceController::GetLatestPricingDate]", DateTime.Now));
+ if (!Authorizations.GetInstance().IsAuthorized(token)) return DateTime.MinValue;
+ DateTime latestPricingDate=PricingDA.GetLatestDate();
+ return latestPricingDate;
+ }
+ catch(Exception exception)
+ {
+ MDTrace.WriteLine(LogLevel.DEBUG,$"Exception:{exception.ToString()}");
+ return Utility.Epoch;
+ }
}
[HttpGet(Name = "GetCompanyNameForSymbol")]
public String GetCompanyNameForSymbol(String token, String symbol)
{
- MDTrace.WriteLine(LogLevel.DEBUG,String.Format("[{0:G}][PortfolioController::GetCompanyNameForSymbol]", DateTime.Now));
- if (!Authorizations.GetInstance().IsAuthorized(token)) return null;
- String companyName=PricingDA.GetNameForSymbol(symbol);
- return companyName;
+ try
+ {
+ MDTrace.WriteLine(LogLevel.DEBUG,String.Format("[{0:G}][PortfolioController::GetCompanyNameForSymbol]", DateTime.Now));
+ if (!Authorizations.GetInstance().IsAuthorized(token)) return null;
+ String companyName=PricingDA.GetNameForSymbol(symbol);
+ return companyName;
+ }
+ catch(Exception exception)
+ {
+ MDTrace.WriteLine(LogLevel.DEBUG,$"Exception:{exception.ToString()}");
+ return null;
+ }
}
}
}
diff --git a/MarketDataServer/Controllers/PriceIndexController.cs b/MarketDataServer/Controllers/PriceIndexController.cs
index 1c01fed..44be825 100755
--- a/MarketDataServer/Controllers/PriceIndexController.cs
+++ b/MarketDataServer/Controllers/PriceIndexController.cs
@@ -15,18 +15,34 @@ namespace MarketDataServer.Controllers
[HttpGet(Name = "GetDistinctPriceIndices")]
public IEnumerable GetDistinctPriceIndices(String token)
{
- MDTrace.WriteLine(LogLevel.DEBUG,String.Format("[{0:G}][PriceIndexController::GetDistinctPriceIndices]",DateTime.Now));
- if (!Authorizations.GetInstance().IsAuthorized(token)) return null;
- return ConsumerPriceIndexDA.GetDistinctIndices();
+ try
+ {
+ MDTrace.WriteLine(LogLevel.DEBUG,String.Format("[{0:G}][PriceIndexController::GetDistinctPriceIndices]",DateTime.Now));
+ if (!Authorizations.GetInstance().IsAuthorized(token)) return null;
+ return ConsumerPriceIndexDA.GetDistinctIndices();
+ }
+ catch(Exception exception)
+ {
+ MDTrace.WriteLine(LogLevel.DEBUG,$"Exception:{exception.ToString()}");
+ return null;
+ }
}
[HttpGet(Name = "GetConsumerPriceIndex")]
public IEnumerable GetConsumerPriceIndex(String token,String indexCode)
{
- MDTrace.WriteLine(LogLevel.DEBUG,String.Format("[{0:G}][PriceIndexController::GetOpenPositionsWithDescriptionAsOf]",DateTime.Now));
- if (!Authorizations.GetInstance().IsAuthorized(token)) return null;
- PriceIndices priceIndices=ConsumerPriceIndexDA.GetConsumerPriceIndex(indexCode);
- return priceIndices;
+ try
+ {
+ MDTrace.WriteLine(LogLevel.DEBUG,String.Format("[{0:G}][PriceIndexController::GetOpenPositionsWithDescriptionAsOf]",DateTime.Now));
+ if (!Authorizations.GetInstance().IsAuthorized(token)) return null;
+ PriceIndices priceIndices=ConsumerPriceIndexDA.GetConsumerPriceIndex(indexCode);
+ return priceIndices;
+ }
+ catch(Exception exception)
+ {
+ MDTrace.WriteLine(LogLevel.DEBUG,$"Exception:{exception.ToString()}");
+ return null;
+ }
}
}
}
diff --git a/MarketDataServer/Controllers/WatchListController.cs b/MarketDataServer/Controllers/WatchListController.cs
index fef06be..9a67e98 100755
--- a/MarketDataServer/Controllers/WatchListController.cs
+++ b/MarketDataServer/Controllers/WatchListController.cs
@@ -13,9 +13,17 @@ namespace MarketDataServer.Controllers
[HttpGet(Name = "GetWatchList")]
public IEnumerable GetWatchList(String token,String watchList)
{
- MDTrace.WriteLine(LogLevel.DEBUG,String.Format("[{0:G}][WatchListController::GetWatchList]", DateTime.Now));
- if (!Authorizations.GetInstance().IsAuthorized(token)) return null;
- return WatchListDA.GetWatchList(watchList);
+ try
+ {
+ MDTrace.WriteLine(LogLevel.DEBUG,String.Format("[{0:G}][WatchListController::GetWatchList]", DateTime.Now));
+ if (!Authorizations.GetInstance().IsAuthorized(token)) return null;
+ return WatchListDA.GetWatchList(watchList);
+ }
+ catch(Exception exception)
+ {
+ MDTrace.WriteLine(LogLevel.DEBUG,$"Exception:{exception.ToString()}");
+ return null;
+ }
}
}
}