This workspace unifies UI, API, and the existing trading_system core into a single platform skeleton.
frontend/– UI (placeholder)api/– FastAPI gatewaytrading_core/– Thin orchestrator wrapper around existingtrading_systemdatabase/– ORM models and DB utilities (skeleton)scripts/– Ops & utilitiestests/– Test suite (placeholder)docs/– Documentation
- Python 3.9 or higher
- Virtual environment (recommended)
If you have an existing virtual environment:
On macOS/Linux:
source venv/bin/activateOn Windows:
venv\Scripts\activateIf you don't have a virtual environment yet:
python3 -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activateMake sure all required packages are installed:
pip install -r requirements.txtThis will install:
- FastAPI (for the API framework)
- Uvicorn (for the ASGI server)
- PyYAML (for configuration)
- pandas, numpy (for data processing)
- ibapi (for Interactive Brokers integration)
- Other dependencies
Test that the API can be imported:
python -c "from unified_trading_platform.api.main import app; print('✓ API ready')"If this fails, make sure:
- Virtual environment is activated
- All dependencies are installed
- You're in the project root directory
Edit unified_trading_platform/api/api_config.yaml to customize:
- API metadata (title, description, contact info)
- Default broker settings (host, port, client_id)
- Default contract/order settings (security_type, currency, time_in_force)
- Default data settings (duration, bar_size, market_data_type)
- Default strategy settings (db_path, status)
There are several ways to run the API:
Basic usage:
python run_api.pyDevelopment mode with auto-reload:
python run_api.py --reload --log-level debugCustom host and port:
python run_api.py --host 127.0.0.1 --port 8080Production mode with multiple workers:
python run_api.py --host 0.0.0.0 --port 8000 --workers 4Available options:
--host: Host to bind to (default: 0.0.0.0)--port: Port number (default: 8000)--reload: Enable auto-reload for development--workers: Number of worker processes (default: 1)--log-level: Log level (critical, error, warning, info, debug, trace)
uvicorn unified_trading_platform.api.main:app --host 0.0.0.0 --port 8000 --reloadpython -m unified_trading_platform.apiThis runs in development mode with auto-reload on port 8000.
uvicorn unified_trading_platform.api.main:app --reloadOnce the server is running, you can access:
-
Swagger UI: http://localhost:8000/docs
- Interactive API documentation where you can test endpoints
- Includes request/response examples
-
ReDoc: http://localhost:8000/redoc
- Alternative documentation format
- Better for reading API specifications
-
OpenAPI JSON: http://localhost:8000/api/v1/openapi.json
- Machine-readable API specification
-
Health Check: http://localhost:8000/health/ready
- Verify the API is running
The API provides the following endpoint groups:
-
/health- Health check endpoints- Check API availability and status
-
/brokers- Broker management- Connect, disconnect, and manage broker connections
- Retrieve account information
-
/data- Market data retrieval- Historical data, option chains, real-time subscriptions
-
/orders- Order management- Submit, cancel, and track orders
- View positions and trade history
-
/strategies- Strategy execution- Initialize, start, stop, and monitor trading strategies
- View portfolio summaries
See unified_trading_platform/api/API_SUMMARY.md for detailed endpoint documentation.
Complete setup and run in one go:
# 1. Activate virtual environment
source venv/bin/activate
# 2. Install dependencies (if not already installed)
pip install -r requirements.txt
# 3. Run the API
python run_api.py --reload
# 4. Open browser to http://localhost:8000/docsFor development, use:
python run_api.py --reload --log-level debugThis provides:
- Auto-reload when code changes
- Debug-level logging
- Better error messages
For production:
python run_api.py --host 0.0.0.0 --port 8000 --workers 4Or use a production ASGI server like Gunicorn:
gunicorn unified_trading_platform.api.main:app -w 4 -k uvicorn.workers.UvicornWorkerOnce running, test the health endpoint:
curl http://localhost:8000/health/readyShould return:
{"status": "ok"}Solution:
# Make sure virtual environment is activated
source venv/bin/activate
# Install dependencies
pip install -r requirements.txt
# Verify installation
pip list | grep fastapiSolution:
# Use a different port
python run_api.py --port 8001Solution:
- Ensure
unified_trading_platform/api/api_config.yamlexists - Check you're running from the project root directory
Solution:
- Make sure you're in the project root directory
- Activate the virtual environment
- Verify all dependencies are installed:
pip list | grep fastapi
Solution:
- Make sure you're running from the project root directory (where
unified_trading_platform/folder is located) - Check that the virtual environment is activated
- Try:
python -c "import sys; print(sys.path)"to verify the project root is in the path
- Check the API documentation at http://localhost:8000/docs
- Review endpoint documentation in
unified_trading_platform/api/API_SUMMARY.md - Connect a broker via
/brokersendpoint - Start using the API endpoints
The API uses unified_trading_platform/api/api_config.yaml for all configuration. This includes:
- API Metadata: Title, description, version, contact info, license
- Tag Metadata: Descriptions for API endpoint groups
- Default Broker Settings: Host, port, client_id for broker connections
- Default Contract/Order Settings: Security type, currency, time-in-force
- Default Data Settings: Duration, bar size, market data type
- Default Strategy Settings: Database path, status values
- Portfolio Defaults: Initial values for portfolio summaries
- Allowed Values: Validation lists for security types, currencies, exchanges, etc.
Changes to the config file take effect on API restart.