Skip to content

algo-traders-club/baby-smith

Repository files navigation

Baby Smith

Baby Smith Logo

Version License: MIT Code Quality Architecture

A comprehensive, modular autonomous trading agent for Hyperliquid, featuring advanced risk management and monitoring.

⚠️ USE AT YOUR OWN RISK ⚠️

πŸŽ‰ Major Update - Version 2.0

Baby Smith has been completely refactored! The codebase has been transformed from a monolithic structure into a modern, modular architecture. See CLAUDE.md for detailed refactoring documentation.

Key Improvements

  • βœ… Modular Architecture - Clean separation of concerns
  • βœ… Advanced Error Handling - Comprehensive exception hierarchy
  • βœ… Type Safety - Full type annotations throughout
  • βœ… Zero Dead Code - Optimized and cleaned codebase
  • βœ… Enhanced Monitoring - Improved dashboard and logging
  • βœ… Better Risk Management - Sophisticated risk controls

⚠️ Important Warning

Baby Smith is experimental software that can autonomously trade with real money. The consequences of bugs, market events, or other unforeseen circumstances could result in immediate and total loss of funds.

By using this software:

  • You acknowledge that you are solely responsible for any losses
  • You understand that autonomous trading is inherently risky
  • You accept that no warranties or guarantees are provided
  • You agree to the terms of the MIT license

Overview

Baby Smith is a sophisticated, modular autonomous trading agent for Hyperliquid perpetual futures. The v2.0 architecture includes:

  • Advanced Market Making - Momentum-driven strategies with dynamic spread calculation
  • Comprehensive Risk Management - Multi-layer risk controls and position limits
  • Modular Design - Separate modules for trading, market data, orders, and positions
  • Enhanced Monitoring - Real-time dashboard with detailed analytics
  • Robust Error Handling - Custom exception hierarchy with graceful recovery
  • Type Safety - Full type annotations for better development experience

Prerequisites

  • Poetry (Python package manager)
  • Docker and Docker Compose (optional)
  • A funded Hyperliquid account
  • Private key with trading permissions
  • Basic understanding of perpetual futures trading

Quick Start

Using Docker (Recommended)

  1. Clone the repository:
git clone https://github.com/hydralabs-sh/baby-smith.git
cd baby-smith
  1. Copy and configure environment variables:
cp .env.template .env
  1. Edit .env with your credentials:
# Required - Trading Account
HL_ACCOUNT_ADDRESS=your_account_address
HL_SECRET_KEY=your_private_key

# Optional - Trading Parameters
HL_ASSET=HYPE
HL_MAX_POSITION=5.0
HL_BASE_POSITION=1.0
HL_LEVERAGE=3
HL_TESTNET=true
  1. Start the agent:
docker compose up

Using Poetry (Development)

  1. Clone and enter the repository:
git clone https://github.com/hydralabs-sh/baby-smith.git
cd baby-smith
  1. Install dependencies using Poetry:
poetry install
  1. Copy and configure environment variables:
cp .env.template .env
# Edit .env with your settings
  1. Run the agent:
poetry run python -m agent_smith.main

Configuration Parameters

Parameter Description Default
HL_ACCOUNT_ADDRESS Your Hyperliquid account address (required) None
HL_SECRET_KEY Private key with trading permissions (required) None
HL_ASSET Trading asset HYPE
HL_MAX_POSITION Maximum position size 5.0
HL_BASE_POSITION Target position size 1.0
HL_LEVERAGE Trading leverage 3
HL_TESTNET Use testnet instead of mainnet true

Architecture

Baby Smith v2.0 features a modular, scalable architecture:

Core Modules (src/agent_smith/core/)

  • trading_engine.py - Main orchestration and trading loop management
  • market_data.py - Real-time market data fetching and validation
  • order_manager.py - Order execution, verification, and management
  • position_manager.py - Position tracking and risk metrics

