AgentSkillsCN

mm

做市交易——双向报价与库存管理相结合

SKILL.md
--- frontmatter
name: mm
description: "Market making - two-sided quoting with inventory management"
emoji: "📊"
gates:
  envs:
    anyOf:
      - POLY_API_KEY
      - KALSHI_API_KEY

Market Making Skill

Automated two-sided quoting on prediction markets with inventory skew, volatility-adjusted spreads, and risk controls.

Supported Platforms

  • Polymarket (post-only maker orders, zero taker fees)
  • Kalshi

Chat Commands

Lifecycle

code
/mm start <platform> <marketId> <tokenId> [flags]   Start market making
/mm stop <id>                                        Stop and cancel all orders
/mm list                                             List active market makers

Monitoring

code
/mm status                     Overview of all active MMs
/mm status <id>                Detailed state for one MM

Configuration

code
/mm config <id>                View current config as JSON
/mm config <id> --spread 3     Update config (takes effect next requote)

Start Flags

FlagDefaultDescription
--spread N2Base half-spread in cents
--min-spread N1Minimum spread floor (cents)
--max-spread N10Maximum spread cap (cents)
--size N50Order size per side (shares)
--max-inventory N500Max inventory before aggressive skew
--skew N0.5Inventory skew factor (0-1)
--vol-mult N10Volatility multiplier for spread widening
--alpha N0.3EMA alpha for fair value smoothing (0-1)
--fv-method Mweighted_midFair value method: mid_price, weighted_mid, vwap, ema
--interval N5000Requote interval in ms
--threshold N1Min price change (cents) to trigger requote
--max-pos N1000Max position value in USD
--max-loss N100Max loss before auto-halt (USD)
--max-orders N1Orders per side (levels)
--level-spacing N(=spread)Cents between price levels
--level-decay N0.5Size decay per level (0-1, e.g. 0.5 = each level half of previous)
--neg-risk truefalseEnable negative risk mode (Polymarket crypto)
--name "Name"autoDisplay name for the outcome

Examples

code
# Start with defaults
/mm start polymarket 0xabc123 98765

# Custom spread and sizing
/mm start polymarket 0xabc123 98765 --spread 3 --size 100 --max-inventory 1000

# Tight spread for liquid market
/mm start polymarket 0xabc123 98765 --spread 1 --min-spread 1 --max-spread 5 --interval 2000

# 3-level quoting: L1=50 shares, L2=25, L3=12 — spaced 2c apart
/mm start polymarket 0xabc123 98765 --max-orders 3 --level-spacing 2 --level-decay 0.5 --size 50

# Check all running MMs
/mm status

# Widen spread on the fly
/mm config polymarket_98765678 --spread 4

# Shut down
/mm stop polymarket_98765678

How It Works

  1. Fair value computed from orderbook (weighted mid, VWAP, or EMA)
  2. Spread adjusted by recent volatility (wider in volatile markets)
  3. Skew shifts quotes away from overweight side to manage inventory
  4. Quotes placed as post-only maker orders (bid and ask)
  5. Requote cycle: cancel all, recalculate, place new orders
  6. Auto-halt if realized P&L exceeds max loss threshold

API Usage

typescript
import { createMMStrategy, type MMConfig } from '../trading/market-making';

const config: MMConfig = {
  id: 'btc-yes',
  platform: 'polymarket',
  marketId: '0x...',
  tokenId: '12345',
  outcomeName: 'BTC > 100k',
  baseSpreadCents: 2,
  minSpreadCents: 1,
  maxSpreadCents: 10,
  orderSize: 50,
  maxInventory: 500,
  skewFactor: 0.5,
  volatilityMultiplier: 10,
  fairValueAlpha: 0.3,
  fairValueMethod: 'weighted_mid',
  requoteIntervalMs: 5000,
  requoteThresholdCents: 1,
  maxPositionValueUsd: 1000,
  maxLossUsd: 100,
  maxOrdersPerSide: 1,
};

const strategy = createMMStrategy(config, { execution, feeds });
botManager.registerStrategy(strategy);
await botManager.startBot(strategy.config.id);