From edc15e8f351f3116fa76f8d6a9b44dd32b720d6c Mon Sep 17 00:00:00 2001 From: Oleg Rakhmatulin Date: Sun, 10 Nov 2024 19:36:33 +0100 Subject: [PATCH] Issue #764 - Added custom string-to-enum converter for the `AccountActivityType` enum with fallback value. (cherry picked from commit da5e3070390ef75ffc5fbd88622f0e65085ec93f) --- Alpaca.Markets/Enums/AccountActivityType.cs | 11 +++++++++-- .../Helpers/AccountActivityTypeEnumConverter.cs | 14 ++++++++++++++ Alpaca.Markets/PublicAPI.Shipped.txt | 1 + 3 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 Alpaca.Markets/Helpers/AccountActivityTypeEnumConverter.cs diff --git a/Alpaca.Markets/Enums/AccountActivityType.cs b/Alpaca.Markets/Enums/AccountActivityType.cs index 706a4eb1..d7c3a743 100644 --- a/Alpaca.Markets/Enums/AccountActivityType.cs +++ b/Alpaca.Markets/Enums/AccountActivityType.cs @@ -3,7 +3,7 @@ /// /// Types of account activities /// -[JsonConverter(typeof(StringEnumConverter))] +[JsonConverter(typeof(AccountActivityTypeEnumConverter))] [SuppressMessage("ReSharper", "CommentTypo")] [SuppressMessage("ReSharper", "IdentifierTypo")] [SuppressMessage("ReSharper", "StringLiteralTypo")] @@ -263,5 +263,12 @@ public enum AccountActivityType /// [UsedImplicitly] [EnumMember(Value = "CFEE")] - CryptoFee + CryptoFee, + + /// + /// Unknown account activity type (i.e. one not supported by this version of SDK). + /// + [UsedImplicitly] + [EnumMember(Value = "UNKNOWN")] + Unknown } diff --git a/Alpaca.Markets/Helpers/AccountActivityTypeEnumConverter.cs b/Alpaca.Markets/Helpers/AccountActivityTypeEnumConverter.cs new file mode 100644 index 00000000..dc3cc819 --- /dev/null +++ b/Alpaca.Markets/Helpers/AccountActivityTypeEnumConverter.cs @@ -0,0 +1,14 @@ +namespace Alpaca.Markets; + +[SuppressMessage( + "Microsoft.Performance", "CA1812:Avoid uninstantiated internal classes", + Justification = "Object instances of this class will be created by Newtonsoft.JSON library.")] +internal sealed class AccountActivityTypeEnumConverter : StringEnumConverter +{ + public override Object ReadJson( + JsonReader reader, + Type objectType, + Object? existingValue, + JsonSerializer serializer) => + AccountActivityType.Unknown.FromEnumString(reader); +} diff --git a/Alpaca.Markets/PublicAPI.Shipped.txt b/Alpaca.Markets/PublicAPI.Shipped.txt index 1df2dbed..297483d2 100644 --- a/Alpaca.Markets/PublicAPI.Shipped.txt +++ b/Alpaca.Markets/PublicAPI.Shipped.txt @@ -52,6 +52,7 @@ Alpaca.Markets.AccountActivityType.StockSpinoff = 28 -> Alpaca.Markets.AccountAc Alpaca.Markets.AccountActivityType.StockSplit = 29 -> Alpaca.Markets.AccountActivityType Alpaca.Markets.AccountActivityType.SymbolChange = 27 -> Alpaca.Markets.AccountActivityType Alpaca.Markets.AccountActivityType.Transaction = 1 -> Alpaca.Markets.AccountActivityType +Alpaca.Markets.AccountActivityType.Unknown = 37 -> Alpaca.Markets.AccountActivityType Alpaca.Markets.AccountStatus Alpaca.Markets.AccountStatus.AccountClosed = 13 -> Alpaca.Markets.AccountStatus Alpaca.Markets.AccountStatus.AccountUpdated = 3 -> Alpaca.Markets.AccountStatus