DEV Community

ByKaranteli
ByKaranteli

Posted on Fully Autonomous

How to Pull Live Crypto Liquidations From 13 Exchange Feeds in Python

Liquidation data is one of those things that looks simple until you try to collect it yourself. Every derivatives venue publishes forced closes in its own format, over its own WebSocket, with its own throttling rules. Some send every print, some send at most one per contract per second, some only expose a delayed list. If you want a single number for "how much got liquidated in the last 24 hours, and on which side", you end up maintaining a dozen socket clients before you write a line of analysis.

This post skips that part. We'll use one JSON endpoint that already merges real liquidation events from 13 exchange feeds, and build a small Python script that:

  1. prints the 24h total split into longs and shorts,
  2. breaks it down by venue, with each feed's coverage label,
  3. lists the symbols with the most liquidated notional,
  4. shows the last 30 finalized UTC days,
  5. pulls the single largest prints of the day.

Everything below uses the requests library and nothing else.

What the data actually is

The endpoint is GET https://bykaranteli.com/api/public/liquidations. It returns the liquidation events the provider's own collectors received from public venue feeds over a rolling 24 hours.

Two details matter before you trust any number from it:

  • It is a floor, not a market total. Some venues throttle their public liquidation stream, so the recorded figure is the minimum that definitely happened. The response labels each venue's feed as full, sampled or delayed so you can see where the gaps are.
  • The estimate is separate and documented. Next to the recorded total there is a market_estimate block that scales the recorded number by open interest coverage, and the method field spells out the formula. Keep the two apart in anything you publish.

That honesty is the whole reason to use a merged feed instead of scraping one venue: you get the coverage metadata with the number.

Get a key

Programs need an account key sent as a bearer token. A free key comes with any verified account. Export it as an environment variable so it never lands in your code:

export BYK_API_KEY="bk_..."
Enter fullscreen mode Exit fullscreen mode

One gotcha from the docs worth repeating: if the variable is empty, curl silently drops the header and you get a 401 key_required. The Python helper below fails early instead.

The client

import os
import sys
import requests

BASE = "https://bykaranteli.com"


def get(path, **params):
    key = os.environ.get("BYK_API_KEY", "").strip()
    if not key:
        sys.exit("Set BYK_API_KEY first (free key with any verified account).")
    r = requests.get(
        f"{BASE}{path}",
        params=params,
        headers={"Authorization": f"Bearer {key}"},
        timeout=20,
    )
    if r.status_code == 401:
        sys.exit(f"401: {r.json().get('code')} - check the key")
    r.raise_for_status()
    return r.json()


def usd(x):
    return f"${x / 1e6:,.1f}M"
Enter fullscreen mode Exit fullscreen mode

1. The 24h headline

data = get("/api/public/liquidations")
rec = data["recorded"]

long_share = rec["long_usd"] / rec["total_usd"] if rec["total_usd"] else 0
print(f"As of {data['generatedAt']} ({data['window']} window)")
print(f"Recorded: {usd(rec['total_usd'])} across {rec['events']:,} events")
print(f"  longs liquidated:  {usd(rec['long_usd'])} ({long_share:.0%})")
print(f"  shorts liquidated: {usd(rec['short_usd'])}")

big = rec["largest"]
print(f"Largest single print: {big['symbol']} {usd(big['usd'])}")
Enter fullscreen mode Exit fullscreen mode

long_usd means long positions that were force-closed. When the long share sits far above 50%, the day's selling hit leveraged longs; far below, shorts got squeezed. That is a description of what happened, not a forecast of what comes next.

At the time of writing the 24h window showed about $938M recorded over roughly 159,000 events, close to an even long/short split.

2. Per venue, with coverage labels

print(f"\n{'venue':<16}{'coverage':<10}{'total':>12}{'longs':>12}{'shorts':>12}{'events':>9}")
for e in sorted(data["by_exchange"], key=lambda e: e["total_usd"], reverse=True):
    flag = " (stale)" if e["stale"] else ""
    print(
        f"{e['venue']:<16}{e['coverage']:<10}"
        f"{usd(e['total_usd']):>12}{usd(e['long_usd']):>12}"
        f"{usd(e['short_usd']):>12}{e['events']:>9,}{flag}"
    )
Enter fullscreen mode Exit fullscreen mode

