Autonomous trading research and execution mesh development standards. Enforces Python 3.12+ best practices, fail-fast error handling, idempotency, and clean commit patterns for trading agents and broker integrations.
Development standards for building a fully autonomous, self-healing trading research and execution mesh.
Build a robust, autonomous trading system with self-healing capabilities, comprehensive monitoring, and reliable execution paths.
Understand the architecture before making changes:
1. Use **Python 3.12+** features and syntax
2. **Never use `type | None` syntax** — always use `Optional[T]` from typing module:
```python
from typing import Optional
# Correct
def get_price(symbol: str) -> Optional[float]:
pass
# Incorrect - DO NOT USE
def get_price(symbol: str) -> float | None:
pass
```
1. **Fail fast** — raise exceptions early when preconditions aren't met
2. **Log all errors** to `logs/*.log` files with appropriate context
3. Include error context: symbol, timestamp, operation type, etc.
4. Use structured logging when possible
Example:
```python
import logging
logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)
handler = logging.FileHandler('logs/trader.log')
logger.addHandler(handler)
try:
result = execute_trade(symbol, quantity)
except BrokerError as e:
logger.error(f"Trade failed for {symbol}: {e}", exc_info=True)
raise
```
**Critical requirement:** All scripts must be safely re-runnable.
1. Check for existing state before creating resources
2. Use unique identifiers to detect duplicate operations
3. Clean up partial states before retrying
4. Document any operations that cannot be idempotent
Example:
```python
def initialize_strategy(strategy_id: str) -> None:
"""Initialize strategy if not already active."""
if is_strategy_active(strategy_id):
logger.info(f"Strategy {strategy_id} already active, skipping")
return
# Safe to initialize
create_strategy(strategy_id)
```
1. **Keep changes small** — aim for PR-sized diffs (< 400 lines changed)
2. **Readable diffs** — avoid reformatting entire files; change only what's needed
3. **Clear commit messages** — describe what changed and why
4. **Single responsibility** — one logical change per commit
At minimum, ensure all changed Python files pass compilation:
```bash
python -m py_compile phases/phase_36.py
python -m py_compile agents/orchestrator.py
python -m py_compile trader/smart_trader.py
```
For critical trading logic, add lightweight functional tests:
```python
def test_order_validation():
"""Ensure orders are validated before submission."""
with pytest.raises(ValueError):
validate_order(symbol="", quantity=-10)
```
1. **Autonomous operation** — systems should run without manual intervention
2. **Self-healing** — detect failures and recover automatically when possible
3. **Observability** — log everything needed to debug production issues
4. **Reliability** — trading systems require higher standards than typical software
5. **Simplicity** — prefer simple, understandable code over clever abstractions
1. Read the relevant files in the critical file structure
2. Understand the data flow for your change
3. Check logs to understand current system behavior
4. Verify your change maintains idempotency
5. Consider failure modes and add appropriate error handling
Leave a review
No reviews yet. Be the first to review this skill!
# Download SKILL.md from killerskills.ai/api/skills/neolight-guardrails/raw