How jmfernandes/robin_stocks works
Project Type and Purpose
• This is an open-source Python SDK (client library) that wraps three external trading APIs: Robinhood, Gemini, and TD Ameritrade.
• Users (scripts, Jupyter notebooks, production code) import this package to perform authentication, fetch market data, place orders, etc., via simple Python calls.
High-Level File/Module Structure
• Top-level:
• setup.py, requirements.txt, CI/CD config (.github/workflows/pythonapp.yml), docs/ (Sphinx sources), examples/, tests/, .test.env.
• Core package: robin_stocks/
• Subpackages: robin_stocks/robinhood, robin_stocks/gemini, robin_stocks/tda
• Each subpackage contains modules for authentication, account, markets, orders, helper utilities, globals, URLs.
Key README Insights
• Emphasis on three supported APIs, usage examples, testing via pytest + pytest-dotenv, publishing to PyPI.
• No internal database or UI—pure client wrapper.
Components
a. User/Application Layer
• Scripts or applications that import robin_stocks.<api_module>
• Example code (examples/ directory)
b. SDK Core Layer
• Authentication module (session management, 2FA, token handling)
• API-specific modules (account, markets, orders, crypto, options, etc.)
• Helper/Globals (shared utilities, endpoint definitions)
• Packaging/Setup (setup.py, versioning)
c. External Services
• Robinhood REST API endpoints
• Gemini REST API endpoints
• TD Ameritrade REST API endpoints
d. Support Infrastructure
• Testing: pytest, test files hitting sandbox endpoints (tests/)
• CI/CD: GitHub Actions (pythonapp.yml) running lint, tests, publish
• Docs: Sphinx (docs/source → HTML) published to ReadTheDocs
Relationship and Data Flow
• Authentication flow:
User code calls auth module → SDK manages credentials from .env → obtains tokens → attaches to subsequent requests
• CI/CD flow: on push → GitHub Actions → run tests, build docs, publish package
Architectural Patterns & Design Principles
• Modular separation by API (robinhood, gemini, tda)
• Layered approach: Authentication → Core actions (orders/markets) → Helpers/Globals
• Single responsibility per module.
• Environment-driven configuration (.test.env / .env).