PT

Nº 02of 12Featured

Atlas — prediction market

A closed prediction market for Atlas Inc.: an order book of YES/NO contracts priced from 1 to 99 cents, the server as the only authority over balances, and an accounting invariant proven by a concurrency test

Year
2026
Status
IN PROGRESS
Role
Sign-in, Admin and the front-end redesign · team of 5
Stack
Python · FastAPI · PostgreSQL · Next.js +7
atlas
Atlas — prediction market — Markets — the YES chance over time and the last minute's trade pulse, with the bots trading
5 screens

1 of 5

Atlas — prediction market — Markets — the YES chance over time and the last minute's trade pulse, with the bots trading

Markets — the YES chance over time and the last minute's trade pulse, with the bots trading

01The project

Insper Code Jr.'s “Projeto Oakwood” case in 2026.2, with Atlas Inc. as the client: a closed prediction market platform, on simulated currency only, where invited participants trade binary contracts — a share of the winning outcome pays one unit, and its price, from 1 to 99 cents, works as the probability the group assigns to the event. There are five screens: Sign-in, Markets, Market (order book, order ticket, chart and trade tape), Wallet and Admin. The hard part is not the screens, it is the accounting: free balances plus locked collateral must equal the total ever credited at every instant, with several people trading at once, and a concurrency test proves it. It is a team of five, and I am the largest contributor to the repository — 93 of the 240 commits on main and 15 merged PRs. The matching engine, the ledger, settlement, infrastructure and coordination belong to my teammates; what is mine is in the highlights.

02What was built

  1. GET /ledger/events, mine: the ledger read as a feed, with each event's sum and the platform totals (free, reserved, collateral and credited) computed server-side in the same REPEATABLE READ snapshot, and the counterparty's identity redacted before it leaves the server

  2. The Sign-in and Admin screens end to end: access only through a single-use invite (a 256-bit token stored as a sha256), Argon2id passwords, expiring sessions, participant, admin and auditor roles, and a filterable audit log

  3. The whole front end redesigned with light and dark themes driven by CSS tokens and AA contrast in both, plus a new Wallet with net worth over time — one PR of +13,321/−4,434 lines across 80 files

  4. Five demo bots (market maker, trend, contrarian, noise and whale) trading through the API only, in an optional Docker Compose profile: the order book, the chart and the Admin monitor move with nobody at the keyboard

  5. A read-only resolution preview for the admin — with a test that actually resolves the market and checks that settlement did what the preview said —, append-only market news, and GET /me/trades to rebuild net worth

  6. From the team: price-time matching, an append-only ledger, settlement, and the invariant proven by two concurrency tests that run 20 times in a row on every merge to main; over 900 backend tests

03Decisions

Decision 01

Question: Why a single-use invite instead of an allowlist of emails?

Answer: The platform is closed, and an invite gives control per person: each one is created, revoked and accepted individually, already carrying its role, and creating, revoking and accepting all become audit events — there is a trail of who invited whom. The token has 256 bits and the database keeps only its sha256; accepting locks the invite row so two simultaneous accepts cannot create two accounts.

Decision 02

Question: Why is the ledger feed a cursor-based poll and not a WebSocket?

Answer: WebSocket or SSE would need one long-lived connection per person and a way to signal across API instances, which the project does not have; for a few dozen people, calling again with a cursor on the event id is enough. What matters is something else: each event's sum and the totals come out of the server in the same REPEATABLE READ snapshot, so free + reserved + collateral = credited holds in every response, even with trades landing in between.

Decision 03

Question: Why doesn't the resolution preview block the confirm button?

Answer: Because an attempt blocked on screen would never reach the API and would drop out of the audit log. The preview only reads — it locks nothing and writes no audit entry — and it also shows the requester's own position; the conflict-of-interest refusal stays in the resolution, which locks the market, records the attempt and explains why. Someone can trade between the preview and the confirmation, so the resolution is what decides.

04Screens

  • mercado-livro.webp

    Market in the dark theme — the order book with depth and the live trade tape

  • carteira.webp

    Wallet — net worth over time and the balance split into available, reserved and in positions

  • administracao.webp

    Admin — the invariant checked live and the ledger read as a feed, with each event's sum

  • entrar.webp

    Sign-in in the dark theme — invite-only access, no public sign-up

1 of 5

Atlas — prediction market — Markets — the YES chance over time and the last minute's trade pulse, with the bots trading

Markets — the YES chance over time and the last minute's trade pulse, with the bots trading

05Stack

  • Python
  • FastAPI
  • PostgreSQL
  • Next.js
  • TypeScript
  • Docker Compose
  • pytest
  • Playwright
  • GitHub Actions
  • Render
  • Supabase
Next project →Nº 03

Transactional e-commerce in Spring Boot: outbox with exponential retry, webhook idempotency, and rate limiting in Redis behind a circuit breaker