[Exchange] Order book + LMSR market maker for artifact markets done

← Capital Markets
LMSR AMM providing continuous liquidity, market orders, limit orders, order matching

Git Commits (20)

[Exchange] Update spec work log — rebase and cleanup [task:exch-cm-04-BOOK]2026-04-26
[Exchange] Restore market bidding compatibility routes [task:exch-cm-04-BOOK]2026-04-26
[Exchange] Guard market-book depth payload shape [task:exch-cm-04-BOOK]2026-04-25
[Exchange] Add LMSR order book and artifact market APIs [task:exch-cm-04-BOOK]2026-04-25
Squash merge: orchestra/task/exch-cm--bidding-system-capital-backed-positions (11 commits)2026-04-25
Squash merge: orchestra/task/exch-cm--settlement-mechanics-resolve-positions-o (1 commits)2026-04-25
Squash merge: orchestra/task/exch-cm--settlement-mechanics-resolve-positions-o (2 commits)2026-04-25
Squash merge: orchestra/task/exch-cm--blockchain-bridge-prep-ledger-compatible (1 commits)2026-04-25
Squash merge: orchestra/task/exch-cm--blockchain-bridge-prep-ledger-compatible (1 commits)2026-04-25
[Exchange] Portfolio management — positions, P&L, exposure, Sharpe [task:exch-cm-05-PORT]2026-04-25
[Verify] Capital-weighted resource allocation — already resolved on main [task:exch-cm-07-RALL]2026-04-25
[Exchange] Capital-weighted resource allocation — spec update [task:exch-cm-07-RALL]2026-04-25
[Exchange] Capital-weighted resource allocation — compute budget from demand [task:exch-cm-07-RALL]2026-04-25
Squash merge: orchestra/task/exch-cm--token-earning-mechanics-mint-on-producti (1 commits)2026-04-25
[Exchange] Work log: fix token_ledger DB path, verify all acceptance criteria [task:exch-cm-01-LEDG]2026-04-16
[Exchange] Fix token_ledger DB path to resolve via SCIDEX_DB env var; falls back to ~/scidex/scidex.db so it works from both main and worktree contexts [task:exch-cm-01-LEDG]2026-04-16
[Exchange] Token ledger with double-entry accounting [task:360e2578-061f-4dd2-962f-524c546d2804]2026-04-06
[Senate] Holistic prioritization run 2: quest fixes + 3 new CI tasks [task:b4c60959-0fe9-4cba-8893-c88013e85104]2026-04-06
[Senate] Holistic prioritization: 6 tasks created for uncovered P88-P95 quests [task:b4c60959-0fe9-4cba-8893-c88013e85104]2026-04-06
[Exchange] Implement capital-weighted resource allocation [task:exch-cm-07-RALL]2026-04-03
Spec File

Goal

Implement an order book with LMSR automated market maker (AMM) providing continuous
liquidity. Agents can place market orders (execute immediately at AMM price) or limit
orders (execute when price reaches target). The AMM ensures there's always a price and
always liquidity — no empty order books.

Design

LMSR Automated Market Maker

The AMM is the counterparty of last resort. It always offers to buy or sell at a computed
price, ensuring continuous liquidity:

# LMSR cost function
def lmsr_cost(q_yes, q_no, b):
    """Cost to move from current state to new state"""
    return b * math.log(math.exp(q_yes/b) + math.exp(q_no/b))

def lmsr_price(q_yes, q_no, b):
    """Current implied probability (price) of 'yes' outcome"""
    return math.exp(q_yes/b) / (math.exp(q_yes/b) + math.exp(q_no/b))

Parameters:

  • b (liquidity parameter): Controls price sensitivity. Higher b = more liquidity, less price impact per trade. Start at b=100 tokens.
  • q_yes / q_no: Accumulated shares on each side.

Order Types

  • Market order: Execute immediately at AMM price
  • Limit order: Execute when market price reaches target
  • Bounty order: Non-refundable commitment to a gap/artifact
  • Acceptance Criteria

    market_maker.py module with LMSR implementation
    lmsr_cost(shares, side, artifact_id) — cost to buy shares on side
    lmsr_price(artifact_id) — current AMM-implied price
    execute_market_order(agent_id, artifact_id, side, tokens) — buy at AMM price
    place_limit_order(agent_id, artifact_id, side, tokens, target_price) — conditional
    cancel_limit_order(order_id) — return locked tokens
    ☐ Limit order matching engine: check pending orders on every price update
    ☐ AMM liquidity parameter b adjustable per artifact type (more liquid for hypotheses)
    ☐ Order book visualization on artifact detail pages (depth chart)
    ☐ API: POST /api/market/order — place market or limit order
    ☐ API: GET /api/market/book/{artifact_id} — current order book + AMM state

    Dependencies

    • exch-cm-03-BID — Bidding system provides the position framework

    Dependents

    • exch-cm-05-PORT — Portfolio needs order execution data

    Work Log

    Sibling Tasks in Quest (Capital Markets) ↗