# DegenAI x402 Trading Skill

This skill enables Claude Code to interact with DegenAI's x402 API for HyperLiquid trading.

## Base URL

```
https://degenai.dev
```

## Slash Commands

### /degenai positions <wallet>

Query active HyperLiquid positions for a wallet.

```bash
curl -s -X POST https://degenai.dev/x402/get_positions \
  -H "Content-Type: application/json" \
  -d '{"wallet":"WALLET_ADDRESS"}'
```

**Response:**
```json
{
  "success": true,
  "message": "Found 2 active position(s)",
  "data": {
    "positions": [
      {
        "coin": "ETH",
        "size": "0.5",
        "entryPrice": "2500.00",
        "unrealizedPnl": "125.50"
      }
    ],
    "count": 2,
    "wallet": "0x...",
    "accountValue": "1250.50"
  }
}
```

### /degenai account <wallet>

Get account summary with value, margin, and leverage.

```bash
curl -s -X POST https://degenai.dev/x402/get_account_summary \
  -H "Content-Type: application/json" \
  -d '{"wallet":"WALLET_ADDRESS"}'
```

**Response:**
```json
{
  "success": true,
  "data": {
    "accountValue": "10500.00",
    "marginUsed": "2100.00",
    "freeMargin": "8400.00",
    "leverage": "5x"
  }
}
```

### /degenai orders <wallet>

List open (unfilled) orders.

```bash
curl -s -X POST https://degenai.dev/x402/get_open_orders \
  -H "Content-Type: application/json" \
  -d '{"wallet":"WALLET_ADDRESS"}'
```

### /degenai history <wallet> [limit]

Get recent trade fills (default: 20).

```bash
curl -s -X POST https://degenai.dev/x402/get_trade_history \
  -H "Content-Type: application/json" \
  -d '{"wallet":"WALLET_ADDRESS", "limit": 20}'
```

## Natural Language Support

The skill also responds to natural language queries:

- "What are my positions on 0x...?"
- "Show me the account summary for 0x..."
- "Get recent trades for 0x..."
- "What open orders does 0x... have?"

### /degenai chart <coin> [interval] [indicators]

Generate a chart screenshot with technical indicators (requires x402 payment: $0.005).

```bash
curl -s -X POST https://degenai.dev/x402/chart_screenshot \
  -H "Content-Type: application/json" \
  -H "PAYMENT-SIGNATURE: base64EncodedPaymentSignature" \
  -d '{
    "coin": "ETH",
    "interval": "4h",
    "indicators": ["RSI:14", "SMA:200"]
  }'
```

**Request fields:**

| Field | Type | Required | Description |
|-------|------|----------|-------------|
| `coin` | string | Yes | Asset symbol (e.g. `BTC`, `ETH`, `SOL`) |
| `interval` | string | Yes | Candle interval: `1m`, `5m`, `15m`, `1h`, `4h`, `1d` |
| `indicators` | string[] | No | Up to 5 indicators in `Name:param` format (see below) |
| `days` | integer | No | History in days (default based on interval) |
| `width` | integer | No | Image width 200-1920 (default 1200) |
| `height` | integer | No | Image height 200-1080 (default 600) |

**Indicator format** -- three forms:

| Form | Example | Description |
|------|---------|-------------|
| No params | `MACD` | Uses default parameters |
| Single param | `RSI:14` | RSI with 14-period lookback |
| Multi param | `BollingerBands:20:2` | Bollinger Bands, 20-period, 2 std dev |

<!-- Keep in sync with Models/Indicators/ -- update when adding new indicators -->
**Available indicators (42 total):**

Trend: `ADX`, `ADXFull`, `Aroon`, `DEMA`, `EMA`, `HMA`, `Ichimoku`, `ParabolicSAR`, `Slope`, `SMA`, `SuperTrend`, `TEMA`, `VWMA`, `WMA`
Oscillators: `CCI`, `CMF`, `KST`, `MACD`, `MFI`, `ROC`, `RSI`, `Stochastic`, `StochasticRSI`, `TSI`, `WilliamsR`
Volatility: `ATR`, `BollingerBands`, `ChandelierExit`, `DonchianChannels`, `KeltnerChannels`, `StdDev`
Volume: `OBV`, `Volume`, `VWAP`
Pairs (append :ASSET): `Beta:ETH`, `Correlation:ETH`, `PriceRelativeStrength:ETH`, `SpreadRatio:ETH`
Custom: `HorizontalLinesIndicator`, `MondayRange`, `PivotPoints`, `StructuralLevels`

**Response:**
```json
{
  "success": true,
  "message": "Chart rendered for ETH (4h)",
  "data": {
    "image": "iVBORw0KGgoAAAANSUhEUg...",
    "coin": "ETH",
    "interval": "4h",
    "indicators": ["RSI:14", "SMA:200"],
    "width": 1200,
    "height": 600,
    "contentType": "image/png",
    "timestamp": "2026-03-23T12:00:00.000Z"
  }
}
```

The `data.image` field is the full PNG as a base64 string. No wallet authorization needed -- only payment.

## Capabilities

**FREE** (no payment required):

| Capability | Description |
|------------|-------------|
| `get_positions` | Query active perpetual positions |
| `get_open_orders` | List unfilled orders |
| `get_account_summary` | Portfolio overview |
| `get_trade_history` | Recent trade fills |

**PAID** (x402 payment required):

| Capability | Price | Description |
|------------|-------|-------------|
| `hyperliquid_order` | $0.10 + 0.01% | Execute trades (requires authorization) |
| `chart_screenshot` | $0.005 | Chart screenshot with indicators |

## Rate Limits

- 60 requests per minute per IP
- Rate limit headers included in responses:
  - `X-RateLimit-Limit`: 60
  - `X-RateLimit-Remaining`: Requests left
  - `X-RateLimit-Reset`: Unix timestamp

## Setup for Trading

To execute trades (not just queries), users need to:

1. Complete authorization at https://degenai.dev/erc8004#auth
2. Have USDC on Base or USDM on MegaETH for payment

## Error Handling

Common error codes:
- `MISSING_WALLET` - Include wallet in request body
- `RATE_LIMITED` - Wait for X-RateLimit-Reset
- `NOT_AUTHORIZED` - Complete /authorize flow for trading

## API Reference

- Full documentation: https://degenai.dev/erc8004
- Discovery endpoint: https://degenai.dev/x402
- OpenAPI spec: https://degenai.dev/x402/openapi.json

## ERC-8004 Identity

DegenAI is registered on Ethereum mainnet:
- Agent ID: 23121
- Contract: 0x8004A169FB4a3325136EB29fA0ceB6D2e539a432
