Skip to content

Use Cases

1. AI Trading Bots

Build autonomous trading agents with real-time data.

python
class TradingBot:
    def __init__(self, wallet):
        self.api = X402Client(wallet=wallet)
    
    async def analyze_and_trade(self):
        # Get real-time price ($0.01)
        eth = await self.api.get("https://api.foursec.xyz/price/ETH")
        
        # Check arbitrage ($0.03)
        arb = await self.api.get("https://api.foursec.xyz/arbitrage-opportunity")
        
        # Assess risk ($0.02)
        vol = await self.api.get("https://api.foursec.xyz/volatility-index/ETH")
        
        if arb['total_opportunities'] > 0:
            profit = arb['opportunities'][0]['estimated_profit_usd']
            if profit > 5.0:
                await self.execute_arbitrage(arb['opportunities'][0])
        
        # Total analysis cost: $0.06 per cycle

2. Portfolio Trackers

python
class PortfolioTracker:
    async def get_portfolio_value(self, holdings):
        total_value = 0
        for symbol, amount in holdings.items():
            price = await self.api.get(
                f"https://api.foursec.xyz/price/{symbol}"
            ).json()
            total_value += price['price_usd'] * amount
        return total_value

3. DeFi Dashboards

python
class MarketDashboard:
    async def generate_report(self):
        tokens = ['BTC', 'ETH', 'SOL', 'ARB', 'OP']
        report = []
        for symbol in tokens:
            price = await self.api.get(f"/price/{symbol}")
            vol = await self.api.get(f"/volatility-index/{symbol}")
            report.append({
                'symbol': symbol,
                'price': price['price_usd'],
                'change': price['change_24h'],
                'risk': vol['risk_level']
            })
        # Cost: $0.15 per report (5 tokens x 2 endpoints)

4. Price Alert Bots

python
alert = client.post("https://api.foursec.xyz/price-alert", json={
    "symbol": "ETH",
    "condition": "below",
    "target_price": 2400,
    "webhook_url": "https://your-bot.com/webhook",
    "duration_hours": 24
}).json()
# Cost: $0.05 per alert

5. Research and Analytics

python
history = client.get(
    "https://api.foursec.xyz/price/history/ETH?interval=1h&limit=720"
).json()
for candle in history['candles']:
    print(f"{candle['timestamp']}: O={candle['open']} H={candle['high']}")
# Cost: $0.02 per request

Cost Calculator

Use CaseRequests/HourCost/HourCost/Day
Trading Bot60$0.60$14.40
Portfolio Tracker12$0.12$2.88
Market Dashboard12$0.30$7.20
Price Alerts1$0.05$1.20
Research5$0.10$2.40

TIP

Use the 30-second cache wisely! Identical requests within 30s are free.

Released under the MIT License.