Skip to content

Commit

Permalink
Issue #764 - Added custom string-to-enum converter for the `AccountAc…
Browse files Browse the repository at this point in the history
…tivityType` enum with fallback value.
  • Loading branch information
OlegRa committed Nov 10, 2024
1 parent f6bde3f commit da5e307
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
11 changes: 9 additions & 2 deletions Alpaca.Markets/Enums/AccountActivityType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/// <summary>
/// Types of account activities
/// </summary>
[JsonConverter(typeof(StringEnumConverter))]
[JsonConverter(typeof(AccountActivityTypeEnumConverter))]
[SuppressMessage("ReSharper", "CommentTypo")]
[SuppressMessage("ReSharper", "IdentifierTypo")]
[SuppressMessage("ReSharper", "StringLiteralTypo")]
Expand Down Expand Up @@ -271,5 +271,12 @@ public enum AccountActivityType
/// </summary>
[UsedImplicitly]
[EnumMember(Value = "CFEE")]
CryptoFee
CryptoFee,

/// <summary>
/// Unknown account activity type (i.e. one not supported by this version of SDK).
/// </summary>
[UsedImplicitly]
[EnumMember(Value = "UNKNOWN")]
Unknown
}
14 changes: 14 additions & 0 deletions Alpaca.Markets/Helpers/AccountActivityTypeEnumConverter.cs
Original file line number Diff line number Diff line change
@@ -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) =>
reader.ReadEnumString(AccountActivityType.Unknown);
}
1 change: 1 addition & 0 deletions Alpaca.Markets/PublicAPI.Shipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,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
Expand Down

0 comments on commit da5e307

Please sign in to comment.