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

# Introduction

> Complete REST and WebSocket API documentation for Lidian stablecoin swap protocol.

# API Reference

Welcome to the Lidian API reference! This section provides comprehensive documentation for all API endpoints, data types, and integration examples.

## Base URLs

`https://api.lidian.finance`

## WebSocket URLs

`wss://ws.lidian.finance`

## Authentication

The API supports two authentication methods:

### 1. API Key Authentication

For server-to-server communication:

```typescript theme={null}
const headers = {
  'x-api-key': 'sk_live_your-api-key-here',
  'Content-Type': 'application/json'
};
```

### 2. SIWE Authentication

For wallet-based authentication using Sign-In with Ethereum:

```typescript theme={null}
// 1. Get nonce
const { nonce } = await fetch('/auth/nonce');

// 2. Create message and sign
const message = `api.lidian.finance wants you to sign in...`;
const signature = await wallet.signMessage(message);

// 3. Verify and get session
const { success, session } = await fetch('/auth/verify', {
  method: 'POST',
  body: JSON.stringify({ message, signature, address: wallet.address })
});
```

## Core API Endpoints

### Quote Flow

1. **Create Quote Request** (`POST /api/v1/quote-requests`) - Submit swap parameters
2. **Get Quotes** (`GET /api/v1/quotes`) - Retrieve competitive quotes from LPs
3. **Accept Quote** (`POST /api/v1/quotes/:id/accept`) - Select best quote
4. **Execute Swap** (`POST /api/v1/swaps`) - Execute the swap with signature

### Order Management

* **List Orders** (`GET /api/v1/orders`) - Get user's orders with filtering
* **Get Order** (`GET /api/v1/orders/:id`) - Detailed order information

### Public Data

* **Public Orders** (`GET /api/public/orders`) - Recent protocol activity
* **Recent Quotes** (`GET /api/public/quotes/recent`) - Latest quotes

### Real-time Updates

* **Server-Sent Events** (`GET /api/public/stream`) - Live protocol updates
* **WebSocket Support** (`GET /ws`) - Real-time streaming (optional)

## Supported Networks

Refer to Developers > Chains and Developers > Tokens for up-to-date network and token support details.

## Rate Limits

| Authentication | Requests/Minute | Concurrent Streams  |
| -------------- | --------------- | ------------------- |
| API Key        | 100             | 3 SSE / 3 WebSocket |
| SIWE (Wallet)  | 60              | 3 SSE / 3 WebSocket |

## Error Handling

### Standard Error Format

```json theme={null}
{
  "error": "Invalid request body",
  "details": [
    {
      "path": "inputToken",
      "message": "Token '0x123...' not found on chain 'base-sepolia'"
    }
  ]
}
```

### Common Error Codes

* `INVALID_TOKEN` - Unsupported token address
* `INVALID_CHAIN` - Unsupported chain
* `INSUFFICIENT_BALANCE` - Not enough tokens for swap
* `QUOTE_EXPIRED` - Quote has expired
* `ORDER_NOT_FOUND` - Order does not exist
* `UNAUTHORIZED` - Invalid authentication
* `RATE_LIMITED` - Too many requests
