Level: Intermediate Β· Duration: 30 minutes Β· Key Takeaway: Master the setup of a multi-agent stock analysis system based on OpenClaw, enabling automated stock selection, deep analysis, and simulated trading.
Target Audience
- Developers with 1-3 years of experience
- Programmers interested in AI Agents and quantitative trading
- Investors looking to build a personal stock assistant
Core Dependencies and Environment
- Node.js 18+
- OpenAI compatible API (Claude/Gemini/DeepSeek, etc.)
- Optional: Telegram Bot Token
- Optional: Historical market data (CSV format)
Project Structure Tree
StockClaw/
βββ config/ # Configuration files
β βββ llm.local.toml # LLM large model configuration
β βββ telegram.json # Telegram integration configuration
β βββ tools.json # Tool configuration
β βββ agents.json # Agent configuration
βββ skills/ # Skill modules
β βββ crypto-stock-market-data/ # Market data acquisition skill
βββ prompts/ # Prompt templates
β βββ agents/ # Specialized agent role definitions
β β βββ value_analyst/ # Value Analyst
β β βββ technical_analyst/ # Technical Analyst
β β βββ news_sentiment_analyst/ # Sentiment Analyst
β β βββ risk_manager/ # Risk Manager
β β βββ portfolio_agent/ # Portfolio Agent
β β βββ trade_executor/ # Trade Executor
β βββ workflows/ # Workflow templates
β β βββ backtest_mode/ # Backtest mode
β β βββ portfolio_review/ # Portfolio review
β βββ shared/ # Shared rules
βββ data/ # Data storage
β βββ portfolio.json # Portfolio status
βββ src/ # Core code
βββ index.ts # Entry file
βββ router.ts # Request routing
βββ ...
Step-by-Step Instructions
1. Clone Project and Install Dependencies
First, clone the StockClaw project from GitHub, then install the dependencies:
git clone https://github.com/24mlight/StockClaw.git
cd StockClaw
npm install
TIP
If you are in mainland China, it is recommended to configure the npm mirror to speed up installation:
npm config set registry https://registry.npmmirror.com
2. Configure the LLM Model
StockClaw supports any OpenAI-compatible LLM API. Create a local configuration file:
# Copy example configuration
cp config/llm.local.example.toml config/llm.local.toml
Edit config/llm.local.toml. Taking Claude as an example:
# config/llm.local.toml
[llm]
# Use OpenAI compatible interface
model = "claude-sonnet-4-20250514"
baseUrl = "https://api.anthropic.com/v1"
apiKey = "sk-ant-your-api-key-here"
# Optional: Advanced configuration
[llm.context]
maxTokens = 200000 # Set based on model context window
compactionThreshold = 150000 # Threshold to trigger compression
If you use DeepSeek, Qwen, or other compatible APIs, simply modify baseUrl and model.
WARNING
The API Key must be kept safe and not submitted to version control. The project ignores config/llm.local.toml by default.
3. Start the Service
Run the start command directly:
npm start
On the first start, the service will automatically detect configuration files. If Telegram configuration is missing, it will prompt you to set it up.
The service runs by default at http://127.0.0.1:8000. Open your browser to access the Web UI.
4. Configure Telegram (Optional)
To interact with StockClaw via Telegram:
- Search for @BotFather in Telegram, create a new bot, and get the Bot Token.
- On the first start, type
yesin the terminal to enable Telegram integration. - Paste your Bot Token.
- Send any message to your bot in Telegram.
- Paste the pairing code shown in the terminal back to complete binding.
Alternatively, manually create the config file config/telegram.json:
{
"enabled": true,
"botToken": "YOUR_BOT_TOKEN_HERE",
"allowedUsers": ["your_telegram_id"]
}
TIP
Once Telegram is linked, you can check stocks, receive analysis reports, and even execute simulated trades from anywhere using your phone.
5. Configure Market Data Skills
StockClaw has built-in skills for cryptocurrency and stock market data. The skills directory is located at skills/, with the core skill being crypto-stock-market-data.
The skill configuration file config/tools.json already includes the built-in skills:
{
"skills": [
{
"name": "crypto-stock-market-data",
"enabled": true,
"path": "skills/crypto-stock-market-data"
}
]
}
This skill provides tools such as:
get_crypto_price- Get real-time crypto pricesget_coin_historical_chart- Get historical K-line dataget_global_market_data- Get global market dataget_company_profile- Get basic company info for stocksget_coin_details- Get detailed token information
6. Create Your First Portfolio
StockClaw manages portfolios using JSON files. Create data/portfolio.json:
{
"cash": 100000,
"positions": [
{
"symbol": "AAPL",
"shares": 100,
"entryPrice": 175.5
},
{
"symbol": "MSFT",
"shares": 50,
"entryPrice": 380.0
},
{
"symbol": "NVDA",
"shares": 25,
"entryPrice": 450.0
}
],
"createdAt": "2026-03-14T00:00:00Z"
}
This configuration represents:
- Initial Cash: $100,000
- Holdings: 100 shares of Apple, 50 shares of Microsoft, 25 shares of NVIDIA
7. Execute Deep Stock Analysis
Now ask StockClaw to analyze a stock via the Web UI or Telegram.
Via Web UI:
- Open
http://127.0.0.1:8000 - Type in the input box:
Do a deep analysis on NVDA
StockClaw will trigger multi-agent collaborative analysis:
- Value Analyst - Analyzes fundamentals, financial data, and valuation levels.
- Technical Analyst - Analyzes price trends, technical indicators, and chart patterns.
- Sentiment Analyst - Analyzes news sentiment, market mood, and institutional holdings.
- Risk Manager - Evaluates potential risks, downside room, and position suggestions.
- Root Agent - Synthesizes all professional opinions to output the final recommendation.
You can watch each specialized agent being called in sequence, culminating in a complete analysis report.
Via Telegram:
/analyze NVDA
8. Simulated Trading Operations
StockClaw supports Paper Trading; all trades are recorded locally and not executed on a real exchange.
Buy Operation:
Buy 10 shares of GOOGL at market price
The system will:
- Fetch real-time quotes
- Verify sufficient cash
- Calculate transaction costs
- Update portfolio status
- Return trade confirmation
Sell Operation:
Sell 5 shares of AAPL
Query Portfolio:
Show my portfolio
Or use the slash command:
/portfolio
9. Run Historical Backtesting
This is one of StockClaw's most powerful featuresβusing historical data to validate your investment strategy.
Backtest Current Portfolio:
Backtest my portfolio for the last 7 trading days
StockClaw will:
- Prepare historical market data
- Isolate decision contexts for each trading day (T-1 constraint)
- Simulate daily trading decisions
- Calculate returns, maximum drawdown, and Sharpe ratio
- Generate a detailed backtest report
WARNING
The longer the backtest period, the more tokens consumed and the longer it takes. It is recommended to start with small tests of 7 or 30 days.
Backtest Specific Strategy:
Backtest a strategy: buy when RSI < 30, sell when RSI > 70
You can also let StockClaw discover investment opportunities:
Find a few US stocks with strong value and technical alignment
Troubleshooting Common Issues
1. LLM API Connection Failure
Symptoms: Connection refused or 401 Unauthorized errors on startup.
Steps:
- Confirm
apiKeyinconfig/llm.local.tomlis correct. - Check if
baseUrlis accessible:curl -I <your-baseUrl>. - Confirm model name is correct (case-sensitive).
- Check logs for detailed error messages.
2. Telegram Bot Fails to Start
Symptoms: No response to Telegram messages.
Steps:
- Confirm Bot Token is correct.
- Check that
enabledistrueinconfig/telegram.json. - Check bot status with
@BotFather. - Ensure you have sent a message to complete user binding.
3. Market Data Retrieval Failure
Symptoms: Failed to fetch stock data message during analysis.
Steps:
- Check network connection.
- Confirm
skills/crypto-stock-market-datais enabled. - Review skill logs for specific API errors.
- Some data sources require an API Key; check if it is configured.
4. Portfolio State Abnormalities
Symptoms: Position data does not update or displays incorrectly.
Steps:
- Check if
data/portfolio.jsonis in valid JSON format. - Confirm file write permissions.
- Check logs for state change records.
5. Inaccurate Backtest Results
Symptoms: Backtest returns do not match reality.
Steps:
- Confirm T-1 snapshot data is being used (cannot use same-day data).
- Check for look-ahead bias.
- Confirm slippage settings are reasonable.
- Review backtest logs for specific trade records.
6. Context Too Long / Truncation
Symptoms: Conversation cuts off midway; analysis is incomplete.
Steps:
- Increase
compactionThresholdinllm.local.toml. - Use
session_compactionto manually compress context. - Shorten the backtest time window.
- Consider switching to a model with a longer context window.
Further Reading / Advanced Directions
1. OpenClaw Official Documentation
Deepen your understanding of OpenClaw's architecture and skill system:
- Website: https://openclaw.ai
- GitHub: https://github.com/openclaw/openclaw
2. Deep Dive into MCP Protocol
StockClaw extends data capabilities via the Model Context Protocol (MCP):
- How to write custom MCP Servers
- Data providers in the MCP ecosystem
3. Multi-Agent System Design
StockClaw demonstrates best practices for agent collaboration:
- Root agent for decision-making and coordination
- Specialized agents providing domain knowledge
- Isolated temporary sessions to avoid polluting the main context
4. Quant Strategy Backtesting
Learn backtesting methodology in depth:
- Avoiding overfitting
- Considering transaction costs and slippage
- Multi-timeframe validation
Now you have mastered the core usage of StockClaw. This AI stock manager built on OpenClaw can help you with stock selection, portfolio management, simulated trading, and historical backtesting. Go ahead and try to let it help you find some investment opportunities!