Skip to main content

CLOB Architecture

Mayybee uses a Central Limit Order Book (CLOB) with price-time priority.

Matching Rules

1

Price Priority

Best price matches first (highest bid, lowest ask)
2

Time Priority

At same price, older orders match first
3

Instant Matching

When buy/sell prices overlap, match happens immediately

Orderbook Visualization

             BIDS (Buys)              ASKS (Sells)

    Price    Size    Orders     Price    Size    Orders
    --------------------------------------------------------
    55c      100     3          52c      50      2
    50c      200     5          55c      100     3
    45c      150     4          60c      75      2
    40c      300     8          65c      200     4

Spread

The spread is the difference between best bid and best ask:
  • Best Bid: 55c
  • Best Ask: 52c
  • Spread: -3c (crossed market, trades will execute)
A crossed market (bid greater than or equal to ask) triggers immediate execution.

Order Types

Limit Order

Specify exact price. Order sits in book until matched or cancelled.
{
  "side": 0,
  "price": 50,
  "size": "10000000000000000000"
}

Market Order (via limit at extreme price)

For immediate execution, use extreme prices:
  • Buy: Use price 99 (will match any ask)
  • Sell: Use price 1 (will match any bid)

Partial Fills

Orders can be partially filled: Example:
  • You place: SELL 100 tokens at 50c
  • Available bid: 60 tokens at 50c
  • Result: 60 filled, 40 remain in book

Real-time Updates

WebSocket Connection

const ws = new WebSocket('wss://api-testnet.mayybee.com');

// Subscribe to orderbook
ws.send(JSON.stringify({
  type: 'subscribe',
  channel: 'orderbook',
  marketId: 'your-market-id'
}));

// Handle updates
ws.onmessage = (event) => {
  const data = JSON.parse(event.data);
  console.log('Update:', data);
};

Update Types

TypeDescription
orderbookFull orderbook snapshot
order_addedNew order in book
order_removedOrder cancelled or filled
tradeTrade executed

API Endpoints

Get Orderbook

GET /api/markets/{marketId}/orderbook?tokenId={tokenId}
{
  "bids": [
    { "price": 55, "size": "100000000000000000000", "orders": 3 },
    { "price": 50, "size": "200000000000000000000", "orders": 5 }
  ],
  "asks": [
    { "price": 52, "size": "50000000000000000000", "orders": 2 },
    { "price": 55, "size": "100000000000000000000", "orders": 3 }
  ],
  "lastUpdate": 1736438400
}

Get Recent Trades

GET /api/markets/{marketId}/trades?tokenId={tokenId}&limit=50
{
  "trades": [
    {
      "id": "trade_123",
      "price": 52,
      "size": "10000000000000000000",
      "buyer": "0xABC...",
      "seller": "0xDEF...",
      "timestamp": 1736438400,
      "txHash": "0x..."
    }
  ]
}