DEV Community

Cover image for Auto-Generated OpenAPI Spec: Build Trading Bots with Interactive API Docs
Wallet Guy
Wallet Guy

Posted on

Auto-Generated OpenAPI Spec: Build Trading Bots with Interactive API Docs

Your trading bot spotted the opportunity: Jupiter shows SOL/USDC at a 0.3% premium, Drift has high funding rates for hedging, and gas is below your threshold. But can your bot execute the complete strategy before the arbitrage window closes? Most trading bots fail here — not because of strategy, but because they're cobbled together with multiple wallet libraries, RPC endpoints, and manual transaction building that breaks under pressure.

Why Trading Infrastructure Breaks When It Matters

Trading bots need split-second execution across multiple protocols. You might need to swap on Jupiter, open a perpetual position on Hyperliquid, stake rewards on Jito, and bridge profits back to Ethereum — all within seconds. But most bots are built with fragmented infrastructure:

  • Wallet chaos: Different libraries for Solana vs EVM, each with its own quirks
  • Gas disasters: Transactions failing because you didn't check network conditions
  • Protocol integration hell: Manually building transaction data for 15+ DeFi protocols
  • No risk controls: Bot drains wallet because of a bug or exploit

When you're competing against sophisticated MEV searchers and institutional trading firms, your infrastructure cannot be your weakness.

Auto-Generated OpenAPI: Your Trading Bot's Foundation

WAIaaS generates a complete OpenAPI 3.0 specification for its 39 REST API endpoints, giving trading bot builders exactly what they need: a reliable, documented, and interactive API reference. Every endpoint from balance queries to complex DeFi actions is documented with request schemas, response formats, and authentication requirements.

The generated specification lives at /doc and includes an interactive Scalar UI at /reference where you can test API calls directly in your browser. This isn't just documentation — it's your testing ground for trading strategies.

Here's how a trading bot checks available protocols and executes a multi-step strategy:

# Get interactive API reference
curl http://127.0.0.1:3100/doc -o trading-api-spec.json

# Check wallet balance before strategy execution
curl http://127.0.0.1:3100/v1/wallet/balance \
  -H "Authorization: Bearer wai_sess_<token>"

# Execute Jupiter swap: SOL → USDC
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

Multi-Protocol Trading Infrastructure

Trading bots need access to multiple DeFi protocols without the complexity of integrating each one separately. WAIaaS provides 15 DeFi protocol integrations through a unified API:

DEX Aggregators: Jupiter (Solana), 0x (Ethereum)

Perpetual Futures: Hyperliquid, Drift

Cross-chain: LI.FI bridging, Across protocol

Liquid Staking: Jito (Solana), Lido (Ethereum)

Prediction Markets: Polymarket for event-driven strategies

Each protocol is accessible through the same authentication pattern and response format, so your trading logic stays consistent even as you add new protocols:

# Check DeFi positions across all protocols
curl http://127.0.0.1:3100/v1/defi/positions \
  -H "Authorization: Bearer wai_sess_<token>"

# Open Hyperliquid perpetual position
curl -X POST http://127.0.0.1:3100/v1/actions/hyperliquid/open-position \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer wai_sess_<token>" \
  -d '{
    "market": "SOL-USD",
    "side": "long",
    "size": "10",
    "leverage": 5
  }'
Enter fullscreen mode Exit fullscreen mode

Gas Conditional Execution: Only Trade When Profitable

Trading bots need to factor gas costs into profitability calculations. WAIaaS includes gas conditional execution — your transactions only execute when network conditions meet your thresholds. No more profitable arbitrage opportunities eaten alive by gas spikes.

The 7-stage transaction pipeline includes gas condition checking, so you can set maximum gas prices per transaction type. Your MEV bot can queue transactions that only execute when gas drops below your profitability threshold.

Risk Controls That Don't Kill Performance

High-frequency trading needs risk controls that work at speed. WAIaaS uses 21 policy types with 4 security tiers to protect your trading capital without slowing execution:

# Create trading-specific policies
curl -X POST http://127.0.0.1:3100/v1/policies \
  -H "Content-Type: application/json" \
  -H "X-Master-Password: <password>" \
  -d '{
    "walletId": "<wallet-uuid>",
    "type": "SPENDING_LIMIT",
    "rules": {
      "instant_max_usd": 1000,
      "daily_limit_usd": 50000,
      "token_limits": {
        "native:solana": {"instant_max": "10"}
      }
    }
  }'
Enter fullscreen mode Exit fullscreen mode

INSTANT tier: Small trades execute immediately

NOTIFY tier: Medium trades execute with logging

DELAY tier: Large trades wait for gas optimization

APPROVAL tier: Whale trades need human confirmation

Your bot gets the speed it needs for small opportunities while protecting against catastrophic losses.

Quick Start: Trading Bot in 5 Steps

Here's how to get your trading bot connected to reliable wallet infrastructure:

  1. Deploy WAIaaS daemon:
docker run -d -p 127.0.0.1:3100:3100 ghcr.io/minhoyoo-iotrust/waiaas:latest
Enter fullscreen mode Exit fullscreen mode
  1. Create 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: <password>" \
  -d '{"name": "trading-bot", "chain": "solana", "environment": "mainnet"}'

# Create session for bot authentication
curl -X POST http://127.0.0.1:3100/v1/sessions \
  -H "Content-Type: application/json" \
  -H "X-Master-Password: <password>" \
  -d '{"walletId": "<wallet-uuid>"}'
Enter fullscreen mode Exit fullscreen mode
  1. Set risk policies for your trading strategy:
curl -X POST http://127.0.0.1:3100/v1/policies \
  -H "Content-Type: application/json" \
  -H "X-Master-Password: <password>" \
  -d '{
    "walletId": "<wallet-uuid>",
    "type": "ALLOWED_TOKENS",
    "rules": {"tokens": [
      {"address": "So11111111111111111111111111111111111111112", "symbol": "SOL", "chain": "solana"},
      {"address": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v", "symbol": "USDC", "chain": "solana"}
    ]}
  }'
Enter fullscreen mode Exit fullscreen mode
  1. Test your first trade:
# Dry-run a Jupiter swap to test integration
curl -X POST http://127.0.0.1:3100/v1/actions/jupiter-swap/swap \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer <session-token>" \
  -d '{
    "inputMint": "So11111111111111111111111111111111111111112",
    "outputMint": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
    "amount": "100000000",
    "dryRun": true
  }'
Enter fullscreen mode Exit fullscreen mode
  1. Explore the interactive API docs: Open http://127.0.0.1:3100/reference to see all available endpoints, test different protocols, and understand response formats.

What's Next

Your trading bot now has access to institutional-grade wallet infrastructure with multi-protocol DeFi access, gas optimization, and configurable risk controls. The auto-generated OpenAPI specification means you can integrate any language or framework that supports REST APIs.

Ready to build faster, more reliable trading bots? Check out the WAIaaS repository for the complete implementation, or visit waiaas.ai to learn more about production deployment options.

Top comments (0)