Optionix is an options and futures trading platform: a FastAPI backend that prices options, calibrates volatility models, tracks portfolios and risk, and reads and writes deployed smart contracts, paired with a React web dashboard, a React Native (Expo) mobile app, and Hardhat contracts. The pricing, calibration, and volatility-forecasting code lives in an ai_models package that the backend loads in-process.
- Overview
- Architecture
- Project Structure
- Feature Status
- Technology Stack
- Installation and Setup
- Running the Stack
- API Surface
- Testing
- CI/CD Pipeline
- Documentation
- Contributing
- License
| Topic | Summary |
|---|---|
| Pricing | Black-Scholes and Monte Carlo pricing, Greeks, implied volatility, and model calibration, served by the backend through the ai_models package. |
| Volatility | A scikit-learn volatility model with SHA-256 integrity-checked artifacts. The production backend image generates the artifacts at build time, and the API falls back to a statistical estimate if they are absent. |
| On-chain | A web3.py service reads and writes the options and futures contracts, which price through Chainlink AggregatorV3Interface feeds. |
| Clients | A React web dashboard and a React Native mobile app, both talking to the same REST API. |
| Tests | 269 backend, 96 AI model, 12 smart contract, 457 web, and 349 mobile tests. All five suites run in CI. |
flowchart TD
web["web-frontend (React, Webpack)"] -->|"HTTP/JSON"| api
mobile["mobile-frontend (React Native, Expo)"] -->|"HTTP/JSON"| api
api["FastAPI backend: auth, market, trading, portfolio, analytics, risk, compliance, blockchain"] --> db[("MySQL")]
api --> redis[("Redis")]
api -->|"ai_bridge, in-process"| ai["ai_models: pricing, calibration, volatility model"]
api -->|"web3.py"| chain["Hardhat contracts: OptionsContract, FuturesContract"]
api --> metrics["/metrics for Prometheus"]
| Supporting service | Image | Host port | Role |
|---|---|---|---|
db |
mysql:8.0 |
3306 (localhost) | Primary database |
redis |
redis:7.2-alpine |
6379 (localhost) | Cache, sessions, and rate limiting |
prometheus |
prom/prometheus:v2.51.0 |
9090 (localhost) | Metrics collection |
grafana |
grafana/grafana:10.4.0 |
3001 (localhost) | Dashboards |
These are defined in infrastructure/docker-compose.yml, together with MySQL and Redis exporters for Prometheus. code/backend/Dockerfile builds the production backend image, which bundles ai_models and generates the volatility artifacts. See docs/architecture.md for detail.
| Path | Purpose |
|---|---|
code/backend |
FastAPI application: routers, services, middleware, security, models, and tests |
code/ai_models |
Pricing, calibration, and volatility package: quantitative, volatility, training |
code/blockchain |
Hardhat project: Solidity contracts, deploy scripts, and tests |
web-frontend |
React (Webpack) dashboard |
mobile-frontend |
React Native (Expo) app |
infrastructure |
Docker, Kubernetes (Helm), Terraform, Ansible, and monitoring configuration |
scripts |
Setup, run, build, test, database, and lint scripts |
docs |
Project documentation |
.github |
CI/CD workflow and its documentation |
| Component | Details |
|---|---|
| API | FastAPI backend with eight routers (auth, market, trading, portfolio, analytics, risk, compliance, blockchain) mounted directly at the root, with no /api prefix, plus /health and a Prometheus /metrics endpoint. |
| Auth | bcrypt password hashing (passlib), JWT access and refresh tokens (python-jose), and TOTP-based MFA (pyotp). SECRET_KEY must be at least 32 characters and ENCRYPTION_KEY exactly 32, and both settings are validated at startup. |
| Pricing and analytics | European, American (CRR lattice), and barrier pricing, Greeks, implied volatility, and Monte Carlo simulation (GBM, jump diffusion, Heston, mean reverting) with variance reduction. Heston and SABR calibration, SVI volatility surfaces, and Dupire local volatility are also available. |
| Volatility model | A scikit-learn pipeline trained on Heston-generated bars, with out-of-sample validation and artifact integrity metadata. Served by POST /market/volatility, with model details at GET /market/model-info. |
| Risk and compliance | VaR, stress tests, portfolio Greeks and heatmaps, limits, and circuit breakers; KYC, sanctions and AML screening, GDPR requests, regulatory reports, and audit logs. |
| On-chain integration | A web3.py service for positions, margin deposits and withdrawals, option purchase and exercise, and transaction lookups against the deployed contracts. |
| Smart contracts | OptionsContract and FuturesContract, each pricing through a Chainlink AggregatorV3Interface feed, built on OpenZeppelin 5 and Solidity 0.8.24, with mock feed and token contracts for testing. |
| Data layer | SQLAlchemy 2 over MySQL (SQLite in tests), with Redis for caching, sessions, and rate limiting. Tables are created through SQLAlchemy metadata. |
| Monitoring | Prometheus metrics and structured logging (structlog) wired into the running app, with Prometheus and Grafana in the infrastructure stack. |
| Web dashboard | React 18 app (JavaScript, Webpack 5) with Home, Sign in, Sign up, Dashboard, Trading, Portfolio, Wallet, Analytics, Risk, Compliance, and Settings pages. |
| Mobile app | React Native (Expo SDK 52) app with the same functional areas through React Navigation, and WalletConnect for mobile wallet connections. |
| Area | Technology |
|---|---|
| Blockchain | Solidity 0.8.24, OpenZeppelin 5, Chainlink contracts, Hardhat |
| Backend API | Python 3.11, FastAPI, Uvicorn, Pydantic v2 |
| Auth | passlib and bcrypt, python-jose (JWT), pyotp (MFA) |
| Blockchain client | web3.py |
| Data layer | SQLAlchemy 2, MySQL (PyMySQL), Redis |
| ML and quant | NumPy, SciPy, pandas, scikit-learn, joblib |
| Observability | prometheus-client, structlog |
| Web frontend | React 18, JavaScript, Webpack 5, styled-components, Chart.js 4, ethers.js 6, React Router |
| Mobile frontend | React Native, Expo (SDK 52), React Navigation, React Native Paper, WalletConnect |
| Infrastructure | Docker, Docker Compose, Kubernetes (Helm chart), Terraform, Ansible |
| Monitoring stack (infra) | Prometheus, Grafana, MySQL and Redis exporters |
| CI/CD | GitHub Actions |
| Testing | pytest (backend and AI models), Hardhat (contracts), Jest (web and mobile) |
Prerequisites: Python 3.11+ and Node.js 20+. Docker is optional.
git clone https://github.com/quantsingularity/Optionix.git
cd Optionix
# Smart contracts
cd code/blockchain
npm install
# Backend and AI models
cd ../backend
python -m venv .venv && source .venv/bin/activate
pip install -r requirements.txt
# Web frontend
cd ../../web-frontend
npm install --legacy-peer-deps
# Mobile frontend
cd ../mobile-frontend
npm install --legacy-peer-depsFor an automated setup:
git clone https://github.com/quantsingularity/Optionix.git
cd Optionix
./scripts/setup_optionix_env.sh
./scripts/run_optionix.shFull, environment-specific instructions are in docs/INSTALLATION.md.
Set the passwords and keys for the supporting services first (ENCRYPTION_KEY must be exactly 32 characters, and JWT_SECRET at least 32):
# 1) Supporting services (from infrastructure/, Docker required)
cd infrastructure
cp .env.example .env # then edit the passwords and keys
docker compose up -d db redis # add prometheus and grafana for monitoring
# 2) Local chain (from code/blockchain)
npx hardhat node # http://127.0.0.1:8545
# 3) Volatility artifacts (from code/, optional: the API falls back to a statistical estimate without them)
python -m ai_models.training.generate_artifacts
# 4) Backend (from code/backend, venv active)
uvicorn app.main:app --reload # http://127.0.0.1:8000, docs at /docs
# 5) Web dashboard (from web-frontend)
npm start # Webpack dev server at http://localhost:3000
# 6) Mobile app (from mobile-frontend)
npm start # press w for web, a for Android, i for iOSTo build the production backend image, which bundles ai_models and its generated artifacts (this is the image CI builds and smoke tests), run from the repository root:
docker build -f code/backend/Dockerfile -t optionix-backend codeFor a local backend, put DATABASE_URL, REDIS_URL, SECRET_KEY, and ENCRYPTION_KEY in code/backend/.env (for example mysql+pymysql://appuser:<DB_PASSWORD>@127.0.0.1:3306/optionix). See docs/USAGE.md and docs/CONFIGURATION.md.
Base URL http://localhost:8000. Interactive docs at /docs (Swagger) and /redoc. Metrics at /metrics.
| Group | Prefix | Endpoints |
|---|---|---|
| System | Site root | GET /, GET /health |
| Auth | /auth |
register, login, me, refresh |
| Market | /market |
POST volatility, GET model-info |
| Trading | /trading |
accounts, accounts/{id}, accounts/{id}/summary, orders (GET, POST), orders/{id} (GET, DELETE), positions, positions/{id} |
| Portfolio | /portfolio |
overview, allocation, performance, risk-metrics, positions/greeks-summary |
| Analytics | /analytics |
price, implied-volatility, volatility-surface, calibrate, greeks/{symbol} |
| Risk | /risk |
var, stress-test, greeks/portfolio, greeks/heatmap, limits, circuit-breakers |
| Compliance | /compliance |
kyc/submit, kyc/status, sanctions/check, aml/alerts, reports (GET) and reports/generate, gdpr/request, audit-logs, status |
| Blockchain | /blockchain |
status, wallet/{address}/balance, wallet/{address}/positions, wallet/{address}/options, options/{id}, margin/deposit, margin/withdraw, options/purchase, options/exercise, transactions/{tx_hash} |
Full request and response shapes are in docs/API.md.
| Suite | Directory | Tests | Run locally |
|---|---|---|---|
| Backend | code/backend |
269 | pytest |
| AI models | code |
96 | python -m pytest ai_models |
| Contracts | code/blockchain |
12 | npx hardhat test |
| Web | web-frontend |
457 | npm test |
| Mobile | mobile-frontend |
349 | npm test |
Run each command from the directory shown. All five suites run in CI. See CI/CD Pipeline.
GitHub Actions (.github/workflows/cicd.yml) runs on pushes and pull requests to main and develop, and on manual dispatch. Every job after the first depends on Code Quality Checks, so the other eight run in parallel once formatting passes.
| # | Job | Depends on | What it does |
|---|---|---|---|
| 1 | Code Quality Checks | None | autoflake and black --check on Python, plus a repository-wide Prettier check (JS, TS, JSON, HTML, CSS, Markdown, Solidity, YAML) |
| 2 | Backend Test & Build | Code Quality Checks | Runs pytest with coverage, builds the backend image, checks it runs as non-root, smoke tests the pricing engine and model artifacts inside it, and uploads the image |
| 3 | AI Models Test & Validation | Code Quality Checks | Byte-compiles ai_models, verifies its public API and 22 modules import cleanly, and runs its tests with coverage |
| 4 | Web-Frontend Test & Build | Code Quality Checks | npm ci, the Jest suite, the production Webpack build, and a build upload |
| 5 | Mobile-Frontend Test & Build | Code Quality Checks | npm ci, the Jest suite with coverage, the Expo web export, and a bundle upload |
| 6 | Smart Contract Compile & Test | Code Quality Checks | Compiles the contracts with Hardhat, runs the contract tests, lints them with solhint, exports the ABIs, and uploads them |
| 7 | Docs Validation | Code Quality Checks | markdownlint, offline link and anchor checks, code-sample syntax checks, docs and scripts consistency checks, and an advisory external link check |
| 8 | Infrastructure Validation | Code Quality Checks | Terraform, the Helm chart for all three environments, and Ansible validation, plus yamllint, Compose and Dockerfile checks, two image builds, and a secret scan |
| 9 | Scripts Validation | Code Quality Checks | ShellCheck, syntax, shebang, and executable-bit checks on every shell script, plus a --help smoke test for the CLI scripts |
Coverage reports and build artifacts are kept for 7 to 30 days. The step-by-step breakdown of each job is in .github/readme/README.md.
| Document | Contents |
|---|---|
| docs/README.md | Documentation index |
| docs/architecture.md | System architecture |
| docs/API.md | REST API reference |
| docs/INSTALLATION.md | Setup for all components |
| docs/CONFIGURATION.md | Environment variables and config |
| docs/USAGE.md | Running and using the platform |
| docs/CLI.md | Helper scripts reference |
| docs/FEATURE_MATRIX.md | Feature status, implemented vs planned |
| docs/TROUBLESHOOTING.md | Common issues and fixes |
| docs/CONTRIBUTING.md | Contribution guide |
| docs/examples/example_pricing.md | Example: options pricing |
| docs/examples/example_monte_carlo.md | Example: Monte Carlo simulation |
| docs/examples/example_blockchain.md | Example: blockchain integration |
See docs/CONTRIBUTING.md.
This project is licensed under the MIT License. See the LICENSE file for details.
