# Risk Flags

The `flags` array in the response identifies specific risk conditions detected for the trade. Use flags to understand *why* a score is elevated and to make targeted decisions in your agent logic.

## Flag Reference

### Order Book Flags

| Flag | Severity | Description |
|---|---|---|
| `thin_book` | Warning | Order book has insufficient depth relative to the trade size |
| `high_slippage` | Warning | Expected slippage is elevated |
| `extreme_slippage` | Critical | Expected slippage is very high, or trade exceeds available book depth |

### Liquidation Flags

| Flag | Severity | Description |
|---|---|---|
| `near_liquidation` | Critical | Position is close to liquidation price |
| `near_backstop` | Critical | Position is close to the backstop liquidation threshold |
| `high_leverage` | Warning | Effective leverage is elevated |
| `adl_risk` | Warning | Auto-deleveraging risk detected for a profitable high-leverage position |
| `partial_liquidation` | Warning | Large position where partial liquidation would cause amplified slippage |

### Funding Flags

| Flag | Severity | Description |
|---|---|---|
| `funding_anomaly` | Warning | Funding rate is statistically abnormal |
| `funding_expensive` | Warning | Projected annualized funding cost is elevated |
| `cex_funding_divergence` | Warning | Hyperliquid funding rate diverges significantly from CEX rates |

### Market Impact Flags

| Flag | Severity | Description |
|---|---|---|
| `high_impact` | Warning | Expected market impact is elevated |
| `low_volume` | Warning | Trade size is large relative to the asset's recent volume |

### VaR Flags

| Flag | Severity | Description |
|---|---|---|
| `high_var` | Warning | Value-at-Risk is elevated relative to notional |
| `limited_history` | Info | Insufficient historical data for full statistical analysis |
| `new_listing` | Info | Asset has limited trading history |

### Open Interest Flags

| Flag | Severity | Description |
|---|---|---|
| `oi_at_cap` | Critical | Asset is at the exchange's open interest cap |
| `oi_near_cap` | Warning | Open interest is approaching the cap |

### Portfolio Flags

| Flag | Severity | Description |
|---|---|---|
| `concentration_risk` | Warning | Portfolio is heavily concentrated in a single asset |
| `correlated_exposure` | Warning | Multiple positions are correlated in the same direction |

### Oracle Flags

| Flag | Severity | Description |
|---|---|---|
| `oracle_divergence` | Warning | Mark price diverges significantly from oracle/index price |

### Data Quality Flags

| Flag | Severity | Description |
|---|---|---|
| `stale_cache` | Info | Cached market data may be slightly delayed |

## Using Flags in Agent Logic

Flags let you build nuanced responses beyond just checking `recommendation`:

```python
result = requests.post(...).json()

# Block on critical flags
critical = [f for f in result["flags"] if f in ["extreme_slippage", "near_liquidation", "near_backstop", "oi_at_cap"]]
if critical:
    agent.abort(f"Critical risk: {critical}")

# Adjust for warnings
if "thin_book" in result["flags"]:
    # Reduce size to match available liquidity
    size = min(size, result["slippage"]["depth_50bps"] * 0.5)

if "funding_expensive" in result["flags"]:
    # Only enter if expected alpha exceeds funding cost
    if expected_return < result["funding"]["annualized_pct"]:
        agent.skip("Funding cost exceeds expected return")

if "correlated_exposure" in result["flags"]:
    # Already exposed to this direction, reduce allocation
    size *= 0.5
```
