Skip to main content

Market Making Guide

This guide explains how to use the mm-sample script from the Clober v2 SDK to run a basic market making bot.

Overview

The mm-sample is a simple market making script built using the Clober v2 SDK. It places and manages bid/ask quotes for a selected token pair on the Clober orderbook DEX.

This example:

  • Fetches the latest price every 5 seconds from the Binance market specified by BINANCE_MARKET_ID
  • Uses that price to compute bid and ask quotes based on your configured spread and size (from ASK and BID)
  • Submits those quotes to Clober as limit orders using the SDK

This sample is ideal for developers who want to:

  • Learn how to use the Clober SDK for market making
  • Understand how to place, claim, and cancel limit orders in one transaction
  • Use off-chain market data (like Binance) to power on-chain quoting strategies

Prerequisites

  • Node.js v18+
  • bun installed globally
  • Access to a private key and RPC endpoint (e.g. Monad Testnet)

Getting Started

1. Clone the repository

git clone https://github.com/clober-dex/v2-sdk.git
cd v2-sdk/examples/mm-sample

2. Install dependencies

bun install

3. Configure environment variables

Create a .env file based on the .env.example:

PRIVATE_KEY=your_private_key
RPC_URL=https://your-monad-rpc
CHAIN_ID=10143
TOKEN0=0xB5a30b0FDc5EA94A52fDc42e3E9760Cb8449Fb37
TOKEN1=0xf817257fed379853cDe0fa4F97AB987181B1E5Ea
BINANCE_MARKET_ID=ETHUSDT
ASK=[[1.001,2],[1.002,3],[1.003,4]]
BID=[[0.999,2000],[0.998,3000],[0.997,4000]]

⚠️ Never share your private key or commit it to source control.

ASK and BID define your quoting strategy:

  • The first number in each entry is the relative price multiplier (e.g. 1.001 means 0.1% above the Binance price)
  • The second number is the base token amount (e.g. 2 WETH)

For example, if the Binance price is $2000:

ASK => [2002, 2], [2004, 3], [2006, 4]
BID => [1998, 2000], [1996, 3000], [1994, 4000]

4. Run the market maker

bun run index.ts

This script will:

  • Poll Binance every 5 seconds or POLL_INTERVAL seconds
  • Calculate on-chain quote prices based on your spread config
  • Cancel outdated orders
  • Place new bid and ask orders to Clober

For more details, check out the Clober SDK documentation or join our community for support.