diff --git a/src/FX.Core/RedisStorageLayer.fs b/src/FX.Core/RedisStorageLayer.fs index 00e03de..8e5abec 100644 --- a/src/FX.Core/RedisStorageLayer.fs +++ b/src/FX.Core/RedisStorageLayer.fs @@ -6,11 +6,38 @@ open System open FsharpExchangeDotNetStandard open System.Text.Json +open System.Text.Json.Serialization open StackExchange.Redis [] module Serialization = - let serializationOptions = JsonSerializerOptions.Default + type SideTypeConverter() = + inherit JsonConverter() + + override this.Read(reader, _typeToConvert, _options) = + reader.GetString() |> Side.Parse + + override this.Write(writer, value, _options ) = + writer.WriteStringValue(value.ToString()) + + type CurrencyTypeConverter() = + inherit JsonConverter() + + override this.Read(reader, _typeToConvert, _options) = + match reader.GetString() with + | "BTC" -> BTC + | "USD" -> USD + | unknownCurrency -> failwithf "Unknown currency: %s" unknownCurrency + + override this.Write(writer, value, _options ) = + writer.WriteStringValue(value.ToString()) + + let serializationOptions = + let options = JsonSerializerOptions() + options.Converters.Add(SideTypeConverter()) + options.Converters.Add(CurrencyTypeConverter()) + options + type OrderQuery = {