Execute Trade Skill
Handles the full trade execution lifecycle with multi-layer safety validation.
Capabilities
This skill enables the agent to:
- •Validate trade signals through confirmation mesh
- •Check L2 liquidity before execution
- •Route orders to appropriate broker adapters
- •Log execution results and update positions
- •Handle failures with circuit breaker logic
Prerequisites
- •Confirmed signal from orderflow-analysis skill
- •Broker adapter configured (Alpaca, Zerodha, Upstox)
- •Risk parameters defined (max position size, max slippage)
Procedural Steps
1. Pre-Flight Liquidity Check
Before any execution request:
code
Call: estimate_slippage(symbol: str, side: "buy" | "sell", quantity: float) Returns: (avg_price: float, slippage_pct: float) or None if insufficient liquidity
2. Confirmation Mesh Validation
Submit signal through validation pipeline:
code
Call: validate_execution(
signal: FootprintSignal,
symbol: str,
side: "buy" | "sell",
quantity: float,
max_slippage_pct: float = 0.5
) -> ConfirmationResult
The mesh validates:
- •Footprint pattern confirmation
- •L2 liquidity sufficiency
- •Risk management rules
- •Circuit breaker status
3. Execute if Approved
Only if result.approved == True:
code
Call: execute_order(
symbol: str,
side: "buy" | "sell",
quantity: float,
order_type: "market" | "limit",
limit_price: float | None,
broker: "alpaca" | "zerodha" | "upstox" | "paper"
) -> ExecutionResult
4. Post-Execution Logging
After execution:
code
Call: log_execution(
execution_result: ExecutionResult,
signal: FootprintSignal,
confirmation: ConfirmationResult
)
This updates:
- •Position ledger
- •Trade history
- •Performance metrics
- •Alert notifications
Safety Guardrails
[!CAUTION] These rules are NON-NEGOTIABLE for autonomous execution:
- •Never bypass confirmation mesh - All trades must pass validation
- •Respect circuit breakers - If tripped, halt all execution for symbol
- •Verify tick-by-tick data - Cross-reference 3 data sources before execution
- •Max position limits - Never exceed configured max_position_size
- •Slippage protection - Abort if estimated slippage > max_slippage_pct
Risk Parameters
| Parameter | Default | Description |
|---|---|---|
| max_position_size | 10,000 | Max shares per position |
| max_notional_value | $100,000 | Max $ value per trade |
| max_slippage_pct | 0.5% | Abort if exceeds |
| min_liquidity_ratio | 2x | Need 2x quantity in book |
| circuit_breaker_cooldown | 5 min | Time after trip |
Execution Modes
Paper Trading (Safe)
code
execute_order(..., broker="paper")
Uses simulated broker with realistic slippage/commission modeling.
Live Trading (Requires Confirmation)
code
execute_order(..., broker="alpaca") # or zerodha, upstox
Routes to real broker API. Agent must log confidence justification.
Example Complete Flow
python
# 1. Receive confirmed signal from orderflow analysis
signal = await analyze_footprint("RELIANCE", 60)
# 2. Pre-flight check
slippage = await estimate_slippage("RELIANCE", "buy", 500)
if slippage and slippage[1] > 0.5:
logger.warning("Slippage too high, aborting")
return
# 3. Confirmation mesh
confirmation = await validate_execution(
signal=signal,
symbol="RELIANCE",
side="buy",
quantity=500,
max_slippage_pct=0.5
)
# 4. Execute only if approved
if confirmation.approved:
result = await execute_order(
symbol="RELIANCE",
side="buy",
quantity=500,
order_type="limit",
limit_price=confirmation.recommended_price,
broker="zerodha"
)
# 5. Log execution
await log_execution(result, signal, confirmation)
else:
logger.warning(f"Rejected: {confirmation.rejection_reason}")
Failure Recovery
If execution fails:
- •Log failure with full context
- •Increment consecutive failure counter
- •If counter >= 5, trip circuit breaker for symbol
- •Alert via configured notification channels (Telegram/Email)
- •Wait for manual review or cooldown expiry