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

Retirement Accounts #168

Open
exploringfinance opened this issue Jul 9, 2023 · 0 comments
Open

Retirement Accounts #168

exploringfinance opened this issue Jul 9, 2023 · 0 comments

Comments

@exploringfinance
Copy link

exploringfinance commented Jul 9, 2023

Have you considered adding the ability to trade your retirement accounts? Your current account API pull only returns the main account, but if you use https://api.robinhood.com/accounts/?default_to_all_accounts=true then you can see all the accounts. It shows the URL and account number for all three.

You could add an optional argument in the RobinHood login function for account type to specify which account to use and then feed this into other functions. It looks like RH will use the account URL in things like place_order, but then others do a base pull which always defaults to the main account.

The following code will return different results if you look at the outputs. The problem is that you are repulling the account number for most of your functions instead of relying on the RobinHood class function so you would need to rebuild a lot of functions.

New_Robinhood = function(username, password, mfa_code, account_type = 'individual'){
  RH <- RobinHood::api_login(username,password,mfa_code)

  url = 'https://api.robinhood.com/accounts/?default_to_all_accounts=true'
  token <- paste("Bearer", RH$api_response.access_token)
  dta <- GET(url, add_headers(Accept = "application/json", 
                              `Content-Type` = "application/json", Authorization = token))
  httr::stop_for_status(dta)
  dta <- RobinHood::mod_json(dta, "fromJSON")
  url_account_id = dta$results$url[dta$results$brokerage_account_type==account_type]
  act_number = dta$results$account_number[dta$results$brokerage_account_type==account_type]
  RH <- c(RH, url = list(account_id = url_account_id, account_number = act_number))
  if (is.null(RH$api_response.access_token)) {
    cat("Login not successful, check username and password.")
  }
  class(RH) <- "RobinHood"
  return(RH)
}

### Produces three different outputs
RH1 = New_Robinhood(username,password,mfa_code)
RH2 = New_Robinhood(username,password,mfa_code, account_type = 'ira_roth')
RH3 = New_Robinhood(username,password,mfa_code, account_type = 'ira_traditional')

### This produces same output because of how the helper functions exist
get_accounts(RH1)
get_accounts(RH2)

### place order works naturally because it uses the RH URL, account and positions require the following APIs:
url = 'https://api.robinhood.com/positions/?account_number=XXXXXXXX'
url = 'https://bonfire.robinhood.com/accounts/XXXXXXXX/unified/'


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

1 participant