---
title: Build a funding monitor
description: Page through Hyperliquid funding history, summarize it, and compare the live rate with Binance and Bybit.
url: https://hl-funding.thally.app/guides/funding-monitor
lastUpdated: 2026-12-04
last_updated: 2026-12-04
last_updated_source: git
lastVerified: 2026-12-04T00:00:00.000Z
---

# Build a funding monitor

Page through Hyperliquid funding history, summarize it, and compare the live rate with Binance and Bybit.

The [quickstart](/quickstart) shows the funding rate right now. A single hour
says little on its own: you want to know whether today's rate is high for that
market, and whether Hyperliquid pays more or less than other venues.

## What you'll achieve

In about 20 minutes you will build a reusable Node.js script that:

- Downloads a coin's full hourly funding history, past the API's 500-record limit.
- Summarizes it: average hourly and annual rate, and how often longs paid.
- Compares Hyperliquid with Binance and Bybit on the same hourly basis.
- Feeds a simple alert when funding moves away from its recent average.

When you finish, this command:

```bash
node funding-monitor.mjs ETH 30
```

prints a 30-day summary and a cross-venue comparison. This is real output from
the finished script:

```text
ETH: last 30 days (720 hourly payments)
  mean hourly rate : 0.00050 %
  mean APR         : 4.42 %
  hours longs paid : 76 %
Predicted next funding, annualized:
  BinPerp    9.52 %
  HlPerp     10.95 %
  BybitPerp  6.67 %
```

## Tools you'll use

- **[Hyperliquid Info API](https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/info-endpoint/perpetuals)**: the `fundingHistory` and
  `predictedFundings` request types, within its
  [rate limits](https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/rate-limits-and-user-limits).
