Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: ActivityType enum out of sync with Alpaca's live APIs causing parsing errors #296

Open
2 tasks done
whitej125 opened this issue Jun 8, 2023 · 0 comments
Open
2 tasks done
Labels
bug Something isn't working

Comments

@whitej125
Copy link

Is there an existing issue for this?

  • I have searched the existing issues

Current Behavior

At least two new enumeration types are being used by Alpaca's REST APIs and are currently not supported by the python SDK. A parsing error/exception occurs when a given account returns an activity of one of these new types.

Alpaca's docs
Code

The two new enums are:
WH - Withheld
This is listed in Alpaca's documentation but does not appear in code.

NC - Name Change
On May 4th we received a message from Alpaca that a new ActivityType would appear starting on May 15th. Both the Alpaca docs AND the alpaca-py are not reflecting this new type.

Below is a snippet of the email from Alpaca's broker support.

We would like to inform you that Alpaca is building an enhancement to support symbol and CUSIP changes represented as account activities. This enhancement will be implemented on the 15th of May.  

Partners will be able to see a new corporate action type (entry_type as NC, which stands for “name change”) in both the account activity endpoint and NTA streaming endpoint.

Solution:
Add these two enumerations to trading/enums.py

Expected Behavior

An account that has NonTradingActivities such as WC or NC should not throw an exception in parsing.

SDK Version I encountered this issue in

0.8.2

Steps To Reproduce

Call `.get_account_activities(...)` for an Alpaca account where an account activity includes a NC activity.  Recently an account that used to hold Fiserv would this issues because they just changed their ticker (and thus an NC activity is produced).

Filled out the Steps to Reproduce section?

  • I have entered valid steps to reproduce my issue or have attached a minimally reproducible case in code that shows my issue happening; and understand that without this my issue will be flagged as invalid and closed after 30 days.

Anything else?

Relevant stack trace.

ValidationError: 1 validation error for ParsingModel[NonTradeActivity]
__root__ -> activity_type
  value is not a valid enumeration member; permitted: 'FILL', 'ACATC', 'ACATS', 'CIL', 'CSD', 'CSW', 'DIV', 'DIVCGL', 'DIVCGS', 'DIVNRA', 'DIVROC', 'DIVTXEX', 'FEE', 'INT', 'JNLC', 'JNLS', 'MA', 'PTC', 'REORG', 'SPIN', 'SPLIT' (type=type_error.enum; enum_values=[<ActivityType.FILL: 'FILL'>, <ActivityType.ACATC: 'ACATC'>, <ActivityType.ACATS: 'ACATS'>, <ActivityType.CIL: 'CIL'>, <ActivityType.CSD: 'CSD'>, <ActivityType.CSW: 'CSW'>, <ActivityType.DIV: 'DIV'>, <ActivityType.DIVCGL: 'DIVCGL'>, <ActivityType.DIVCGS: 'DIVCGS'>, <ActivityType.DIVNRA: 'DIVNRA'>, <ActivityType.DIVROC: 'DIVROC'>, <ActivityType.DIVTXEX: 'DIVTXEX'>, <ActivityType.FEE: 'FEE'>, <ActivityType.INT: 'INT'>, <ActivityType.JNLC: 'JNLC'>, <ActivityType.JNLS: 'JNLS'>, <ActivityType.MA: 'MA'>, <ActivityType.PTC: 'PTC'>, <ActivityType.REORG: 'REORG'>, <ActivityType.SPIN: 'SPIN'>, <ActivityType.SPLIT: 'SPLIT'>])

...

    for activity_list in self.broker_client.get_account_activities(
  File "alpaca/broker/client.py", line 519, in _get_account_activities_iterator
    yield mapping(result)
  File "alpaca/broker/client.py", line 452, in <lambda>
    mapping=lambda raw_activities: [
  File "alpaca/broker/client.py", line 453, in <listcomp>
    self._parse_activity(activity) for activity in raw_activities
  File "alpaca/broker/client.py", line 557, in _parse_activity
    return parse_obj_as(NonTradeActivity, data)
  File "pydantic/tools.py", line 38, in pydantic.tools.parse_obj_as
    return model_type(__root__=obj).__root__
  File "pydantic/main.py", line 341, in pydantic.main.BaseModel.__init__
    raise validation_error
@haxdds haxdds added the bug Something isn't working label Jul 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants