capital-trader
v1.0.20
Published
An automated trading bot for Capital.com with AI-powered strategy generation via Claude or ChatGPT.
Maintainers
Readme
Capital Trader CLI
An automated trading bot for Capital.com with AI-powered strategy generation via Claude or ChatGPT.
Features
- Capital Live Trading — Connects to Capital.com via REST API and WebSocket for real-time order execution
- AI Strategy Generation — Uses AI to generate, backtest, and optimize trading strategies from natural language
- Backtesting Dashboard — Simulates strategies on historical data and opens HTML with performance metrics
- Demo & Live Support — Switch between demo and live environments by editing configuration file
- Extremely Flexible — Runs on any device including Raspberry Pi, VPS, or low-power servers
Requirements
- Node.js 18+
- Capital.com account with API key
- Anthropic API key (for AI strategy generation)
Installation
Install CLI
npm i -g capital-traderConfiguration
Edit ~/.capital/config.json
{
"username": "your-capital-username",
"password": "your-capital-password",
"apiKey": "your-capital-api-key",
"anthropicKey": "sk-ant-...",
"environment": "demo",
"epic": "BTCUSD",
"orderSize": "0.025",
"timeframe": "MINUTE_15",
"max": "1000",
"tokens": "10000",
"retries": "3"
}| Key | Description | Example |
|-----|-------------|---------|
| username | Capital.com login email | [email protected] |
| password | Capital.com password | |
| apiKey | Capital.com API key | |
| anthropicKey | Anthropic Claude API key | sk-ant-... |
| environment | "demo" or "live" | "demo" |
| epic | Market identifier | "BTCUSD", "EURUSD" |
| orderSize | Position size per trade | "0.025" |
| timeframe | Candle interval | "MINUTE_15", "MINUTE" |
| max | Historical candles to fetch | "1000" |
| tokens | Max AI tokens to use | "15000" |
| retries | Max AI generation retries | "3" |
Usage
# Start bot
capital
# Show help
capital --help
# Show strategy
capital --code
# Test strategy
capital --test
# Get config path
capital --config
# Set config value
capital --set orderSize 0.005
# Reset strategy
capital --clearAI Strategy Generation
Pass any natural language instruction to the CLI:
capital "create a good strategy based on macd and rsi"
capital "add custom take profit on price * 1.001"
capital "make the strategy more conservative"
capital "only open orders on red candles"If the new strategy underperforms, it is automatically discarded.
Strategy is saved inside config.json file.
Project Structure
src/
├── cli.js # Entry point and command router
├── bot.js # Live trading loop
├── ai.js # AI strategy generation and validation
├── cfg.js # Display config path and values
├── test.js # Backtesting and dashboard generation
├── strat.js # Display raw code strategy
├── help.js # Display help instructions
├── set.js # Config setter
├── clear.js # Strategy reset
└── utils/
├── capital.js # Capital.com API client (REST + WebSocket)
├── strategy.js # Strategy simulator and indicator calculations
├── generate.js # Claude/OpenAI API calls
├── testing.js # Backtesting engine
└── constant.js # Config loader and utilitiesDisclaimer
This software is for educational purposes. Automated trading carries significant financial risk. Always test thoroughly on a demo account before using real funds. Past backtest performance does not guarantee future results.
⭐ If you find this useful!
