Skip to content

Commit 43a8221

Browse files
prod
1 parent e9f0584 commit 43a8221

14 files changed

+4276
-22
lines changed

.env.example

Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
# OmniQuant Production Environment Configuration
2+
# Copy to .env and fill in your values
3+
4+
# ============================================================================
5+
# Environment
6+
# ============================================================================
7+
ENVIRONMENT=production # development, staging, production
8+
DEBUG=false
9+
APP_NAME=OmniQuant
10+
APP_VERSION=2.0.0
11+
12+
# ============================================================================
13+
# Database Configuration (PostgreSQL)
14+
# ============================================================================
15+
DB_HOST=localhost
16+
DB_PORT=5432
17+
DB_NAME=omniquant_prod
18+
DB_USER=omniquant_user
19+
DB_PASSWORD=CHANGE_THIS_STRONG_PASSWORD_123!@#
20+
DB_POOL_SIZE=20
21+
DB_MAX_OVERFLOW=40
22+
23+
# ============================================================================
24+
# Redis Configuration
25+
# ============================================================================
26+
REDIS_HOST=localhost
27+
REDIS_PORT=6379
28+
REDIS_PASSWORD=CHANGE_THIS_REDIS_PASSWORD_456!@#
29+
REDIS_DB=0
30+
REDIS_MAX_CONNECTIONS=100
31+
32+
# ============================================================================
33+
# Broker API Credentials
34+
# ============================================================================
35+
# Alpaca (Paper Trading: https://paper-api.alpaca.markets)
36+
# Alpaca (Live Trading: https://api.alpaca.markets)
37+
ALPACA_API_KEY=YOUR_ALPACA_API_KEY_HERE
38+
ALPACA_SECRET_KEY=YOUR_ALPACA_SECRET_KEY_HERE
39+
ALPACA_BASE_URL=https://paper-api.alpaca.markets
40+
41+
# Interactive Brokers
42+
IB_HOST=127.0.0.1
43+
IB_PORT=7497 # TWS: 7497 (paper), 7496 (live) | IB Gateway: 4002 (paper), 4001 (live)
44+
IB_CLIENT_ID=1
45+
46+
# Polygon.io
47+
POLYGON_API_KEY=YOUR_POLYGON_API_KEY_HERE
48+
49+
# ============================================================================
50+
# Security Configuration (CRITICAL!)
51+
# ============================================================================
52+
# Generate with: openssl rand -hex 32
53+
SECRET_KEY=GENERATE_A_SECURE_256_BIT_KEY_HERE_DO_NOT_USE_THIS_DEFAULT
54+
JWT_ALGORITHM=HS256
55+
ACCESS_TOKEN_EXPIRE_MINUTES=30
56+
REFRESH_TOKEN_EXPIRE_DAYS=7
57+
58+
# API Rate Limiting
59+
RATE_LIMIT_PER_MINUTE=1000
60+
RATE_LIMIT_BURST=50
61+
62+
# CORS (comma-separated list)
63+
ALLOWED_ORIGINS=http://localhost:3000,https://yourdomain.com
64+
65+
# ============================================================================
66+
# Trading Configuration
67+
# ============================================================================
68+
# Position Limits
69+
MAX_POSITION_SIZE=500000.0
70+
MAX_LEVERAGE=2.0
71+
POSITION_CONCENTRATION_LIMIT=0.25
72+
73+
# Risk Limits
74+
MAX_DRAWDOWN_PCT=0.15
75+
DAILY_LOSS_LIMIT=10000.0
76+
77+
# Execution
78+
COMMISSION_RATE=0.0002 # 2 basis points
79+
SLIPPAGE_BPS=1.0 # 1 basis point
80+
RISK_FREE_RATE=0.02 # 2% annual
81+
82+
# Order Management
83+
ORDER_TIMEOUT_SECONDS=30
84+
MAX_RETRY_ATTEMPTS=3
85+
86+
# ============================================================================
87+
# Monitoring & Alerting
88+
# ============================================================================
89+
# Logging
90+
LOG_LEVEL=INFO # DEBUG, INFO, WARNING, ERROR, CRITICAL
91+
LOG_FORMAT=json # json or text
92+
LOG_FILE=/var/log/omniquant/app.log
93+
94+
# Prometheus Metrics
95+
PROMETHEUS_PORT=9090
96+
METRICS_ENABLED=true
97+
98+
# Alert Channels
99+
SLACK_WEBHOOK_URL=https://hooks.slack.com/services/YOUR/SLACK/WEBHOOK
100+
ALERT_EMAIL=[email protected]
101+
PAGERDUTY_API_KEY=YOUR_PAGERDUTY_KEY
102+
103+
# Health Checks
104+
HEALTH_CHECK_INTERVAL=60
105+
106+
# ============================================================================
107+
# API Server Configuration
108+
# ============================================================================
109+
API_HOST=0.0.0.0
110+
API_PORT=8000
111+
API_WORKERS=4
112+
API_TIMEOUT=60
113+
API_MAX_CONNECTIONS=1000
114+
115+
# WebSocket
116+
WS_PING_INTERVAL=20
117+
WS_PING_TIMEOUT=20
118+
119+
# ============================================================================
120+
# Feature Flags (Optional)
121+
# ============================================================================
122+
ENABLE_LIVE_TRADING=false
123+
ENABLE_PAPER_TRADING=true
124+
ENABLE_BACKTESTING=true
125+
ENABLE_RESEARCH_MODE=true
126+
127+
# ============================================================================
128+
# AWS Configuration (Optional)
129+
# ============================================================================
130+
AWS_REGION=us-east-1
131+
AWS_ACCESS_KEY_ID=YOUR_AWS_ACCESS_KEY
132+
AWS_SECRET_ACCESS_KEY=YOUR_AWS_SECRET_KEY
133+
S3_BUCKET_NAME=omniquant-backups
134+
135+
# ============================================================================
136+
# External Services (Optional)
137+
# ============================================================================
138+
SENTRY_DSN=https://[email protected]/project-id
139+
DATADOG_API_KEY=YOUR_DATADOG_API_KEY
140+
141+
# ============================================================================
142+
# Development Overrides (Only for ENVIRONMENT=development)
143+
# ============================================================================
144+
# These are ignored in production
145+
DEV_AUTO_RELOAD=true
146+
DEV_DEBUG_SQL=false
147+
DEV_MOCK_BROKER=true

