funding-arb-screener
by tordagaz-ops
README.md
# funding-arb-screener
**Perpetual-futures funding rates from five exchanges, in one call — with the
delta-neutral spread, the annualized carry and the break-even time already
worked out.**
Funding is the one payment in crypto that repeats every few hours and is easy to
miss. A pair paying 0.01% every eight hours is not "0.01%" — it is 10.95% a
year, and the same pair on a different venue may be paying 0.008%, which is a
real, market-neutral spread you can hold with two opposing positions and no
directional risk. Finding that spread by hand means five tabs, five symbols
spellings and a calculator.
This server does it in one request. Ask for `BTC/USDT` and get back every venue
that trades it, its current rate, the interval that rate applies to, the
annualized equivalent, the mark price and 24-hour turnover — plus which venue
you should sell and which you should buy, what that pair of legs is worth per
year, and how many funding periods it takes just to pay the trading fees.
```text
get_funding_rates("BTC/USDT") → 5 venues + the best spread
scan_funding_opportunities() → the whole market, ranked
get_funding_history("BTC/USDT","bybit") → is this rate normal, or a squeeze?
list_venues() → which exchanges are answering
```
- Works with **no API key** — every venue endpoint used here is public.
- **One tool, five venues.** Exchanges are a parameter, never a different repo.
- **Fails soft.** A venue that is down returns a named failure next to the data
from the venues that are up. You never get an empty result because one
exchange had a bad minute.
- **Documented in English, Spanish and Russian**, including the tool
descriptions the model reads. Set `MCP_LOCALE`.
[Español](README.es.md) · [Русский](README.ru.md)
---
## Why a spread, and not just a rate
A funding rate on its own tells you what the crowd is doing. The spread between
two venues tells you what you can *do*:
1. Sell the perpetual on the venue with the **highest** rate.
2. Buy the same perpetual on the venue with the **lowest** rate.
3. Both legs are the same asset, so price moves cancel. Each funding tick, you
receive on the short leg and pay on the long leg; the difference is yours.
Two numbers decide whether that is worth the trouble, and this server returns
both for every symbol:
| Field | Meaning |
| --- | --- |
| `spread_annualized_pct` | The net carry if the current rates held for a year, in percent. |
| `breakeven_periods` | How many funding periods of edge it takes to cover the round-trip fees. |
| `breakeven_days` | The same thing in days, using the two legs' intervals. |
| `price_gap_bps` | How much higher the short leg's mark price is, in basis points. Positive is good: you sell higher and buy lower. |
The break-even assumes **four fee touches** — two legs, opened and closed — at
`4 × fee_bps`. The default `fee_bps=5.5` is a taker fee on either side; pass
your own.
---
## Install
```bash
pip install mcp-funding-arb-screener
```
Or from this repository:
```bash
git clone https://github.com/tordagaz-ops/funding-arb-screener
cd funding-arb-screener
python -m venv .venv
.venv\Scripts\activate # Windows
source .venv/bin/activate # macOS / Linux
pip install -e ".[dev]"
```
The package needs Python 3.10+ and installs `mcp` and `httpx`. Nothing else.
## Run
```bash
python -m mcp_funding_arb # stdio, for a desktop client
MCP_TRANSPORT=http python -m mcp_funding_arb # http on port 8000
MCP_TRANSPORT=sse python -m mcp_funding_arb # sse on port 8000
```
A client configuration looks like this:
```json
{
"mcpServers": {
"funding-arb-screener": {
"command": "python",
"args": ["-m", "mcp_funding_arb"],
"env": { "MCP_LOCALE": "en" }
}
}
}
```
---
## The four tools
### `get_funding_rates`
One symbol, every venue that lists it.
| Parameter | Type | Default | Notes |
| --- | --- | --- | --- |
| `symbol` | string | — | `BTC/USDT`, `BTCUSDT`, `btc-usdt` all work. |
| `venues` | list or string | all five | `["bybit","okx"]` or `"bybit, okx"`. |
| `fee_bps` | number | `5.5` | Per-leg taker fee used for break-even. |
```json
{
"symbol": "BTC/USDT",
"venue_count": 5,
"spread": { "short_venue": "okx", "long_venue": "gate", "spread_annualized_pct": 4.37,
"breakeven_days": 18.4, "price_gap_bps": 0.67 },
"venues": [
{ "venue": "okx", "funding_rate": 8.74e-05, "funding_interval_hours": 8.0,
"annualized_pct": 9.57, "mark_price": 60816.9, "turnover_24h": 9.32e9 }
],
"failed_venues": {}
}
```
Measured on a September evening, five venues answered `BTC/USDT` in **1.4
seconds** — Bybit 7.42%/yr, Binance 8.73%, OKX 9.57%, Bitget 5.80%, Gate 5.20%,
for a 4.37% spread with a 0.67 bps price gap and an 18-day break-even.
### `scan_funding_opportunities`
The whole market, or a shortlist you name.
| Parameter | Type | Default | Notes |
| --- | --- | --- | --- |
| `symbols` | list or string | — | Narrow the scan to these pairs. |
| `venues` | list or string | all five | Limit the fleet. |
| `min_annualized_pct` | number | `5.0` | Drop rows below this carry. |
| `min_turnover_24h` | number | `1000000` | Drop illiquid pairs. |
| `limit` | integer | `10` | Rows returned, 1–50. |
| `shortlist` | integer | `40` | Symbols kept after ranking by turnover, 2–200. |
| `sort` | string | `annualized` | `annualized`, `spread` or `turnover`. |
Measured: **1,233 symbols in 2.5 seconds**. The scan ranks every venue's whole
book by 24-hour turnover, keeps the top `shortlist`, then fetches funding for
just those symbols on just the venues that list them — two phases, no symbol
fan-out into the void.
### `get_funding_history`
Was that rate real, or one crowded hour?
| Parameter | Type | Default | Notes |
| --- | --- | --- | --- |
| `symbol` | string | — | |
| `venue` | string | `bybit` | One venue: history is per exchange. |
| `points` | integer | `20` | 1–200 settlements. |
Returns the samples plus `mean_rate`, `median_rate`, `stdev_rate`,
`positive_share`, `annualized_mean_pct` and `cumulative_pct` — what you would
have paid or received over the window, and how reliable the sign is. Measured on
a 30-point Bybit window: mean 2.28e-05 per 8 h (2.50%/yr), positive 73.3% of the
time.
### `list_venues`
Which exchanges are answering right now. `probe=false` returns the configured
list without touching the network — useful as a health check for your own
monitoring. `probe=true` (default) asks each venue for `BTC/USDT` and reports
latency and error code per venue.
---
## Failure model
Every tool returns a dict. Nothing raises at the caller, and a partial answer is
preferred to no answer:
```json
{
"error": "no_data",
"message": "No exchange returned a quote for FOO/USDT.",
"failed_venues": { "bybit": "unknown_symbol", "okx": "timeout" }
}
```
| Code | Meaning |
| --- | --- |
| `empty_symbol` | The symbol arrived blank. |
| `invalid_symbol` | Not a recognisable pair. |
| `unknown_symbol` | A valid pair, but no venue lists it. |
| `unknown_venue` | You asked for an exchange this server does not carry. |
| `too_few_venues` | Fewer than two venues: there is no spread to compute. |
| `invalid_limit`, `invalid_number`, `invalid_sort` | Bad argument, named. |
| `timeout`, `network_error` | A venue did not answer in 3.5 s. |
| `upstream_rejected`, `bad_payload` | The venue answered with an error or nonsense. |
Timeouts are per venue and per attempt: 3.5 s, two attempts, with a 1–5 s
ticker cache in front. A call therefore has a ceiling of about 6 s even when
everything is on fire, and partial results come back inside it.
## Exchanges
| Venue | Symbol form | Funding endpoint | Interval source |
| --- | --- | --- | --- |
| Bybit | `BTCUSDT` | `/v5/market/funding/history` | `instruments-info.fundingInterval` (minutes) |
| Binance | `BTCUSDT` | `/fapi/v1/fundingRate` | 8 h, or `fundingInfo` when published |
| OKX | `BTC-USDT-SWAP` | `/api/v5/public/funding-rate-history` | derived from two settlement stamps |
| Bitget | `BTCUSDT` | `/api/v2/mix/market/history-fund-rate` | 8 h default |
| Gate.io | `BTC_USDT` | `/api/v4/futures/usdt/funding_rate` | 8 h |
Every adapter speaks the venue's own dialect: Bybit reports errors inside an
HTTP 200 body, numbers arrive as strings almost everywhere, Binance returns a
bare object instead of a one-element list, and Gate's market-wide ticker
endpoint never answers at all — which is why Gate is queried contract by
contract, four at a time, and why a whole-market scan gives it a short list
rather than the universe.
### About that 7,788% row
Some venues fund hourly and others every eight hours. Annualizing each leg on
its own clock is the correct way to compare *who pays what per year*, but it
means a 1-hour squeeze on one venue against an 8-hour rate on another can
produce a five-digit annualized figure that no one will ever collect. Read the
row, not the rank: `short_interval_hours` and `long_interval_hours` are always
returned, `breakeven_days` tells you how fast the edge turns into money, and
`min_turnover_24h` keeps the thin pairs out. Funding rates are also the most
volatile number in a perpetual; the annualized figure is a snapshot, not a
promise.
## Localization
`MCP_LOCALE` selects the language of tool titles, descriptions, parameter
documentation and every error message:
```bash
MCP_LOCALE=es python -m mcp_funding_arb
MCP_LOCALE=ru python -m mcp_funding_arb
```
`en` is the default and is also what an unknown value falls back to. Symbol
names, venue names and numeric fields are never translated, so a client can
switch language mid-conversation without touching its parsing.
## Tests
```bash
pytest # everything: 142 tests
pytest -m "not live" # offline only: unit + protocol, no network
pytest -m live # only the tests that talk to real exchanges
```
The suite has four layers, each with a job:
- **Unit** — funding arithmetic, each venue's wire format, the scan's two-phase
plumbing, all through `httpx.MockTransport`. No network, no sleep.
- **Tool level** — the four tools driven through a real MCP client session, so
the schema, the annotations and the JSON on the wire are checked, not just
the Python.
- **End to end** — the server started as a subprocess and spoken to in raw
JSON-RPC over stdio, the way a real client does it.
- **Live** — the five exchanges, marked so a laptop without a connection can
skip them instead of failing.
## Pricing
Published on MCPize as a pay-per-call tool. A single screening call covers five
exchanges and the whole scan; you pay once per MCP call, not per HTTP request
the server makes on your behalf.
## Licence
MIT. See [LICENSE](LICENSE).
This server cannot be deployed
Maintenance
ActivityMaintained
ResponsivenessNo recent community issues