/hyperliquid-ai-trading-agent

Hyperliquid AI Trading Agent

Primary LanguagePythonMIT LicenseMIT

Hyperliquid AI Trading Agent

Hyperliquid AI Trading Agent is an advanced, AI-powered trading bot that harnesses the intelligence of state-of-the-art large language models (LLMs) to analyze live market data from TAAPI, execute real-time trades, and maximize results on the Hyperliquid decentralized exchange. Designed for reliability, flexibility, and security, this agent continually tracks selected cryptocurrency assets, leverages leading technical indicators, and manages buy, sell, or hold decisions through robust automated strategies. Stop-loss and take-profit mechanisms are built-in, ensuring dynamic risk management throughout every session.


Architecture

Explore the Full Architecture Documentation for subsystem details, data flow diagrams, and key design principles.

Architecture Diagram


Table of Contents


Structure

  • src/main.py: Launches the application, handles user input, and manages the main trading loop.
  • src/agent/decision_maker.py: Implements LLM-based trading decision logic via OpenRouter and TAAPI indicators.
  • src/indicators/taapi_client.py: Interfaces with TAAPI to retrieve essential technical indicators.
  • src/trading/hyperliquid_api.py: Directly interacts with the Hyperliquid DEX to execute trades.
  • src/config_loader.py: Responsible for parsing and centralizing configuration from the .env file.

Environment Configuration

Configure your environment swiftly:

Create your .env file (reference .env.example), with the following keys:

  • TAAPI_API_KEY
  • HYPERLIQUID_PRIVATE_KEY (or LIGHTER_PRIVATE_KEY)
  • OPENROUTER_API_KEY
  • LLM_MODEL
  • Optional: OPENROUTER_BASE_URL (default: https://openrouter.ai/api/v1)
  • Optional: OPENROUTER_REFERER, OPENROUTER_APP_TITLE

Obtaining API Keys

  • TAAPI_API_KEY: Sign up at TAAPI.io and obtain your API key via the dashboard.
  • HYPERLIQUID_PRIVATE_KEY: Generate an Ethereum-compatible private key, e.g., using MetaMask or the eth_account library. Keep this key confidential.
  • OPENROUTER_API_KEY: Create your account at OpenRouter.ai and generate an API key in your settings.
  • LLM_MODEL: Specify a model such as "x-ai/grok-4". See the OpenRouter documentation for supported models.

Usage

Launch the agent with:

poetry run python src/main.py --assets BTC ETH --interval 1h

Local API Endpoints

When running, the agent exposes these minimal API endpoints:

  • GET /diary?limit=200: Returns recent trading diary entries in JSON format.
  • GET /logs?path=llm_requests.log&limit=2000: Streams recent log file entries.

Bind the host/port by setting these variables in your environment:

  • API_HOST (default: 0.0.0.0)
  • API_PORT or APP_PORT (default: 3000)

Docker Support

Build and run with ease:

docker build --platform linux/amd64 -t trading-agent .
docker run --rm -p 3000:3000 --env-file .env trading-agent
# Access the agent: curl http://localhost:3000/diary

Smart Tool Calling

The agent leverages dynamic tool calls to access any TAAPI indicator (including EMA, RSI, and more) on demand. See the TAAPI Indicator Reference and this EMA Example to learn more.


Deployment to EigenCloud

Run the trading agent securely on EigenCloud within a Trusted Execution Environment (TEE) and enjoy secure, decentralized key management.

Prerequisites

  • Allowlisted Ethereum account on Sepolia testnet (EigenCloud Onboarding).
  • Docker installed on your machine.
  • Access to Sepolia ETH for deployments.

Installation

For macOS/Linux:

curl -fsSL https://eigenx-scripts.s3.us-east-1.amazonaws.com/install-eigenx.sh | bash

For Windows:

curl -fsSL https://eigenx-scripts.s3.us-east-1.amazonaws.com/install-eigenx.ps1 | powershell -

Initial Setup

docker login
eigenx auth login  # Or: eigenx auth generate --store

Deploy the Agent

cp .env.example .env
# Edit .env: Set ASSETS, INTERVAL, and all API keys.
eigenx app deploy

Monitoring

eigenx app info --watch
eigenx app logs --watch

Updating Deployment

After code or configuration changes:

eigenx app upgrade <app-name>

For a full CLI reference, consult the EigenX Documentation.


Support

For technical inquiries, support, or to connect with the developer community, reach out via Telegram:
Telegram