Order Execution
Position sizing
Always size before you trade. The size_position tool calculates safe share count from three constraints:
Returns: share count, dollar risk, capital used, margin impact.
Order types
Simple order
Bracket order (recommended)
The bracket creates three linked orders:
- Entry — your entry order
- Take profit — limit sell at target (OCA-linked to stop)
- Stop loss — stop order at invalidation (OCA-linked to TP)
When either TP or SL fills, the other auto-cancels via OCA group.
Trailing stop bracket
Or use fixed trailing amount:
Modifying orders
Use modify_order to change price/quantity on an existing order without breaking bracket links:
Never cancel and re-place bracket legs — this breaks the OCA group. Always use modify_order to preserve bracket integrity.
Order management
Session guardrails
The session risk gate tracks:
- Daily P&L — locks trading at max daily loss
- Trade count — limits trades per session
- Consecutive losses — cooldown after loss streaks
Check with session_state. Manual lock: session_lock. Reset: session_reset.