# fundingRates

{% hint style="info" %}
New endpoint - this endpoint is not a part of original Hyperliquid API and is added by us for builder convenience.
{% endhint %}

Broadcasts the funding rate for every coin once per hour (\~290 coins per event). Clients can calculate per-user funding payments as `funding_rate * position_size`.

### Subscribe

```json
{
    "method": "subscribe",
    "subscription": {
        "type": "fundingRates"
    }
}
```

### Unsubscribe

```json
{
    "method": "unsubscribe",
    "subscription": {
        "type": "fundingRates"
    }
}
```

### Update data format

One message per hour containing all coins and their funding rates for that period.

```json
{
    "type": "fundingRates",
    "seq": 1,
    "cursor": "500:1704067200000",
    "data": {
        "timestamp": 1704067200000,
        "rates": [
            { "coin": "BTC", "funding_rate": "0.0000125" },
            { "coin": "ETH", "funding_rate": "-0.0000638576" },
            { "coin": "SOL", "funding_rate": "0.0000125" },
            { "coin": "hyna:BTC", "funding_rate": "-0.0000373477" },
            { "coin": "xyz:GOLD", "funding_rate": "0.0000067899" }
        ]
    }
}
```

### Field reference

| Field                  | Type   | Description                                                                                  |
| ---------------------- | ------ | -------------------------------------------------------------------------------------------- |
| `timestamp`            | number | Block timestamp when funding was applied (milliseconds since epoch)                          |
| `rates`                | array  | Array of per-coin funding rate objects                                                       |
| `rates[].coin`         | string | Coin/market name, including DEX prefix (e.g. `"ETH"`, `"hyna:BTC"`, `"xyz:GOLD"`)            |
| `rates[].funding_rate` | string | Funding rate as a decimal string with full precision (e.g. `"0.0000125"`, `"-0.0007643369"`) |

### Examples

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

```javascript
const WebSocket = require('ws');

const ws = new WebSocket(`wss://api.hydromancer.xyz/ws?token=${process.env.HYDROMANCER_API_KEY}`);

ws.on('message', (data) => {
    const msg = JSON.parse(data);

    if (msg.type === 'connected') {
        ws.send(JSON.stringify({
            method: 'subscribe',
            subscription: {
                type: 'fundingRates'
            }
        }));
    } else if (msg.type === 'ping') {
        ws.send(JSON.stringify({ type: 'pong' }));
    } else if (msg.type === 'fundingRates') {
        console.log(`Funding rates at ${new Date(msg.data.timestamp).toISOString()}: ${msg.data.rates.length} coins`);
        for (const { coin, funding_rate } of msg.data.rates) {
            console.log(`  ${coin}: ${funding_rate}`);
        }
    }
});
```

{% endtab %}

{% tab title="Python" %}

```python
import websocket
import json
import os
from datetime import datetime, timezone

def on_message(ws, message):
    msg = json.loads(message)

    if msg['type'] == 'connected':
        ws.send(json.dumps({
            "method": "subscribe",
            "subscription": {
                "type": "fundingRates"
            }
        }))
    elif msg['type'] == 'ping':
        ws.send(json.dumps({'type': 'pong'}))
    elif msg['type'] == 'fundingRates':
        ts = datetime.fromtimestamp(msg['data']['timestamp'] / 1000, tz=timezone.utc)
        rates = msg['data']['rates']
        print(f"Funding rates at {ts.isoformat()}: {len(rates)} coins")
        for r in rates:
            print(f"  {r['coin']}: {r['funding_rate']}")
    elif msg['type'] == 'subscriptionUpdate':
        print(f"Subscription update: {msg}")
    elif msg['type'] == 'error':
        print(f"Error: {msg}")

ws = websocket.WebSocketApp(
    f"wss://api.hydromancer.xyz/ws?token={os.environ.get('HYDROMANCER_API_KEY')}",
    on_message=on_message
)
ws.run_forever()
```

{% endtab %}
{% endtabs %}

#### Common errors

1. ```
   Connection timeout - Respond to ping messages
   ```
2. ```
   Invalid API key
   ```


---

# 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/websocket/fundingrates.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.
