alienbrett / PyAlly

Ally Invest API Module for Python3
https://alienbrett.github.io/PyAlly/
MIT License
57 stars 28 forks source link

issue getting holdings when there is only 1 asset. #53

Closed alphatrades4 closed 4 years ago

alphatrades4 commented 4 years ago

There is a corner case when there is only 1 asset in an account. The code below from holdings.py expects a list in response but for only one asset it doesn't return a list.

def extract ( self, response ): """Extract certain fields from response """ response = response.json()['response'] holdings = response['accountholdings']['holding']

    return list( map( Holdings._flatten_holding, holdings ) )

The fix that I am doing locally is this to get over the issue.

def extract ( self, response ): """Extract certain fields from response """ response = response.json()['response'] holdings = response['accountholdings']['holding']

    **if not isinstance(holdings, list):
        holdings = [holdings]**

    return list( map( Holdings._flatten_holding, holdings ) )
JTraversa commented 4 years ago

Early morning for me but a couple typo'd references later and I've referenced it in PR #54

alienbrett commented 4 years ago

Thanks JTraversa, this issue appears fixed and is in the latest release