| skill_id | error_handling_protocols |
| name | Error Handling Protocols |
| version | 1.0.0 |
| description | Standard protocols for handling errors, API failures, and infrastructure issues |
| author | Trading System CTO |
| tags | error-handling, reliability, api-failures, infrastructure |
Error Handling Protocols
Standard protocols for handling errors, API failures, and infrastructure issues in the trading system.
API Failure Handling
Data Source Failures
Priority Order (fail fast, use reliable sources first):
- Try Alpaca API (most reliable)
- Try Polygon.io (reliable paid source)
- Use cached data (if < 24 hours old)
- Try yfinance (unreliable free source)
- Skip Alpha Vantage if rate-limited (fail fast)
Timeout Handling
- Alpha Vantage: Max 90 seconds total (fail fast)
- yfinance: 30-second timeout per request
- Alpaca: 60-second timeout per request
- Polygon.io: 30-second timeout per request
Rate Limit Handling
- Alpha Vantage: Skip immediately if rate-limited (don't retry)
- yfinance: Exponential backoff (2s, 4s, 8s)
- Alpaca: Respect rate limits, use retry logic
- Polygon.io: Respect rate limits, use retry logic
Workflow Failure Handling
GitHub Actions Failures
- Detect failure: Check workflow status
- Capture error: Log to Sentry (if configured)
- Fallback: Use cached data if available
- Alert: Notify via logs (future: Slack/email)
- Recovery: Manual performance log update script available
Trading Execution Failures
- Pre-trade validation: Check all circuit breakers
- API failures: Retry with exponential backoff
- Order failures: Log and continue (don't halt system)
- Data failures: Use cached data, skip day if necessary
Error Monitoring
Sentry Integration
- Automatic: Captures exceptions and errors
- Context: Adds trading-specific context
- GitHub Actions: Includes workflow context
- Optional: Fails gracefully if not configured
Logging Standards
- ERROR: Critical failures requiring attention
- WARNING: Degraded functionality (fallbacks used)
- INFO: Normal operations and decisions
- DEBUG: Detailed execution traces
Graceful Degradation
When Data Sources Fail
- Try reliable sources first (Alpaca, Polygon)
- Use cached data if available (< 24 hours old)
- Skip unreliable sources (yfinance, Alpha Vantage)
- Skip trading day if no data available (better than bad data)
When Workflow Fails
- Manual recovery:
scripts/update_performance_log.py - Next run: Will use latest code (fixes applied)
- Monitoring: Sentry tracks failures for analysis
Best Practices
- Fail fast: Don't wait 10+ minutes for rate-limited APIs
- Use reliable sources: Prioritize paid APIs over free ones
- Cache aggressively: Use cached data when APIs fail
- Monitor proactively: Sentry detects issues before they cascade
- Document failures: Log all failures for analysis
Integration
These protocols are enforced in:
src/utils/market_data.py(data source priority)src/utils/error_monitoring.py(Sentry integration).github/workflows/daily-trading.yml(workflow error handling)