#20927: feat(trading): add /buy and /sell order commands
size: XL
## Summary
- Add `OrderSide`, `OrderType`, `OrderRequest`, `OrderResult` types and extend `BrokerProvider` with `placeOrder()`
- Implement `placeOrder` in `AlpacaProvider` via `POST /v2/orders` (paper trading by default)
- Implement mock `placeOrder` returning `status: "accepted"` with a fake ID
- Add `/buy` and `/sell` auto-reply commands with market and limit order support
- Add `trading_order` agent tool (TypeBox schema) for LLM-driven order placement
- Add `trading buy` / `trading sell` CLI subcommands with `--limit` flag
## Usage
```
/buy AAPL 10 → market buy 10 shares
/buy AAPL 10 limit 150 → limit buy @ $150
/sell AAPL 5 → market sell 5 shares
/sell AAPL 5 limit 180 → limit sell @ $180
openclaw trading buy AAPL 10
openclaw trading sell AAPL 5 --limit 180
```
## Test plan
- [ ] Mock provider: `/buy AAPL 10` → confirmation with fake ID
- [ ] Mock provider: `/sell AAPL 5 limit 180` → limit order confirmation
- [ ] Mock provider: `/buy` (no args) → usage hint
- [ ] CLI: `openclaw trading buy AAPL 10` → JSON output
- [ ] TypeScript: `pnpm tsc --noEmit` passes
🤖 Generated with [Claude Code](https://claude.com/claude-code)
<!-- greptile_comment -->
<h3>Greptile Summary</h3>
Added trading plugin with `/buy` and `/sell` order commands via Alpaca Markets API. Implemented order placement with market and limit order types, plus portfolio tracking and price quotes. Added CLI subcommands (`openclaw trading buy/sell`) and agent tools (`trading_order`, `trading_portfolio`, `trading_price`).
- Uses `Type.Union` in tool schemas which violates AGENTS.md:184 guardrails (produces `anyOf` that some providers reject) — must use `stringEnum` helper instead
- AGENTS.md documentation incomplete — missing `/buy`, `/sell` commands and `trading_order` tool in Registered Components table
- Clean provider pattern with mock and Alpaca implementations
- Proper lazy initialization and error handling throughout
- Warning messages for irreversible sell orders in live mode
<h3>Confidence Score: 3/5</h3>
- Safe to merge with fixes — schema issue will cause tool failures on some LLM providers
- Score reflects one critical syntax issue (`Type.Union` in tool schemas violates established guardrails and will break on providers like Vertex AI) and incomplete documentation. The implementation is otherwise solid with proper validation, error handling, and safety warnings for live trading. The schema fix is straightforward (swap `Type.Union` for `stringEnum`), and docs need updating to match implemented features.
- extensions/trading/index.ts requires schema fix, AGENTS.md needs complete feature documentation
<sub>Last reviewed commit: 04de311</sub>
<!-- greptile_other_comments_section -->
<sub>(3/5) Reply to the agent's comments like "Can you suggest a fix for this @greptileai?" or ask follow-up questions!</sub>
**Context used:**
- Context from `dashboard` - CLAUDE.md ([source](https://app.greptile.com/review/custom-context?memory=fd949e91-5c3a-4ab5-90a1-cbe184fd6ce8))
- Context from `dashboard` - AGENTS.md ([source](https://app.greptile.com/review/custom-context?memory=0d0c8278-ef8e-4d6c-ab21-f5527e322f13))
<!-- /greptile_comment -->
Most Similar PRs
#20132: Add trading plugin for portfolio tracking and price quotes via Alpaca…
by Sjeror11 · 2026-02-18
82.5%
#4767: fix(agents): handle read alias required schema
by RomeroYang · 2026-01-30
68.5%
#7113: feat(providers): add CommonStack provider support
by flhoildy · 2026-02-02
66.9%
#20081: feat: post-compaction triage UX — fuzzy ok + stage-2 gate + Discord...
by PrivacySmurf · 2026-02-18
66.5%
#11788: feat: inter-agent communication via CLI scripts
by jingkang0822 · 2026-02-08
66.4%
#10894: Docs: fix legacy branding, add config reference, expand cron troubl...
by biv0711 · 2026-02-07
66.3%
#9123: Feat/smart router backport and custom model provider
by JuliusYang3311 · 2026-02-04
66.2%
#21076: feat(quota): unify provider quota tracking and usage UI across prov...
by romeroej2 · 2026-02-19
66.0%
#16746: feat(extensions): add BlockRun LLM provider with ClawRouter integra...
by 1bcMax · 2026-02-15
65.9%
#6512: Claude/setup open claw agent f v sqk
by franelcisco · 2026-02-01
65.7%