DEV Community

Cover image for 39 REST API Routes: Complete Trading Bot Integration Guide
Wallet Guy
Wallet Guy

Posted on

39 REST API Routes: Complete Trading Bot Integration Guide

Trading bots need reliable wallet infrastructure with low-latency execution and built-in risk controls. WAIaaS provides 39 REST API routes that handle everything from basic token transfers to complex multi-protocol DeFi strategies, with gas optimization and policy enforcement built directly into the transaction pipeline.

Why Wallet Infrastructure Makes or Breaks Trading Bots

Your arbitrage bot spots a 2% price difference between Jupiter and Drift. You have maybe 3-4 seconds before other bots close the gap. But your current setup requires three separate wallet integrations, manual gas estimation, and zero protection against fat-finger trades that could drain your entire balance.

This is where most trading bots fail — not in strategy logic, but in execution infrastructure. You need wallet operations that are fast, reliable, and protected by configurable policies. Every API call should execute predictably, whether you're swapping $100 or $10,000.

The Complete API: From Basic Operations to Advanced Trading

WAIaaS exposes 39 REST API routes covering every aspect of wallet operations. Let's walk through how a sophisticated trading bot would use these endpoints.

Session Authentication for High-Frequency Operations

Trading bots need fast authentication without compromising security. WAIaaS uses JWT session tokens that avoid expensive cryptographic operations on every request:

# Create a session for your trading bot (one-time setup)
curl -X POST http://127.0.0.1:3100/v1/sessions \
  -H "Content-Type: application/json" \
  -H "X-Master-Password: my-secret-password" \
  -d '{"walletId": "<wallet-uuid>"}'
Enter fullscreen mode Exit fullscreen mode

Once you have a session token, every subsequent API call uses fast Bearer authentication:

# Check wallet balance (sub-100ms response)
curl http://127.0.0.1:3100/v1/wallet/balance \
  -H "Authorization: Bearer wai_sess_eyJhbGciOiJIUzI1NiJ9..."
Enter fullscreen mode Exit fullscreen mode

Multi-Protocol DeFi Execution

Your trading bot can access 15 DeFi protocols through standardized action endpoints. Execute swaps on Jupiter, open perp positions on Drift, and provide liquidity on Kamino — all through the same API pattern:

# Swap SOL → USDC on Jupiter
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"
  }'
Enter fullscreen mode Exit fullscreen mode
# Open leveraged position on Hyperliquid
curl -X POST http://127.0.0.1:3100/v1/actions/hyperliquid/place-order \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer wai_sess_<token>" \
  -d '{
    "coin": "ETH",
    "is_buy": true,
    "sz": "0.1",
    "limit_px": "3500",
    "order_type": "Limit"
  }'
Enter fullscreen mode Exit fullscreen mode

Gas-Conditional Execution

This is where WAIaaS shines for trading bots. You can set gas price thresholds so transactions only execute when network conditions are favorable:

# Only execute this swap if gas < 50 gwei
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": "TRANSFER",
    "to": "recipient-address",
    "amount": "0.1",
    "gasCondition": {
      "maxGasPrice": "50000000000"
    }
  }'
Enter fullscreen mode Exit fullscreen mode

Transaction Simulation and Dry-Run

Before risking real funds, simulate transactions to verify they'll succeed:

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": "TRANSFER",
    "to": "recipient-address",
    "amount": "0.1",
    "dryRun": true
  }'
Enter fullscreen mode Exit fullscreen mode

This returns the exact same response format as a real transaction, but without broadcasting to the network. Perfect for testing complex DeFi strategies.

Batch Transaction Execution

Execute multiple operations atomically. Critical for arbitrage strategies that need guaranteed execution across multiple protocols:

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": "BATCH",
    "transactions": [
      {
        "type": "TRANSFER",
        "to": "address1",
        "amount": "0.1"
      },
      {
        "type": "TOKEN_TRANSFER",
        "to": "address2",
        "tokenAddress": "token-mint",
        "amount": "100"
      }
    ]
  }'
Enter fullscreen mode Exit fullscreen mode

Policy-Based Risk Management

Configure spending limits and security policies that protect your bot from catastrophic losses. The 7-stage transaction pipeline enforces these policies automatically:

# Create a policy that limits instant trades to $100
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": 100,
      "notify_max_usd": 500,
      "delay_max_usd": 2000,
      "delay_seconds": 900,
      "daily_limit_usd": 5000
    }
  }'
Enter fullscreen mode Exit fullscreen mode

WAIaaS supports 21 policy types with 4 security tiers. Trades under $100 execute instantly. Trades $100-$500 execute with notifications. Larger trades can be delayed or require manual approval.

Real-Time Transaction Monitoring

Monitor transaction status and get detailed execution data:

# Get transaction details and status
curl http://127.0.0.1:3100/v1/transactions/<tx-id> \
  -H "Authorization: Bearer wai_sess_<token>"