Strategy Modules (src/agent_smith/strategies/)

  • enhanced_market_maker.py - Advanced market making with momentum analysis
  • risk_manager.py - Comprehensive risk management system
  • momentum_analyzer.py - Technical analysis and signal generation
  • order_utils.py - Order processing and validation utilities

Dashboard Modules (src/agent_smith/dashboard/)

  • main.py - Dashboard orchestration and rendering
  • data_fetchers.py - Data collection and processing
  • chart_components.py - Interactive charts and visualizations
  • ui_components.py - User interface components and styling

Exception Handling (src/agent_smith/exceptions/)

  • Custom exception hierarchy for robust error handling
  • Specific exceptions for different error scenarios
  • Graceful error recovery and logging

For detailed architecture documentation, see CLAUDE.md

Monitoring

The agent provides a real-time dashboard at http://localhost:8501 showing:

  • Current positions
  • Account value
  • Recent trades
  • PnL metrics
  • Market data

Risk Controls

Enhanced risk management system with multiple layers of protection:

Position Management

  • Dynamic position limits based on market conditions
  • Automated position reduction when limits are approached
  • Real-time utilization monitoring with alerts

Order Safety

  • Pre-execution validation for all orders
  • Slippage protection with dynamic adjustment
  • Order size validation against minimum notional requirements
  • Price deviation checks to prevent errant orders

Market Conditions

  • Spread threshold monitoring - avoid trading in illiquid conditions
  • Volatility-based adjustments - reduce exposure during high volatility
  • Rate limiting with exponential backoff - prevent API violations

Performance-Based Controls

  • Consecutive loss limits - pause trading after multiple losses
  • Win rate monitoring - adjust strategy based on performance
  • Risk metrics tracking - comprehensive performance analysis

What's New in v2.0

🎯 Complete Refactoring

The entire codebase has been refactored from a monolithic structure (1600+ line files) into a clean, modular architecture:

  • File size reduction: All files now under 500 lines
  • Modular design: Clear separation of concerns across 30+ focused modules
  • Zero dead code: Removed 120+ lines of unused code
  • Type safety: 95%+ type annotation coverage
  • Error handling: Comprehensive exception hierarchy with specific error types

πŸ“Š Before vs After

Metric Before After Improvement
Max file size 1,651 lines 366 lines -78%
Files > 500 lines 3 files 0 files βœ…
Dead code 120+ lines 0 lines βœ…
Type coverage ~20% ~95% +75%

πŸ”§ Technical Improvements

  • Dependency injection for better testability
  • Event-driven architecture with proper separation
  • Centralized configuration with environment variable support
  • Comprehensive logging with structured output
  • Performance optimizations throughout

πŸ“š For complete refactoring details, see CLAUDE.md

Development

The project uses Poetry for dependency management. To set up a development environment:

  1. Install Poetry if you haven't already:
curl -sSL https://install.python-poetry.org | python3 -
  1. Install dependencies:
poetry install
  1. Activate the virtual environment:
poetry shell
  1. Run tests:
poetry run pytest
  1. Run the agent:
poetry run python -m agent_smith.main

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Install development dependencies: poetry install --with dev
  4. Run tests: poetry run pytest
  5. Commit your changes
  6. Push to the branch
  7. Create a Pull Request

Project Dependencies

This project uses Poetry for dependency management. Key dependencies include:

  • hyperliquid-python-sdk
  • streamlit (for dashboard)
  • pandas (for data processing)
  • loguru (for logging)
  • pydantic (for config)

To add new dependencies:

poetry add package_name

For development dependencies:

poetry add --group dev package_name

License

This project is licensed under the MIT License - see the LICENSE file for details.

Disclaimer

THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

The developers of Baby Smith take no responsibility and assume no liability for any money lost through the use of this software. Use at your own risk.

Support

For questions and support:


Remember: This is experimental software for educational purposes. Never trade with more money than you can afford to lose.

Β© Copyright 2025 Algo Traders Club LLC - MIT License

About

A simple autonomous perps trading agent on Hyperliquid L1

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published