Skip to content

LLM Parser: Support 'pullback' and price timing context #344

@iAmGiG

Description

@iAmGiG

Problem

User request: "buy QQQ at a pullback" currently produces SELL suggestion instead of understanding user wants to BUY at a lower price.

User Feedback (Testing Session)

User: buy qqq at a pullback

Expected: 
- Recognize user wants to BUY (not sell)
- Understand \"pullback\" = wait for price to drop
- Suggest limit order below current price

Actual:
- System suggested SELL (because MACD bearish)
- Ignored user's explicit BUY request
- No pullback price suggested

Root Cause

LLM parser extracts action="buy" correctly, but:

  1. Doesn't understand "pullback" timing context
  2. Strategy analyzer overrides user intent with its own signal
  3. No limit price suggestion for pullback entry

Solution: Enhance Parser for Timing Context

Add Timing Intent Field

@dataclass
class TradeRequest:
    ticker: str
    action: str  # \"review\", \"buy\", \"sell\"
    request_type: str = \"trade\"
    timing: Optional[str] = None  # NEW: \"now\", \"pullback\", \"breakout\", \"dip\"
    limit_price: Optional[float] = None
    # ... other fields

Enhanced Parser Prompt

Detect timing context:
- \"buy at a pullback\" → action=\"buy\", timing=\"pullback\"
- \"buy on a dip\" → action=\"buy\", timing=\"dip\"
- \"buy at market\" → action=\"buy\", timing=\"now\"
- \"buy on breakout\" → action=\"buy\", timing=\"breakout\"
- \"wait for pullback to buy\" → action=\"buy\", timing=\"pullback\"

If timing is \"pullback\" or \"dip\":
- Suggest limit_price below current price (e.g., 2-5% discount)

Orchestrator Behavior Change

if request.action == \"buy\" and request.timing == \"pullback\":
    current_price = get_current_price(request.ticker)
    suggested_entry = current_price * 0.97  # 3% pullback
    
    print(f\"QQQ currently at ${current_price:.2f}\")
    print(f\"Suggested pullback entry: ${suggested_entry:.2f} (-3%)\")
    print(\"Place limit order at this price? [yes/no/custom]\")

Timing Context Keywords

"Pullback" / "Dip":

  • User wants to buy below current price
  • Suggest 2-5% discount limit order
  • Wait for price to come down

"Breakout":

  • User wants to buy above current price
  • Suggest limit order at resistance level
  • Wait for price to break through

"Market" / "Now":

  • User wants immediate execution
  • Use market order or current price limit

"Wait for":

  • User wants to defer, monitor price
  • Set price alert, don't execute immediately

Implementation Priority

High - Improves UX significantly, respects user intent

Related Issues

Acceptance Criteria

  • Parser extracts timing context from natural language
  • "pullback" requests suggest limit price below current
  • "breakout" requests suggest limit price above current
  • User's explicit action (buy/sell) never overridden by signals
  • Documentation updated with timing examples

Sub-issues

Metadata

Metadata

Assignees

Labels

enhancementNew feature or requestuser-experienceUser experience and interface improvements

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions