Skip to content

About

Resources

Stars

1 star

Watchers

0 watching

Forks

Repository files navigation

title Tradeverse AI
emoji 📈
colorFrom blue
colorTo green
sdk docker
app_port 7860

Tradeverse AI

Tradeverse AI is a full-stack simulated trading platform. It lets users manage a virtual wallet, buy and sell equities in a paper portfolio, view live market prices, and run an experimental decision engine that combines news sentiment, vector search, and technical indicators.

The project is intended as a trading education and engineering showcase. It does not execute real trades and does not predict the future.

Architecture

The application is split into three services:

  1. Frontend: React, Vite, Tailwind CSS v4, React Router, Axios, and Lucide React.
  2. Backend: Node.js, Express, MongoDB, Mongoose, JWT cookies, Redis price caching, and Finnhub API integrations.
  3. AI Engine: Python, FastAPI, Pinecone, Sentence Transformers, FinBERT, Finnhub news, Yahoo Finance (yfinance) for technical indicators, volatility filters, and market-regime heuristics.
graph TD
    Client[React Frontend] --> Backend[Express Backend]
    Backend --> AI[FastAPI AI Engine]
    Backend --> MongoDB[(MongoDB)]
    Backend --> Redis[(Redis Cache)]
    Backend --> Finnhub[Finnhub API]
    AI --> Pinecone[(Pinecone)]
    AI --> Finnhub
    AI --> Yahoo[Yahoo Finance]
Loading

Key Features

  • HttpOnly-cookie authentication with access and refresh tokens
  • Virtual wallet and paper-trading portfolio
  • Buy and sell order execution with MongoDB transactions
  • Weighted average price calculation for repeated buys
  • Trade history and portfolio endpoints
  • Redis-backed live price caching
  • Five-page trading dashboard: overview, markets, portfolio, AI engine, and auto-pilot
  • Light and dark themes with a runtime token system and no flash on load
  • TradingView chart, holdings table, allocation donut, and a live execution log
  • AI signal endpoint combining sentiment and technical indicators
  • Auto-pilot bot with risk-based position sizing, stop-loss, and take-profit guardrails
  • Backend controller tests for core trade behavior

Repository Layout

Tradeverse-Frontend/   React dashboard
  src/components/      Layout (TopNav, TickerTape), charts, and UI primitives
  src/context/         Auth and theme providers
  src/hooks/           Data layer: wallet, live prices, AI execution, bot
  src/pages/dashboard/ The five dashboard pages
Tradeverse-Backend/    Express API and MongoDB models
Tradeverse-AI/         FastAPI decision engine and market-news scripts
Tradeverse-AI/notebooks/  Standalone Colab notebooks for model experiments
docker-compose.yml     Redis-only local helper

Frontend Design System

The interface is a warm-paper trading desk in light mode with a fully derived dark mode, typeset in DM Sans and JetBrains Mono.

Theming is a three-layer token system rather than scattered hex values:

  • Semantic tokens (--tv-page, --tv-card, --tv-ink, --tv-accent, ...) are declared in src/index.css on :root, on :root[data-theme="dark"], and under prefers-color-scheme: dark.
  • Tailwind v4 @theme inline maps those tokens onto utilities such as bg-card, text-ink, and border-line. The inline keyword matters: without it, Tailwind bakes literal colour values into the utilities and runtime theme switching breaks.
  • Components reference utilities only, never raw tokens, so flipping the theme repaints the whole app without a React re-render.

Dark mode is a re-derivation, not an inversion: surfaces step up in lightness for elevation, the accent desaturates, and shadows give way to borders.

Two implementation notes worth knowing before editing the UI:

  • SVG colours must be applied through a style prop. Presentation attributes such as stroke="var(--tv-up)" do not resolve CSS variables, so every themed chart sets style={{ stroke: ... }} instead.
  • The stored theme is applied by a small inline script in index.html before first paint, so a dark preference never flashes light on load.

Environment Variables

Create .env files from the provided examples:

  • Tradeverse-Frontend/.env.example
  • Tradeverse-Backend/.env.example
  • Tradeverse-AI/.env.example

