diff options
| author | Somhairle H. Marisol <[email protected]> | 2026-09-22 02:13:04 +0800 |
|---|---|---|
| committer | Somhairle H. Marisol <[email protected]> | 2026-09-22 02:13:04 +0800 |
| commit | 7da3c3d938e4b64a43963d602ab4a0a8c89f6f9e (patch) | |
| tree | 6fc3c06f6474aa4ad06fde775b3618e8bf392fba /src/FundLab.Api/App.fs | |
| parent | 0d1af831c10683bb1e5a5853e5924c5ddfb1310d (diff) | |
| download | fund-lab-7da3c3d938e4b64a43963d602ab4a0a8c89f6f9e.tar.gz | |
Add real AKShare stock quote probe slice (3d-17)
Diffstat (limited to 'src/FundLab.Api/App.fs')
| -rw-r--r-- | src/FundLab.Api/App.fs | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/src/FundLab.Api/App.fs b/src/FundLab.Api/App.fs index b083c37..9565485 100644 --- a/src/FundLab.Api/App.fs +++ b/src/FundLab.Api/App.fs @@ -357,6 +357,7 @@ type MarketProbes = NavDates: INavDateProbe NavSeries: INavSeriesProbe BondQuotes: IBondQuoteProbe + StockQuotes: IStockQuoteProbe } type BondQuoteApiResponse = @@ -367,6 +368,14 @@ type BondQuoteApiResponse = maturityDate: string option } +type StockQuoteApiResponse = + { + code: string + name: string option + price: string option + currency: string + } + module App = let addOptionFriendlyJson (services: IServiceCollection) = let settings = @@ -1728,11 +1737,28 @@ module App = ctx | Error failure -> marketDataError failure next ctx + let private getStockQuote (probe: IStockQuoteProbe) : HttpHandler = + fun next ctx -> + let code = ctx.Request.Query["code"].ToString() + + match probe.GetQuote(code, ctx.RequestAborted) with + | Ok quote -> + json + ({ code = quote.Code + name = quote.Name + price = quote.Price |> Option.map decimalText + currency = quote.Currency } + : StockQuoteApiResponse) + next + ctx + | Error failure -> marketDataError failure next ctx + let private marketProbeRoutes (probes: MarketProbes) = [ GET >=> route "/market/nav-dates" >=> getMarketNavDates probes.NavDates GET >=> route "/market/nav-series" >=> getMarketNavSeries probes.NavSeries GET >=> route "/market/bond-quote" >=> getBondQuote probes.BondQuotes + GET >=> route "/market/stock-quote" >=> getStockQuote probes.StockQuotes ] let private createApplicationInternal |
