alpaca-trade-api-python icon indicating copy to clipboard operation
alpaca-trade-api-python copied to clipboard

Rename class to asset_class in list_assets

Open tallm0cha opened this issue 2 years ago • 2 comments

Is there an existing issue for this?

  • [X] I have searched the existing issues

Is your feature request related to a problem? Please describe.

I am trying to get a list of all asset classes to filter for different strategies. Current list asset returns: Asset({` 'class': 'us_equity', 'easy_to_borrow': True, 'exchange': 'OTC', 'fractionable': False, 'id': 'fb514a1e-243c-4334-8b5d-da2b5735037b', 'marginable': False, 'name': 'Tier One Silver Inc Common Shares (Canada)', 'shortable': True, 'status': 'active', 'symbol': 'TSLVF', 'tradable': False})

In its current form, I can't use the class values as it is a python keyword in the following: assdf = pd.DataFrame({ 'asset_class':[asset.class for asset in active_assets if asset.tradable], 'symbol':[asset.symbol for asset in active_assets if asset.tradable], 'exchange': [asset.exchange for asset in active_assets if asset.tradable], 'shortable': [asset.shortable for asset in active_assets if asset.tradable], 'fractionable': [asset.fractionable for asset in active_assets if asset.tradable], 'marginable': [asset.marginable for asset in active_assets if asset.tradable]})

Describe the solution you'd like.

No response

Describe an alternate solution.

Maybe there's a workaround and I'd appreciate the advice

Anything else? (Additional Context)

No response

tallm0cha avatar Feb 11 '22 18:02 tallm0cha

I know about these workarounds:

getattr(asset, "class")

and

asset._raw["class"]

gnvk avatar Feb 15 '22 14:02 gnvk

@tallm0cha sorry about this one, due to the current design of the api these types are all just essentially fancy wrappers around the raw maps; this kind of thing is one of the main points we wanted to address in the new design of the sdk :disappointed:

Does the workaround suggested above work for you ? Am I good to close out this issue?

drew887 avatar Apr 29 '22 15:04 drew887