Key variables include:

  • Frontend:
    • VITE_API_URL (Backend API URL, all AI traffic is proxied here)
  • Backend:
    • MONGODB_URI (MongoDB connection string)
    • ACCESS_TOKEN_SECRET / REFRESH_TOKEN_SECRET (JWT authentication secrets)
    • REDIS_URL (Redis cache URL for live price caching)
    • FINNHUB_API_KEY (Finnhub API key for live price quotes)
    • AI_SERVICE_URL / AI_SERVICE_SECRET (AI Engine endpoint and shared secret)
    • Cloudinary avatar-upload keys (CLOUDINARY_CLOUD_NAME, CLOUDINARY_API_KEY, CLOUDINARY_API_SECRET)
  • AI Engine:
    • PINECONE_API_KEY (Pinecone API key for news vector search)
    • FINNHUB_API_KEY (Finnhub API key for fetching real-time market news)
    • API_SECRET (Shared secret, must match backend's AI_SERVICE_SECRET)

Local Setup

Install dependencies in each service:

cd Tradeverse-Backend
npm install

cd ../Tradeverse-Frontend
npm install

cd ../Tradeverse-AI
pip install -r requirements.txt

Start Redis if you want price caching:

docker-compose up -d

This compose file intentionally starts Redis only. Full multi-service Docker orchestration is not included because the project is currently optimized for local development on limited disk space.

Run the services:

cd Tradeverse-Backend
npm run dev
cd Tradeverse-Frontend
npm run dev
cd Tradeverse-AI
uvicorn main:app --host 0.0.0.0 --port 8001

API Overview

Auth and User

  • POST /api/v1/users/register
  • POST /api/v1/users/login
  • POST /api/v1/users/logout
  • POST /api/v1/users/refresh-token
  • POST /api/v1/users/wallet/add
  • POST /api/v1/users/wallet/withdraw
  • GET /api/v1/users/balance

Trading

  • GET /api/v1/trades/price/:symbol
  • POST /api/v1/trades/buy
  • POST /api/v1/trades/sell
  • GET /api/v1/trades/portfolio
  • GET /api/v1/trades/history

AI (Proxied through Backend)

  • POST /api/v1/ai/ask (Query news memory via Pinecone)
  • POST /api/v1/ai/predict (Get ensemble trading recommendation)
  • GET /api/v1/ai/health (Upstream connection health and warmup status)

FastAPI AI Service (Internal API)

  • POST /api/predict (Ensemble strategy prediction)
  • POST /search (Embeds and queries news memory)
  • GET / (Liveliness check)
  • GET /warmup (Trigger embedding models lazy load)

AI Strategy

The AI engine is a heuristic decision system, not a guaranteed market predictor. It combines:

  • FinBERT sentiment from recent market headlines
  • Pinecone vector search for relevant news memory
  • RSI and moving-average signals
  • Volatility guardrails
  • Market-regime weighting
  • A bounded Kelly-style risk allocation value

The output should be treated as a paper-trading signal for experimentation.

Auto-pilot Position Sizing

When the bot acts on a BUY signal, the position is sized by the engine's risk_pct applied to cash buying power, then trimmed by the "Max capital / trade" setting:

riskDollars   = buyingPower × risk_pct / 100
cappedDollars = min(riskDollars, maxCapital)
quantity      = floor(cappedDollars / livePrice)

maxCapital is therefore a ceiling, not a budget — raising it can only ever trim a position, never enlarge one. Because whole shares are the smallest unit, a small balance combined with a conservative risk_pct can size to zero shares on a high-priced symbol. When that happens the bot buys a single share, provided that share fits inside both the per-trade cap and available buying power, and logs that it did so. Without that fallback the bot skipped such symbols on every cycle indefinitely.

Known limitation: sizing uses cash only and ignores the market value of open holdings, so an account holding positions is sized more conservatively than a pure-equity risk model would suggest.

Backtesting

The repository includes Tradeverse-AI/colab_backtester.py as a backtesting experiment, plus Tradeverse-AI/notebooks/sentiment_backtest_colab.ipynb, a standalone Colab notebook that exercises the FinBERT sentiment model in isolation against historical prices with no backend running. Use them to reproduce and update performance claims before adding any specific return or drawdown numbers to a resume.

Current limitation: the backtest is educational and should be reviewed for assumptions such as transaction costs, slippage, lookahead bias, and survivorship bias before presenting results as rigorous.

Tests

Backend:

cd Tradeverse-Backend
npm test

Frontend (Vitest configured; currently contains no test files):

cd Tradeverse-Frontend
npm run lint
npm test          # Runs vitest; exits with 1 if no tests are found
npm run build     # Verify the production bundle compiles

AI Engine:

cd Tradeverse-AI
# Run tests inside virtual environment
pytest tests/ -v

Known Limitations

  • Full Docker orchestration is intentionally omitted to save local disk space.
  • The AI service depends on external APIs and model downloads.
  • MongoDB transactions require a deployment that supports transactions.
  • The app is a simulator and is not connected to a real broker.
  • Demo data is not seeded automatically yet.

Future Improvements

  • Add a seed script for demo users and sample portfolios
  • Add integration tests around auth and wallet flows
  • Add full Docker Compose or a cloud deployment recipe
  • Add broker-sandbox integration, such as Alpaca paper trading
  • Improve backtesting rigor and publish reproducible results

About

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages