diff options
Diffstat (limited to 'src/FundLab.Api/App.fs')
| -rw-r--r-- | src/FundLab.Api/App.fs | 39 |
1 files changed, 36 insertions, 3 deletions
diff --git a/src/FundLab.Api/App.fs b/src/FundLab.Api/App.fs index 34b4f2d..370f503 100644 --- a/src/FundLab.Api/App.fs +++ b/src/FundLab.Api/App.fs @@ -331,6 +331,12 @@ type MarketDataNavApiResponse = observations: MarketDataObservationApiResponse list } +type MarketNavDatesApiResponse = + { + code: string + dates: string list + } + module App = let addOptionFriendlyJson (services: IServiceCollection) = let settings = @@ -1634,7 +1640,23 @@ module App = GET >=> routef "/instruments/%s/nav" (getNav marketData) ] - let private createApplicationInternal (repository: FundRepository) (marketData: IMarketDataService option) : HttpHandler = + let private getMarketNavDates (probe: INavDateProbe) : HttpHandler = + fun next ctx -> + let code = ctx.Request.Query["code"].ToString() + + match probe.RecentNavDates(code, 5, ctx.RequestAborted) with + | Ok dates -> + json ({ code = code.Trim(); dates = dates |> List.map dateText } : MarketNavDatesApiResponse) next ctx + | Error failure -> marketDataError failure next ctx + + let private navDateProbeRoutes (probe: INavDateProbe) = + [ GET >=> route "/market/nav-dates" >=> getMarketNavDates probe ] + + let private createApplicationInternal + (repository: FundRepository) + (marketData: IMarketDataService option) + (navDateProbe: INavDateProbe option) + : HttpHandler = let apiRoutes = [ GET >=> route "/portfolio/summary" >=> emptyPortfolio @@ -1665,6 +1687,7 @@ module App = GET >=> routef "/funds/%s" (getFund repository) ] @ (marketData |> Option.map marketDataRoutes |> Option.defaultValue []) + @ (navDateProbe |> Option.map navDateProbeRoutes |> Option.defaultValue []) choose [ GET >=> route "/health" >=> health @@ -1676,7 +1699,17 @@ module App = ] let createApplicationWithMarketData (repository: FundRepository) (marketData: IMarketDataService) : HttpHandler = - createApplicationInternal repository (Some marketData) + createApplicationInternal repository (Some marketData) None + + let createApplicationWithNavDateProbe (repository: FundRepository) (probe: INavDateProbe) : HttpHandler = + createApplicationInternal repository None (Some probe) + + let createApplicationWithMarketDataAndProbe + (repository: FundRepository) + (marketData: IMarketDataService) + (probe: INavDateProbe) + : HttpHandler = + createApplicationInternal repository (Some marketData) (Some probe) let createApplication (repository: FundRepository) : HttpHandler = - createApplicationInternal repository None + createApplicationInternal repository None None |
