A simulation-based AI trading agent that uses real-time market data from TAAPI to make trading decisions using AI models, with performance visualization through a simple GUI. Based on the Nocturn repository but modified for simulation trading.
- Simulation-based trading (no real money involved)
- AI-powered trading decisions using technical indicators
- Real-time portfolio visualization dashboard
- Support for open-source LLMs (Ollama, etc.) as well as commercial APIs
- NEW: Python quant library fallback mechanism - automatic fallback to quantitative analysis when LLM services are unavailable
- NEW: Advanced Risk Management System - comprehensive risk profile-based trading with customizable parameters (low/medium/high risk)
- NEW: Dynamic Asset Selection - risk-based asset universes with adaptive filtering
- Configurable starting funds and risk parameters
- Simple GUI for monitoring portfolio performance
Before getting started, you'll need:
- Python 3.8+ installed on your system
- API Key from TAAPI.io for technical indicators (get a free key at https://taapi.io/)
- Access to an LLM - either:
- OpenAI API key (or compatible service), OR
- Local LLM running with Ollama (instructions below)
- Git for cloning the repository
git clone https://github.com/your-username/hypeAI.git
cd hypeAI# Create a virtual environment
python -m venv venv
# Activate the virtual environment
# On Linux/Mac:
source venv/bin/activate
# On Windows:
venv\Scripts\activate
# Install required packages
pip install -r requirements.txt- Copy the example environment file:
cp .env.example .env- Edit the
.envfile with your settings:
- Install Ollama from https://ollama.ai/
- Pull a model you want to use:
ollama pull llama3.2- Run Ollama:
ollama serve- Edit your
.envfile:
LLM_API_KEY=dummy_key_for_ollama
LLM_BASE_URL=http://localhost:11434/v1
LLM_MODEL=llama3.2- Get an OpenAI API key from https://platform.openai.com/api-keys
- Edit your
.envfile:
LLM_API_KEY=your_openai_api_key_here
LLM_BASE_URL=https://api.openai.com/v1
LLM_MODEL=gpt-4oMost OpenAI-compatible services can be configured with the appropriate base URL and model name.
- Get a free API key from https://taapi.io/
- Add it to your
.envfile:
TAAPI_API_KEY=your_taapi_api_key_here# Activate your virtual environment
source venv/bin/activate # Linux/Mac
# OR
venv\Scripts\activate # Windows
# Run the agent with default settings (BTC, ETH, 1h interval, $1000 starting funds)
python src/main.py
# Run with custom assets
python src/main.py --assets BTC ETH SOL AVAX DOGE --interval 1h --starting-funds 5000
# Run with low risk profile (conservative trading)
python src/main.py --risk-profile low --assets BTC ETH --starting-funds 1000
# Run with high risk profile (aggressive trading)
python src/main.py --risk-profile high --assets SOL ARB LINK DOGE APT PEPE --starting-funds 1000
# Run with custom risk parameters
python src/main.py --risk-profile medium --stop-loss 8 --position-size-limit 5 --assets BTC ETH SOL --starting-funds 2000
# Run with custom parameters overriding risk profile defaults
python src/main.py --risk-profile low --stop-loss 6 --risk-per-trade 1.5 --assets BTC ETH --interval 4h --starting-funds 10000While the agent is running, open a new terminal window, activate the virtual environment, and run:
# Activate your virtual environment
source venv/bin/activate # Linux/Mac
# OR
venv\Scripts\activate # Windows
# Run the Streamlit dashboard
streamlit run src/gui.pyThe dashboard will open in your browser at http://localhost:8501
- Portfolio Value Over Time: Line chart showing how your simulated portfolio value changes over time
- Metrics: Current portfolio value, total P&L (Profit & Loss), and number of trades executed
- Performance Statistics: Total return percentage, maximum and minimum portfolio values
- Recent Trades: Table showing the last 10 trades made by the AI agent with risk profile information
- Risk Profile Display: Shows the risk profile currently being used by the trading agent
The AI agent analyzes technical indicators (RSI, MACD, EMA, etc.) and makes BUY, SELL, or HOLD decisions based on market conditions. In simulation mode, these decisions affect your virtual portfolio value.
The system now includes sophisticated risk management features:
- Low Risk: Conservative trading with tight stop-loss (3-5%), small position sizing (1-2%), and conservative entry signals
- Medium Risk: Balanced trading with moderate stop-loss (6-8%), medium position sizing (2-4%), and balanced entry signals
- High Risk: Aggressive trading with wider stop-loss (9-12%), higher position sizing (4-6%), and aggressive entry signals
--stop-loss: Custom stop-loss percentage (overrides profile default)--position-size-limit: Custom position size limit as percentage (overrides profile default)--risk-per-trade: Custom risk percentage per trade (overrides profile default)--take-profit: Custom take-profit percentage
- Assets are automatically classified based on volatility, liquidity, and market cap
- Risk-appropriate assets are selected based on your chosen profile
- Dynamic filtering ensures assets meet current quality standards
The system includes a robust Python quant library fallback that activates when LLM services become unavailable. When the AI service fails, the system automatically uses Python libraries (pandas-ta, ta) to calculate technical indicators and make trading decisions based on:
- RSI (Relative Strength Index)
- MACD (Moving Average Convergence Divergence)
- EMA (Exponential Moving Average)
- SMA (Simple Moving Average)
- Bollinger Bands
- Stochastic Oscillator
- Additional quantitative analysis methods
This ensures continuous operation even when external AI services are down.
TAAPI_API_KEY: API key for technical indicatorsLLM_API_KEY: API key for your LLM serviceLLM_BASE_URL: Base URL for LLM API (e.g., OpenAI, Ollama, etc.)LLM_MODEL: Model name to use for trading decisionsSIMULATION_MODE: Should remaintruefor this simulationSTARTING_FUNDS: Initial virtual amount to start with (default: 1000.0)RISK_PER_TRADE: Risk percentage per trade (default: 0.02 for 2%)RISK_PROFILE: Default risk profile (low, medium, high; default: medium)CUSTOM_STOP_LOSS: Custom stop-loss percentage override (in %, e.g., 5.0 for 5%)CUSTOM_POSITION_SIZE: Custom position size limit override (in %, e.g., 4.0 for 4%)CUSTOM_RISK_PER_TRADE: Custom risk per trade override (in %, e.g., 2.5 for 2.5%)
When running python src/main.py:
--assets: List of assets to trade (default: BTC ETH; if not specified, uses risk-appropriate assets)--interval: Trading interval (default: 1h)--starting-funds: Starting simulated funds amount (default: 1000.0)--risk-profile: Risk profile for trading (low, medium, high; default: medium)--stop-loss: Custom stop-loss percentage (overrides profile default)--position-size-limit: Custom position size limit as percentage (overrides profile default)--risk-per-trade: Custom risk percentage per trade (overrides profile default)--take-profit: Custom take-profit percentage
This agent works with any OpenAI-compatible API, including:
- OpenAI GPT models
- Anthropic Claude (via OpenRouter)
- Local models via Ollama (Llama, Mistral, etc.)
- vLLM-hosted models
- Other OpenAI-compatible APIs
To use a different model, update the LLM_BASE_URL and LLM_MODEL in your .env file.
- The agent fetches technical indicators from TAAPI.io
- The AI analyzes the indicators and market conditions to make trading decisions based on your selected risk profile
- The simulation engine processes these decisions and adjusts your portfolio value
- Trade results are logged for the GUI dashboard
- The portfolio value changes based on simulated market movements
- Risk management parameters are automatically applied based on your selected profile
The simulation is designed to approximate real market behavior while using virtual funds.
The system implements a sophisticated fallback mechanism using Python quantitative analysis libraries. When the primary LLM service is unavailable, the system seamlessly switches to using:
- pandas-ta: Advanced technical analysis indicators
- ta: Financial technical analysis library
- numpy/scipy: Mathematical and statistical computations
This fallback provides reliable trading decisions based on multiple technical indicators using quantitative analysis methods, ensuring continuous operation without depending solely on external AI services.
- ✅ This is a simulation - no real money is used
⚠️ The agent uses AI for trading decisions but results are not guaranteed⚠️ Past performance in simulation does not indicate future results⚠️ Use at your own risk⚠️ This is for educational purposes only⚠️ Always test with conservative settings first when using custom parameters
-
"Module not found" errors: Make sure you've activated your virtual environment and installed requirements:
source venv/bin/activate # Linux/Mac pip install -r requirements.txt
-
API Key errors: Verify your API keys are correctly set in
.envand the file is loaded:# Check if .env file is being loaded python -c "from dotenv import load_dotenv; load_dotenv(); import os; print(os.getenv('TAAPI_API_KEY'))"
-
Ollama not connecting: Make sure Ollama is running:
ollama serve
And verify you have pulled the model:
ollama pull llama3.2
-
Streamlit dashboard not showing data: Make sure the trading agent is running first to generate data.
- Start with fewer assets (e.g., just BTC) to reduce API calls
- Increase the interval (e.g.,
--interval 4hinstead of--interval 1h) to reduce frequency - Monitor your TAAPI.io usage to avoid hitting rate limits
- Use the appropriate risk profile for your trading style and experience level
- If the LLM service is not working, the system will automatically use the Python quant library fallback
- Check console output for "Error getting AI decision" messages to confirm fallback activation
- The fallback mechanism includes comprehensive error handling for missing or None indicator values
This project is open source and available under the MIT License.