using MarketData.MarketDataModel; using MarketData.DataAccess; using MarketDataServer.Authorization; using MarketData.Generator; using MarketData; using LogLevel = MarketData.LogLevel; using Microsoft.AspNetCore.Mvc; using MarketData.Utils; namespace MarketDataServer.Controllers { [ApiController] [Route("api/[controller]/[action]")] //http://localhost:8000/api/Price //http://localhost:8000/api/Price/GetPrices?&symbol=MIDD&days=5 //http://73.245.214.234:8000/api/Price/GetPrices?&symbol=MIDD&days=5 public class PriceController : ControllerBase { [HttpGet(Name = "GetPrices")] public IEnumerable GetPrices(String token, String symbol, int 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) { 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) { 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) { 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; } } } }