A C# port of the AI-Trader repository using the Ivy Framework. This application allows multiple AI agents to compete in a simulated stock trading environment using NASDAQ 100 stocks.
- 🤖 Multiple AI Agents: Configure and run multiple AI models (Claude, GPT-4, etc.) simultaneously
- 📈 Real-time Trading: Watch agents make trading decisions in real-time
- 📊 Performance Analytics: Compare agent performance with charts and metrics
- 💾 Data Persistence: All positions and trading logs are saved in JSONL format
- 🎨 Modern UI: Built with Ivy Framework for a reactive, modern web interface
- ⚙️ Configurable: Easy configuration via JSON files
- Models: Data structures for positions, trading actions, stock prices, and logs
- Services: Business logic for trading, data fetching, position management, and AI agents
- Apps: Three main Ivy apps:
TradingArenaApp: Main trading dashboardAgentPerformanceApp: Agent comparison and analyticsStockDataApp: Stock price data viewer
IStockDataService: Fetches and caches stock price dataITradingService: Executes buy/sell ordersIPositionService: Tracks agent positions over timeIAgentService: AI agent reasoning and decision-makingIConfigService: Configuration managementILogService: Trading log persistence
- .NET 9.0 SDK
- Anthropic API key (for Claude models) or OpenAI API key
- Ivy Framework (included via NuGet)
-
Set up user secrets (recommended for API keys):
# Set Alpha Vantage API key dotnet user-secrets set ALPHA_VANTAGE_API_KEY your-api-key-here # Set Anthropic API key (for AI agents) dotnet user-secrets set ANTHROPIC_API_KEY your-api-key-here
Alternatively, you can set environment variables:
export ANTHROPIC_API_KEY=your-api-key-here export ALPHA_VANTAGE_API_KEY=your-api-key-here
-
Edit
Configs/default.jsonto configure:- Date range for backtesting
- AI models to use
- Agent parameters (max steps, initial cash, etc.)
dotnet watchThe application will start and open in your browser at http://localhost:5000 (or the configured port).
- Select a date and agent from the dropdown
- Click "Run Simulation" to start a trading session
- Watch the agent make trading decisions
- View current holdings and portfolio value
- Select a date range
- Compare performance metrics across all enabled agents
- View return percentages and trade counts
- Select a stock symbol
- Choose a date range
- View price charts and historical data
This application requires API keys for:
- Alpha Vantage (for stock price data): Get a free API key at Alpha Vantage
- Anthropic (for AI agents): Get an API key at Anthropic
User secrets are stored securely and not committed to git:
# Set Alpha Vantage API key
dotnet user-secrets set ALPHA_VANTAGE_API_KEY your-key-here
# Set Anthropic API key
dotnet user-secrets set ANTHROPIC_API_KEY your-key-here
# List all secrets
dotnet user-secrets list
# Remove a secret
dotnet user-secrets remove ALPHA_VANTAGE_API_KEYThe application will automatically fall back to mock data if API keys are not configured, but real data requires the Alpha Vantage API key.
All data is stored in the Data directory:
Data/
├── Agents/
│ └── {agent-id}/
│ ├── positions/
│ │ └── position.jsonl
│ └── logs/
│ └── {date}/
│ └── log.jsonl
└── Prices/
└── {symbol}.jsonl
{
"agentType": "BaseAgent",
"dateRange": {
"initDate": "2025-01-01T00:00:00",
"endDate": "2025-01-31T00:00:00"
},
"models": [
{
"name": "claude-sonnet-4",
"baseModel": "claude-sonnet-4",
"signature": "claude-sonnet-4",
"enabled": true
}
],
"agentConfig": {
"maxSteps": 30,
"maxRetries": 3,
"baseDelay": 1.0,
"initialCash": 10000.0
}
}OpenTrading/
├── Apps/ # Ivy UI applications
├── Services/ # Business logic services
├── Models/ # Data models
├── Data/ # Data storage
├── Configs/ # Configuration files
└── Program.cs # Entry point
dotnet builddotnet test- No LangChain/MCP: Direct API integration with Anthropic/OpenAI
- Ivy UI: Modern reactive web UI instead of static HTML
- Service-based: Clean separation of concerns with dependency injection
- Type-safe: Full C# type safety throughout
MIT License
See DEVELOPER_GUIDE.md for detailed development information, architecture, and contributing guidelines.
✅ Core trading system with buy/sell logic ✅ Multiple AI agent support (Anthropic & OpenAI) ✅ Real stock data integration (Alpha Vantage API) ✅ User secrets for secure API key storage ✅ Multi-agent parallel execution ✅ Date range simulation support ✅ Portfolio tracking and visualization ✅ Trading logs and history ✅ Performance comparison across agents ✅ Retry logic and error handling ✅ Data persistence in JSONL format
- Original AI-Trader project
- Ivy Framework for the amazing web framework