From 7da3c3d938e4b64a43963d602ab4a0a8c89f6f9e Mon Sep 17 00:00:00 2001 From: "Somhairle H. Marisol" Date: Tue, 22 Sep 2026 02:13:04 +0800 Subject: Add real AKShare stock quote probe slice (3d-17) --- src/FundLab.Api/MarketData.fs | 44 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) (limited to 'src/FundLab.Api/MarketData.fs') diff --git a/src/FundLab.Api/MarketData.fs b/src/FundLab.Api/MarketData.fs index ad2a623..87ef145 100644 --- a/src/FundLab.Api/MarketData.fs +++ b/src/FundLab.Api/MarketData.fs @@ -48,6 +48,17 @@ type MarketDataBondQuotePayload = MaturityDate: DateOnly option } +type MarketDataStockQuotePayload = + { + Source: string + SourceRevision: string + CollectedAt: DateTimeOffset + Code: string + Name: string option + Price: decimal option + Currency: string + } + type MarketDataInstrumentRecord = { Code: string @@ -354,3 +365,36 @@ module MarketData = } with | :? JsonException -> Error "payload must be valid JSON" + + let parseStockQuotePayload (json: string) : Result = + try + use document = JsonDocument.Parse(json) + let root = document.RootElement + + result { + let! source, sourceRevision, collectedAt = validateEnvelope root "stock-quote" + let! instrumentProperty = requiredProperty root "instrument" + let! codeProperty = requiredString instrumentProperty "code" + + if not (isFundCode codeProperty) then + return! Error "stock code must contain exactly six digits" + + let! quoteProperty = requiredProperty root "quote" + let! name = optionalString quoteProperty "name" + let! priceProperty = requiredProperty quoteProperty "price" + let! price = optionalDecimal "price" priceProperty + let! currency = requiredString quoteProperty "currency" + + return + { + Source = source + SourceRevision = sourceRevision + CollectedAt = collectedAt + Code = codeProperty + Name = name + Price = price + Currency = currency + } + } + with + | :? JsonException -> Error "payload must be valid JSON" -- cgit v1.2.3