Guru Meditation/work/Piggy Broker
Broker infrastructure · flagship

Piggy Broker

A whitelabel trading venue in a box — aggregate liquidity, route flow A-book or B-book through an internal matching engine, run a full dealing desk with live exposure, hedging and margin, all under your brand.

live · piggytrader.cc/brokerFIX 4.4 + RESTMulti-tenant · RLS700+ tests

01Overview

Piggy Broker is a multi-tenant trading venue in a box. It aggregates liquidity over FIX 4.4 and REST, routes flow A-book or B-book through an internal matching engine, runs a full dealing desk with live exposure, hedging and margin — and puts web, desktop and mobile terminals in traders' hands. All under the operator's brand, on their domain.

visit piggytrader.cc/broker

02The problem it solves

Standing up a real brokerage means building — or buying and integrating — liquidity aggregation, an execution layer, a risk and dealing desk, a margin engine, multi-tenant isolation, surveillance, reporting and client terminals. Most of that is unglamorous machinery a venue needs but no one wants to write. Piggy Broker ships it as one coherent backend so an operator can launch under their own brand rather than assembling a stack.

Result an operator launches a branded brokerage on infrastructure that normally takes a team years to build.

03What we built

Liquidity & execution

A purpose-built FIX 4.4 engine handles logon and heartbeat negotiation, sequence tracking, resend handling and auto-reconnect, speaking NewOrderSingle, ExecutionReport, cancels and market data. Alongside it: REST/WebSocket connectors (Binance, Alpaca, OANDA, a generic adapter and ccxt) plus MT4 / MT5 manager bridges. Piggy builds a consolidated best-bid/offer across every provider, attributes each side to its source, evicts stale feeds, and ranks A-book orders by price, then size, reject-rate and priority — splitting a clip across legs when one venue can't fill it all.

Routing & the internal book

Per account group, flow is handled A-book (passed through, hedged to the best LP via best-execution), B-book (internalised against the broker's own book, risk surfaced live), or MIXED (a configurable percentage to each). An internal matching engine maintains a full price-time-priority order book at L1 and L2, so clients of the same broker can cross each other. Piggy records exactly why it made each routing decision.

Risk & the dealing desk

Net exposure, margin and hedging in one view: per-symbol net quantity and weighted-average price kept hot in Redis and broadcast as fills land; automatic hedging past a lot threshold or queued for dealer approval; a margin engine with real-time equity, margin level, margin calls, configurable stop-out and ESMA-style negative-balance protection; largest-loser-first stop-out liquidation; Black-Scholes delta margining for options; and LP health monitoring on the console.

Pricing & revenue

Pricing is set per account group — markup in basis points per side, commission per lot, and long/short swaps with the Wednesday triple handled automatically. Every fill, swap and commission flows into treasury and the general ledger, with multi-currency P&L and margin converted to the base currency off the live book.

04Compliance & back office

The parts regulators ask about are in the box, not on a roadmap: true PostgreSQL row-level security across 61 tables (every query scoped to one org, enforced by the database), trade surveillance and AML detectors, KYC and sanctions screening, outbound FIX drop-copy and transaction reporting, per-org LP credentials sealed with AES-256-GCM envelope encryption (one tenant's keys can never decrypt another's), white-label branding with custom domains per tenant, and CRM sync with HubSpot, Zoho or Salesforce.

05Tech

FastAPI SQLAlchemy 2.0 async asyncpg PostgreSQL · RLS Redis native WebSockets Alembic mypy strict Prometheus FIX 4.4
Test suite700+ automated tests
API surface175 endpoints
Isolation61 row-isolated tables (RLS)
Migrations53 database migrations
StatusLive · piggytrader.cc/broker

06Highlights

  • FIX 4.4 liquidity aggregation across multiple LPs with a consolidated, source-attributed best-bid/offer.
  • Best-execution routing that ranks venues and splits a clip across legs when needed.
  • A-book / B-book / MIXED routing decided per account group, with the reason recorded on every order.
  • Internal price-time matching engine (L1 & L2) so a broker's clients can cross each other.
  • Dealing desk with live net-exposure, auto and manual hedging, and largest-loser-first stop-out.
  • Margin engine with stop-out and ESMA-style negative-balance protection; Black-Scholes delta margining for options.
  • Multi-tenant PostgreSQL RLS across 61 tables; encrypted per-org LP credentials.
  • Built to institutional standard: 700+ tests, 175 API endpoints, async Python on FastAPI.

Related work