API Documentation

API Overview

Trenchr provides both internal API routes and external integrations for wallet analysis and real-time features.

REST API

Standard HTTP endpoints

Real-time

WebSocket subscriptions

GraphQL

Coming soon

Wallet Analysis API

GET
/api/analyze-wallet

Analyzes a Solana wallet address and returns comprehensive trading metrics.

Query Parameters
ParameterTypeRequiredDescription
addressstringYesValid Solana wallet address
Example Request
curl "https://trenchr.app/api/analyze-wallet?address=7xKXtg2CW87d97TXJSDpbD5jBkheTqA83TZRuJosgAsU"
Success Response (200)
{
  "address": "7xKXtg2CW87d97TXJSDpbD5jBkheTqA83TZRuJosgAsU",
  "winRate": 62.5,
  "solBalance": 15.75,
  "totalProfit": 1250.5,
  "realizedProfit7d": 125.25,
  "realizedProfit30d": 890.75,
  "totalValue": 2850.25,
  "riskScore": 45
}
Error Response (400)
{
  "error": "Wallet address is required"
}

Supabase Integration

Authentication

// Sign Up
const { data, error } = await supabase.auth.signUp({
  email: 'user@example.com',
  password: 'securepassword',
  options: {
    data: {
      username: 'trencher_legend'
    }
  }
})

// Sign In
const { data, error } = await supabase.auth.signInWithPassword({
  email: 'user@example.com',
  password: 'securepassword'
})

Database Operations

// Create/Update User Profile
const { data, error } = await supabase
  .from('users')
  .upsert({
    id: user.id,
    username: 'trencher_legend',
    display_name: 'The BONK Believer',
    trading_style: 'Degen'
  })
  .select()
  .single()

// Record a Swipe
const { error } = await supabase
  .from('swipes')
  .insert({
    swiper_id: currentUserId,
    swiped_id: targetUserId,
    direction: 'right'
  })

Real-time Subscriptions

// Listen for New Messages
const subscription = supabase
  .channel(`messages:${matchId}`)
  .on(
    'postgres_changes',
    {
      event: 'INSERT',
      schema: 'public',
      table: 'messages',
      filter: `match_id=eq.${matchId}`
    },
    (payload) => {
      const newMessage = payload.new
      // Handle new message
    }
  )
  .subscribe()

Rate Limiting

Current Limits
EndpointLimitWindow
/api/analyze-wallet60 requests1 minute
All API routes1000 requests1 hour
Rate Limit Headers
X-RateLimit-Limit: 60
X-RateLimit-Remaining: 59
X-RateLimit-Reset: 1640995200

TypeScript Types

// User types
interface User {
  id: string
  email: string
  username: string
  display_name?: string
  bio?: string
  wallet_address?: string
  trading_style?: 'Degen' | 'Swing' | 'Copy' | 'Sniper'
  wallet_size_tier?: 'Micro' | 'Small' | 'Medium' | 'Large' | 'Whale'
  // ... more fields
}

// Wallet analysis types
interface WalletAnalysisData {
  address: string
  winRate: number
  solBalance: number
  totalProfit: number
  realizedProfit7d: number
  realizedProfit30d: number
  totalValue: number
  riskScore: number
}