summaryrefslogtreecommitdiff
path: root/src/FundLab.Api/App.fs
diff options
context:
space:
mode:
authorSomhairle H. Marisol <[email protected]>2026-09-22 00:19:09 +0800
committerSomhairle H. Marisol <[email protected]>2026-09-22 00:19:09 +0800
commit0597ac74757e223c17a6477ff49d69a559168279 (patch)
tree3ab8934481bf9aaef89163fd216f15248fe118ac /src/FundLab.Api/App.fs
parent36ee23a0c406c16e975276238a861299899ec79a (diff)
downloadfund-lab-0597ac74757e223c17a6477ff49d69a559168279.tar.gz
Add real AKShare NAV-date probe slice (3d-12)
Diffstat (limited to 'src/FundLab.Api/App.fs')
-rw-r--r--src/FundLab.Api/App.fs39
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