diff options
Diffstat (limited to 'src/FundLab.Api/MarketData.fs')
| -rw-r--r-- | src/FundLab.Api/MarketData.fs | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/src/FundLab.Api/MarketData.fs b/src/FundLab.Api/MarketData.fs index 152ffd7..12e4893 100644 --- a/src/FundLab.Api/MarketData.fs +++ b/src/FundLab.Api/MarketData.fs @@ -71,6 +71,9 @@ type MarketDataStockQuotePayload = Name: string option Price: decimal option Currency: string + Market: string option + Adjust: string option + Suspended: bool option } type MarketDataStockDailyBar = @@ -87,6 +90,8 @@ type MarketDataStockDailyPayload = SourceRevision: string CollectedAt: DateTimeOffset Code: string + Market: string option + Adjust: string option Bars: MarketDataStockDailyBar list } @@ -183,6 +188,27 @@ module MarketData = else Error(sprintf "payload property '%s' must be null or a string" name)) + let private optionalBool (root: JsonElement) name = + optionalProperty root name + |> Result.bind (function + | None -> Ok None + | Some property -> + match property.ValueKind with + | JsonValueKind.Null -> Ok None + | JsonValueKind.True -> Ok(Some true) + | JsonValueKind.False -> Ok(Some false) + | _ -> Error(sprintf "payload property '%s' must be null or a boolean" name)) + + let private optionalStringOrMissing (root: JsonElement) name = + optionalProperty root name + |> Result.bind (function + | None -> Ok None + | Some property when property.ValueKind = JsonValueKind.Null -> Ok None + | Some property when property.ValueKind = JsonValueKind.String -> + let value = property.GetString() + if String.IsNullOrWhiteSpace value then Ok None else Ok(Some value) + | Some _ -> Error(sprintf "payload property '%s' must be null or a string" name)) + let private validateEnvelope root operation = result { let! schemaVersion = requiredString root "schema_version" @@ -475,6 +501,9 @@ module MarketData = let! priceProperty = requiredProperty quoteProperty "price" let! price = optionalDecimal "price" priceProperty let! currency = requiredString quoteProperty "currency" + let! market = optionalStringOrMissing quoteProperty "market" + let! adjust = optionalStringOrMissing quoteProperty "adjust" + let! suspended = optionalBool quoteProperty "suspended" return { @@ -485,6 +514,9 @@ module MarketData = Name = name Price = price Currency = currency + Market = market + Adjust = adjust + Suspended = suspended } } with @@ -530,12 +562,17 @@ module MarketData = if List.isEmpty bars then return! Error "observations must not be empty" + let! market = optionalStringOrMissing root "market" + let! adjust = optionalStringOrMissing root "adjust" + return { Source = source SourceRevision = sourceRevision CollectedAt = collectedAt Code = codeProperty + Market = market + Adjust = adjust Bars = bars } } |
