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

Accounts fails to parse when multiple accounts exist #68

Open
garygause opened this issue Jun 4, 2021 · 1 comment
Open

Accounts fails to parse when multiple accounts exist #68

garygause opened this issue Jun 4, 2021 · 1 comment

Comments

@garygause
Copy link

I have three ally stock accounts and when running:

a.accounts()

the json data returned by Ally is not parsed properly into a dataframe. It contains only one row/column with all the json data in it. Also, I might expect it to only return info for the account number listed when instantiating the ally object, rather than all accounts.

Works fine with accounts(dataframe=False) but then has to be parsed manually. No big deal, but thought I would point it out.

@LaikaN57 LaikaN57 self-assigned this Jun 7, 2021
@LaikaN57
Copy link
Collaborator

LaikaN57 commented Jun 7, 2021

I took a quick look at this. It looks like it is "working", but maybe not(?). Let me try to explain a bit...

The GET Accounts API shows that we will end up with JSON like this:

{
  "response": {
    "accounts": {
      "accountsummary": [
        {
          "account": ... ,
          "accountbalance": { ... },
          "accountholdings": { ... }
        },
        ...
      ]
    }
  }
}

In our code, we extract the response and accounts keys but we do not extract the accountsummary key. I am not a Pandas expert but I believe this leads to a Pandas DataFrame that has a single row in a single named column accountsummary with the only cell containing an object-type. I would guess that you could then just cast the value of that cell to another Pandas DataFrame to get a Nx3 matrix where N is the number of accounts you have and the datatypes for the three columns are int, object, object (or similar).

... but wait...

I also saw that it looks like we solve for this by trying to flatten the JSON. When I did my quick investigation, it looked like this flattening was not happening(?). We should build out the unit tests for this function to verify that it is working correctly. I also found a good reference article about this type of scenario (referenced below).

Ref:

  1. https://medium.com/swlh/converting-nested-json-structures-to-pandas-dataframes-e8106c59976e

@LaikaN57 LaikaN57 removed their assignment Jun 7, 2021
@LaikaN57 LaikaN57 added bug Something isn't working question Further information is requested and removed bug Something isn't working question Further information is requested labels Feb 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants