Add profiling to MarketDataServer controllers

This commit is contained in:
2025-04-27 10:55:25 -04:00
parent cebf9f63e6
commit 1c1c0c35f4
9 changed files with 161 additions and 32 deletions

View File

@@ -5,6 +5,7 @@ using MarketData.Generator;
using MarketData;
using LogLevel = MarketData.LogLevel;
using Microsoft.AspNetCore.Mvc;
using MarketData.Utils;
namespace MarketDataServer.Controllers
{
@@ -20,9 +21,10 @@ namespace MarketDataServer.Controllers
[HttpGet(Name = "GetOpenPositionsWithDescription")]
public IEnumerable<PositionWithDescription> GetOpenPositionsWithDescription(String token)
{
Profiler profiler = new Profiler();
try
{
MDTrace.WriteLine(LogLevel.DEBUG,String.Format("[{0:G}][PortfolioController::GetOpenPositionsWithDescriptionAsOf]",DateTime.Now));
MDTrace.WriteLine(LogLevel.DEBUG,$"Start");
if (!Authorizations.GetInstance().IsAuthorized(token)) return null;
List<PositionWithDescription> positionsWithDescription=new List<PositionWithDescription>();
PortfolioTrades openTrades=PortfolioDA.GetOpenTrades();
@@ -39,15 +41,20 @@ namespace MarketDataServer.Controllers
{
MDTrace.WriteLine(LogLevel.DEBUG,$"Exception:{exception.ToString()}");
return null;
}
}
finally
{
MDTrace.WriteLine(LogLevel.DEBUG,$"Done, total took {profiler.End()} (ms)");
}
}
[HttpGet(Name = "GetAccounts")]
public IEnumerable<String> GetAccounts(String token)
{
Profiler profiler = new Profiler();
try
{
MDTrace.WriteLine(LogLevel.DEBUG,String.Format("[{0:G}][PortfolioController::GetAccounts]",DateTime.Now));
MDTrace.WriteLine(LogLevel.DEBUG,$"Start");
if (!Authorizations.GetInstance().IsAuthorized(token)) return null;
return PortfolioDA.GetAccounts();
}
@@ -56,14 +63,19 @@ namespace MarketDataServer.Controllers
MDTrace.WriteLine(LogLevel.DEBUG,$"Exception:{exception.ToString()}");
return null;
}
finally
{
MDTrace.WriteLine(LogLevel.DEBUG,$"Done, total took {profiler.End()} (ms)");
}
}
[HttpGet(Name = "GetAccountsWithOpenTrades")]
public IEnumerable<String> GetAccountsWithOpenTrades(String token)
{
Profiler profiler = new Profiler();
try
{
MDTrace.WriteLine(LogLevel.DEBUG,String.Format("[{0:G}][PortfolioController::GetAccountsWithOpenTrades]", DateTime.Now));
MDTrace.WriteLine(LogLevel.DEBUG,$"Start");
if (!Authorizations.GetInstance().IsAuthorized(token)) return null;
return PortfolioDA.GetAccountsWithOpenTrades();
}
@@ -72,14 +84,19 @@ namespace MarketDataServer.Controllers
MDTrace.WriteLine(LogLevel.DEBUG,$"Exception:{exception.ToString()}");
return null;
}
finally
{
MDTrace.WriteLine(LogLevel.DEBUG,$"Done, total took {profiler.End()} (ms)");
}
}
[HttpGet(Name = "GetStopLimit")]
public StopLimit GetStopLimit(String token,String symbol)
{
Profiler profiler = new Profiler();
try
{
MDTrace.WriteLine(LogLevel.DEBUG,String.Format("[{0:G}][PortfolioController::GetStopLimit]",DateTime.Now));
MDTrace.WriteLine(LogLevel.DEBUG,$"Start");
if(!Authorizations.GetInstance().IsAuthorized(token)) return null;
StopLimit stopLimit=PortfolioDA.GetStopLimit(symbol);
return stopLimit;
@@ -89,14 +106,19 @@ namespace MarketDataServer.Controllers
MDTrace.WriteLine(LogLevel.DEBUG,$"Exception:{exception.ToString()}");
return null;
}
finally
{
MDTrace.WriteLine(LogLevel.DEBUG,$"Done, total took {profiler.End()} (ms)");
}
}
[HttpGet(Name = "GetPortfolioTradesWithParityPrice")]
public PortfolioTradesWithParityPrice GetPortfolioTradesWithParityPrice(String token, String symbol)
{
Profiler profiler = new Profiler();
try
{
MDTrace.WriteLine(LogLevel.DEBUG,String.Format("[{0:G}][PortfolioController::GetPortfolioTradesWithParityPrice]", DateTime.Now));
MDTrace.WriteLine(LogLevel.DEBUG,$"Start");
if (!Authorizations.GetInstance().IsAuthorized(token)) return null;
Price zeroPrice=null;
DateTime latestPricingDate=PricingDA.GetLatestDate(symbol);
@@ -114,6 +136,10 @@ namespace MarketDataServer.Controllers
MDTrace.WriteLine(LogLevel.DEBUG,$"Exception:{exception.ToString()}");
return null;
}
finally
{
MDTrace.WriteLine(LogLevel.DEBUG,$"Done, total took {profiler.End()} (ms)");
}
}
}
}