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.
# 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.market_maker.py module with LMSR implementationlmsr_cost(shares, side, artifact_id) — cost to buy shares on sidelmsr_price(artifact_id) — current AMM-implied priceexecute_market_order(agent_id, artifact_id, side, tokens) — buy at AMM priceplace_limit_order(agent_id, artifact_id, side, tokens, target_price) — conditionalcancel_limit_order(order_id) — return locked tokensb adjustable per artifact type (more liquid for hypotheses)POST /api/market/order — place market or limit orderGET /api/market/book/{artifact_id} — current order book + AMM stateexch-cm-03-BID — Bidding system provides the position frameworkexch-cm-05-PORT — Portfolio needs order execution data