Skip to content

Add recurring investments API support#1633

Open
parthchandak02 wants to merge 9 commits into
jmfernandes:masterfrom
parthchandak02:master
Open

Add recurring investments API support#1633
parthchandak02 wants to merge 9 commits into
jmfernandes:masterfrom
parthchandak02:master

Conversation

@parthchandak02

Copy link
Copy Markdown

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
- Add 'Enhancements and Additions' section to README.rst documenting:
  * Enhanced portfolio performance checker with caching and progress bars
  * Portfolio comparison tool
  * New dependencies (requests-cache, tqdm)
- Add portfolio_comparison_report.json to .gitignore
- Remove portfolio_comparison_table.md (now ignored)
DhruvaBansal00 added a commit to DhruvaBansal00/robin_stocks that referenced this pull request May 23, 2026
Upstream PR jmfernandes#1633 (jmfernandes/robin_stocks). Cherry-picks only the
SDK-side changes from the PR; skips the unrelated repo bloat
(fork-branded README sections, compare_portfolio_changes.py script
at the repo root, examples/recurring_investments/ scripts, new tqdm
and requests-cache deps, .gitignore additions).

What was taken:

- robin_stocks/robinhood/recurring_investments.py: new module with
  five functions for the bonfire.robinhood.com/recurring_schedules/
  endpoint — get, create, update, cancel, and a next-investment-date
  helper. These endpoints are undocumented and may break.
- robin_stocks/robinhood/urls.py: recurring_schedules_url and
  next_investment_date_url helpers.
- robin_stocks/robinhood/globals.py + helper.py: opt-in, thread-safe
  rate-limiting hooked into request_get/request_post/request_delete/
  request_document, controlled by enable_rate_limiting(delay) /
  disable_rate_limiting(). Disabled by default to preserve
  backwards-compatible request timing.
- robin_stocks/robinhood/__init__.py: exports the new public API.

Adds matching MCP coverage:

- robin_stocks_mcp/tools/robinhood_recurring.py registers two read
  tools (rh_get_recurring_investments, rh_get_next_investment_date)
  and three write tools (rh_create_recurring_investment,
  rh_update_recurring_investment, rh_cancel_recurring_investment)
  guarded by the read-only mode.
- tests/mcp/test_robinhood_recurring_tools.py covers dispatch for
  every tool plus the read-only guard for each write.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
DhruvaBansal00 added a commit to DhruvaBansal00/robin_stocks that referenced this pull request May 23, 2026
DhruvaBansal00 added a commit to DhruvaBansal00/robin_stocks that referenced this pull request May 23, 2026
Caught while auditing MCP coverage after merging PR jmfernandes#1633: the SDK's
opt-in rate-limiter ships with toggle helpers but they had no MCP
wrapper, so an MCP client couldn't turn rate limiting on/off without
restarting with env config.

Both are marked as read-tools because they only mutate local SDK
state (no server-side effect), so the read-only guard does not need
to block them.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@DhruvaBansal00

DhruvaBansal00 commented May 23, 2026

Copy link
Copy Markdown

Thanks for this contribution! jmfernandes/robin_stocks appears to be unmaintained, so I've started a community-maintained fork at https://github.com/DhruvaBansal00/robin_stocks_v2 and merged this PR there: DhruvaBansal00/robin_stocks_v2@c595f22

It's included with test coverage in the new repo, alongside 11 other open PRs from here. If you'd like a maintained build with this change, that's where to find it.

Cherry-picked the recurring-investments module + opt-in rate limiter; left out the unrelated portfolio script/examples to keep the merge focused.

- Track .test.env.example instead; gitignore local .test.env

Co-authored-by: Cursor <cursoragent@cursor.com>
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.

2 participants