Skip to main content
Glama
liquidation-map

liquidation-map

by tordagaz-ops
README.md
# liquidation-map

Estimated liquidation clusters for Binance USD-M perpetuals, and the measured positioning behind them — in one server, without an API key.

**Documentation:** [English](README.md) · [Español](README.es.md) · [Русский](README.ru.md)

Binance stopped publishing forced orders. `/fapi/v1/allForceOrders` answers **404**, and the real margin brackets behind `/fapi/v1/leverageBracket` answer **401** without a signed request. Every "liquidation map" that shows you exact numbers today is either charging you for an archive or inventing levels. This server does neither: it takes the open interest and price history the exchange *does* still publish, works out which side opened in each bucket, and places those entries at the leverage tiers you ask for — returning `kind: "estimate"` and the share of the flow it could actually attribute, so you can see how much of the map is modelled and how much is measured.

## The problem this server exists for

The exchange publishes two things that matter, and neither is a liquidation:

| What Binance publishes | What it tells you | What it does not |
| --- | --- | --- |
| `/futures/data/openInterestHist` | total notional open per bucket, all accounts together | who is long, who is short, at what entry |
| `/fapi/v1/klines` | the traded price of the same bucket | nothing about margin |

From those two series, aligned bucket by bucket, you can recover the *direction* of the change: open interest up while price goes up means longs are being opened; open interest up while price goes down means shorts are. Those entries are then placed at a price where a position of that leverage would run out of margin. That is a model with two assumptions stated up front — an entry price per bucket, and one maintenance margin for every position — and the server repeats both in every payload's `method`.

The second half of the server is a different question, and it is measured, not modelled: are the people who are already positioned crowded on one side? Account ratios, top-trader ratios, top-position ratios and taker flow are all published and all live here.

```
  /futures/data/openInterestHist          /fapi/v1/klines
        │  notional per hour                    │  VWAP per hour
        └──────────────┬───────────────────────┘
                       │  joined on the bucket's open time
                       ▼
        ┌──────────────────────────────────────────────┐
        │  OI up   + price up    ->  long added        │
        │  OI up   + price down  ->  short added       │
        │  OI down + price up    ->  short closed      │
        │  OI down + price down  ->  long closed       │
        │  newest bucket         ->  still forming     │
        └───────────────────────┬──────────────────────┘
                                ▼
        ┌──────────────────────────────────────────────┐
        │  entry x (1 - (1 - mmr) / leverage)  -> long │
        │  entry x (1 + (1 - mmr) / leverage)  -> short│
        │  mmr = 0.004, one tier, stated in every call │
        └───────────────────────┬──────────────────────┘
                                ▼
        levels below the mark (longs) and above it (shorts),
        within the band you asked for, heaviest first
```

## The four tools

| Tool | What you get | Defaults |
| --- | --- | --- |
| `liquidation_map` | Estimated levels for each leverage tier, the nearest level on each side, the heaviest "magnet", the share of the flow that was attributable, and the seven sentences of method | `leverage="10,25,50,100"`, `period="1h"`, `limit=200`, `band_pct=15`, `cluster_pct=0.25`, `mmr=0.004` |
| `open_interest_history` | Every bucket with its flow label, the 24h change in notional and in price, and the flow split | `period="1h"`, `limit=100` |
| `positioning` | Funding (now, next settlement, last three), basis, three long/short ratios with their window averages and percentiles, taker flow, and a crowding verdict with its inputs | `period="1h"`, `limit=100` |
| `list_symbols` | Which contracts exist, sorted by turnover or 24h change, with a text filter | `sort="volume"`, `limit=25` |

## Install and run

```bash
pip install -e .
python -m mcp_liquidation_map          # stdio, the default
MCP_TRANSPORT=sse python -m mcp_liquidation_map
```

```json
{
  "mcpServers": {
    "liquidation-map": {
      "command": "python",
      "args": ["-m", "mcp_liquidation_map"],
      "env": { "MCP_LOCALE": "en" }
    }
  }
}
```

