←All Agent Setups
Risk-governed perps on HyperliquidMedium complexityPerps traders

OpenClaw + CoinGlass + RiskState + Hyperliquid

Perpetual-futures trading agent. CoinGlass supplies funding, open interest, and liquidation context; RiskState caps notional exposure and blocks leverage when a directional squeeze is detected; Hyperliquid executes the perp on-chain, non-custodially, via a no-withdraw API wallet.

How it works

1

CoinGlass provides market intelligence

Your agent queries CoinGlass for real-time market data — funding rates, open interest, liquidation maps, CVD, and ETF flows. Hobbyist or starter tier.

2

RiskState gates the decision

Before any execution, your agent calls POST /v1/risk-state. The response contains max_size_fraction (position ceiling), allowed_actions (what’s permitted), and structural_blockers (hard stops). If blockers exist, the agent halts. Otherwise, it sizes the trade within the policy limit. 30+ signals scored in real-time, 60-second cache, SHA-256 audit hash.

3

Hyperliquid executes within limits

The trade is submitted to Hyperliquid using built-in wallet actions. Transaction signing handled by the Agentic Wallet — no private key management. Position size never exceeds what RiskState permitted.

Integration code

Copy this into your project. Replace the API keys with your own.

openclaw_riskstate_hyperliquid.py
import requests
from hyperliquid.exchange import Exchange
from hyperliquid.utils import constants

# 1. Derivatives context from CoinGlass (funding / OI / liquidations)
funding = requests.get(
    "https://open-api-v3.coinglass.com/api/futures/funding-rate",
    headers={"coinglassSecret": COINGLASS_KEY},
    params={"symbol": "BTC"}
).json()

# 2. Get risk policy from RiskState (perps interpretation)
policy = requests.post(
    "https://api.riskstate.ai/v1/risk-state",
    headers={"Authorization": f"Bearer {RISKSTATE_KEY}"},
    json={"asset": "BTC", "include_details": True}
).json()

max_size = policy["exposure_policy"]["max_size_fraction"]  # max notional %
bias = policy["exposure_policy"]["direction_bias"]
blockers = policy["risk_flags"]["structural_blockers"]
squeeze = policy["positioning"]["squeeze_direction"]

# 3. Enforce governance before opening a leveraged perp
if "SQUEEZE_RISK" in blockers:
    print(f"BLOCKED: squeeze risk ({squeeze}) - no leveraged entry")
elif bias == "NEUTRAL":
    print("No directional edge - stand aside")
else:
    # 4. Size notional within the cap, choose your own leverage
    leverage = 5
    notional = portfolio_value * max_size      # 0.33 -> 33% notional
    is_buy = bias == "LONG_PREFERRED"
    # no-withdraw API wallet: can trade, cannot withdraw
    ex = Exchange(agent_wallet, constants.MAINNET_API_URL)
    ex.update_leverage(leverage, "BTC")
    ex.market_open("BTC", is_buy, notional / mark_price)
    print(f"Opened {'LONG' if is_buy else 'SHORT'} {notional:.0f} @ {leverage}x")

What your agent receives from RiskState

Every call to /v1/risk-state returns these three blocks. Your agent reads them in order.

Exposure Policy

Binding
  • max_size_fraction — hard ceiling
  • leverage_allowed — boolean
  • allowed_actions — enum list
  • blocked_actions — enum list

Market Intelligence

Context
  • tactical_state — LEAN BULL, etc.
  • market_regime — TREND, RANGE...
  • binding_constraint — source + why
  • risk_flags — blockers + risks

Auditability

Trust
  • policy_hash — SHA-256
  • confidence_score — 0-100
  • data_sources — per-signal
  • ttl_seconds — cache hint

Start building

Get an API key in under a minute. Free during beta.