> ## Documentation Index
> Fetch the complete documentation index at: https://docs.galadriel.co/llms.txt
> Use this file to discover all available pages before exploring further.

# How the Marketplace Works

> Understanding Galadriel's orderbook-based GPU marketplace

# How the Marketplace Works

Galadriel operates as a **two-sided marketplace** connecting GPU providers (supply) with ML engineers and companies (demand). Prices are determined by market forces through a **continuous double auction** using a central limit order book (CLOB), similar to financial exchanges.

## Marketplace Basics

### Two-Sided Market

```
Supply Side (Providers)          Orderbook          Demand Side (Customers)
─────────────────────            ────────           ─────────────────────────
"I'll sell 8 GPUs                                   "I'll buy 16 GPUs
 at min $3.20/hr"          ────────────────>         at max $3.50/hr"
                           Match when feasible
                           <────────────────

Match occurs when: buyer_max_price >= seller_min_price
Matched price: seller's ask (buyer pays seller's price)
```

**Key Principles:**

* **Transparent pricing**: Full orderbook visibility for all participants
* **Fair matching**: Price-time priority (best price wins, ties broken by timestamp)
* **Low latency**: Under 100ms order placement to match
* **Atomic transactions**: All-or-nothing for multi-node orders
* **Anti-gaming**: Rate limiting, price collars, wash trade prevention

## Order Types

### 1. Market Order (Instant Fill)

Execute immediately at the best available price.

```bash theme={null}
galadriel order buy --gpu-type h100 --gpus 8 --duration 12h --type market
```

**Characteristics:**

* ✅ Instant execution (guaranteed fill)
* ✅ No waiting time
* ⚠️ Pay current market price (may be higher)
* 🎯 Use when: Need GPUs immediately, deadline-driven workloads

**Example:**

```
Current best ask: $3.75/GPU/hr
Your order: 8 GPUs × 12h

✓ Matched immediately at $3.75/GPU/hr
✓ Total cost: $360 (8 × 12 × $3.75)
✓ Provisioning...
```

### 2. Limit Order (Wait for Price)

Execute only at your specified price or better.

```bash theme={null}
galadriel order buy --gpu-type h100 --gpus 16 --duration 24h --price 3.50
```

**Characteristics:**

* ✅ Control max price (never pay more than your limit)
* ✅ Save 10-30% in off-peak hours
* ⚠️ May not fill if price stays high
* ⚠️ Waiting time (minutes to hours)
* 🎯 Use when: Flexible timing, cost-sensitive workloads

**Example:**

```
Order submitted to marketplace
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Your order: 16x H100 @ max $3.50/hr
Market price: $3.75/hr (you're $0.25 below)
Status: PENDING

Position in queue: #3
Estimated fill time: 2-4 hours
Expires in: 4 hours (auto-cancel if not filled)

💡 Tip: Market is trending down. Your order likely to fill.
```

### 3. Flexible Timing Order (Best Price)

Execute anytime within a time window for optimal price.

```bash theme={null}
galadriel order buy --gpu-type h100 --gpus 8 --duration 8h --flex 48h --price 3.00
```

**Characteristics:**

* ✅ Best price guarantee (within your time window)
* ✅ Platform auto-schedules during low demand
* ✅ Typical savings: 25-40%
* ⚠️ Must be flexible on exact start time
* 🎯 Use when: No time constraints, maximize savings

**Example:**

```
Analyzing market patterns...
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Current price: $3.75/hr (above your max)
Tonight 10pm-6am: Expected $2.80-3.20/hr ✨
Tomorrow 2pm-6pm: Expected $3.60-4.00/hr

Recommended: Schedule for tonight 11pm
Expected price: $2.95/hr
Expected cost: $189 (vs $300 at current price)
Savings: $111 (37% off)

Create scheduled order? [Y/n]
```

## Orderbook Structure

### Example Orderbook

```
8xH100 | us-west-1 | 2025-11-11 14:00
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

SELL ORDERS (Ask)                    PRICE
$4.20/hr: 32 GPUs available          ┃
$3.99/hr: 64 GPUs available          ┃
$3.80/hr: 16 GPUs available          ┃
$3.50/hr: 24 GPUs available          ┃ ← Best Ask: $3.50/hr
════════════════════════════════════════════════ ← Spread: $0.10
$3.40/hr: 16 GPUs wanted             ┃ ← Best Bid: $3.40/hr
$3.20/hr: 32 GPUs wanted             ┃
$3.00/hr: 48 GPUs wanted             ┃
$2.80/hr: 64 GPUs wanted             ┃

BUY ORDERS (Bid)

Last traded: $1.30/hr
24h volume: 2,400 GPU-hours
Market depth: 136 GPUs ask, 160 GPUs bid
```

### Key Terms

* **Best Bid**: Highest price buyers are willing to pay (\$3.40/hr in example)
* **Best Ask**: Lowest price sellers are willing to accept (\$3.50/hr in example)
* **Spread**: Difference between best bid and ask (\$0.10 in example)
* **Mid Price**: Average of best bid and ask (($3.40 + $3.50) / 2 = \$1.30)
* **Market Depth**: Total GPUs available at each price level

## Matching Algorithm

### Price-Time Priority

Orders are matched using **price-time priority**:

1. **Price Priority**: Best prices matched first
   * Buy orders: Highest price first
   * Sell orders: Lowest price first

2. **Time Priority**: At the same price, earlier orders matched first (FIFO)

**Example:**

