Skip to content

Reduce maximum order size to 50 shares#50

Open
IamJasonBian wants to merge 3 commits intomainfrom
reduce-lot-size-to-50
Open

Reduce maximum order size to 50 shares#50
IamJasonBian wants to merge 3 commits intomainfrom
reduce-lot-size-to-50

Conversation

@IamJasonBian
Copy link
Copy Markdown
Owner

@IamJasonBian IamJasonBian commented Mar 18, 2026

Summary

  • Changed DEFAULT_LOT_SIZE from 250 to 50 share - BTC is going up!
  • Reduce DCA until we have a growth strat

IamJasonBian and others added 3 commits March 2, 2026 18:12
Changed the default Netlify Blob store from 'order-book' to 'state-logs'
to write state snapshots directly to long-term storage while the UI
manages the cut-over between blob stores.

This allows the UI to handle reading from both old (order-book) and new
(state-logs) blob stores during the transition period without the
archive workflow interfering by moving blobs between stores.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Critical fixes for Pattern Day Trading protection:

1. **Check filled orders, not just open orders** (pdt_gate.py:71-160)
   - OLD: Only checked open orders from today
   - NEW: Checks recent filled stock + option orders (last 1 day)
   - Uses `last_transaction_at` (fill time) not `created_at` (order time)
   - Prevents PDT violations from orders that filled earlier in the day

2. **Add same-day fill cache** (pdt_gate.py:19)
   - Cache format: {symbol: {'buy': date, 'sell': date}}
   - Faster checks after initial API fetch
   - Auto-clears fills from previous days

3. **Track option fills for underlying stocks** (pdt_gate.py:122-154)
   - BUY to open option = BUY underlying (for PDT purposes)
   - SELL to close option = SELL underlying (for PDT purposes)
   - Prevents day trades via options on same underlying

4. **Block paired orders if day trade risk** (main.py:239-255)
   - Before placing paired buy+sell orders, check both sides for PDT risk
   - Skip paired order placement if either side would violate PDT
   - Prevents immediate round trips from paired DCA orders

5. **Clear warning messages** (pdt_gate.py:66-69)
   - "⚠️ WILL CREATE DAY TRADE" when opposite side filled today
   - Shows day trade count (e.g., "0/3 used")
   - Helps traders make informed decisions

Test coverage:
- tests/test_pdt_guard.py: Live data validation
- Verified with real positions: BTC stock + IWN options

Before this fix:
❌ Could sell BTC same day as buy (missed filled order)
❌ Could close IWN options same day (missed option fills)
❌ Paired orders could create instant day trades

After this fix:
✅ Detects BTC buy from today → warns on sell attempt
✅ Detects IWN option opens from today → warns on close attempt
✅ Blocks paired orders if day trade risk detected

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Changed DEFAULT_LOT_SIZE from 250 to 50 to limit order sizes for risk
management. This affects:
- Live strategy order sizing (momentum_dca_strategy.py)
- Backtest simulations
- All paired buy/sell orders

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Copy link
Copy Markdown
Owner Author

Code Review — PR #50

Overall: Simple config change — DEFAULT_LOT_SIZE from 250 to 50. Makes sense if BTC price has appreciated and you want to reduce DCA exposure per cycle.

Note

This same change is already included in PR #45's diff (along with the blob store rename and PDT fixes). Merging both will cause a conflict or redundancy. Recommend merging whichever PR lands first and rebasing the other.


Generated by Claude Code

Copy link
Copy Markdown
Owner Author

Follow-up Review — PR #50

The lot size change itself is fine, but this PR contains significant unrelated changes that need attention:

  1. Title/scope mismatch — The PR is titled "Reduce maximum order size to 50 shares" but includes a full pdt_gate.py rewrite (+107/-10), a pricing formula change, a blob store rename, and a new test file. The actual lot size change is 1 line. Consider splitting or updating the title.

  2. Stop price formula is a silent behavior changestop_price changed from round(current_price * (1 - stop_offset_pct), 2) (percentage-based) to round(current_price + 1.00, 2) (hardcoded $1 above). For BTC, a $1 offset is essentially zero. This needs explicit justification.

  3. Option PDT mapping may be inverted — In _would_create_day_trade, "buy to close" (covering a short) maps to 'buy', but semantically it's a closing action and should map to 'sell' for PDT equivalence. This could produce false negatives on short option PDT detection.

  4. _pdt_gate accessed via getattr with silent None fallback — PDT checking is silently skipped if the attribute is missing. If PDT safety is critical, this should raise an explicit warning rather than failing silently.

  5. test_pdt_guard.py requires live credentials — The file lives in tests/ (pytest-discoverable) but makes real API calls to Robinhood. Running pytest in CI would fail or hit live accounts. Move it to scripts/ or mark with @pytest.mark.skip.


Generated by Claude Code

Copy link
Copy Markdown
Owner Author

Stale PR notice — This PR has been open for 25 days with no new commits since Mar 18. Two prior reviews flagged a title/scope mismatch (the 1-line lot-size change is bundled with a pdt_gate.py rewrite, a silent stop-price formula change, and a new live-credential test file), plus an overlap with PR #45. Please split the unrelated changes, address the feedback, or close if superseded by #45.


Generated by Claude Code

Copy link
Copy Markdown
Owner Author

Stale — 5 weeks, no activity since Mar 18. The 1-line lot-size change is buried under a pdt_gate.py rewrite and a stop-price formula change that were flagged in two prior reviews. This significantly overlaps with PR #45. Recommend closing this PR and making the lot-size change a standalone 1-line PR, or folding it into #45 after that PR is cleaned up.


Generated by Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant