API Reference
Welcome to the Hyperliquid Trading Agent API Reference. This section provides detailed documentation of the Python modules, classes, and functions that make up the trading agent.
Overview
The trading agent is organized into several key modules:
- Core - Main agent, executor, and portfolio management
- Governance - Strategy governance, regime detection, and risk controls
- Signals - Signal collection, processing, and caching
- Backtesting - Historical simulation and performance analysis
Module Organization
Usage Patterns
Basic Agent Usage
python
from hyperliquid_agent.agent import TradingAgent
from hyperliquid_agent.config import load_config
# Load configuration
config = load_config("config.toml")
# Initialize agent
agent = TradingAgent(config)
# Run single cycle
await agent.run_cycle()Governed Agent Usage
python
from hyperliquid_agent.governed_agent import GovernedAgent
from hyperliquid_agent.config import load_config
# Load configuration
config = load_config("config.toml")
# Initialize governed agent
agent = GovernedAgent(config)
# Run with governance
await agent.run_cycle()Backtesting Usage
python
from hyperliquid_agent.backtesting.runner import BacktestRunner
from hyperliquid_agent.backtesting.models import BacktestConfig
# Configure backtest
config = BacktestConfig(
start_date="2024-01-01",
end_date="2024-03-31",
initial_capital=10000.0
)
# Run backtest
runner = BacktestRunner(config)
results = await runner.run()Type Hints
All modules use Python type hints for better IDE support and type checking. Key types include:
TradeAction- Represents a trade decisionExecutionResult- Result of trade executionPortfolioState- Current portfolio stateSignalData- Signal collection resultRegimeType- Market regime classification
Error Handling
Most functions raise specific exceptions that you should handle:
ConfigurationError- Invalid configurationExecutionError- Trade execution failureValidationError- Invalid input dataAPIError- Hyperliquid API errors
See Also
- Architecture Overview - High-level system design
- Getting Started - Quick start guide
- Configuration - Configuration reference