A market maker profits by quoting both sides of the orderbook and capturing the spread. This recipe shows how to build a basic bot using the Provider API’s REST and WebSocket endpoints.
Market making involves significant risk. This is educational code, not production-ready. Always start on testnet and use proper risk management.
Price Monitor — Connects via WebSocket to stream real-time mid prices and detect drift from your quoted spread.Order Manager — Uses REST to place bid/ask quotes and cancel stale orders when price moves.
const CONFIG = { provider: "hyperliquid", symbol: "ETH", // Spread: 5 bps on each side of mid spreadBps: 5, // Order size orderSize: "0.5", // Refresh interval (ms) refreshInterval: 5000, // Max position size before hedging maxPosition: "5.0",};
Track your inventory (net position) and skew quotes accordingly. If you accumulate a long position, lower the bid and raise the ask to encourage sells.
Volatility-Adjusted Spread
Widen your spread during high volatility (detect via funding rate or price velocity). Tighten during calm periods.
Multi-Level Quoting
Instead of a single bid/ask, place multiple orders at different price levels to provide deeper liquidity.
Cross-Provider Hedging
If you get filled on one provider, hedge the position on another provider to remain delta-neutral. See the Cross-Provider Arb recipe.