Executor pattern, RobinhoodClient, deferred task scheduler#53
Executor pattern, RobinhoodClient, deferred task scheduler#53IamJasonBian wants to merge 3 commits into
Conversation
- Split SafeCashBot into RobinhoodClient (thin broker wrapper) and Executor (execution quality layer: PDT gate, spread checker, fill logger/auditor) - Add Brokerage ABC for dependency inversion - Add TradeTask, ScheduledTask, DeferredTask for Command/Strategy pattern - Executor owns deferred queue; PDT-blocked orders deferred to next trading day - Fix cancel_order_by_id → cancel_order throughout tests and main - Align lot_size and strategy pricing defaults across tests
- Singleton: create() returns cached instance, one login per process - Factory: create() owns env/auth/verify, __init__ is a plain setter - Fix: _execute_stale_refresh passed dry_run kwarg cancel_order doesn't accept - Fix: verbose print blocks in _execute_* now only fire in dry_run; live logging owned by RobinhoodClient - Fix: validate_buy_order accepts buying_power to skip redundant API call; called once upstream in _execute_buy_order - Remove: _compute_btc_correlations, _get_daily_returns, _pearson_from_return_dicts (unused in RobinhoodClient)
Code Review — PR #53Overall: Well-structured refactor splitting Issues
Strengths
Generated by Claude Code |
Follow-up Review — PR #53A few additional items not covered in the initial review:
Generated by Claude Code |
|
Stale PR notice — This PR has been open for 15 days with no new commits since Mar 27. Two code reviews have been posted with actionable items (e.g., Generated by Claude Code |
|
Stale — 4 weeks, no activity since Mar 27. Two prior reviews identified actionable bugs: Generated by Claude Code |
Code Deletion Opportunities — PR #53Focused follow-up on redundant code within 1. Extract duplicated order-parsing logic (~50 lines → ~20)
Extract a 2. Move analytics out of the broker client (~130 lines deletable)
Move these to a dedicated 3.
|
IamJasonBian
left a comment
There was a problem hiding this comment.
Stale — large refactor that overlaps with PR #32.
This PR introduces the Brokerage ABC, Executor, and TradeTask/DeferredTask patterns, which is a cleaner architecture than PR #32's ExecutionManager. However, both PRs are stale and likely have significant merge conflicts with main.
Cross-PR overlap:
- PR #32 adds
execution/execution_manager.py,price_discovery.py,fill_monitor.py,slippage_controller.py - This PR adds
utils/brokerage.py(ABC), restructuresRobinhoodClientout ofSafeCashBot, and addstrade_task.py - Both touch
main.pyextensively. Merging both is not viable without major reconciliation.
Recommendation: Decide which execution architecture to keep. If the Brokerage ABC / Executor pattern here is the winner, close PR #32 and rebase this. If pieces of #32's price discovery or slippage control are wanted, port them into this PR's architecture.
Code note on TradeTask / DeferredTask: The in-memory _deferred_queue will lose deferred orders on process restart. If the engine runs on Render (PR #52), crashes or deploys will silently drop queued orders. Consider persisting the queue to the state log or at least logging a warning on startup if the queue was non-empty.
Generated by Claude Code
Summary
SafeCashBotintoRobinhoodClient(thin broker wrapper) andExecutor(execution quality layer)BrokerageABC (utils/brokerage.py) for dependency inversion —Executordepends on the interface, not the concrete clientTradeTask/ScheduledTask/DeferredTask(trade_task.py) using Command + Strategy patterns_deferred_queue, drained at top of each engine cyclecancel_order_by_id→cancel_orderacrossmain.pyand all testslot_sizeand strategy pricing defaults so tests match live configTest plan
pytest tests/— all 166 tests pass