DEV Community

Cover image for Building a Hyperliquid Trading Bot: Perps, Spot, and Sub-Accounts
Wallet Guy
Wallet Guy

Posted on

Building a Hyperliquid Trading Bot: Perps, Spot, and Sub-Accounts

Your Hyperliquid perpetual bot spotted the perfect setup — funding rates are paying 50% APR while spot is trading at a discount. But by the time you've manually signed into three different platforms, connected wallets, and navigated UIs, the opportunity is gone. Professional traders need infrastructure that executes as fast as they think.

Why Trading Infrastructure Matters

Every millisecond counts in crypto trading. Whether you're running statistical arbitrage between Jupiter and centralized exchanges, or managing a complex delta-neutral strategy across perpetual futures and spot markets, your wallet infrastructure can make or break your edge. Manual wallet management, fragmented APIs, and missing risk controls turn profitable opportunities into costly delays.

The best traders automate everything — not just strategy logic, but the entire execution pipeline from signal generation to settlement confirmation. You need wallet infrastructure that speaks your language: REST APIs, policy engines, and multi-protocol access through a single interface.

Professional Trading Infrastructure with WAIaaS

WAIaaS provides the wallet infrastructure that serious trading operations require. Instead of managing multiple wallet connections and signing flows, your bot gets one REST API that spans 14 DeFi protocols across Solana and EVM chains — including Hyperliquid perpetuals, Jupiter swaps, and cross-chain bridges.

Hyperliquid Integration: Perps, Spot, and Sub-Accounts

Hyperliquid's unified API covers perpetual futures, spot trading, and sub-account management. Through WAIaaS, your trading bot can execute complex strategies without dealing with wallet connection hassles:

# Open a 10x long position on ETH perpetual
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": "1.0",
    "limit_px": "3500",
    "order_type": {"limit": {"tif": "Gtc"}},
    "reduce_only": false
  }'
Enter fullscreen mode Exit fullscreen mode

Sub-accounts let you compartmentalize strategies while maintaining unified reporting:

# Create sub-account for delta-neutral strategy
curl -X POST http://127.0.0.1:3100/v1/actions/hyperliquid/create-sub-account \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer wai_sess_<token>" \
  -d '{
    "name": "delta-neutral-arb"
  }'
Enter fullscreen mode Exit fullscreen mode

Multi-Protocol Trading Through One API

Professional strategies often span multiple venues. A typical delta-neutral play might involve shorting perpetuals on Hyperliquid while longing spot on Jupiter. WAIaaS handles the complexity:

# Step 1: Short ETH perp on Hyperliquid
curl -X POST http://127.0.0.1:3100/v1/actions/hyperliquid/place-order \
  -H "Authorization: Bearer wai_sess_<token>" \
  -d '{
    "coin": "ETH",
    "is_buy": false,
    "sz": "2.0",
    "limit_px": "3500"
  }'

# Step 2: Buy ETH spot via Jupiter swap
curl -X POST http://127.0.0.1:3100/v1/actions/jupiter-swap/swap \
  -H "Authorization: Bearer wai_sess_<token>" \
  -d '{
    "inputMint": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
    "outputMint": "7vfCXTUXx5WJV5JADk17DUJ4ksgau7utNKj4b963voxs",
    "amount": "7000000000"
  }'
Enter fullscreen mode Exit fullscreen mode

Gas Conditional Execution

Gas costs can destroy trading profits, especially for high-frequency strategies. WAIaaS includes gas conditional execution — transactions only execute when gas prices meet your thresholds:

# Only execute when gas < 50 gwei
curl -X POST http://127.0.0.1:3100/v1/transactions/send \
  -H "Authorization: Bearer wai_sess_<token>" \
  -d '{
    "type": "TRANSFER",
    "to": "0x742d35cc1cf",
    "amount": "0.1",
    "gasCondition": {
      "maxGasPrice": "50000000000"
    }
  }'
Enter fullscreen mode Exit fullscreen mode

