Onyx Predictions Market — Developer Hub

Sports prediction exchange for NBA, MLB, NFL & NHL binary contracts. This is the API server running on port 3000.

💰 How Pricing Works

Binary Contracts

Every prediction market has two contracts: YES and NO. Each contract trades between $0.01 and $0.99, representing the probability of the outcome.

Example: "Will Houston win?"
YES contract$0.65
NO contract$0.35

Payouts

If your contract wins, it pays out $1.00. If it loses, it pays $0.00.

Buy YES at $0.65
✅ Houston wins+$0.35 profit
❌ Houston loses-$0.65 loss

Order Book

Prices are set by limit orders from traders. The best bid/ask form the spread. Orders match using FIFO price-time priority.

Order Book Snapshot
Best Bid$0.63 × 25
Best Ask$0.67 × 15
Spread$0.04

Settlement

Markets settle automatically when the game ends. YES = $1.00 if the outcome occurred, NO = $1.00 otherwise. Voided markets refund at original cost.

Data Source

Live prices stream from the NJT Market Data WebSocket (staging) via the Bridge process. The bridge subscribes to all NBA, MLB, NFL, and NHL products and publishes quote updates to Redis in real-time. The API WS server at /ws (port 3000) forwards these to connected browser clients.

📚 Documentation

⚡ Quick Start

# Check API health
curl http://localhost:3000/api/health

# List markets
curl http://localhost:3000/api/markets?sport=NBA&limit=5

# Register a user
curl -X POST http://localhost:3000/api/auth/register \
  -H 'Content-Type: application/json' \
  -d '{"email":"test@example.com","username":"testuser","password":"password123"}'

# Place an order (with auth token)
curl -X POST http://localhost:3000/api/orders \
  -H 'Authorization: Bearer <token>' \
  -H 'Content-Type: application/json' \
  -d '{"contract_id":"uuid","side":"buy","order_type":"limit","price":0.50,"qty":5}'

🏗️ Architecture

API Server
Express REST API • Port 3000
TypeScript, Knex, PostgreSQL, Redis
Bridge
NJT MD WebSocket → Redis → WS server
QuoteBridge (NJT MD WS), OrderRouter, ExecutionSync
Portal
Next.js 14 • Port 3001
React, TailwindCSS, SWR, WebSocket
Database
PostgreSQL 16 • Port 5434
12 tables, idempotent inline schema, Knex query builder