{"id":47701669,"url":"https://github.com/jamestford/pyhood","last_synced_at":"2026-04-02T17:21:42.872Z","repository":{"id":344892552,"uuid":"1183559022","full_name":"jamestford/pyhood","owner":"jamestford","description":"A modern Python client for the Robinhood API — with automatic token refresh and no auth headaches","archived":false,"fork":false,"pushed_at":"2026-03-23T23:40:18.000Z","size":17232,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-03-24T16:45:58.749Z","etag":null,"topics":["algorithmic-trading","api-client","automated-trading","finance","fintech","investing","options","options-trading","pyhood","python","quantitative-finance","robinhood-api","stock-market","stocks","trading"],"latest_commit_sha":null,"homepage":"https://jamestford.github.io/pyhood","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jamestford.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"docs/contributing.md","funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null},"funding":{"github":"jamestford"}},"created_at":"2026-03-16T18:20:29.000Z","updated_at":"2026-03-23T23:39:57.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/jamestford/pyhood","commit_stats":null,"previous_names":["jamestford/pyhood"],"tags_count":9,"template":false,"template_full_name":null,"purl":"pkg:github/jamestford/pyhood","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jamestford%2Fpyhood","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jamestford%2Fpyhood/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jamestford%2Fpyhood/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jamestford%2Fpyhood/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jamestford","download_url":"https://codeload.github.com/jamestford/pyhood/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jamestford%2Fpyhood/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31311317,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-02T12:59:32.332Z","status":"ssl_error","status_checked_at":"2026-04-02T12:54:48.875Z","response_time":89,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["algorithmic-trading","api-client","automated-trading","finance","fintech","investing","options","options-trading","pyhood","python","quantitative-finance","robinhood-api","stock-market","stocks","trading"],"created_at":"2026-04-02T17:21:42.215Z","updated_at":"2026-04-02T17:21:42.860Z","avatar_url":"https://github.com/jamestford.png","language":"Python","funding_links":["https://github.com/sponsors/jamestford"],"categories":[],"sub_categories":[],"readme":"# pyhood\n\n\u003cdiv align=\"center\"\u003e\n\u003cimg src=\"assets/logo-tight.png\" alt=\"pyhood logo\" width=\"200\"\u003e\n\n**A modern, reliable Python client for the Robinhood API.**\n\u003c/div\u003e\n\n[![CI](https://github.com/jamestford/pyhood/actions/workflows/ci.yml/badge.svg)](https://github.com/jamestford/pyhood/actions/workflows/ci.yml)\n[![PyPI](https://img.shields.io/pypi/v/pyhood.svg)](https://pypi.org/project/pyhood/)\n[![Docs](https://img.shields.io/badge/docs-jamestford.github.io%2Fpyhood-blue)](https://jamestford.github.io/pyhood)\n[![Python 3.10+](https://img.shields.io/badge/python-3.10%2B-blue.svg)](https://www.python.org/downloads/)\n[![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](LICENSE)\n[![Coverage](https://img.shields.io/badge/coverage-79%25-yellow.svg)](#)\n[![Security](https://github.com/jamestford/pyhood/actions/workflows/security.yml/badge.svg)](https://github.com/jamestford/pyhood/actions/workflows/security.yml)\n[![Code style: ruff](https://img.shields.io/badge/code%20style-ruff-000000.svg)](https://github.com/astral-sh/ruff)\n\nA modern, reliable Python client for the Robinhood API.\n\nBuilt for automated trading — with auth that doesn't break, proper error handling, and sane defaults.\n\n## Why pyhood?\n\n- 🪙 **Dual API support** — The only Python library that wraps both Robinhood's unofficial stocks/options API and their official Crypto Trading API. One library, full coverage.\n\n- 🔐 **Auth that just works** — Login with timeouts, automatic token refresh, and session persistence. Authenticate once, stay connected for days. No more scripts that hang forever waiting for device approval.\n- 🔄 **Automatic token refresh** — pyhood uses OAuth refresh tokens to renew your session silently — no credentials, no device approval, no human in the loop. Built for unattended automation.\n- 🏷️ **Type hints everywhere** — Full type annotations, dataclass responses, IDE-friendly. No more guessing what's in a dict.\n- 🛡️ **Built-in rate limiting** — Automatic request throttling and retry logic so you don't get locked out.\n- 📊 **Options-first** — Deep options chain support with Greeks, volume/OI analysis, and earnings integration. Supports both equity and index options (SPX, NDX, VIX, RUT).\n- 📈 **Futures trading** — Contract details, real-time quotes, order history, and P\u0026L calculation for Robinhood futures.\n- 🏦 **IRA/Retirement accounts** — Trade stocks and options in Traditional and Roth IRAs. The only Python Robinhood library with retirement account support.\n- 💰 **Banking \u0026 dividends** — Query ACH transfers, linked bank accounts, and dividend history.\n- 📋 **Watchlists** — Create, manage, and modify your Robinhood watchlists programmatically.\n- 🔍 **Research \u0026 discovery** — Analyst ratings, news feed, S\u0026P 500 movers, trending stocks, instrument popularity, and stock splits.\n- 📑 **Portfolio \u0026 documents** — Portfolio historicals, option historicals, account statements, and trade confirmations.\n- 🧪 **Tested and maintained** — 212 tests, CI across Python 3.10-3.13, linted with ruff. If it breaks, we know immediately.\n\n## Quick Start\n\n```python\nimport pyhood\nfrom pyhood.client import PyhoodClient\n\n# Login (with timeout — never hangs)\nsession = pyhood.login(username=\"you@email.com\", password=\"...\", timeout=90)\nclient = PyhoodClient(session)\n\n# Stock data\nquote = client.get_quote(\"AAPL\")\nprint(f\"AAPL: ${quote.price:.2f} ({quote.change_pct:+.1f}%)\")\n\n# Options chains (works for equities and indexes)\nchain = client.get_options_chain(\"SPX\", expiration=\"2026-04-17\")\nfor option in chain.calls:\n    print(f\"  {option.strike} call | IV: {option.iv:.0%} | Delta: {option.delta:.2f}\")\n\n# Account\npositions = client.get_positions()\nbalance = client.get_buying_power()\n```\n\n## IRA Trading\n\npyhood can discover and trade in IRA/retirement accounts — something no other Python Robinhood library supports.\n\n```python\n# Discover all accounts (including IRA)\naccounts = client.get_all_accounts()\n\n# Check IRA buying power\nbp = client.get_buying_power(account_number=\"YOUR_IRA_ACCOUNT\")\n\n# Buy options in your Roth IRA\norder = client.buy_option(\n    symbol=\"NKE\", strike=55.0, expiration=\"2026-04-02\",\n    option_type=\"call\", quantity=3, price=1.60,\n    account_number=\"YOUR_IRA_ACCOUNT\",\n)\n```\n\nSee the [Account documentation](https://jamestford.github.io/pyhood/account/) for details on IRA account discovery and limitations.\n\n## Authentication\n\nRobinhood requires **device approval** on first login. After that, pyhood keeps your session alive automatically.\n\n### First Login\n\n1. Have the **Robinhood mobile app** open on your phone\n2. Call `pyhood.login()` — it will trigger a device approval request\n3. Tap **\"Yes, it's me\"** in the Robinhood app when prompted\n4. pyhood saves the session token to `~/.pyhood/session.json` for reuse\n\n```python\nimport pyhood\n\n# First login — will wait up to 90s for you to approve on phone\nsession = pyhood.login(\n    username=\"you@email.com\",\n    password=\"your_password\",\n    timeout=90,  # seconds to wait for device approval\n)\n```\n\n### Staying Authenticated\n\nOnce you've approved the device, pyhood handles the rest:\n\n```python\n# Reuses cached session — no approval needed\nsession = pyhood.login(username=\"you@email.com\", password=\"your_password\")\n\n# Or refresh explicitly — no credentials needed at all\nsession = pyhood.refresh()\n```\n\nSessions last several days (observed 5-8 days). When the access token expires, pyhood automatically refreshes it using the stored refresh token — **no device approval, no credentials, no human interaction**. This is what makes pyhood safe for automated scripts and cron jobs.\n\nDevice approval is only needed again if the refresh token itself expires (typically much longer than the access token).\n\n### Error Handling\n\npyhood raises specific exceptions so you know exactly what went wrong:\n\n```python\nfrom pyhood.exceptions import (\n    LoginTimeoutError,            # Timed out waiting for device approval\n    DeviceApprovalRequiredError,  # Approval prompt sent but not completed\n    MFARequiredError,             # SMS/email code needed — pass mfa_code parameter\n    TokenExpiredError,            # Refresh token expired — full re-login needed\n    AuthError,                    # Generic auth failure\n)\n\ntry:\n    session = pyhood.login(username=\"...\", password=\"...\", timeout=90)\nexcept LoginTimeoutError:\n    print(\"Open Robinhood app and approve the device, then try again\")\nexcept MFARequiredError:\n    code = input(\"Enter the code from SMS/email: \")\n    session = pyhood.login(username=\"...\", password=\"...\", mfa_code=code)\nexcept AuthError as e:\n    print(f\"Login failed: {e}\")\n```\n\n### ⚠️ Rate Limits\n\nRobinhood aggressively rate-limits authentication. If login fails:\n\n- **Do NOT retry immediately** — wait at least 5 minutes\n- 2-3 failed attempts will lock out your account's API access for 5-10 minutes\n- Each login attempt generates a new device approval — old approvals don't carry over\n- See the [Rate Limits](https://jamestford.github.io/pyhood/rate-limits/) documentation for details\n\n## Install\n\n```bash\npip install pyhood\n```\n\n## Crypto Trading (Official API)\n\npyhood also supports Robinhood's **official** Crypto Trading API — no device approval needed, just API keys.\n\n```python\nfrom pyhood.crypto import CryptoClient\n\n# API key auth — generate keys at robinhood.com/account/crypto\ncrypto = CryptoClient(api_key=\"rh-api-...\", private_key_base64=\"...\")\n\n# Market data\nquotes = crypto.get_best_bid_ask(\"BTC-USD\", \"ETH-USD\")\nprice = crypto.get_estimated_price(\"BTC-USD\", \"buy\", 0.001)\n\n# Historical OHLCV data\ncandles = crypto.get_historicals(\"BTC-USD\", interval=\"hour\", span=\"week\")\nfor c in candles:\n    print(f\"{c.begins_at}  O:{c.open_price}  H:{c.high_price}  L:{c.low_price}  C:{c.close_price}\")\n\n# Account \u0026 holdings\naccount = crypto.get_account()\nholdings = crypto.get_holdings(account.account_number, \"BTC\")\n\n# Place an order\norder = crypto.place_order(\n    account_number=account.account_number,\n    side=\"buy\",\n    order_type=\"market\",\n    symbol=\"BTC-USD\",\n    order_config={\"asset_quantity\": \"0.001\"},\n)\n```\n\nGenerate your API keys at [robinhood.com/account/crypto](https://robinhood.com/account/crypto). See the [Crypto documentation](https://jamestford.github.io/pyhood/crypto/) for full details.\n\n## Futures Trading\n\npyhood supports Robinhood's futures API — contracts, quotes, orders, and P\u0026L tracking.\n\n```python\nclient = PyhoodClient(session)\n\n# Contract details\ncontract = client.get_futures_contract(\"ESH26\")\nprint(f\"{contract.name} — multiplier: {contract.multiplier}\")\n\n# Real-time quote\nquote = client.get_futures_quote(\"ESH26\")\nprint(f\"Last: {quote.last_price}  Bid: {quote.bid}  Ask: {quote.ask}\")\n\n# P\u0026L across all closed futures trades\npnl = client.calculate_futures_pnl()\nprint(f\"Realized P\u0026L: ${pnl:.2f}\")\n```\n\nSee the [Futures documentation](https://jamestford.github.io/pyhood/futures/) for full details.\n\n## Banking \u0026 Dividends\n\n```python\n# Check linked bank accounts\naccounts = client.get_bank_accounts()\n\n# View transfer history\ntransfers = client.get_transfers()\n\n# Initiate a deposit\ntransfer = client.initiate_transfer(\n    amount=500.00,\n    direction=\"deposit\",\n    ach_relationship_url=accounts[0].url,\n)\n\n# Dividend history\ndividends = client.get_dividends()\naapl_divs = client.get_dividends_by_symbol(\"AAPL\")\n```\n\n## Watchlists\n\n```python\n# Get all watchlists\nwatchlists = client.get_watchlists()\n\n# Get a specific watchlist\ndefault = client.get_watchlist(\"Default\")\nprint(default.symbols)  # ['AAPL', 'MSFT', ...]\n\n# Add / remove symbols\nclient.add_to_watchlist([\"NVDA\", \"TSLA\"])\nclient.remove_from_watchlist([\"TSLA\"])\n```\n\n## Markets \u0026 Trading Hours\n\n```python\n# List available exchanges\nmarkets = client.get_markets()\n\n# Check if NYSE is open on a specific date\nhours = client.get_market_hours(\"XNYS\", \"2026-03-30\")\nprint(f\"Open: {hours.is_open}, {hours.opens_at} — {hours.closes_at}\")\n```\n\n## Research \u0026 Discovery\n\n```python\n# Analyst ratings\nrating = client.get_ratings(\"AAPL\")\nprint(f\"Buy: {rating.num_buy}, Hold: {rating.num_hold}, Sell: {rating.num_sell}\")\n\n# News articles\narticles = client.get_news(\"AAPL\")\nfor a in articles:\n    print(f\"{a.source}: {a.title}\")\n\n# S\u0026P 500 movers\nmovers = client.get_movers(\"up\")\n\n# Trending stocks (100 most popular on Robinhood)\npopular = client.get_tags(\"100-most-popular\")\n\n# How many RH users hold a stock\ncount = client.get_popularity(\"AAPL\")\n\n# Stock split history\nsplits = client.get_splits(\"AAPL\")\n```\n\n## Portfolio \u0026 Option Historicals\n\n```python\n# Portfolio value over time\nhistory = client.get_portfolio_historicals(\n    account_number=\"123456\", interval=\"day\", span=\"year\",\n)\nfor candle in history:\n    print(f\"{candle.begins_at}: ${candle.adjusted_close_equity:.2f}\")\n\n# Historical option pricing\ncandles = client.get_option_historicals(\"option-id-here\", interval=\"day\", span=\"month\")\n\n# Account documents (statements, trade confirms, tax docs)\ndocs = client.get_documents(doc_type=\"account_statement\")\n```\n\n## Development Status\n- ✅ Stocks/options market data (unofficial API) — functional (equity + index options)\n- ✅ Futures trading (contracts, quotes, orders, P\u0026L) — functional\n- ✅ Crypto trading (official API) — functional\n- ✅ Authentication with automatic token refresh — functional\n- ✅ Full order management for stocks/options — functional\n- ✅ Banking (ACH transfers, deposits/withdrawals) — functional\n- ✅ Watchlists (create/manage) — functional\n- ✅ Dividends (query history) — functional\n- ✅ Markets/Trading Hours (exchange schedules) — functional\n- ✅ User profile \u0026 notification settings — functional\n- ✅ Research \u0026 discovery (ratings, news, movers, tags, popularity) — functional\n- ✅ Portfolio historicals \u0026 option historicals — functional\n- ✅ Documents \u0026 statements — functional\n- ✅ Day trades, margin calls, deposit schedules — functional\n\n## Acknowledgments\n\npyhood stands on the shoulders of the community that figured out Robinhood's unofficial API:\n\n- [**robin_stocks**](https://github.com/jmfernandes/robin_stocks) by [Josh Fernandes](https://github.com/jmfernandes) — The most widely used Python library for Robinhood. Its auth flow, endpoint mapping, and API patterns laid the groundwork that pyhood builds from.\n- [**pyrh**](https://github.com/robinhood-unofficial/pyrh) by [Robinhood Unofficial](https://github.com/robinhood-unofficial) — An early Python client that pioneered OAuth token refresh and session management patterns for the Robinhood API.\n- [**Robinhood**](https://github.com/sanko/Robinhood) by [Sanko](https://github.com/sanko) — The original unofficial API documentation that mapped out Robinhood's endpoints and made all of these libraries possible.\n\nThese projects made Robinhood accessible to developers. pyhood continues that mission with a focus on reliability and automation.\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjamestford%2Fpyhood","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjamestford%2Fpyhood","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjamestford%2Fpyhood/lists"}