DEV Community

Cover image for Keep Your Trading Bot Online: Monitoring 15 DeFi Protocol Health Status
Wallet Guy
Wallet Guy

Posted on

Keep Your Trading Bot Online: Monitoring 15 DeFi Protocol Health Status

Your trading bot found the perfect arbitrage opportunity across protocols, but when it tries to execute, half your DeFi integrations are down or experiencing high slippage. Building reliable automated trading systems means constantly monitoring the health and performance of 15+ DeFi protocols before your bot commits capital.

When trading bots operate across multiple protocols like Jupiter, Drift, Hyperliquid, and Polymarket, a single integration failure can break your entire strategy. Your bot needs real-time visibility into protocol status, gas conditions, and execution reliability to make informed routing decisions and avoid costly failures.

Why Protocol Health Monitoring Matters

Trading bots operate in an environment where milliseconds matter and failed transactions burn gas. Unlike manual trading, automated systems can't visually assess if a protocol's interface is slow or if liquidity has dried up. Your bot needs programmatic access to protocol health metrics before routing trades.

Consider a multi-leg arbitrage strategy: buy on Jupiter, short on Hyperliquid, bridge profits via LI.FI. If any protocol is degraded, the entire strategy becomes unprofitable. Advanced trading bots monitor protocol health continuously and adjust routing in real-time.

Monitoring DeFi Protocol Status with WAIaaS

WAIaaS provides built-in health monitoring for all 15 integrated DeFi protocols through its provider status API. Your trading bot can check protocol availability, response times, and error rates before committing to trades.

Check All Protocol Status

curl http://127.0.0.1:3100/v1/providers/status \
  -H "Authorization: Bearer wai_sess_<token>"
Enter fullscreen mode Exit fullscreen mode

This returns health status for all 15 DeFi protocols: aave-v3, across, dcent-swap, drift, erc8004, hyperliquid, jito-staking, jupiter-swap, kamino, lido-staking, lifi, pendle, polymarket, xrpl-dex, zerox-swap.

Protocol-Specific Health Checks

# Check Jupiter DEX status before large swaps
curl http://127.0.0.1:3100/v1/providers/jupiter-swap/status \
  -H "Authorization: Bearer wai_sess_<token>"
Enter fullscreen mode Exit fullscreen mode

The health check API returns response times, recent error rates, and availability metrics. Your bot can set thresholds (e.g., skip Jupiter if response time > 2 seconds) and fall back to alternative protocols.

Gas Conditional Execution

For gas-sensitive strategies, WAIaaS includes gas conditional execution. Your trades only execute when gas prices meet your profitability thresholds:

curl -X POST http://127.0.0.1:3100/v1/actions/jupiter-swap/swap \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer wai_sess_<token>" \
  -d '{
    "inputMint": "So11111111111111111111111111111111111111112",
    "outputMint": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
    "amount": "1000000000",
    "gasCondition": {
      "maxGasPrice": "20",
      "waitTimeout": 300
    }
  }'
Enter fullscreen mode Exit fullscreen mode

This prevents your bot from executing unprofitable trades during gas spikes while keeping positions queued for optimal execution windows.

Multi-Protocol Trading Example

Here's how to build a trading bot that monitors protocol health before executing cross-protocol strategies:

import { WAIaaSClient } from '@waiaas/sdk';

const client = new WAIaaSClient({
  baseUrl: 'http://127.0.0.1:3100',
  sessionToken: process.env.WAIAAS_SESSION_TOKEN,
});

async function checkProtocolHealth(providers: string[]): Promise<string[]> {
  const healthyProviders = [];

  for (const provider of providers) {
    try {
      const status = await client.getProviderStatus(provider);
      // Only use providers with <2s response time and >95% success rate
      if (status.avgResponseTime < 2000 && status.successRate > 0.95) {
        healthyProviders.push(provider);
      }
    } catch (error) {
      console.log(`Provider ${provider} unhealthy: ${error.message}`);
    }
  }

  return healthyProviders;
}

