Skip to content

4SEC Market Data APIMulti-DEX Aggregated Crypto Prices

Real-time prices, funding rates, liquidation data, and risk metrics from 8+ DEXes and major CEXes. Pay per request with USDC on Base via x402 protocol.

Quick Example

Get started in under 5 minutes. Install the x402 SDK and start fetching aggregated market data.

javascript
// Install: npm install @x402/fetch viem
import { wrapFetchWithPayments } from "@x402/fetch";
import { privateKeyToAccount } from "viem/accounts";
import { createWalletClient, http } from "viem";
import { base } from "viem/chains";

// 1. Setup wallet on Base network
const account = privateKeyToAccount("0x_your_private_key");
const walletClient = createWalletClient({
  account,
  chain: base,
  transport: http("https://mainnet.base.org"),
});

// 2. Create payment-enabled fetch
const fetchWithPayment = wrapFetchWithPayments(fetch, {
  client: walletClient,
});

// 3. Fetch real-time ETH price ($0.01 USDC)
const response = await fetchWithPayment(
  "https://api.foursec.xyz/price/ETH"
);
const data = await response.json();
console.log(`ETH: $${data.price_usd}`); // ETH: $2450.32
bash
# Step 1: Make request (returns 402 Payment Required)
curl -i https://api.foursec.xyz/price/ETH

# Step 2: Use x402 CLI for automatic payment
npx x402-cli fetch \
  https://api.foursec.xyz/price/ETH \
  --key 0x_your_private_key

# Step 3: Get response with aggregated data
# {"symbol":"ETH","price_usd":2450.32,"sources":3,...}
python
# Install: pip install httpx web3 eth-account
import httpx

# Make request (see Python SDK for auto-payment)
response = httpx.get("https://api.foursec.xyz/price/ETH")

# Handle 402 payment flow
if response.status_code == 402:
    payment_header = response.headers.get("x-payment")
    # Sign USDC transfer and retry
    # See: /integration/python for full guide
    pass

# For simpler flow, use JavaScript SDK

Example Response

json
{
  "symbol": "ETH",
  "price_usd": 2450.32,
  "change_24h": 2.45,
  "volume_24h_usd": 12500000,
  "total_sources": 3,
  "spread": 0.07,
  "sources": [
    {
      "dex": "Uniswap V3",
      "price": 2450.30,
      "liquidity_usd": 5200000
    },
    {
      "dex": "BaseSwap",
      "price": 2450.35,
      "liquidity_usd": 3100000
    },
    {
      "dex": "SushiSwap",
      "price": 2450.28,
      "liquidity_usd": 4200000
    }
  ]
}

API Endpoints and Pricing

Pay-as-you-go with USDC on Base via the x402 protocol. No subscriptions, no commitments.

DEX Endpoints

EndpointCostDescription
GET /price/:symbol$0.01Real-time aggregated price from 8+ DEXes
GET /price/history/:symbol$0.02Historical OHLCV candlestick data
GET /volume/:symbol$0.0224h trading volume across all DEXes
GET /spread/:pair$0.02Bid/ask spread analysis
GET /arbitrage-opportunity$0.05Cross-DEX arbitrage scanner
GET /volatility-index/:symbol$0.03Risk metrics: VaR, Sharpe, volatility
POST /price-alert$0.04Create webhook price alert

Funding Rate Endpoints

EndpointCostDescription
GET /funding-rate/:symbol$0.02Current perpetual funding rate with signal
GET /funding-rate/history/:symbol$0.03Historical funding rate data
GET /funding-rate/extreme$0.02Extreme funding rates scanner across markets

Liquidation Endpoints

EndpointCostDescription
GET /liquidation/heatmap/:symbol$0.05Liquidation heatmap with cascade risk levels
GET /liquidation/recent$0.03Recent liquidations with long/short breakdown
POST /liquidation/alert$0.06Create liquidation cascade alert webhook

CEX Market Data (v1)

EndpointCostDescription
GET /api/v1/prices$0.005Batch CEX prices (e.g. ?symbols=btc,eth,sol)
GET /api/v1/market/:id$0.005Market details by CoinGecko ID
GET /api/v1/market/:id/history$0.01Historical market data from CEX

Free Endpoints

