Skip to content

quantitative-technologies/zo-market-maker-ts

Β 
Β 

Repository files navigation

01 Market Maker

A simple market maker bot for 01 Exchange. Be the liquidity you wish to see in the market.

Thanks to @c1ted.

Market Maker

Requirements

  • Node.js v25+ - Required for Uint8Array.prototype.toHex() (TC39 proposal) used by the SDK

Disclaimer

Use at your own risk. The author is not responsible for any losses incurred when using this code.

This code is intended for educational purposes ONLY - do not use this code for real trades unless you fully understand what it does.

This is not a sophisticated market making program. It is intended to demonstrate how to connect to 01 Exchange using the SDK. Test with a fresh account.

Note: Only tested with BTC and ETH markets.

Quick Start

# Install
npm i

# Setup
cp .env.example .env
# Edit .env and set PRIVATE_KEY

# Run BTC bot
npm run bot -- btc

# Run ETH bot
npm run bot -- eth

# Market monitor
npm run monitor -- btc

Project Structure

src/
β”œβ”€β”€ bots/mm/           # Market Maker bot
β”‚   β”œβ”€β”€ index.ts       # MarketMaker class
β”‚   β”œβ”€β”€ config.ts      # Configuration
β”‚   β”œβ”€β”€ position.ts    # Position tracking
β”‚   └── quoter.ts      # Quote generation
β”œβ”€β”€ cli/               # Entry points
β”‚   β”œβ”€β”€ bot.ts         # Bot CLI
β”‚   └── monitor.ts     # Market monitor TUI
β”œβ”€β”€ pricing/           # Price feeds (shared)
β”‚   β”œβ”€β”€ binance.ts     # Binance WebSocket
β”‚   └── fair-price.ts  # Fair price calculation
β”œβ”€β”€ sdk/               # 01 Exchange SDK (shared)
β”‚   β”œβ”€β”€ account.ts     # Account stream
β”‚   β”œβ”€β”€ client.ts      # SDK client wrapper
β”‚   β”œβ”€β”€ orderbook.ts   # Orderbook stream
β”‚   └── orders.ts      # Order operations
β”œβ”€β”€ utils/             # Utilities (shared)
β”‚   └── logger.ts      # Logging
└── types.ts           # Shared types

Architecture

Bot connects to 01 Exchange via official SDK (@n1xyz/nord-ts).

flowchart LR
    Binance["Binance WS"]
    Exchange["01 Exchange"]

    subgraph Bot
        SDK["SDK"]
        Pricing["Pricing"]
        Strategy["Strategy"]
    end

    Binance -->|"mid price"| Pricing
    SDK <--> Exchange
    SDK -->|"mid price"| Pricing
    Pricing -->|"fair price"| Strategy
    Strategy -->|"order requests"| SDK
    SDK -.->|"positions, orders"| Strategy
Loading

How It Works

Buy low, sell high.

Quoting

|------- 10bps -------|------- 10bps -------|
Buy Order          Fair Price          Sell Order
$99,900             $100,000             $100,100
  • Fair Price: Based on Binance mid
  • Buy/Sell: Fair Β± spread
  • Filled = bought low / sold high β†’ profit

Position Management

When position gets too big, switch to close mode:

  • Normal: Quote both sides (10bps)
  • Close: One side only, tighter spread (5bps)

Configuration

Edit src/bots/mm/config.ts:

export const DEFAULT_CONFIG = {
  spreadBps: 10, // Spread from fair price (10 bps = 0.1%)
  takeProfitBps: 5, // Spread in close mode
  orderSizeUsd: 100, // Order size in USD
  closeThresholdUsd: 10, // Trigger close mode when position >= this
  warmupSeconds: 10, // Seconds to warm up before quoting
  updateThrottleMs: 100, // Min interval between quote updates
  orderSyncIntervalMs: 3000, // Interval for syncing orders from API
  statusIntervalMs: 1000, // Interval for status display
  fairPriceWindowMs: 300000, // Window for fair price calculation (5 min)
  positionSyncIntervalMs: 5000, // Interval for position sync
}
npm run bot -- BTC
npm run bot -- ETH

Commands

# Run market maker
npm run bot -- btc

# Market monitor
npm run monitor -- btc

# Build
npm run build

# Run benchmarks (watch mode)
npm run bench

# Run benchmarks (single run, CI-friendly)
npm run bench:run

# Or via make
make bench

Benchmarks cover the tick-to-trade hot path β€” see docs/t2t-hot-path.md for details.

Docker

# Setup
cp .env.example .env
# Edit .env and set PRIVATE_KEY

# Run with docker compose
docker compose up -d

# View logs
docker compose logs -f

# Stop
docker compose down

# Rebuild after code changes
docker compose up -d --build

Edit docker-compose.yml to change the symbol or add more bots:

services:
  mm-btc:
    build: .
    command: ["BTC"]
    restart: unless-stopped
    env_file:
      - .env

  mm-eth:
    build: .
    command: ["ETH"]
    restart: unless-stopped
    env_file:
      - .env

Environment Variables

Variable Description Required
PRIVATE_KEY Base58 Solana private key Yes
RPC_URL Solana RPC endpoint (for monitor) No
LOG_LEVEL Log level: debug, info, warn, error No

Market Monitor

npm run monitor -- btc

Market Monitor

License

MIT

About

An example market maker bot for 01.xyz 🐈️

Resources

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages

  • TypeScript 95.6%
  • Shell 3.4%
  • Other 1.0%