- **[Node.js](https://nodejs.org/en/download) 18 or later**: built-in
  [`fetch`](https://nodejs.org/api/globals.html#fetch), and
  [ES modules](https://nodejs.org/api/esm.html) (`.mjs` files with `import`,
  `export`, and top-level `await`). Check with `node --version`.
- **A scheduler** (optional): cron or any job runner, for the alert.

Complete the [quickstart](/quickstart) first, so you know the request shape
and what an hourly rate means.

## 1. Wrap the API call

Every request goes to the same URL, so put it in one function. Read the body
as text first: on some errors the API returns a non-JSON message, and you
want to see it.

```js
const API_URL = 'https://api.hyperliquid.xyz/info';

async function info(body) {
  const res = await fetch(API_URL, {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify(body),
  });
  const text = await res.text();
  if (res.status === 500 && text === 'null' && body.coin) {
    throw new Error(`Unknown coin "${body.coin}". Use the exact name from metaAndAssetCtxs, e.g. ETH (not eth or ETH-PERP).`);
  }
  if (!res.ok) {
    throw new Error(`${body.type} failed with ${res.status}: ${text}`);
  }
  return JSON.parse(text);
}
```

The special case for `500` with the body `null` is deliberate. That is what
the API returns for a coin name it does not know, and the raw message gives no
hint. See [Troubleshooting](#troubleshooting).

## 2. Fetch the full history

`fundingHistory` takes a `coin` and a `startTime` in milliseconds (plus an
optional `endTime`, which defaults to now), and returns one record per hour,
oldest first:

```json
{ "coin": "ETH", "fundingRate": "0.0000125", "premium": "-0.0001010427", "time": 1796392800036 }
```

> **Warning:**
  One call returns **at most 500 records**, about 20 days of hourly data. A
  30-day request silently stops at 500. The official endpoint reference does
  not mention this limit, so check for it yourself.

To get everything, keep requesting from the last timestamp you received.
`startTime` is inclusive, so add 1 ms to avoid a duplicate row:

```js
const PAGE_LIMIT = 500;

async function getFundingHistory(coin, startTime) {
  const all = [];
  let cursor = startTime;
  while (true) {
    const page = await info({ type: 'fundingHistory', coin, startTime: cursor });
    all.push(...page);
    if (page.length < PAGE_LIMIT) break;
    cursor = page[page.length - 1].time + 1;
  }
  return all;
}
```

For 30 days this makes two calls and returns 720 records.

## 3. Summarize it

The mean hourly rate, annualized, tells you what holding a short would have
earned. The share of positive hours tells you how consistently longs paid.

```js
const HOURS_PER_YEAR = 24 * 365;

function summarize(history) {
  const rates = history.map((h) => Number(h.fundingRate));
  const mean = rates.reduce((sum, r) => sum + r, 0) / rates.length;
  return {
    hours: rates.length,
    meanHourlyPct: mean * 100,
    meanAprPct: mean * HOURS_PER_YEAR * 100,
    positiveShare: rates.filter((r) => r > 0).length / rates.length,
  };
}
```

In the example output, ETH averaged 4.42% APR while the current rate is
10.95%: funding is running well above its 30-day average.

## 4. Compare venues

`predictedFundings` returns the next expected funding rate on Hyperliquid
(`HlPerp`), Binance (`BinPerp`), and Bybit (`BybitPerp`) for each coin:

```json
["ETH", [
  ["BinPerp",   { "fundingRate": "0.00008695", "nextFundingTime": 1796428800000, "fundingIntervalHours": 8 }],
  ["HlPerp",    { "fundingRate": "0.0000125",  "nextFundingTime": 1796410800000, "fundingIntervalHours": 1 }],
  ["BybitPerp", { "fundingRate": "0.00006092", "nextFundingTime": 1796428800000, "fundingIntervalHours": 8 }]
]]
```

These rates are **per settlement interval**, not per hour. Binance's
0.00008695 every 8 hours is about 0.0000109 per hour, less than
Hyperliquid's 0.0000125, even though it looks seven times larger. Divide by
`fundingIntervalHours` before comparing. This is the same moment as the
sample output at the top of the page (9.52% vs 10.95%).

```js
async function compareVenues(coin) {
  const all = await info({ type: 'predictedFundings' });
  const entry = all.find(([name]) => name === coin);
  if (!entry) return null;
  const out = {};
  for (const [venue, data] of entry[1]) {
    // Skip venues that don't list the coin (null) or don't report an interval.
    if (!data || !data.fundingIntervalHours) continue;
    out[venue] = (Number(data.fundingRate) / data.fundingIntervalHours) * HOURS_PER_YEAR * 100;
  }
  return out; // annualized %, per venue
}
```

> **Note:**
  Intervals differ by coin, not only by venue. On 2026-12-04, Binance settled
  123 coins every 4 hours, 63 every 8 hours, and 3 every hour; Bybit's split
  was similar. Never assume 8 hours. Two kinds of entry are skipped: `null`
  entries (53 of 235 coins have at least one), where that exchange doesn't
  list the coin, and 21 Binance entries that omit `fundingIntervalHours`
  (the ones sampled all reported a rate of `"0.0"`). The official example
  response doesn't show `fundingIntervalHours` at all.

## 5. Run the complete script

### The full script

Save it as `funding-monitor.mjs`:

```js title="funding-monitor.mjs" expandable
// funding-monitor.mjs
// Summarizes a coin's funding history on Hyperliquid and compares the current
// Hyperliquid rate with Binance and Bybit, normalized to an hourly rate.
// Requires Node.js 18+. No API key, no dependencies.
// Run: node funding-monitor.mjs ETH 30   (coin, days of history)

const API_URL = 'https://api.hyperliquid.xyz/info';
const HOURS_PER_YEAR = 24 * 365;
const PAGE_LIMIT = 500; // fundingHistory returns at most 500 rows per call

async function info(body) {
  const res = await fetch(API_URL, {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify(body),
  });
  const text = await res.text();
  if (res.status === 500 && text === 'null' && body.coin) {
    throw new Error(`Unknown coin "${body.coin}". Use the exact name from metaAndAssetCtxs, e.g. ETH (not eth or ETH-PERP).`);
  }
  if (!res.ok) {
    throw new Error(`${body.type} failed with ${res.status}: ${text}`);
  }
  return JSON.parse(text);
}

// Fetch every hourly funding record between startTime and now.
// One call returns at most 500 rows, so page forward from the last timestamp.
export async function getFundingHistory(coin, startTime) {
  const all = [];
  let cursor = startTime;
  while (true) {
    const page = await info({ type: 'fundingHistory', coin, startTime: cursor });
    all.push(...page);
    if (page.length < PAGE_LIMIT) break;
    cursor = page[page.length - 1].time + 1; // startTime is inclusive
  }
  return all;
}

export function summarize(history) {
  const rates = history.map((h) => Number(h.fundingRate));
  const mean = rates.reduce((sum, r) => sum + r, 0) / rates.length;
  return {
    hours: rates.length,
    meanHourlyPct: mean * 100,
    meanAprPct: mean * HOURS_PER_YEAR * 100,
    positiveShare: rates.filter((r) => r > 0).length / rates.length,
  };
}

// predictedFundings returns [coin, [[venue, {fundingRate, nextFundingTime,
// fundingIntervalHours} | null], ...]]. Venues settle on different intervals
// (Hyperliquid every hour, Binance and Bybit every 1, 4 or 8 hours depending
// on the coin), so divide by the interval before comparing.
export async function compareVenues(coin) {
  const all = await info({ type: 'predictedFundings' });
  const entry = all.find(([name]) => name === coin);
  if (!entry) return null;
  const out = {};
  for (const [venue, data] of entry[1]) {
    // Skip venues that don't list the coin (null) or don't report an interval.
    if (!data || !data.fundingIntervalHours) continue;
    out[venue] = (Number(data.fundingRate) / data.fundingIntervalHours) * HOURS_PER_YEAR * 100;
  }
  return out; // annualized %, per venue
}

async function main() {
  const coin = process.argv[2] ?? 'ETH';
  const days = Number(process.argv[3] ?? 30);
  const startTime = Date.now() - days * 24 * 60 * 60 * 1000;

  const history = await getFundingHistory(coin, startTime);
  if (history.length === 0) {
    console.log(`No funding records for ${coin} in the last ${days} days.`);
    return;
  }
  const s = summarize(history);
  console.log(`${coin}: last ${days} days (${s.hours} hourly payments)`);
  console.log(`  mean hourly rate : ${s.meanHourlyPct.toFixed(5)} %`);
  console.log(`  mean APR         : ${s.meanAprPct.toFixed(2)} %`);
  console.log(`  hours longs paid : ${(s.positiveShare * 100).toFixed(0)} %`);

  const venues = await compareVenues(coin);
  if (venues) {
    console.log('Predicted next funding, annualized:');
    for (const [venue, apr] of Object.entries(venues)) {
      console.log(`  ${venue.padEnd(10)} ${apr.toFixed(2)} %`);
    }
  }
}

if (typeof process !== 'undefined' && process.argv?.[1]?.endsWith('funding-monitor.mjs')) {
  main().catch((err) => {
    console.error(err.message);
    process.exit(1);
  });
}
```

### Run it

The same file is in the repository as
[`examples/funding-monitor.mjs`](https://raw.githubusercontent.com/0xLisanAlGaib/hyperliquid-funding-guide/main/examples/funding-monitor.mjs).
It targets Node.js: outside Node (a browser console or an agent's JavaScript
sandbox), remove the `export` keywords and replace the last block with
`await main()` and a hard-coded coin and day count.

Run it with a coin and a number of days:

```bash
node funding-monitor.mjs ETH 30
node funding-monitor.mjs BTC 60
```

You should see the summary and venue table shown at the top of this page.

## Turn it into an alert

The functions are exported, so you can import them into a scheduled job. A
simple rule is to alert when the live rate is far from its recent average:

```js
import { getFundingHistory, summarize, compareVenues } from './funding-monitor.mjs';

const s = summarize(await getFundingHistory('ETH', Date.now() - 7 * 86_400_000));
const live = (await compareVenues('ETH')).HlPerp; // Hyperliquid's live predicted rate
if (Math.abs(live - s.meanAprPct) > 20) {
  console.log(`ETH funding ${live.toFixed(1)}% APR vs 7-day mean ${s.meanAprPct.toFixed(1)}%`);
}
```

Run it hourly with cron or any scheduler, since Hyperliquid settles funding every hour.

## Troubleshooting

| Symptom | Cause | Fix |
| --- | --- | --- |
| `415 Expected request with Content-Type: application/json` | Missing header | Send `Content-Type: application/json` on every request. |
| `422 Failed to deserialize the JSON body into the target type` | A required field is missing or has the wrong type, most often `startTime` sent as a string or left out | Send `startTime` as a number, e.g. `Date.now() - 86_400_000`. |
| History starts in May 2023 no matter what you ask for | `startTime` was sent in **seconds** instead of milliseconds. The API accepts it and returns the oldest records | Use milliseconds: `Date.now()`, not `Date.now() / 1000`. |
| `500` with body `null` | Unknown coin name | Coin names are case-sensitive and have no suffix: `ETH`, not `eth` or `ETH-PERP`. Copy names from `metaAndAssetCtxs`. |
| History stops after about 20 days | 500-record cap per response | Paginate as in [step 2](#2-fetch-the-full-history). |
| Venue comparison looks wrong by 4× or 8× | Comparing per-interval rates | Divide by `fundingIntervalHours` as in [step 4](#4-compare-venues). Intervals vary by coin. |
| `TypeError: Cannot read properties of null` in venue code | The venue does not list that coin | Skip `null` entries. |
| A recent `startTime` returns `[]` | No settlement yet in that window | Funding settles on the hour. Use a window of at least one hour. |
| Requests start failing under load | Rate limiting: REST requests share a weight budget of 1200 per minute; most info requests cost 20, and `fundingHistory` adds weight for every 20 records returned | Cache `metaAndAssetCtxs` and `predictedFundings` (one call covers every coin) and space out history calls. A 45-day history for three coins is nine calls, well within budget. See Hyperliquid's [rate limits](https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/rate-limits-and-user-limits). |

## Related

- [Introduction](/introduction): how to read a funding rate correctly.
- [Hyperliquid funding mechanics](https://hyperliquid.gitbook.io/hyperliquid-docs/trading/funding): the official formula and cap.
- [Info endpoint reference](https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/info-endpoint/perpetuals): every perpetuals request type.