Skip to content

LinkTechLabs/Prediction-Market-Analyzer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Prediction Market Analyzer

A full-stack application that aggregates and analyzes prediction market data from platforms like Polymarket. Built with a modern tech stack featuring a FastAPI backend, Next.js frontend, and PostgreSQL (Supabase) for data persistence.

Python FastAPI Next.js TypeScript TailwindCSS PostgreSQL

Overview

Prediction markets are platforms where users trade on the outcomes of future events, with prices reflecting the crowd's probability estimates. This project provides:

  • Real-time data aggregation from the Polymarket API
  • Normalized market data with standardized pricing across different outcome types
  • RESTful API for querying and filtering markets
  • Modern dashboard UI displaying market probabilities and metadata
  • Persistent storage with PostgreSQL via Supabase

Tech Stack

Backend

  • FastAPI — High-performance async Python web framework
  • asyncpg — Async PostgreSQL driver for connection pooling
  • httpx — Async HTTP client for API requests
  • Pydantic — Data validation and serialization
  • Supabase (PostgreSQL) — Cloud-hosted database

Frontend

  • Next.js 16 — React framework with App Router
  • React 19 — UI library
  • TypeScript — Type-safe JavaScript
  • Tailwind CSS 4 — Utility-first styling

Infrastructure

  • Terraform — Infrastructure as Code (AWS provider configured)

Project Structure

prediction-market-analyzer/
├── backend/
│   ├── app/
│   │   ├── main.py              # FastAPI application entry point
│   │   ├── routers/
│   │   │   └── markets.py       # Market API endpoints
│   │   ├── schemas/
│   │   │   └── market.py        # Pydantic models
│   │   └── services/
│   │       ├── db_service.py    # Database connection pool & queries
│   │       └── polymarket_service.py  # Polymarket API integration
│   └── scripts/
│       └── sync_polymarket.py   # Data sync script
├── frontend/
│   └── app/
│       ├── page.tsx             # Main dashboard page
│       ├── layout.tsx           # Root layout
│       └── globals.css          # Global styles
├── infra/
│   └── aws/
│       └── main.tf              # Terraform AWS configuration
└── docs/

Features

Implemented ✅

  • Polymarket API integration with async data fetching
  • Normalized market data extraction (handles Yes/Up/Win/Pass outcomes)
  • PostgreSQL database with connection pooling
  • RESTful API endpoints (GET /markets, GET /markets/{id})
  • CORS configuration for local development
  • Health check endpoint
  • Next.js dashboard with market listing
  • Responsive UI with Tailwind CSS
  • Data sync script for batch market ingestion

Roadmap 🚧

  • Price history tracking and trend analysis
  • AI-powered market summaries
  • Kalshi integration (multi-provider support)
  • Market filtering and search
  • Individual market detail pages
  • Real-time WebSocket updates
  • AWS deployment via Terraform

Getting Started

Prerequisites

  • Python 3.11+
  • Node.js 18+
  • PostgreSQL database (or Supabase account)

Backend Setup

  1. Navigate to the backend directory:

    cd backend
  2. Create and activate a virtual environment:

    python -m venv .venv
    source .venv/bin/activate  # On Windows: .venv\Scripts\activate
  3. Install dependencies:

    pip install fastapi uvicorn asyncpg httpx python-dotenv pydantic
  4. Configure environment variables: Create a .env file in the project root:

    SUPABASE_DSN=postgresql://user:password@host:port/database
  5. Run the sync script to populate data:

    python -m scripts.sync_polymarket
  6. Start the API server:

    uvicorn app.main:app --reload

    The API will be available at http://localhost:8000

Frontend Setup

  1. Navigate to the frontend directory:

    cd frontend
  2. Install dependencies:

    npm install
  3. Start the development server:

    npm run dev

    The dashboard will be available at http://localhost:3000

API Reference

Endpoints

Method Endpoint Description
GET /health Health check
GET /markets List all markets
GET /markets/{market_id} Get market details with price history

Example Response

{
  "id": "poly-12345",
  "provider": "polymarket",
  "title": "Will Bitcoin reach $100k by end of 2025?",
  "url": "https://polymarket.com/market/btc-100k",
  "current_price": 0.63,
  "last_updated": "2025-11-29T09:00:00Z"
}

Database Schema

CREATE TABLE prediction_markets (
  id TEXT PRIMARY KEY,
  provider TEXT NOT NULL,
  title TEXT NOT NULL,
  current_price DECIMAL,
  last_updated TIMESTAMP WITH TIME ZONE
);

Architecture

┌─────────────┐     ┌─────────────┐     ┌─────────────┐
│   Next.js   │────▶│   FastAPI   │────▶│  Supabase   │
│  Frontend   │     │   Backend   │     │ PostgreSQL  │
└─────────────┘     └─────────────┘     └─────────────┘
                           │
                           ▼
                    ┌─────────────┐
                    │ Polymarket  │
                    │    API      │
                    └─────────────┘

License

MIT


Built as a portfolio project demonstrating full-stack development with modern async Python, React, and cloud database integration.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published