DEV Community

Cover image for PERP_ALLOWED_MARKETS: Lock Your AI Agent to Specific Futures Markets
Wallet Guy
Wallet Guy

Posted on

PERP_ALLOWED_MARKETS: Lock Your AI Agent to Specific Futures Markets

Your trading bot found a profitable perpetual futures opportunity, but executing on the wrong market could blow your risk limits. When you're running automated strategies across multiple derivatives exchanges, market restrictions become critical for capital preservation.

Trading bots operating in DeFi perpetual futures face a dangerous problem: unlimited market access. Your algorithm might identify profitable opportunities on obscure, illiquid markets that align with your strategy but violate your risk management rules. Without proper controls, a bot optimized for ETH-PERP might start trading exotic altcoin futures, exposing your capital to unexpected volatility and liquidity risks.

Why Market Restrictions Matter for Algo Trading

Professional trading operations don't give algorithms unlimited market access. Traditional firms use position limits, approved instrument lists, and risk controls to prevent strategies from wandering into unsuitable markets. But most DeFi wallet solutions lack these institutional-grade controls.

Your perpetual futures bot needs the same discipline. Maybe your strategy works well on major pairs (ETH-PERP, BTC-PERP) but hasn't been backtested on exotic markets. Or you want to limit exposure to specific sectors while your bot explores opportunities across protocols like Hyperliquid and Drift.

Without market restrictions, your bot might execute technically valid but strategically dangerous trades.

PERP_ALLOWED_MARKETS: Surgical Market Control

WAIaaS provides the PERP_ALLOWED_MARKETS policy type specifically for perpetual futures trading restrictions. This policy creates a whitelist of approved markets across all supported derivatives protocols, blocking any futures trades outside your defined universe.

The policy integrates with WAIaaS's 15 DeFi protocol providers, including Hyperliquid integration for perpetual futures, spot trading, and sub-accounts, plus Drift support for Solana-based derivatives trading.

Here's how to lock your trading bot to specific perpetual markets:

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_ALLOWED_MARKETS",
    "rules": {
      "allowed_markets": [
        {"protocol": "hyperliquid", "market": "ETH-PERP"},
        {"protocol": "hyperliquid", "market": "BTC-PERP"},
        {"protocol": "drift", "market": "SOL-PERP"},
        {"protocol": "drift", "market": "ETH-PERP"}
      ]
    }
  }'
Enter fullscreen mode Exit fullscreen mode

Now your trading bot can only execute perpetual futures trades on these four specific markets. Any attempt to trade other instruments gets blocked at the policy layer, before execution.

Multi-Protocol Trading with Unified Risk Controls

Your arbitrage bot might identify spreads between Hyperliquid and Drift, requiring simultaneous positions across protocols. WAIaaS handles this through a single API while maintaining consistent risk controls.

Execute a Hyperliquid perpetual trade:

curl -X POST http://127.0.0.1:3100/v1/actions/hyperliquid/perp-order \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer wai_sess_<token>" \
  -d '{
    "market": "ETH-PERP",
    "side": "long",
    "size": "1.5",
    "orderType": "market",
    "reduceOnly": false
  }'
Enter fullscreen mode Exit fullscreen mode

Execute a Drift position in the same strategy:

curl -X POST http://127.0.0.1:3100/v1/actions/drift/perp-order \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer wai_sess_<token>" \
  -d '{
    "market": "SOL-PERP",
    "side": "short",
    "baseAssetAmount": "100",
    "orderType": "market"
  }'
Enter fullscreen mode Exit fullscreen mode

Both trades go through the same PERP_ALLOWED_MARKETS policy check. If your bot attempts to trade an unauthorized market on either protocol, the transaction gets denied before reaching the exchange.

Combining Market Restrictions with Other Trading Controls

Professional trading bots need multiple risk layers. WAIaaS's 21 policy types work together to create comprehensive trading controls.

Combine market restrictions with position size 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_POSITION_USD",
    "rules": {
      "max_position_usd": 50000,
      "per_market_limits": {
        "ETH-PERP": 25000,
        "BTC-PERP": 25000,
        "SOL-PERP": 10000
      }
    }
  }'
Enter fullscreen mode Exit fullscreen mode

Add leverage restrictions for additional safety:

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": {
      "max_leverage": 10,
      "market_overrides": {
        "ETH-PERP": 5,
        "BTC-PERP": 3
      }
    }
  }'
Enter fullscreen mode Exit fullscreen mode

Now your bot operates within a complete risk framework: only approved markets, position size limits, and leverage caps. All enforced automatically at the transaction level.

Gas Conditional Execution for MEV Protection

High-frequency trading bots need optimal execution costs. WAIaaS includes gas conditional execution — transactions execute only when gas price meets your threshold, protecting MEV strategies from unprofitable execution during network congestion.

Your bot can queue perpetual trades that only execute when gas conditions are favorable, maintaining strategy profitability across market conditions.

Quick Start: Set Up Market-Restricted 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 get session token:
npm install -g @waiaas/cli
waiaas init
waiaas start
waiaas wallet create --name "perp-bot" --chain "ethereum" --environment "mainnet"
waiaas session create --wallet-id <wallet-uuid>
Enter fullscreen mode Exit fullscreen mode
  1. Set market restrictions policy:
curl -X POST http://127.0.0.1:3100/v1/policies \
  -H "Content-Type: application/json" \
  -H "X-Master-Password: <your-password>" \
  -d '{
    "walletId": "<wallet-uuid>",
    "type": "PERP_ALLOWED_MARKETS",
    "rules": {
      "allowed_markets": [
        {"protocol": "hyperliquid", "market": "ETH-PERP"}
      ]
    }
  }'
Enter fullscreen mode Exit fullscreen mode
  1. Integrate with your trading bot:
import { WAIaaSClient } from '@waiaas/sdk';

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

// Your bot's perpetual trading logic
const position = await client.executeAction('hyperliquid', 'perp-order', {
  market: 'ETH-PERP',  // Only allowed market
  side: 'long',
  size: '1.0',
  orderType: 'market'
});
Enter fullscreen mode Exit fullscreen mode
  1. Test market restriction enforcement: Try executing a trade on an unauthorized market — it should get blocked by the policy engine before reaching the exchange.

Ready to build institutional-grade trading infrastructure? Explore the complete codebase at https://github.com/minhoyoo-iotrust/WAIaaS and learn more about professional DeFi automation at https://waiaas.ai.

What's Next

Market restrictions are just one layer of WAIaaS's comprehensive risk management system. You can combine perpetual market controls with spending limits, time restrictions, and approval workflows to create exactly the risk profile your trading operation needs.

Top comments (0)