Skip to content

Conversation

@parthchandak02
Copy link

Summary

This PR adds comprehensive support for Robinhood's recurring investments feature, allowing users to programmatically create, retrieve, update, and cancel recurring investment schedules.

Changes

New Module: robin_stocks/robinhood/recurring_investments.py

  • get_recurring_investments() - Fetch all recurring investments (supports filtering by account or asset types)
  • create_recurring_investment() - Create new recurring investments with configurable frequency and amount
  • update_recurring_investment() - Update existing investments (pause/resume, change amount/frequency)
  • cancel_recurring_investment() - Cancel recurring investments (uses PATCH with state="deleted")
  • get_next_investment_date() - Get the next investment date for a given frequency

Modified Files

  • robin_stocks/robinhood/urls.py - Added URL helper functions for recurring investment endpoints
  • robin_stocks/robinhood/__init__.py - Exported all new recurring investment functions

Technical Details

  • Endpoint: Uses bonfire.robinhood.com/recurring_schedules/ (discovered through reverse engineering)
  • Authentication: Uses existing @login_required decorator and session management
  • Patterns: Follows existing library patterns and conventions
  • Error Handling: Proper error handling and status code checking

Testing

✅ Tested with real Robinhood account:

  • Successfully fetched 100+ existing recurring investments
  • Created new recurring investments
  • Updated recurring investments (pause/resume)
  • Cancelled recurring investments
  • Verified all functions work correctly

Example Usage

n
import robin_stocks.robinhood as rh

rh.login(username='...', password='...')

Get all recurring investments

investments = rh.get_recurring_investments()

Create a new recurring investment

rh.create_recurring_investment('TSLA', 50.0, frequency='weekly')

Pause an investment

rh.update_recurring_investment(schedule_id, state='paused')

Cancel an investment

rh.cancel_recurring_investment(schedule_id)## Notes

  • Uses unofficial endpoint (Robinhood doesn't provide a public API)
  • Consistent with existing robin_stocks approach since Robinhood doesn't offer a public API
  • All functions follow library conventions and patterns

- Add recurring_investments.py module with full CRUD operations
- Add get_recurring_investments() to fetch all recurring investments
- Add create_recurring_investment() to create new recurring investments
- Add update_recurring_investment() to update/pause/resume investments
- Add cancel_recurring_investment() to cancel investments (uses PATCH)
- Add get_next_investment_date() to get next investment date
- Add URL helper functions for recurring investments endpoints
- Export all functions in __init__.py

Uses bonfire.robinhood.com/recurring_schedules/ endpoint discovered through
reverse engineering. Addresses feature request for native recurring investments
support in robin_stocks.
- Change investment_target to investment_asset (matches Robinhood's POST format)
- Change instrument_id to asset_id
- Add account_number, ref_id, and other required fields
- Fixes HTTP 400 errors when creating recurring investments
…ignore

- Add examples/recurring_investments/ with example scripts:
  - create_from_csv.py: Bulk create recurring investments from CSV
  - get_all_recurring.py: List all recurring investments
  - create_recurring.py: Create single recurring investment
  - cancel_recurring.py: Cancel recurring investment
  - README.md: Documentation for examples
- Update .gitignore to ignore logs/ and recurring.csv files
- Move recurring.csv to examples folder (ignored by git)
- Add thread-safe rate limiting to helper.py (request_get, request_post, request_delete, request_document)
- Rate limiting disabled by default for backward compatibility
- Add enable_rate_limiting() and disable_rate_limiting() functions
- Move config.py to examples/recurring_investments/ (better location)
- Update create_from_csv.py to use core rate limiting
- Update .gitignore to exclude trapezoid folder and user data files

Rate limiting is opt-in and maintains full backward compatibility.
All existing code continues to work without changes.
… scripts

- Add compare_portfolio_changes.py utility to compare original vs current portfolio
- Add generate_final_portfolio_summary.py to create theme-based portfolio summaries
- Enhance get_all_recurring.py with Rich formatting, export options, and company info
- Fix update_recurring_investment() to use PATCH method correctly
- Improve cancel_recurring_investment() Content-Type handling
- Add portfolio_comparison_table.md with verified company information
- Update .gitignore to exclude .cursor/ and portfolio summary files
- Update README with new script documentation
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

Successfully merging this pull request may close these issues.

1 participant