# clearinghouseState

Get the complete clearinghouse state for a single user.

## POST Request

| Field  | Type   | Description                                                                                                                                                      |
| ------ | ------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `type` | string | Must be `"clearinghouseState"`                                                                                                                                   |
| `user` | string | Ethereum address (0x-prefixed, 42 characters)                                                                                                                    |
| `dex`  | string | Perp DEX name. Defaults to empty string (native DEX). Use `"ALL_DEXES"` to fetch clearinghouse state across all dexes (native + all HIP-3 dexes) in one request. |

### Usage

If ALL\_DEXES is not passed one call will consume 1 point.

When passing ALL\_DEXES as dex the points consumed is the number of dexes that are operational. Therefore, you should be mindful about if you really need to this.

{% tabs %}
{% tab title="cURL" %}

```bash
curl -X POST https://api.hydromancer.xyz/info \
  -H "Authorization: Bearer $HYDROMANCER_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "type": "clearinghouseState",
    "user": "0x0000000000000000000000000000000000000000"
  }'
```

{% endtab %}

{% tab title="Python" %}

```python
import requests
import os

response = requests.post(
    'https://api.hydromancer.xyz/info',
    json={
        'type': 'clearinghouseState',
        'user': '0x0000000000000000000000000000000000000000'
    },
    headers={
        'Authorization': f'Bearer {os.environ.get("HYDROMANCER_API_KEY")}',
        'Content-Type': 'application/json'
    }
)

print(response.json())
```

{% endtab %}

{% tab title="Javascript" %}

```javascript
import axios from 'axios';

try {
    const response = await axios.post('https://api.hydromancer.xyz/info', {
        type: 'clearinghouseState',
        user: '0x0000000000000000000000000000000000000000'
    }, {
        headers: {
            'Authorization': `Bearer ${process.env.HYDROMANCER_API_KEY}`,
            'Content-Type': 'application/json'
        }
    });

    console.log(response.data);
} catch (error) {
    console.error('Error:', error.message);
}
```

{% endtab %}
{% endtabs %}

<details>

<summary>Response</summary>

```json
{
  "marginSummary": {
    "accountValue": "50000.00",
    "totalMarginUsed": "10000.00",
    "totalNtlPos": "25000.00",
    "totalRawUsd": "45000.00",
    "withdrawable": "15000.00"
  },
  "crossMarginSummary": {
    "accountValue": "50000.00",
    "totalMarginUsed": "10000.00",
    "totalNtlPos": "25000.00",
    "totalRawUsd": "45000.00",
    "withdrawable": "15000.00"
  },
  "assetPositions": [
    {
      "position": {
        "coin": "BTC",
        "entryPx": "45000.00",
        "leverage": {
          "type": "cross",
          "value": 5
        },
        "liquidationPx": "40000.00",
        "marginUsed": "5000.00",
        "maxTradeSzs": ["100000.00", "100000.00"],
        "positionValue": "50000.00",
        "returnOnEquity": "0.10",
        "szi": "1.0",
        "unrealizedPnl": "500.00"
      },
      "type": "oneWay"
    }
  ],
  "time": 1234567890123
}
```

</details>

<details>

<summary>Response ALL_DEXES</summary>

```json
{
    "native": {
      "marginSummary": {
        "accountValue": "50000.00",
        "totalMarginUsed": "10000.00",
        "totalNtlPos": "25000.00",
        "totalRawUsd": "45000.00",
        "withdrawable": "15000.00"
      },
      "crossMarginSummary": {
        "accountValue": "50000.00",
        "totalMarginUsed": "10000.00",
        "totalNtlPos": "25000.00",
        "totalRawUsd": "45000.00",
        "withdrawable": "15000.00"
      },
      "assetPositions": [],
      "time": 1234567890123
    },
    "xyz": {
      "marginSummary": {
        "accountValue": "10000.00",
        "totalMarginUsed": "2000.00",
        "totalNtlPos": "5000.00",
        "totalRawUsd": "9000.00",
        "withdrawable": "3000.00"
      },
      "crossMarginSummary": {
        "accountValue": "10000.00",
        "totalMarginUsed": "2000.00",
        "totalNtlPos": "5000.00",
        "totalRawUsd": "9000.00",
        "withdrawable": "3000.00"
      },
      "assetPositions": [],
      "time": 1234567890123
    }, 
    ....
  }
```

</details>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.hydromancer.xyz/readme/rest-api/user-position-data/clearinghousestate.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