EndpointCostDescription
GET /healthFreeHealth check
GET /api/v1/statusFreeDetailed system status
GET /price-alert/:idFreeCheck price alert status
DELETE /price-alert/:idFreeCancel a price alert
GET /price-alertsFreeList all active price alerts
GET /liquidation/alertsFreeList all active liquidation alerts
GET /FreeAPI information and endpoint list
GET /openapi.jsonFreeOpenAPI specification
GET /.well-known/x402.jsonFreex402 payment discovery

Smart Caching = Cost Savings

All paid endpoints have a 30-second cache TTL. Identical requests within 30 seconds are free (served from cache). Use this aggressively to reduce costs by up to 70%.

Supported DEXes

We aggregate prices from 8+ major decentralized exchanges across multiple chains:

DEXChainsPopular Pairs
Uniswap V3Base, EthereumETH/USDC, BTC/USDC, USDC/USDT
SushiSwapBase, EthereumETH/USDC, ETH/USDT, LINK/ETH
CurveEthereum3pool, ETH/stETH, FRAX/USDC
BaseSwapBaseETH/USDC, BASE/ETH, USDbC/USDC
AerodromeBaseETH/USDC, AERO/ETH, cbETH/ETH
PancakeSwap V3Base, BSCETH/USDC, BNB/USDC, CAKE/BNB
Balancer V2EthereumETH/USDC, WBTC/ETH, BAL/ETH
CamelotArbitrumETH/USDC, ARB/ETH, GMX/ETH

Why Multi-DEX Aggregation?

Single-DEX prices can be misleading. Here's why aggregation matters:

  • 🎯 Accurate Pricing — Volume-weighted average across multiple sources eliminates outliers
  • 📉 Reduced Slippage — See real market depth, not just one pool's liquidity
  • 💹 Arbitrage Detection — Spot price discrepancies across DEXes in real-time
  • 🛡️ Manipulation Resistance — Harder to manipulate aggregated prices vs single source
  • 📊 Better Risk Metrics — Spread analysis across all markets gives true volatility picture

How x402 Payment Works

The x402 protocol enables seamless pay-per-request API access:

Client                    4SEC API                  Base Network
  |                          |                          |
  |-- GET /price/ETH ------->|                          |
  |                          |                          |
  |<-- 402 Payment Required -|                          |
  |    (X-PAYMENT header)    |                          |
  |                          |                          |
  |-- Sign USDC transfer ----------------------------->|
  |                          |                          |
  |-- GET + Payment Proof -->|                          |
  |                          |-- Verify on-chain ------>|
  |                          |<-- Confirmed ------------|
  |                          |                          |
  |<-- 200 OK + Data --------|                          |
  |    {"price_usd": 2450.32}|                          |
  |                          |                          |
  1. Request — Your app calls any API endpoint
  2. 402 Response — API returns payment requirements in X-PAYMENT header
  3. Sign — SDK automatically signs USDC transfer from your wallet
  4. Retry — Client retries request with payment proof
  5. Verify — API verifies payment on Base chain
  6. Data — API returns the requested data

Total Cost

Each /price/:symbol request costs just $0.01 USDC. Same request within 30s is free from cache.

Who Uses 4SEC?

  • 🤖 Trading Bots — Real-time price feeds for automated strategies
  • 📊 Portfolio Trackers — Accurate valuations across all holdings
  • 📱 Dashboards — Market data for analytics and monitoring
  • 🔔 Alert Systems — Webhook notifications for price movements
  • 💰 Funding Rate Arbitrage — Monitor extreme rates for short/long opportunities
  • 🔥 Liquidation Monitors — Track cascades and risk levels
  • 🏢 CEX Analysts — Compare DEX vs CEX prices for insights
  • 🧠 AI Agents — Autonomous agents that pay for their own data
  • 🔬 Research Tools — Historical data and risk analysis

Get Started

Ready to integrate? Choose your path:

StepResourceTime
1Quick Start Guide5 minutes
2Setup Your Wallet10 minutes
3Explore API Reference15 minutes
4Build Your Integration30 minutes

Need Help?

  • 📖 FAQ — Common questions and answers
  • 🐛 Troubleshooting — Fix common issues
  • 💬 GitHub — Report bugs and request features

Built with x402 protocol on Base