OptiTrade is a Vite + React single-page application for monitoring and operating our trading agent. Supabase powers auth/data, Tailwind handles styling, and TypeScript keeps state predictable. This document is the on-ramp for new contributors.
| Path | Purpose |
|---|---|
frontend/ |
React application (source, configs, tooling) |
backend/ |
FastAPI gateway for bot control, trades, and Supabase-facing APIs |
model_service/ |
Lightweight FastAPI wrapper around the trading model |
scripts/ |
Data collection + feature engineering utilities for the ML pipeline |
docs/ |
Living documentation bundle: structure guide, improvements, work log |
requirements.txt |
Python dependencies for backend + model services |
README.md |
Quick-start checklist (this file) |
Need more detail? docs/STRUCTURE.md walks through every folder and convention.
Используйте скрипты для автоматического запуска всех компонентов:
Windows:
# PowerShell
.\scripts\start_all.ps1
# Или Batch
scripts\start_all.batLinux/macOS:
chmod +x scripts/start_all.sh
./scripts/start_all.shСкрипты автоматически:
- Создадут виртуальное окружение (если нужно)
- Установят зависимости
- Запустят все три сервиса (Model Service, Backend, Frontend)
cd frontend
npm install
cp .env.example .env # or create manually
npm run dev -- --hostOpen the printed URL (defaults to http://localhost:5173/). If Supabase credentials are missing, the app automatically falls back to a demo mode so you can click through the UI.
Python 3.9+ and PostgreSQL are required. From the repo root:
1. Setup PostgreSQL database:
# Install PostgreSQL (if not installed)
# macOS - automated:
./scripts/install_postgresql.sh
# macOS - manual:
brew install postgresql@15
brew services start postgresql@15
# Ubuntu/Debian:
sudo apt-get install postgresql postgresql-contrib
sudo systemctl start postgresql
# Create database and user (after PostgreSQL is installed and running)
./scripts/setup_db.sh
# Or manually:
psql postgres
CREATE DATABASE optitrade;
CREATE USER optitrade WITH PASSWORD 'optitrade';
GRANT ALL PRIVILEGES ON DATABASE optitrade TO optitrade;
\q2. Install dependencies and run services:
python -m venv .venv
source .venv/bin/activate # Windows: .venv\Scripts\activate
pip install -r requirements.txt
# Terminal 1 – model service (с поддержкой RL моделей)
MODEL_TYPE=ppo USE_RL_MODEL=true uvicorn model_service.main:app --host 127.0.0.1 --port 8001 --reload
# Terminal 2 – backend gateway
uvicorn backend.main:app --host 127.0.0.1 --port 8000 --reloadhttp://127.0.0.1:8000/health— backend health checkhttp://127.0.0.1:8000/bot/status— bot status from databasehttp://127.0.0.1:8000/model/predict— backend proxy to the model servicehttp://127.0.0.1:8001/predict— direct model endpointhttp://127.0.0.1:8001/health— model service health check
The backend automatically creates all tables on first run. All data is persisted in PostgreSQL.
Note: If PostgreSQL is not set up, the backend will show a warning but still start. Tables will be created automatically when the database becomes available.
Проект интегрирован с обученными RL моделями из папки RL_algorithms/:
- PPO (Proximal Policy Optimization) - по умолчанию
- A2C (Advantage Actor-Critic)
- SAC (Soft Actor-Critic)
Модели автоматически загружаются из RL_algorithms/models/{MODEL_TYPE}/ при запуске Model Service.
Если RL модель не найдена или отключена, используется упрощенный режим предсказаний.
Frontend:
VITE_SUPABASE_URL=
VITE_SUPABASE_ANON_KEY=
VITE_API_BASE_URL=http://127.0.0.1:8000
Backend + Model Service (loaded via .env or host environment):
# Create .env file in project root:
ADMIN_API_KEY=devkey
MODEL_SERVICE_URL=http://127.0.0.1:8001
DATABASE_URL=postgresql://postgres:postgres@localhost:5432/optitrade
# Model Service configuration:
MODEL_TYPE=ppo # ppo, a2c, or sac
USE_RL_MODEL=true # true to use RL models, false for simple mode
# MODEL_PATH= # Optional: explicit path to model fileDefault PostgreSQL connection:
- User:
postgres - Password:
postgres - Database:
optitrade - Host:
localhost:5432
Local PostgreSQL:
-
Install PostgreSQL (if not already installed):
# macOS brew install postgresql@15 brew services start postgresql@15 # Ubuntu/Debian sudo apt-get install postgresql postgresql-contrib sudo systemctl start postgresql
-
Create database and user:
# Connect to PostgreSQL psql postgres # Create database and user CREATE DATABASE optitrade; CREATE USER optitrade WITH PASSWORD 'optitrade'; GRANT ALL PRIVILEGES ON DATABASE optitrade TO optitrade; \q
-
The application will automatically create tables on first run.
For production, update DATABASE_URL in your environment to point to your cloud PostgreSQL instance (e.g., AWS RDS, Supabase, Neon, etc.).
Copy frontend/.env.example, paste your Supabase values, and keep .env local (Git already ignores it).
⚠️ Right nowfrontend/.envships with placeholder values (placeholder.supabase.co). Replace them with real Supabase keys before release.
Run every command from frontend/:
npm run dev– Vite dev servernpm run build– production buildnpm run preview– serve the production bundle locallynpm run lint– ESLintnpm run typecheck– isolatedtscrunnpm run format/npm run format:check– Prettier write/checknpm run test/npm run test:run– Vitest + Testing Library suite (JSDOM)
DEPLOYMENT.md– deployment guide for local setupDEPLOYMENT_VPS.md– comprehensive VPS deployment guidedocs/STRUCTURE.md– project anatomy and conventionsdocs/IMPROVEMENTS.md– prioritized backlog with recommended librariesdocs/PAPER_VS_LIVE_TRADING.md– explanation of trading modesdocs/BACKTESTING.md– backtesting documentationdocs/MODEL_MANAGEMENT.md– RL model management guide
See DEPLOYMENT.md for detailed local setup instructions.
See DEPLOYMENT_VPS.md for complete VPS deployment guide with:
- System setup and dependencies
- Systemd service configuration
- Nginx reverse proxy setup
- SSL certificates with Let's Encrypt
- Security recommendations
- Performance optimization
- Troubleshooting guide
Before pushing to GitHub:
- Remove temporary files and logs
- Update
.env.examplewith required variables (no secrets!) - Ensure all tests pass
- Update documentation if needed
See LICENSE file for details.