# Risk Management

## Monitor Liquidation Risk

{% code title="monitor\_liquidation\_risk.py" %}

```python
import requests

response = requests.get(
    "https://api.synthdata.co/insights/liquidation",
    headers={"Authorization": "Apikey YOUR_API_KEY"},
    params={"asset": "BTC"}
)

data = response.json()
current_price = data['current_price']

for level in data['data']:
    price_change = level['price_change']
    long_prob_24h = level['long_liquidation_probability']['24']
    short_prob_24h = level['short_liquidation_probability']['24']
    
    print(f"{price_change} move - Long liq: {long_prob_24h:.1%}, Short liq: {short_prob_24h:.1%}")
```

{% endcode %}

## Dynamic Stop-Loss

{% code title="dynamic\_stop\_loss.py" %}

```python
import requests

response = requests.get(
    "https://api.synthdata.co/insights/prediction-percentiles",
    headers={"Authorization": "Apikey YOUR_API_KEY"},
    params={"asset": "BTC"}
)

data = response.json()
current_price = data['current_price']
percentiles = data['forecast_future']['percentiles']

# Set stop-loss at 5th percentile of 24h forecast
stop_loss = percentiles[-1]['0.05']
```

{% endcode %}

## Portfolio VaR

{% code title="portfolio\_var.py" %}

```python
import requests

positions = [
    {"asset": "BTC", "entry": 88000, "value": 10000},
    {"asset": "ETH", "entry": 3000, "value": 5000}
]

total_value = sum(p['value'] for p in positions)
portfolio_var = 0

for position in positions:
    response = requests.get(
        "https://api.synthdata.co/insights/prediction-percentiles",
        headers={"Authorization": "Apikey YOUR_API_KEY"},
        params={"asset": position['asset']}
    )
    
    data = response.json()
    worst_case = data['forecast_future']['percentiles'][-1]['0.05']
    pnl = (worst_case - position['entry']) / position['entry']
    portfolio_var += position['value'] * pnl

var_5 = total_value + portfolio_var
```

{% endcode %}


---

# 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.synthdata.co/insights/risk-management.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.
