TradingBot is an AI-powered automated trading system for the Indian stock market, designed to work with brokers like Zerodha and Groww. It consists of a C# API backend and a Python-based signal engine, connected via Docker, and is highly configurable and extendable.
- π AI-driven signal generation (Python, OpenAI API)
- πΌ Execute buy/sell orders via broker APIs (e.g., Kite Connect)
- π Configurable modes: Auto trade / Signal-only
- βοΈ Trading strategy options: intraday, long-term, swing, options, etc.
- π Risk management: daily limits, trade caps, risk/reward ratio
- π Modular architecture for plug-in strategy and AI service integration
- π§ͺ Local testing and Docker support for development
TradingBot/
βββ TradingBot.Api/ # C# ASP.NET Core backend (REST API)
βββ TradingBot.SignalEngine/ # Python signal engine (AI, ML logic)
βββ TradingBot.Tests/ # C# Unit Tests
βββ docker-compose.yml # Orchestrates multi-container dev environment
βββ docs/ # Project documentation
βββ README.md # This file
- Docker and Docker Compose
- .NET 8.0 SDK (for local development)
- Python 3.11+ (for local development)
git clone <repository-url>
cd TradingBot
Create a .env
file in the root directory:
# Optional: OpenAI API Key for AI strategy
OPENAI_API_KEY=your_openai_api_key_here
# Optional: Database connection (if using external DB)
DB_CONNECTION_STRING=your_db_connection_string
# Build and start all services
docker-compose up --build
# Or run in background
docker-compose up -d --build
- API Documentation: http://localhost:5000/swagger
- Signal Engine: http://localhost:8000/docs
- API Health: http://localhost:5000/health
- Signal Engine Health: http://localhost:8000/health
curl http://localhost:5000/api/trade/config
curl -X POST http://localhost:5000/api/trade/signal \
-H "Content-Type: application/json" \
-d '{
"symbols": ["AAPL", "MSFT"],
"strategy": "moving_average",
"tradeMode": "paper"
}'
curl -X POST http://localhost:5000/api/trade/execute \
-H "Content-Type: application/json" \
-d '{
"symbol": "AAPL",
"quantity": 10,
"price": 150.00,
"side": "buy",
"orderType": "market",
"tradeType": "intraday"
}'
curl http://localhost:5000/api/portfolio
The Python signal engine supports multiple trading strategies:
- Uses SMA crossover with RSI confirmation
- Volume-based validation
- Configurable periods and thresholds
- Simple price action analysis
- Volume confirmation
- RSI overbought/oversold signals
- OpenAI GPT integration for advanced analysis
- Technical indicator synthesis
- Fallback to technical analysis
# Moving Average Strategy
curl -X POST http://localhost:8000/signal \
-H "Content-Type: application/json" \
-d '{"symbol": "AAPL", "strategy": "moving_average"}'
# AI Strategy (requires OpenAI API key)
curl -X POST http://localhost:8000/signal \
-H "Content-Type: application/json" \
-d '{"symbol": "AAPL", "strategy": "ai"}'
# Basic Strategy
curl -X POST http://localhost:8000/signal \
-H "Content-Type: application/json" \
-d '{"symbol": "AAPL", "strategy": "basic"}'
Edit TradingBot.Api/appsettings.Development.json
:
{
"TradeSettings": {
"EnableAutoBuy": true,
"EnableAutoSell": true,
"EnableSignalOnly": false,
"MaxDailyBuyAmount": 10000.00,
"MaxDailySellAmount": 10000.00,
"MaxDailyTrades": 10,
"TradeTypesEnabled": ["Intraday", "Swing", "LongTerm"]
}
}
Each strategy can be configured with custom parameters. See individual strategy files in TradingBot.SignalEngine/strategies/
.
-
C# API Development:
cd TradingBot.Api dotnet restore dotnet run
-
Python Signal Engine Development:
cd TradingBot.SignalEngine pip install -r requirements.txt uvicorn main:app --reload --host 0.0.0.0 --port 8000
- Create a new strategy class in
TradingBot.SignalEngine/strategies/
- Extend
BaseStrategy
class - Implement
generate_signal()
method - Register in
main.py
STRATEGIES dictionary
Example:
from .base import BaseStrategy, TradeSignal
class MyCustomStrategy(BaseStrategy):
def generate_signal(self, df: pd.DataFrame, symbol: str) -> TradeSignal:
# Your custom logic here
return TradeSignal(...)
cd TradingBot.Tests
dotnet test
# Test health endpoint
curl http://localhost:8000/health
# Test signal generation
curl -X POST http://localhost:8000/signal \
-H "Content-Type: application/json" \
-d '{"symbol": "AAPL"}'
- API:
GET /health
- Signal Engine:
GET /health
# View all logs
docker-compose logs
# View specific service logs
docker-compose logs tradingbot-api
docker-compose logs signal-engine
-
Azure Container Registry:
# Build and push images docker build -t yourregistry.azurecr.io/tradingbot-api . docker build -t yourregistry.azurecr.io/tradingbot-signal-engine . docker push yourregistry.azurecr.io/tradingbot-api docker push yourregistry.azurecr.io/tradingbot-signal-engine
-
Azure Kubernetes Service (AKS):
- Deploy using provided Kubernetes manifests
- Configure secrets for API keys
- Set up monitoring and logging
Variable | Description | Required |
---|---|---|
OPENAI_API_KEY |
OpenAI API key for AI strategy | No |
DB_CONNECTION_STRING |
Database connection string | Yes (prod) |
BROKER_API_KEY |
Broker API credentials | Yes (live) |
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests
- Submit a pull request
This project is licensed under the MIT License - see the LICENSE file for details.
- Documentation: Check the
docs/
folder - Issues: Create an issue on GitHub
- Discussions: Use GitHub Discussions
See docs/roadmap.md for detailed roadmap and upcoming features.