@@ -9,9 +9,12 @@ This file provides comprehensive guidance to Claude Code (claude.ai/code) and ot
99- Market data access (historical, real-time quotes, news)
1010- Stock analysis tools (screeners, ML predictions, sentiment)
1111- Full type safety with mypy strict mode
12- - Comprehensive test coverage (109+ tests)
12+ - Comprehensive test coverage (350+ tests)
13+ - Caching system with LRU and Redis support
14+ - Feed management with automatic subscription detection
15+ - Batch operations for multi-symbol data fetching
1316
14- ** Current Version** : 2.2 .0
17+ ** Current Version** : 3.0 .0
1518** Python Support** : 3.10+
1619** License** : MIT
1720
@@ -21,6 +24,7 @@ This file provides comprehensive guidance to Claude Code (claude.ai/code) and ot
2124- Python 3.10 or higher
2225- uv package manager (recommended) or pip
2326- Alpaca API credentials (paper trading credentials for testing)
27+ - Optional: Redis server for caching (falls back to memory cache if not available)
2428
2529### Initial Setup
2630``` bash
@@ -64,7 +68,7 @@ uv tree
6468
6569### Testing
6670``` bash
67- # Run all tests with API credentials
71+ # Run all tests with API credentials (recommended)
6872./test.sh
6973
7074# Run specific test file
@@ -81,8 +85,17 @@ uv run pytest -q tests
8185
8286# Run tests with markers
8387uv run pytest -m " not slow"
88+
89+ # Skip CI-specific tests locally
90+ uv run pytest -m " not ci_skip"
8491```
8592
93+ #### CI Test Configuration
94+ Tests are configured to handle rate limiting in CI environments:
95+ - Tests marked with ` @pytest.mark.ci_skip ` are skipped in CI
96+ - Tests marked with ` @pytest.mark.rate_limited ` have automatic delays in CI
97+ - See ` tests/conftest.py ` for CI detection and rate limit handling
98+
8699### Code Quality
87100``` bash
88101# Run all quality checks (recommended before committing)
@@ -124,20 +137,24 @@ py-alpaca-api/
124137│ ├── exceptions.py # Custom exception hierarchy
125138│ ├── trading/ # Trading operations
126139│ │ ├── __init__.py # Trading module exports
127- │ │ ├── account.py # Account management
140+ │ │ ├── account.py # Account management & configuration
128141│ │ ├── orders.py # Order execution & management
129142│ │ ├── positions.py # Position tracking
130143│ │ ├── watchlists.py # Watchlist CRUD
131144│ │ ├── market.py # Market hours & calendar
132145│ │ ├── news.py # Financial news aggregation
133- │ │ └── recommendations.py # Stock sentiment analysis
146+ │ │ ├── recommendations.py # Stock sentiment analysis
147+ │ │ └── corporate_actions.py # Dividends, splits, mergers
134148│ ├── stock/ # Market data & analysis
135149│ │ ├── __init__.py # Stock module exports
136150│ │ ├── assets.py # Asset information
137- │ │ ├── history.py # Historical data retrieval
151+ │ │ ├── history.py # Historical data retrieval (with batch support)
138152│ │ ├── screener.py # Gainers/losers screening
139153│ │ ├── predictor.py # ML predictions (Prophet)
140- │ │ └── latest_quote.py # Real-time quotes
154+ │ │ ├── latest_quote.py # Real-time quotes (with batch support)
155+ │ │ ├── trades.py # Trade data access
156+ │ │ ├── snapshots.py # Market snapshots
157+ │ │ └── metadata.py # Market metadata (conditions, exchanges)
141158│ ├── models/ # Data models
142159│ │ ├── account_model.py # Account dataclass
143160│ │ ├── order_model.py # Order dataclass
@@ -147,8 +164,13 @@ py-alpaca-api/
147164│ │ ├── quote_model.py # Quote dataclass
148165│ │ ├── clock_model.py # Market clock dataclass
149166│ │ └── model_utils.py # Conversion utilities
167+ │ ├── cache/ # Caching system
168+ │ │ ├── __init__.py # Cache exports
169+ │ │ ├── cache_config.py # Cache configuration
170+ │ │ └── cache_manager.py # LRU & Redis cache implementation
150171│ └── http/ # HTTP layer
151- │ └── requests.py # Request handling with retries
172+ │ ├── requests.py # Request handling with retries
173+ │ └── feed_manager.py # Feed management & auto-fallback
152174├── tests/ # Test suite
153175│ ├── test_trading/ # Trading tests
154176│ ├── test_stock/ # Stock tests
@@ -264,6 +286,26 @@ def test_feature_scenario_expected_result(alpaca):
264286- Clean up test data after each test (cancel orders, etc.)
265287- Use small quantities/notional values to avoid account limits
266288
289+ ## ⚙️ Type Checking Configuration
290+
291+ ### Special Configurations
292+ The project uses specific mypy configurations for certain modules:
293+
294+ ``` toml
295+ # pyproject.toml
296+ [[tool .mypy .overrides ]]
297+ module = " py_alpaca_api.cache.cache_manager"
298+ warn_unused_ignores = false
299+ warn_unreachable = false
300+
301+ [tool .ruff .lint .per-file-ignores ]
302+ "src/py_alpaca_api/cache/cache_manager.py" = [" PLC0415" ] # Allow local import for optional redis
303+ ```
304+
305+ These are needed because:
306+ - Redis is an optional dependency (local import required)
307+ - Mypy has limitations with dataclass type checking
308+
267309## 🐛 Common Issues & Solutions
268310
269311### Issue: ValidationError instead of ValueError
@@ -372,13 +414,70 @@ df = df[df["column"] > value]
372414- ` ruff-format ` : Format Python code
373415- ` mypy ` : Type check Python code
374416
417+ ## 💾 Caching System
418+
419+ ### Overview
420+ The caching system reduces API calls and improves performance:
421+ - ** LRU Memory Cache** : Default, no setup required
422+ - ** Redis Cache** : Optional, falls back to memory if unavailable
423+ - ** Configurable TTLs** : Different cache durations per data type
424+
425+ ### Configuration
426+ ``` python
427+ from py_alpaca_api.cache import CacheConfig, CacheType
428+
429+ # Memory cache (default)
430+ config = CacheConfig(
431+ cache_type = CacheType.MEMORY ,
432+ max_size = 1000 ,
433+ default_ttl = 300 # 5 minutes
434+ )
435+
436+ # Redis cache
437+ config = CacheConfig(
438+ cache_type = CacheType.REDIS ,
439+ redis_host = " localhost" ,
440+ redis_port = 6379 ,
441+ redis_password = " optional_password"
442+ )
443+ ```
444+
445+ ### Default TTLs
446+ - Market hours/calendar: 1 day
447+ - Assets: 1 hour
448+ - Account data: 1 minute
449+ - Positions: 10 seconds
450+ - Orders: 5 seconds
451+ - Quotes: 1 second
452+ - Market metadata: 1 day
453+
454+ ## 🔄 Feed Management
455+
456+ ### Automatic Feed Detection
457+ The feed manager automatically detects your subscription level and falls back gracefully:
458+ - ** SIP** → ** IEX** → ** OTC** (automatic fallback chain)
459+ - Caches failed feeds to avoid repeated attempts
460+ - Per-endpoint feed configuration
461+
462+ ### Usage
463+ ``` python
464+ # Automatic feed selection
465+ quotes = alpaca.stock.latest_quote.get(" AAPL" ) # Uses best available feed
466+
467+ # Manual feed selection
468+ quotes = alpaca.stock.latest_quote.get(" AAPL" , feed = " iex" )
469+ ```
470+
375471## 📈 Performance Considerations
376472
3774731 . ** Rate Limiting** : Alpaca API has rate limits, use caching when possible
3784742 . ** Batch Operations** : Combine multiple requests when feasible
475+ - Automatic batching for 200+ symbols
476+ - Concurrent request processing
3794773 . ** DataFrame Operations** : Use vectorized operations over loops
3804784 . ** Prophet Models** : Cache trained models for repeated predictions
3814795 . ** News Fetching** : Implement caching to avoid repeated scraping
480+ 6 . ** CI Testing** : Tests marked with ` @pytest.mark.ci_skip ` or ` @pytest.mark.rate_limited `
382481
383482## 🔒 Security
384483
@@ -408,16 +507,35 @@ For new contributors:
408507
409508## 💡 Tips for AI Assistants
410509
411- 1 . ** Always run tests** after making changes
510+ 1 . ** Always run tests** after making changes using ` ./test.sh `
4125112 . ** Use type hints** in all new code
4135123 . ** Follow existing patterns** in the codebase
414- 4 . ** Check pre-commit hooks ** before committing
513+ 4 . ** Run ` make check ` ** before committing - this runs all quality checks
4155145 . ** Update tests** when changing functionality
4165156 . ** Document breaking changes** clearly
4175167 . ** Preserve backward compatibility** when possible
418- 8 . ** Use descriptive commit messages**
517+ 8 . ** Use descriptive commit messages** with conventional format (feat:, fix:, docs:, etc.)
518+ 9 . ** Handle rate limiting** in tests with appropriate markers
519+ 10 . ** Use caching** for frequently accessed data
520+ 11 . ** Check CI status** after pushing changes
521+ 12 . ** Update DEVELOPMENT_PLAN.md** when completing tasks
522+
523+ ### Important Commands
524+ ``` bash
525+ # Before committing
526+ make check # Run all quality checks
527+ ./test.sh # Run tests with API keys
528+
529+ # Fix issues
530+ make format # Auto-format code
531+ make lint # Fix linting issues
532+
533+ # Development
534+ uv sync --all-extras --dev # Install dependencies
535+ git checkout -b feature/name # Create feature branch
536+ ```
419537
420538---
421539
422- * Last Updated: Version 2.2 .0*
540+ * Last Updated: Version 3.0 .0*
423541* Maintained by: py-alpaca-api team*
0 commit comments