Each row carries coverage and stale, plus last_event_at. If you are building a dashboard, show the coverage label next to the number. A sampled feed with a big total is still an undercount; a stale feed means its socket has been quiet past its normal threshold and the row should not be read as "zero liquidations".

The coverage array at the bottom of the payload has the longer explanation per venue (what is collected, since when), which is handy for a tooltip.

3. Which symbols got hit

print("\nTop symbols by liquidated notional:")
for s in data["by_symbol"][:10]:
    ls = s["long_usd"] / s["total_usd"] if s["total_usd"] else 0
    print(f"  {s['symbol']:<12}{usd(s['total_usd']):>10}  long share {ls:.0%}  ({s['events']:,} events)")
Enter fullscreen mode Exit fullscreen mode

by_symbol comes sorted by total. You will notice it is not only crypto: stock and commodity perpetuals show up too (at the time of writing two equity-linked perps were in the top five), because several venues now list them and their liquidations land in the same feeds.

4. The last 30 days

The same payload includes a daily array of finalized UTC days, so you don't need a second call for a quick history:

print("\nLast 30 finalized UTC days:")
for d in data["daily"]:
    ls = d["long_usd"] / d["total_usd"] if d["total_usd"] else 0
    bar = "#" * int(d["total_usd"] / 50e6)
    print(f"  {d['date']}  {usd(d['total_usd']):>10}  L {ls:>4.0%}  {bar}")
Enter fullscreen mode Exit fullscreen mode

Each # is $50M, which is enough to spot the cascade days at a glance. If you need more than 30 days, data["links"]["daily_dataset"] points to the liquidations-daily dataset (CSV and JSON), which goes back to the start of the record in July 2026.

5. The largest single prints

Totals hide the individual events. A second endpoint ranks the biggest prints:

lb = get("/api/public/liquidation-leaderboard", window="24h", limit=5)
print("\nLargest prints, last 24h:")
for p in lb["largest"]:
    side = "long liquidated" if p["side"] == "SELL" else "short liquidated"
    print(f"  #{p['rank']} {p['symbol']:<10}{usd(p['usd']):>9}  {side:<17} at {p['price']:,.2f}  {p['event_time']}")
Enter fullscreen mode Exit fullscreen mode

Note the side convention: SELL means a long was liquidated (the venue sold to close it), BUY means a short was. window accepts 24h, 7d or 30d, and limit goes up to 100.

Polling it

The 24h window is rolling and generatedAt tells you when the snapshot was built, so a simple loop that only reacts when the timestamp moves is enough:

import time

last = None
while True:
    d = get("/api/public/liquidations")
    if d["generatedAt"] != last:
        last = d["generatedAt"]
        r = d["recorded"]
        print(f"{last}  {usd(r['total_usd'])}  longs {r['long_usd'] / max(r['total_usd'], 1):.0%}")
    time.sleep(300)
Enter fullscreen mode Exit fullscreen mode

Be honest with yourself about what you are building here. The free key is meant for evaluation and personal scripts. Something that runs around the clock (a bot, a shared dashboard, a polling agent) is what the paid plans are for, and they also add the WebSocket stream (wss://bykaranteli.com/ws/v1) with a liquidations event channel, which beats polling anyway.

Same data inside an AI assistant

If you would rather ask than script, the same numbers are exposed as an MCP server. npx -y bykaranteli-mcp runs it locally in Claude Desktop, Cursor or any MCP client, and the hosted endpoint https://mcp.bykaranteli.com works as a custom connector with the same key. The tool is get_liquidations; ask "how much was liquidated in the last 24 hours and on which side" and it calls the endpoint above. The setup steps are at bykaranteli.com/guide/connect.

Live version

If you want to compare your script's output with the rendered board, the live page is bykaranteli.com/liquidations. Quote the timestamp and attribute "ByKaranteli (bykaranteli.com)" if you publish numbers from it.

Wrap-up

One authenticated GET gives you the recorded 24h total, the long/short split, per-venue rows with coverage labels, the top symbols and 30 days of history. A second call gives the largest prints. The useful habit to carry over: always show the coverage label and the "floor" caveat next to a liquidation total, because no public feed sees everything.

Get a free API key → https://bykaranteli.com/register?next=%2Fdashboard%2Fapi&utm_source=devto&utm_medium=referral&utm_campaign=liquidations-python

Full endpoint list: bykaranteli.com/developers.


Drafted with AI assistance, reviewed against the live API docs. This post describes a data API; nothing here is investment advice.

Top comments (0)