Skip to main content

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:
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:
// 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

AuthenticationRequests/MinuteConcurrent Streams
API Key1003 SSE / 3 WebSocket
SIWE (Wallet)603 SSE / 3 WebSocket

Error Handling

Standard Error Format

{
  "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