A sophisticated probability analysis agent that integrates with Kalshi prediction markets to provide users with enhanced winning probabilities through ensemble analysis, adaptive risk management, and intelligent recommendation systems.
- Real-time Kalshi API Integration with RSA-PSS authentication
- Multi-method Ensemble Analysis combining sentiment, statistical, and ML models
- Adaptive Risk Management with user-configurable controls
- Web Dashboard with live updates via WebSocket
- Optional Automated Trading with strict safety constraints
- Comprehensive Performance Tracking and visualization
- Sentiment Analysis: Twitter, Reddit, and news sentiment aggregation
- Statistical Analysis: Technical indicators, pattern recognition, mean reversion
- Machine Learning: Random Forest, Gradient Boosting, LSTM, ARIMA models
- Ensemble Combination: Dynamic weight optimization and confidence weighting
- Maximum position sizing (5% of portfolio by default)
- Category exposure limits (20% per category)
- Daily loss limits (2% of portfolio)
- Kelly Criterion position sizing with fractional Kelly
- Stop-loss rules and correlation monitoring
- Emergency stop functionality
- Python 3.9+
- Node.js 18+
- PostgreSQL 12+
- Redis 6+
- Docker & Docker Compose (recommended)
-
Clone the repository
git clone <repository-url> cd UX-builder
-
Set up environment variables
# Copy environment templates cp backend/.env.example .env cp frontend/.env.example frontend/.env # Edit .env file with your configuration nano .env
-
Start the application
# Start all services docker-compose up -d # Or start with monitoring docker-compose --profile monitoring up -d
Note: Redis now binds to
${REDIS_HOST_PORT:-6380}to avoid conflicts with local Redis instances. SetREDIS_HOST_PORT=6379(or another open port) in your.envif you need a different mapping. -
Access the application
- Frontend: http://localhost:3000
- Backend API: http://localhost:8000
- API Documentation: http://localhost:8000/docs
- Grafana (if enabled): http://localhost:3001
-
Install Python dependencies
cd backend pip install -r requirements.txt -
Set up database
# Create PostgreSQL database createdb kalshi_agent # Run migrations (if using Alembic) alembic upgrade head
-
Configure environment
cp .env.example .env # Edit .env with your configuration -
Start the backend
uvicorn app.main:app --reload --host 0.0.0.0 --port 8000
-
Install Node.js dependencies
cd frontend npm install -
Configure environment
cp .env.example .env # Edit .env with your configuration -
Start the frontend
npm start
# Kalshi API Configuration
KALSHI_API_KEY=your_api_key_here
KALSHI_PRIVATE_KEY=your_private_key_here
KALSHI_PRIVATE_KEY_FILE=/optional/path/to/private_key.pem
KALSHI_PRIVATE_KEY_BASE64=optional_base64_encoded_private_key
KALSHI_ENVIRONMENT=sandbox # sandbox or production
# Database Configuration
DATABASE_URL=postgresql://user:password@localhost:5432/kalshi_agent
REDIS_URL=redis://localhost:6379/0
# Security
SECRET_KEY=your_secret_key_here_change_in_production
CORS_ORIGINS=http://localhost:3000,https://yourdomain.com
# External API Keys (optional, for sentiment analysis)
NEWS_API_KEY=your_news_api_key
TWITTER_API_KEY=your_twitter_api_key
TWITTER_API_SECRET=your_twitter_api_secret
REDDIT_CLIENT_ID=your_reddit_client_id
REDDIT_CLIENT_SECRET=your_reddit_client_secret# API Configuration
REACT_APP_API_URL=http://localhost:8000
REACT_APP_WS_URL=ws://localhost:8000
# Feature Flags
REACT_APP_ENABLE_AUTO_TRADING=false
REACT_APP_ENABLE_ADVANCED_CHARTS=true
REACT_APP_ENABLE_NOTIFICATIONS=true- Create a Kalshi account at Kalshi
- Generate API keys in your account settings
- Create RSA key pair for authentication:
openssl genrsa -out private_key.pem 2048 openssl rsa -in private_key.pem -pubout -out public_key.pem
- Upload public key to Kalshi and configure API access
- Handling Docker Compose .env files: multiline private keys can break parsing. Either mount a key file and set
KALSHI_PRIVATE_KEY_FILE, or encode your key to a single line and setKALSHI_PRIVATE_KEY_BASE64(e.g.,base64 -w0 private_key.pem).
- Register/Login to the web dashboard
- Configure your risk profile (conservative, moderate, aggressive)
- Connect your Kalshi account with API credentials
- View market opportunities in the dashboard
- Analyze specific markets with detailed ensemble analysis
- Execute trades manually or enable automated trading
- Real-time portfolio overview
- Performance charts and metrics
- Risk monitoring and alerts
- Top trading opportunities
- Browse available Kalshi markets
- Detailed ensemble analysis
- Individual model breakdowns
- Historical performance tracking
- Manual order placement
- Risk assessment before trades
- Position management
- Portfolio allocation tracking
- Configure risk parameters
- Monitor exposure limits
- Emergency stop functionality
- Risk alerts and notifications
UX-builder/
βββ backend/ # FastAPI backend
β βββ app/
β β βββ api/ # API endpoints
β β βββ core/ # Core business logic
β β β βββ analyzers/ # Analysis engines
β β β βββ kalshi_client.py
β β β βββ risk_manager.py
β β β βββ portfolio.py
β β βββ models/ # Database models
β β βββ utils/ # Utilities
β βββ requirements.txt
β βββ Dockerfile
βββ frontend/ # React frontend
β βββ src/
β β βββ components/ # React components
β β βββ hooks/ # Custom hooks
β β βββ services/ # API services
β β βββ types/ # TypeScript types
β βββ package.json
β βββ Dockerfile
βββ docker-compose.yml # Docker configuration
βββ README.md
cd backend
pytest tests/ -v --cov=appcd frontend
npm test# Format code
black app/
isort app/
# Lint code
flake8 app/
mypy app/# Format code
npm run lint:fix
# Type check
npm run type-checkThe system aims to achieve:
- API Response Time: < 200ms (95th percentile)
- WebSocket Latency: < 500ms for real-time updates
- Ensemble Model Accuracy: > 70% on binary predictions
- Win Rate Target: > 65% on executed trades
- Maximum Drawdown: < 15%
- Annual Return Target: > 20%
- RSA-PSS authentication for Kalshi API
- JWT-based authentication for web interface
- Environment variable configuration
- Rate limiting and circuit breakers
- Comprehensive input validation
- Secure WebSocket connections
All API endpoints require JWT authentication:
curl -H "Authorization: Bearer <token>" http://localhost:8000/api/marketsGET /api/markets- List available marketsGET /api/markets/{id}- Get market detailsGET /api/markets/{id}/history- Get price history
POST /api/analysis/refresh- Trigger analysisGET /api/analysis/opportunities- Get opportunitiesGET /api/analysis/{id}- Get market analysis
POST /api/trading/orders- Place orderGET /api/trading/positions- Get positionsGET /api/trading/portfolio/metrics- Get portfolio metrics
WS /ws- Real-time updates- Subscribe to market updates
- Portfolio updates
- Risk alerts
- Trade notifications
Full API documentation available at: http://localhost:8000/docs
# Check PostgreSQL is running
docker-compose ps postgres
# Check logs
docker-compose logs postgres- Check firewall settings
- Verify CORS configuration
- Ensure WebSocket port is accessible
- Verify JWT token is valid
- Check API key configuration
- Ensure user account is active
docker-compose logs -f backendCheck browser developer console
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- π§ Email: support@kalshi-agent.com
- π Issues: GitHub Issues
- π Documentation: Wiki
- Kalshi for the prediction markets platform
- FastAPI for the backend framework
- React for the frontend framework
- Ant Design for UI components
- All contributors and beta testers
Run the lightweight migration helper to create watchlist/risk tables:
cd backend
python -c "from app.models.migrations import run_migrations; run_migrations()"Run targeted tests:
cd backend
pytest