Your arbitrage bot queues transactions during high gas periods and executes automatically when conditions improve.

Risk Controls for Trading Bots

Automated trading requires automated risk management. WAIaaS's policy engine provides 21 policy types including position size limits, leverage caps, and spending controls:

# Set max leverage for perpetual trading
curl -X POST http://127.0.0.1:3100/v1/policies \
  -H "X-Master-Password: my-secret-password" \
  -d '{
    "type": "PERP_MAX_LEVERAGE",
    "rules": {
      "max_leverage": 10,
      "markets": ["ETH", "BTC"]
    }
  }'
Enter fullscreen mode Exit fullscreen mode

Position size limits prevent a single trade from risking the entire portfolio:

# Cap position sizes by market
curl -X POST http://127.0.0.1:3100/v1/policies \
  -H "X-Master-Password: my-secret-password" \
  -d '{
    "type": "PERP_MAX_POSITION_USD",
    "rules": {
      "max_position_usd": 50000,
      "per_market_limits": {
        "ETH": 25000,
        "BTC": 25000
      }
    }
  }'
Enter fullscreen mode Exit fullscreen mode

Real-Time Portfolio Monitoring

Trading bots need continuous position monitoring. WAIaaS tracks DeFi positions across all 14 integrated protocols:

# Get unified portfolio view
curl http://127.0.0.1:3100/v1/defi/positions \
  -H "Authorization: Bearer wai_sess_<token>"
Enter fullscreen mode Exit fullscreen mode

This returns positions from Hyperliquid, Jupiter, Kamino, Drift, and other protocols in a standardized format. Your monitoring dashboard gets one API call instead of integrating with each protocol separately.

Cross-Chain Arbitrage Infrastructure

Inter-chain arbitrage requires reliable bridging. WAIaaS integrates LI.FI and Across protocols for seamless asset movement:

# Bridge USDC from Ethereum to Solana for Jupiter trading
curl -X POST http://127.0.0.1:3100/v1/actions/lifi/bridge \
  -H "Authorization: Bearer wai_sess_<token>" \
  -d '{
    "fromChain": "ethereum",
    "toChain": "solana", 
    "fromToken": "0xA0b86a33E6441",
    "toToken": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
    "amount": "1000000000"
  }'
Enter fullscreen mode Exit fullscreen mode

Your arbitrage bot can now capture opportunities across chains without manual intervention.

Quick Start: Deploy a Trading Bot

Here's how to get trading infrastructure running in under 10 minutes:

1. Start WAIaaS with Docker

git clone https://github.com/minhoyoo-iotrust/WAIaaS.git
cd WAIaaS
docker compose up -d
Enter fullscreen mode Exit fullscreen mode

2. Create wallets for your strategies

npm install -g @waiaas/cli
waiaas quickset --mode mainnet  # Creates Ethereum + Solana wallets
Enter fullscreen mode Exit fullscreen mode

3. Set up risk policies

# Create spending limits and position caps
curl -X POST http://127.0.0.1:3100/v1/policies \
  -H "X-Master-Password: <password>" \
  -d '{
    "type": "SPENDING_LIMIT",
    "rules": {
      "instant_max_usd": 1000,
      "daily_limit_usd": 50000
    }
  }'
Enter fullscreen mode Exit fullscreen mode

4. Install the SDK in your trading bot

npm install @waiaas/sdk
Enter fullscreen mode Exit fullscreen mode

5. Connect your bot and start trading

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

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

// Your bot can now execute across 14 DeFi protocols
const balance = await client.getBalance();
const positions = await client.getDeFiPositions();
Enter fullscreen mode Exit fullscreen mode

What's Next

You now have professional-grade wallet infrastructure that scales with your trading operation. The complete WAIaaS documentation covers advanced topics like batch transactions, dry-run simulation, and integration with AI trading frameworks.

Ready to build? Get the code at GitHub or learn more at waiaas.ai.

Top comments (0)