Enter fullscreen mode Exit fullscreen mode

The response includes execution stage, gas costs, and any policy decisions that affected the transaction.

Advanced Trading Scenarios

Cross-Chain Arbitrage Bot

Your bot spots a price difference between Ethereum and Solana markets. WAIaaS handles the complexity:

# 1. Bridge USDC from Ethereum to Solana via LI.FI
curl -X POST http://127.0.0.1:3100/v1/actions/lifi/transfer \
  -H "Authorization: Bearer wai_sess_<token>" \
  -d '{
    "fromChain": "ethereum",
    "toChain": "solana",
    "fromToken": "0xA0b86a33E6c5...",
    "toToken": "EPjFWdd5Auf...",
    "amount": "1000000000"
  }'

# 2. Once bridged, swap USDC → SOL on Jupiter
curl -X POST http://127.0.0.1:3100/v1/actions/jupiter-swap/swap \
  -H "Authorization: Bearer wai_sess_<token>" \
  -d '{
    "inputMint": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
    "outputMint": "So11111111111111111111111111111111111111112",
    "amount": "1000000000"
  }'
Enter fullscreen mode Exit fullscreen mode

Yield Farming Bot

Automatically compound rewards across multiple protocols:

# 1. Check current DeFi positions
curl http://127.0.0.1:3100/v1/defi/positions \
  -H "Authorization: Bearer wai_sess_<token>"

# 2. Harvest rewards from Kamino
curl -X POST http://127.0.0.1:3100/v1/actions/kamino/harvest \
  -H "Authorization: Bearer wai_sess_<token>" \
  -d '{"position_id": "<position-id>"}'

# 3. Swap rewards to base asset
curl -X POST http://127.0.0.1:3100/v1/actions/jupiter-swap/swap \
  -H "Authorization: Bearer wai_sess_<token>" \
  -d '{"inputMint": "<reward-token>", "outputMint": "<base-token>"}'

# 4. Reinvest in strategy
curl -X POST http://127.0.0.1:3100/v1/actions/kamino/deposit \
  -H "Authorization: Bearer wai_sess_<token>" \
  -d '{"strategy": "<strategy-id>", "amount": "<amount>"}'
Enter fullscreen mode Exit fullscreen mode

MEV Protection and Timing

Use the transaction pipeline's delay mechanism for MEV-sensitive operations:

# Delay execution by 60 seconds to avoid MEV
curl -X POST http://127.0.0.1:3100/v1/transactions/send \
  -H "Authorization: Bearer wai_sess_<token>" \
  -d '{
    "type": "TRANSFER",
    "amount": "1.0",
    "delaySeconds": 60
  }'
Enter fullscreen mode Exit fullscreen mode

OpenAPI Documentation for Development

WAIaaS auto-generates OpenAPI 3.0 specs with interactive documentation:

# Download machine-readable API spec
curl http://127.0.0.1:3100/doc -o openapi.json

# View interactive docs in browser
open http://127.0.0.1:3100/reference
Enter fullscreen mode Exit fullscreen mode

The interactive Scalar API reference lets you test endpoints directly, perfect for development and debugging.

Quick Start: Deploy Your Trading Bot

Step 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

Step 2: Create a trading wallet and session

# Create Solana mainnet wallet
curl -X POST http://127.0.0.1:3100/v1/wallets \
  -H "Content-Type: application/json" \
  -H "X-Master-Password: my-secret-password" \
  -d '{"name": "trading-bot", "chain": "solana", "environment": "mainnet"}'

# Create session for your bot
curl -X POST http://127.0.0.1:3100/v1/sessions \
  -H "Content-Type: application/json" \
  -H "X-Master-Password: my-secret-password" \
  -d '{"walletId": "<wallet-uuid>"}'
Enter fullscreen mode Exit fullscreen mode

Step 3: Configure trading policies

# Set spending limits and risk controls
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,
      "daily_limit_usd": 10000
    }
  }'
Enter fullscreen mode Exit fullscreen mode

Step 4: Test with a simple swap

# Execute your first trade
curl -X POST http://127.0.0.1:3100/v1/actions/jupiter-swap/swap \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer wai_sess_<your-token>" \
  -d '{
    "inputMint": "So11111111111111111111111111111111111111112",
    "outputMint": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
    "amount": "100000000"
  }'
Enter fullscreen mode Exit fullscreen mode

Step 5: Monitor and scale

Use the transaction monitoring endpoints to track performance and adjust your strategies based on real execution data.

The infrastructure handles wallet management, transaction signing, policy enforcement, and protocol integrations. You focus on strategy logic and market analysis.

What's Next

Ready to build? Check out the GitHub repository for complete setup instructions and examples. Visit waiaas.ai for comprehensive documentation and advanced configuration guides.

Your trading bot deserves infrastructure that matches its sophistication. Stop wrestling with wallet integrations and start executing profitable strategies.

Top comments (0)