Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
37-tool crypto derivatives data suite: funding rates, open interest, liquidations, Hyperliquid whale tracking, and ETF flows.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
tools/liquidations.py
1#!/usr/bin/env python32"""3Coinglass Liquidations Module45Provides liquidation data across exchanges: individual liquidations6and aggregated (long/short) liquidation summaries.7"""89import sys10import json11import argparse12from typing import Dict, Any, Optional1314from ._api import cg_request151617def get_liquidations(18symbol: str = "BTC",19time_type: str = "h24"20) -> Optional[Dict[str, Any]]:21"""22Get liquidation data across exchanges.2324Args:25symbol: Coin symbol (BTC, ETH, SOL, etc.)26time_type: Time window (h1, h4, h12, h24).2728Returns:29Dict with liquidation data: long/short amounts, counts.3031Raises:32CoinglassError: On API failure.33"""34# Map h-format to API format35range_map = {"h1": "1h", "h4": "4h", "h12": "12h", "h24": "24h"}36v4_range = range_map.get(time_type, time_type)37params = {"symbol": symbol.upper(), "range": v4_range}38return cg_request(39"api/futures/liquidation/exchange-list", params=params40)414243def get_liquidation_aggregated(44symbol: str = "BTC",45time_type: str = "h24"46) -> Optional[Dict[str, Any]]:47"""48Get aggregated liquidation summary (total longs vs shorts).4950Args:51symbol: Coin symbol.52interval: Time interval.5354Returns:55Dict with total long/short liquidations and ratio.56"""57data = get_liquidations(symbol, time_type)58if not data:59return None6061# Aggregate across exchanges62entries = data if isinstance(data, list) else [data]63total_long = 064total_short = 065for entry in entries:66total_long += entry.get("longLiquidationUsd", 0) or 067total_short += entry.get("shortLiquidationUsd", 0) or 06869total = total_long + total_short70return {71"symbol": symbol.upper(),72"interval": time_type,73"total_long_usd": total_long,74"total_short_usd": total_short,75"total_usd": total,76"long_ratio": total_long / total if total else 0,77"short_ratio": total_short / total if total else 0,78"dominant": "long" if total_long > total_short else "short",79}808182def main():83"""CLI entry point."""84parser = argparse.ArgumentParser(85description="Coinglass Liquidation Tools"86)87parser.add_argument("--symbol", "-s", default="BTC")88parser.add_argument("--interval", "-i", default="h4")89parser.add_argument("--exchange", "-e", default=None)90parser.add_argument("--aggregated", "-a", action="store_true",91help="Show aggregated summary")92args = parser.parse_args()9394try:95if args.aggregated:96result = get_liquidation_aggregated(97args.symbol, args.interval98)99else:100result = get_liquidations(101args.symbol, args.interval102)103104if result:105print(json.dumps(result, indent=2))106else:107print("No data found", file=sys.stderr)108except Exception as e:109print(f"Error: {e}", file=sys.stderr)110sys.exit(1)111112113if __name__ == "__main__":114main()115