examples: add LBR Anti-Setup algo trading bot for Magnificent 7#665
Open
idsts2670 wants to merge 4 commits intoalpacahq:masterfrom
Open
examples: add LBR Anti-Setup algo trading bot for Magnificent 7#665idsts2670 wants to merge 4 commits intoalpacahq:masterfrom
idsts2670 wants to merge 4 commits intoalpacahq:masterfrom
Conversation
Adds a production-ready implementation of Linda Raschke's LBR 3/10 Anti-Setup strategy for the Magnificent 7 stocks using AWS Lambda and Alpaca's Trading API, including: - Serverless deployment via AWS Lambda + EventBridge (9:30 AM ET daily) - MACD/ADX/EMA/ATR signal logic with 6-rule filter - ATR-based trailing stops and equal-weight rebalancing - DynamoDB portfolio state persistence - Educational Jupyter notebook walkthrough - pytest test suite (17 tests) - Pre-deployment checklist docs Update examples/stocks/README.md with correct relative paths and consistent table headers. Made-with: Cursor
ea8fcc1 to
92e00ce
Compare
Prevent repo-level pytest from collecting tests inside standalone example projects under examples/. Made-with: Cursor
Made-with: Cursor
## Architecture & Flow Improvements - **Idempotency gate**: Add dedup check with DynamoDB atomic conditional put to prevent duplicate CloudWatch invocations from creating double orders - **Buying power validation**: Insert decision gate after account snapshot to validate sufficient funds before order submission - **Rebalance synchronization**: Replace fixed sleep delays with explicit polling confirmation; ensure sells complete before buys submit, both flow through WAIT_SELL/WAIT_BUY gates - **Exit order accuracy**: Replace ASK price estimation with actual fill prices (GET_FILLS); compute stop levels and trail percentages from avg_fill_price and filled_qty; align TimeInForce (DAY) across entry and exit to prevent orphaned GTC orders - **Cancel order verification**: Add verification step to detect partial fills; refresh account snapshot (RESNAPSHOT) when fills detected before proceeding to rebalance - **Comprehensive error handling**: Add retry/backoff loops with circuit breaker patterns for all external API calls (get_clock, get_price_history, get_account, get_all_positions, get_orders, cancel_order, MarketOrderRequest, _store_portfolio); include timeout specs, max retry counts, and alerting thresholds; log clear warnings on all failure paths - **DST handling**: Replace CloudWatch Events with EventBridge Scheduler using timezone-aware cron (America/New_York) to ensure bot runs at 9:30 AM ET year-round, not affected by daylight saving transitions ## Code Hardening - **Defensive quote access**: Update _get_ask_price() to use .get() for nested dict access instead of direct bracket; handle missing askPrice keys and invalid values with logging; return None safely for all error cases - **Quote validation in stop setup**: Add defensive checks before accessing entry_quotes in stop-loss calculation; log and skip symbol if quote unavailable or askPrice missing - **Fix pytz version constraint**: Update from invalid future version 2026.1.post1 to valid range >=2025.1,<2027 - **Fix notebook title**: Correct README reference from IBR to LBR (Linda Bradford Raschke strategy) All changes verified against current code; callers already safely handle None returns and graceful degradation.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
examples/stocks/lbr-anti-setup-trading-bot/— a production-ready implementation of Linda Raschke's LBR 3/10 Anti-Setup strategy using AWS Lambda and Alpaca's Trading APIexamples/stocks/README.mdwith correct relative paths and consistent table headersWhy
Adds an advanced, serverless algorithmic trading example for Alpaca API users who want to learn how to build and deploy a real trading bot using cloud infrastructure.
What's Included
notebooks/ibr_algorithm_walkthrough.ipynb— step-by-step walkthrough with live Alpaca datadocs/PRE-DEPLOYMENT.mdpre-flight checklistTest plan
uv run pytest tests/ -vpasses (17 tests)Made with Cursor