alpacahq / alpacahq/alpaca-py

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

未關閉
#296 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視
bug
主要語言
Python
星號
1.5k
分支
397
平均合併
1 天 16 小時
30 天內合併 PR
6

描述

### Is there an existing issue for this?

- [X] 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](https://alpaca.markets/docs/api-references/broker-api/accounts/account-activities/#enumactivitytype)
[Code](https://github.com/alpacahq/alpaca-py/blob/master/alpaca/trading/enums.py#L4-L32)

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

```markdown
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?

- [X] 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=[, , , , , , , , , , , , , , , , , , , , ])

...

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
mapping=lambda raw_activities: [
File "alpaca/broker/client.py", line 453, in
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
```

貢獻指南

開啟貢獻指南

評估

這個 Issue 還沒有評估資料。

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。