async function executeArbitrageStrategy() {
  // Check health before routing
  const dexProviders = ['jupiter-swap', 'zerox-swap'];
  const perpProviders = ['hyperliquid', 'drift'];
  const bridgeProviders = ['lifi', 'across'];

  const healthyDex = await checkProtocolHealth(dexProviders);
  const healthyPerp = await checkProtocolHealth(perpProviders);
  const healthyBridge = await checkProtocolHealth(bridgeProviders);

  if (healthyDex.length === 0) {
    console.log('No healthy DEX protocols available');
    return;
  }

  // Execute trades using healthy protocols only
  const spotTrade = await client.executeAction(healthyDex[0], 'swap', {
    inputMint: 'So11111111111111111111111111111111111111112',
    outputMint: 'EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v',
    amount: '1000000000'
  });

  if (healthyPerp.length > 0) {
    // Hedge position on healthy perp exchange
    await client.executeAction(healthyPerp[0], 'place-order', {
      market: 'SOL-PERP',
      side: 'short',
      size: '1.0',
      orderType: 'market'
    });
  }

  console.log(`Arbitrage executed: spot on ${healthyDex[0]}, perp on ${healthyPerp[0]}`);
}
Enter fullscreen mode Exit fullscreen mode

Transaction Simulation Before Execution

Avoid costly failed transactions by simulating trades before commitment:

curl -X POST http://127.0.0.1:3100/v1/transactions/send \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer wai_sess_<token>" \
  -d '{
    "type": "CONTRACT_CALL",
    "to": "JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4",
    "data": "0x...",
    "dryRun": true
  }'
Enter fullscreen mode Exit fullscreen mode

The dry-run API returns gas estimates, slippage projections, and potential failure reasons without spending gas. Your bot can validate trades across multiple protocols and choose optimal execution paths.

Risk Controls for Automated Trading

Trading bots need built-in risk management to prevent catastrophic losses. WAIaaS provides 21 policy types with 4 security tiers to protect your capital:

Spending Limits

curl -X POST http://127.0.0.1:3100/v1/policies \
  -H "Content-Type: application/json" \
  -H "X-Master-Password: my-secret-password" \
  -d '{
    "walletId": "<wallet-uuid>",
    "type": "SPENDING_LIMIT",
    "rules": {
      "instant_max_usd": 1000,
      "notify_max_usd": 5000,
      "delay_max_usd": 25000,
      "delay_seconds": 300,
      "daily_limit_usd": 50000
    }
  }'
Enter fullscreen mode Exit fullscreen mode

Protocol-Specific Limits

curl -X POST http://127.0.0.1:3100/v1/policies \
  -H "Content-Type: application/json" \
  -H "X-Master-Password: my-secret-password" \
  -d '{
    "walletId": "<wallet-uuid>",
    "type": "PERP_MAX_LEVERAGE",
    "rules": {
      "maxLeverage": 5,
      "allowedMarkets": ["SOL-PERP", "ETH-PERP", "BTC-PERP"]
    }
  }'
Enter fullscreen mode Exit fullscreen mode

These policies enforce risk limits at the infrastructure level, preventing your bot from exceeding position sizes even if trading logic has bugs.

Quick Start: Deploy a Monitored Trading Bot

  1. Deploy WAIaaS with Docker
   git clone https://github.com/minhoyoo-iotrust/WAIaaS.git
   cd WAIaaS
   docker compose up -d
Enter fullscreen mode Exit fullscreen mode
  1. Create trading wallet and session
   npm install -g @waiaas/cli
   waiaas quickstart
Enter fullscreen mode Exit fullscreen mode
  1. Set up protocol health monitoring
   # Check all protocol status
   curl http://127.0.0.1:3100/v1/providers/status \
     -H "Authorization: Bearer wai_sess_<your-token>"
Enter fullscreen mode Exit fullscreen mode
  1. Configure risk policies
   # Set daily spending limit
   curl -X POST http://127.0.0.1:3100/v1/policies \
     -H "X-Master-Password: <password>" \
     -d '{"type": "SPENDING_LIMIT", "rules": {"daily_limit_usd": 10000}}'
Enter fullscreen mode Exit fullscreen mode
  1. Deploy your bot with health checks
   // Your trading bot now monitors protocol health before each trade
   const healthyProviders = await checkProtocolHealth(['jupiter-swap', 'hyperliquid']);
   if (healthyProviders.length > 0) {
     await executeStrategy(healthyProviders);
   }
Enter fullscreen mode Exit fullscreen mode

Building reliable trading bots requires more than just market analysis — you need infrastructure that monitors protocol health, manages risk, and executes trades efficiently across multiple DeFi protocols. WAIaaS provides the wallet infrastructure layer that lets you focus on trading strategy rather than integration complexity.

Ready to build more reliable trading bots? Check out the complete codebase at GitHub or explore the full API documentation at waiaas.ai.

Top comments (0)