```
Three buy orders at $3.50/hr:
1. Order A: 8 GPUs (submitted 10:00 AM)
2. Order B: 16 GPUs (submitted 10:05 AM)
3. Order C: 8 GPUs (submitted 10:10 AM)

Sell order arrives: 16 GPUs @ $3.50/hr

Match result:
- Order A: 8 GPUs matched (earliest)
- Order B: 8 GPUs matched (partial fill)
- Order C: 0 GPUs matched (waiting)
```

### Node Boundary Rounding

All orders must respect **8-GPU node boundaries**:

```
Requested: 10 GPUs → Rounded down to 8 GPUs (1 node)
Requested: 16 GPUs → Exact match, 2 nodes
Requested: 20 GPUs → Rounded down to 16 GPUs (2 nodes)
Requested: 24 GPUs → Exact match, 3 nodes
```

## Order Lifecycle

```
┌─────────────┐
│   CREATED   │  Order submitted via API
└──────┬──────┘
       │
       ↓
┌─────────────┐
│   PENDING   │  Waiting in orderbook
└──────┬──────┘
       │
       ├──────────────────────────┐
       │                          │
       ↓ (partial match)          ↓ (full match)
┌─────────────┐            ┌─────────────┐
│   PARTIAL   │            │   FILLED    │
└──────┬──────┘            └──────┬──────┘
       │                          │
       ↓ (rest filled)             ↓
┌─────────────┐            ┌─────────────┐
│   FILLED    │───────────>│ PROVISIONING│
└─────────────┘            └──────┬──────┘
                                  │
                                  ↓
                           ┌─────────────┐
                           │    ACTIVE   │  Lease created
                           └─────────────┘
```

**Alternative endings:**

* **CANCELLED**: User cancels before fill
* **EXPIRED**: Order expires (limit orders can have TTL)
* **FAILED**: Provisioning failed after match

## Viewing the Orderbook

### CLI

```bash theme={null}
# View orderbook
galadriel orderbook --gpu-type h100 --zone us-west-1

# With more depth
galadriel orderbook --gpu-type h100 --zone us-west-1 --depth 20

# Get price estimate for market order
galadriel prices estimate --gpu-type h100 --gpus 16 --zone us-west-1
```

### API

```http theme={null}
GET /api/v1/orderbook?instance_type=8xh100&zone=us-west-1&depth=10
Authorization: Bearer <token>

Response:
{
  "instance_type": "8xh100",
  "zone": "us-west-1",
  "timestamp": "2025-11-11T14:00:00Z",
  "market_depth": {
    "best_bid": 1.30,
    "best_ask": 1.40,
    "spread": 0.10,
    "mid_price": 1.35
  },
  "bids": [
    {"price": 1.30, "gpus": 24, "orders": 3},
    {"price": 1.25, "gpus": 16, "orders": 2}
  ],
  "asks": [
    {"price": 1.40, "gpus": 16, "orders": 2},
    {"price": 1.45, "gpus": 8, "orders": 1}
  ]
}
```

## Managing Orders

### Check Order Status

```bash theme={null}
galadriel order get ord_abc123
```

Output:

```
ORDER ID:     ord_abc123
TYPE:         limit
SIDE:         buy
GPU TYPE:     h100
GPU COUNT:    16
LIMIT PRICE:  $3.50/hr
STATUS:       partial
FILLED:       8/16 GPUs (50%)
AVG PRICE:    $1.30/hr
CREATED:      2h ago
EXPIRES:      in 2h

MATCHES:
  - 8 GPUs @ $1.30/hr (matched 1h ago)
    Lease: lse_xyz123
```

### Cancel Order

```bash theme={null}
# Cancel entire order
galadriel order cancel ord_abc123

# Cancel remaining GPUs (keep partial fills)
galadriel order cancel ord_abc123 --keep-partial
```

### List Orders

```bash theme={null}
# All pending orders
galadriel order list --status pending

# All orders (including filled/cancelled)
galadriel order list --status all

# Filter by side
galadriel order list --side buy
```

## Platform Fees

All transactions include a **10% platform fee**:

```
Example Transaction:
  Customer pays: $1.35/GPU/hr × 16 GPUs × 24h = $518.40
  Platform fee (10%): $51.84
  Provider receives (90%): $466.56
```

**Fee Transparency:**

* Always shown before order confirmation
* Included in total cost estimates
* Clearly broken down in invoices
* Applied to both primary and secondary (resale) markets

## Anti-Gaming Protections

Galadriel implements several protections to ensure fair markets:

### 1. Minimum Order Value

```
Minimum: $10 total order value
Minimum duration: 1 hour
```

### 2. Rate Limiting

```
Max orders per minute: 10
Max cancellations per minute: 20
```

### 3. Price Collars

```
Orders cannot be more than ±50% of reference price
Reference price = last trade or mid-market price
```

### 4. Wash Trade Prevention

```
Cannot match orders with yourself
Cannot trade within same organization
```

## Next Steps

<CardGroup cols={2}>
  <Card title="Pricing Guide" icon="dollar-sign" href="/marketplace/pricing">
    Learn pricing strategies and save money
  </Card>

  <Card title="Cluster Specs" icon="microchip" href="/marketplace/cluster-specs">
    GPU types, system specs, and access model
  </Card>

  <Card title="Reselling Guide" icon="arrow-right-arrow-left" href="/marketplace/reselling">
    Resell unused GPU time
  </Card>

  <Card title="API Reference" icon="code" href="/api-reference">
    Complete REST API documentation
  </Card>
</CardGroup>