`MCP_LOCALE` takes `en`, `es` or `ru`. It changes every sentence, description and note; it never changes a number, a symbol name or an interval code.


## Deploy to Render (free)

The repository ships a `render.yaml` Blueprint, so the server runs on a public
HTTPS URL with no API key, no card and no Docker step.

1. Open the Render dashboard and press **New -> Blueprint**
   (<https://dashboard.render.com/blueprints>).
2. Connect GitHub and give Render access to this repository.
3. Select the repository and press **Apply**. Render reads `render.yaml`:
   build `pip install .`, start `python -m mcp_liquidation_map`, health check `/health`.
4. When the first build finishes (2-4 minutes), open the URL Render shows:
   `https://liquidation-map.onrender.com`.

That page is the human view of the server: it lists every tool. The MCP endpoint is
`https://liquidation-map.onrender.com/mcp` (Streamable HTTP), so a client entry looks like:

```json
{"mcpServers": {"liquidation-map": {"url": "https://liquidation-map.onrender.com/mcp"}}}
```

`curl https://liquidation-map.onrender.com/health` answers with the tool count, which is the
quickest way to prove the deployment is alive.

Free-plan notes: the instance sleeps after 15 minutes without traffic, so the next
request takes about 50 seconds; 512 MB is enough for this server. If you rename the
service or attach a domain, also update `MCP_PUBLIC_HOST` in `render.yaml`, or the
Host check answers `421`.

## What a call returns

```json
{
  "status": "ok",
  "kind": "estimate",
  "symbol": "BTCUSDT",
  "mark_price": 60680.0,
  "leverage_tiers": [10, 25, 50, 100],
  "window": {
    "interval": "1h", "buckets": 200, "mmr": 0.004,
    "from": "2026-11-18T11:00:00+00:00", "to": "2026-11-26T18:00:00+00:00"
  },
  "coverage": {
    "attributed_usd": 2630404758.25,
    "total_flow_usd": 5934488573.42,
    "unclear_flow_usd": 719395866.06,
    "attributed_share": 0.4432,
    "buckets_used": 60,
    "buckets_read": 200,
    "crossed": 18
  },
  "clusters": [
    {"price": 54824.07206, "side": "long", "leverage": 10,
     "notional_usd": 311916605.63, "entries": 7, "distance_pct": -9.651, "crossed": false}
  ],
  "totals": {
    "levels": 93,
    "long_usd": 6248985997.95, "short_usd": 2468940440.18,
    "long_share": 0.7168, "overhang": 2.531,
    "nearest_long":  {"price": 60590.64311, "side": "long", "leverage": 100, "distance_pct": -0.147,
                      "notional_usd": 35623197.56, "entries": 1, "crossed": false},
    "nearest_short": {"price": 60730.63318, "side": "short", "leverage": 25, "distance_pct": 0.083,
                      "notional_usd": 55682118.8, "entries": 1, "crossed": false},
    "magnet": {"price": 60282.12383, "side": "long", "leverage": 100, "distance_pct": -0.656,
               "notional_usd": 311916605.63, "entries": 7, "crossed": false, "weight": 269895093.0}
  },
  "summary_line": "BTCUSDT at 60680: 93 levels within 15% — long side 6.25B, short side 2.47B; nearest long 60590.6 (-0.147%), nearest short 60730.6 (+0.083%)",
  "method": ["...seven sentences, in the requested language..."],
  "notes": [
    "An estimate built from open-interest and price history, not a list of exchange-confirmed liquidations.",
    "18 estimated levels had already been crossed by the mark price and are left out: those positions are gone, so their margin is no longer there."
  ]
}
```

`open_interest_history` answers per bucket — the last two settled hours and the forming one, verbatim from a live call:

```json
{
  "status": "ok",
  "points": [
    {"at": "2026-11-26T16:00:00+00:00", "price": 60565.65043, "open_interest_usd": 5940629411.79,
     "delta_usd": 38988163.41, "change_pct": 0.661, "flow": "long_added",
     "flow_note": "longs added"},
    {"at": "2026-11-26T17:00:00+00:00", "price": 60504.33015, "open_interest_usd": 5922167494.99,
     "delta_usd": -18461916.8, "change_pct": -0.311, "flow": "long_closed",
     "flow_note": "longs closed"},
    {"at": "2026-11-26T18:00:00+00:00", "price": 60605.71231, "open_interest_usd": 5940757134.95,
     "delta_usd": 18589639.95, "change_pct": 0.314, "flow": "forming",
     "flow_note": "still forming"}
  ],
  "summary": {
    "first_usd": 5725130095.85, "last_usd": 5940757134.95,
    "change_usd": 215627039.09, "change_pct": 3.766,
    "peak_usd": 5940757134.95, "trough_usd": 5572002541.88,
    "price_change_pct": -0.446,
    "flow": {"attributed_usd": 1167875639.13, "total_flow_usd": 2370854286.63,
             "unclear_flow_usd": 336436587.64, "attributed_share": 0.4926, "buckets_used": 31}
  },
  "summary_line": "BTCUSDT 1h: open interest 5.73B to 5.94B (+3.77%, 215.63M) while price moved -0.45% over 100 intervals"
}
```

`positioning` is the measured half:

```json
{
  "status": "ok",
  "funding": {"rate_pct": 0.01, "next_in_minutes": 313,
              "history": [{"at": "2026-11-26T16:00:00+00:00", "rate_pct": 0.0045}]},
  "basis": {"rate_pct": -0.05, "index_price": 60533.27848},
  "ratios": {
    "accounts":      {"now": 2.3659, "average": 2.5163, "percentile": 25.0, "long_share": 0.7029},
    "top_accounts":  {"now": 2.8168, "average": 2.903,  "percentile": 28.0, "long_share": 0.738},
    "top_positions": {"now": 1.9289, "average": 1.7663, "percentile": 96.0, "long_share": 0.6586}
  },
  "taker": {"now": 1.0816, "average": 1.0145, "percentile": 75.0, "buy_share": 0.5196},
  "crowding": {
    "verdict": "balanced", "verdict_note": "positioning is balanced",
    "score": 0.46, "confidence": "low", "confidence_note": "low confidence",
    "signals": [
      "accounts 2.3659 against 2.5163 on average (-5.98%)",
      "top traders 2.8168 against 2.9030 on average (-2.97%)",
      "top positions 1.9289 against 1.7663 on average (+9.20%)",
      "taker buy/sell 1.0816 against 1.0145 on average (+6.61%)"
    ]
  }
}
```

Read that last block as a sentence: wallets are 2.37 long per short, which is *below* their 100-hour average (25th percentile), while the notional behind the top traders' positions is 1.93 and sits at the 96th percentile. The crowd is not leaning in; the money is. A single blended "long/short ratio" would hide that.

## How the estimate is built

1. **Alignment.** Open interest buckets carry a `timestamp`; klines carry an open time. They are joined on that number, never on position, and a bucket with no matching kline is reported as `unclear` rather than given a guessed price.
2. **Attribution.** `ΔOI` against a price move of at least 0.05% decides the side; a flow below 0.2% of the window's mean notional is reported as no change. Signed, the four cases are the four flow labels.
3. **The forming bucket.** The newest bucket's open interest and volume are both partial. It is labelled `forming`, and it counts in neither the numerator nor the denominator of the coverage share.
4. **The liquidation price.** For a long, `entry × (1 − (1 − mmr) / leverage)`; for a short, `entry × (1 + (1 − mmr) / leverage)`. With `mmr = 0.004` this puts a 10x long 9.96% below its entry and a 100x long 0.996% below it.
5. **Clustering.** Entries of the same side and the same leverage whose levels are within `cluster_pct` of each other are merged, so seven hours of gradual accumulation read as one level with `entries: 7`.
6. **Crossed levels.** A long level above the mark price, or a short level below it, has already been hit: those positions are gone. They are counted in `coverage.crossed` and excluded from the totals.
7. **Coverage.** `attributed_share` is the fraction of all open-interest flow in the window that the model could name. On the measured window below it is 0.4432 — 56.7% of the flow was closing, flat or too small to sign, and no level was invented for it.

**Levels are not additive.** The same entries appear once per leverage tier, because each tier is a different assumption about the same money. Adding the long side across tiers overstates it; `long_usd` in this payload (6.25B) is larger than the open interest itself (5.94B) for exactly that reason.

## Measured, not claimed

All figures below were produced by `measure_liq.py` against live Binance on **2026-11-26T18:46:27Z**, BTCUSDT, 1h buckets, 200-bucket window.

| Endpoint | Status without a key |
| --- | --- |
| `/futures/data/openInterestHist` | 200 |
| `/fapi/v1/klines` | 200 |
| `/futures/data/globalLongShortAccountRatio` | 200 |
| `/futures/data/topLongShortAccountRatio` | 200 |
| `/futures/data/topLongShortPositionRatio` | 200 |
| `/futures/data/takerlongshortRatio` | 200 |
| `/futures/data/basis` | 200 |
| `/fapi/v1/premiumIndex` | 200 |
| `/fapi/v1/fundingRate` | 200 |
| `/fapi/v1/ticker/24hr` | 200 |
| `/fapi/v1/allForceOrders` | **404** — the page no longer exists |
| `/fapi/v1/leverageBracket` | **401** — `{"code":-2014,"msg":"API-key format invalid."}` |

Latency, one fresh process per call, then a second call in the same process:

| Tool | Cold (median of 3) | Warm | Requests | Downloaded | Payload |
| --- | --- | --- | --- | --- | --- |
| `liquidation_map` | 1053.4 ms | 5.3 ms | 4 | 269.3 KB | 21 104 chars |
| `open_interest_history` | 717.1 ms | 3.9 ms | 3 | 238.4 KB | 25 111 chars |
| `positioning` | 772.5 ms | 2.3 ms | 8 | 258.7 KB | 1 858 chars |
| `list_symbols` | 662.8 ms | 5.7 ms | 2 | 503.2 KB | 5 638 chars |

The cold number is network, not arithmetic: the eight `positioning` reads are issued concurrently, and a warm call answers from the cache in 2.3 ms. `exchangeInfo` is 1.1 MB and is not fetched by any of these — only `list_symbols` and an unknown-symbol fallback ever need it.

The BTCUSDT map at that moment:

| Fact | Value |
| --- | --- |
| Mark price | 60 680.0 |
| Levels inside a 15% band | 93 |
| Levels already crossed, excluded | 18 |
| Buckets read / buckets that named a side | 200 / 60 |
| Attributed share of flow | 44.32% (2.63B of 5.93B) |
| Long side / short side | 6.25B / 2.47B (overhang 2.531) |
| Nearest long | 60 590.64311 — 0.147% away, 35.62M, 100x |
| Nearest short | 60 730.63318 — 0.083% away, 55.68M, 25x |
| Heaviest single level (magnet) | 60 282.12383 — 0.656% away, 311.92M, 7 entries, 100x |

The same server on other inputs:

| Call | Result |
| --- | --- |
| `open_interest_history(BTCUSDT, 1h, 100)` | 5.73B → 5.94B (+3.766%, +215.63M) while price fell 0.446%; 49.26% of the flow attributed over 31 buckets |
| `positioning(BTCUSDT, 1h, 100)` | funding +0.01% with 313 minutes to the next settlement and 0.00797 / 0.00849 / 0.0045 recorded; basis −0.05% on an index of 60 533.27848; verdict `balanced`, score 0.46, confidence `low` |
| `liquidation_map(SOLUSDT)` | 72 levels, 19 crossed, 42.31% coverage, mark 71.3734, nearest long 71.2828 (−0.127%), nearest short 71.4963 (+0.172%) |
| `liquidation_map(BTCUSDT, 4h, 60, five tiers, 25% band)` | 74 levels from 60 buckets, 40.62% coverage, nearest long −0.182%, nearest short +0.738% |
| `list_symbols(limit=25)` | 767 USDT perpetuals known, top by turnover: BTCUSDT, ETHUSDT, SOXLUSDT, XAUUSDT, ZECUSDT |

## When the map is empty

An empty `clusters` list is not an error. It means one of three things, and the payload says which:

- nothing opened in the window (`coverage.buckets_used` is 0),
- everything that opened is further than `band_pct` from the mark price,
- every level it found had already been crossed by price.

The `notes` array carries the sentence, in the requested language.

## What it refuses to claim

- **Not exchange liquidations.** There is no such public feed on Binance any more. `kind` is `estimate` and the method is repeated in every map payload.
- **Not the real margin brackets.** Tier 1 uses `mmr = 0.004`. Higher tiers exist and are behind a signed request; a position large enough to sit in one will be liquidated slightly earlier than modelled.
- **Not cross margin.** One isolated position per entry, no shared collateral, no hedged pairs.
- **Not an entry price.** Each bucket's entries are assumed to be at that bucket's traded VWAP. A position opened and closed inside one bucket is invisible.
- **No keys, no orders.** The server never signs a request and never sends one that changes anything.
- **Not a signal.** It tells you where the fuel is and who is crowded; it does not tell you the next candle.

## Languages

One sentence, three catalogues, same numbers:

```
en  long side 6.25B, short side 2.47B; nearest long 60590.6 (-0.147%), nearest short 60730.6 (+0.083%)
es  lado long 6.25B, lado short 2.47B; long más cercano 60590.6 (-0.147%), short más cercano 60730.6 (+0.083%)
ru  лонги 6.25B, шорты 2.47B; ближайший лонг 60590.6 (-0.147%), ближайший шорт 60730.6 (+0.083%)
```

The catalogue is checked in CI: every key the code can render exists in all three languages, with the same placeholders, and no Russian or Spanish sentence is left byte-identical to the English one.

## Tests

```bash
pytest              # 115 offline tests: arithmetic, tools over a fake exchange, the stdio wire
pytest -m live      # 7 tests against Binance itself
```

The offline layers need no network: the fake exchange holds hand-built open-interest and price series, so a failure points at the model rather than at a field name changing upstream.

## Free, and donations welcome

This server is free: every tool can be called without payment, registration or
an API key. If it saves you time or money, you can send a donation -- it goes
straight to the developer, with no platform in between.

| Network | Asset | Address |
| --- | --- | --- |
| Base | USDC / ETH | `0x832e9e0FC60c35A07cf80846A9eD27aa7cb4F637` |
| Ethereum | ETH | `0x832e9e0FC60c35A07cf80846A9eD27aa7cb4F637` |

Nothing in the code is gated on donations: no telemetry, no licence check, no
expiring demo. The whole source is MIT-licensed.

## Licence

MIT.

TDQS

A3.7/5.0

Scored across 4 tools

Disambiguation5/5

Each tool has a clearly distinct role: symbol discovery, the liquidation-cluster map, the underlying open-interest series, and measured positioning/crowding metrics. Although the latter three are related analytics, their outputs and descriptions make the boundaries unambiguous.

Naming Consistency4/5

All names use lower snake_case and are readable, but they do not follow a uniform verb_noun pattern: list_symbols uses a verb prefix while the others are resource/analytics nouns. This is a minor deviation rather than a confusing mix of conventions.

Tool Count5/5

Four tools is well scoped for a focused liquidation-map analytics server. Each tool contributes a necessary part of the workflow: discovery, core map, underlying data, and positioning context.

Completeness4/5

The surface covers the main workflow from finding a symbol through examining liquidation clusters, open-interest history, and positioning. Minor gaps remain around richer historical context such as funding/basis history or actual liquidation prints, but agents can work around them.

Maintenance

ActivityMaintained
ResponsivenessNo recent community issues