Dockerfile.prod

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# Production Dockerfile for OmniQuant
2+
# Multi-stage build for optimized image size
3+
4+
# ============================================================================
5+
# Stage 1: Builder
6+
# ============================================================================
7+
FROM python:3.11-slim as builder
8+
9+
# Set working directory
10+
WORKDIR /app
11+
12+
# Install system dependencies
13+
RUN apt-get update && apt-get install -y \
14+
gcc \
15+
g++ \
16+
make \
17+
libpq-dev \
18+
curl \
19+
&& rm -rf /var/lib/apt/lists/*
20+
21+
# Copy requirements
22+
COPY requirements.txt .
23+
24+
# Create virtual environment and install dependencies
25+
RUN python -m venv /opt/venv
26+
ENV PATH="/opt/venv/bin:$PATH"
27+
RUN pip install --no-cache-dir --upgrade pip && \
28+
pip install --no-cache-dir -r requirements.txt
29+
30+
# ============================================================================
31+
# Stage 2: Runtime
32+
# ============================================================================
33+
FROM python:3.11-slim
34+
35+
# Set labels
36+
LABEL maintainer="[email protected]"
37+
LABEL version="2.0.0"
38+
LABEL description="OmniQuant Production Trading Software"
39+
40+
# Create non-root user
41+
RUN groupadd -r omniquant && useradd -r -g omniquant omniquant
42+
43+
# Install runtime dependencies only
44+
RUN apt-get update && apt-get install -y \
45+
libpq5 \
46+
curl \
47+
&& rm -rf /var/lib/apt/lists/*
48+
49+
# Set working directory
50+
WORKDIR /app
51+
52+
# Copy virtual environment from builder
53+
COPY --from=builder /opt/venv /opt/venv
54+
55+
# Copy application code
56+
COPY --chown=omniquant:omniquant . .
57+
58+
# Set environment variables
59+
ENV PATH="/opt/venv/bin:$PATH" \
60+
PYTHONUNBUFFERED=1 \
61+
PYTHONDONTWRITEBYTECODE=1 \
62+
ENVIRONMENT=production
63+
64+
# Create necessary directories
65+
RUN mkdir -p /app/data /app/logs /app/models && \
66+
chown -R omniquant:omniquant /app
67+
68+
# Switch to non-root user
69+
USER omniquant
70+
71+
# Expose ports
72+
EXPOSE 8000 9090
73+
74+
# Health check
75+
HEALTHCHECK --interval=30s --timeout=10s --start-period=40s --retries=3 \
76+
CMD curl -f http://localhost:8000/health || exit 1
77+
78+
# Run application
79+
CMD ["uvicorn", "src.api.main:app", "--host", "0.0.0.0", "--port", "8000", "--workers", "4"]

0 commit comments

Comments
 (0)