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/open_interest.py
1#!/usr/bin/env python32"""3Coinglass Open Interest Module45Fetch aggregate open interest data across major cryptocurrency exchanges.6"""78import sys9import json10import argparse11from typing import Dict, Any, Optional, List1213from ._api import cg_request1415# MCP Tool Schema16MCP_OPEN_INTEREST_SCHEMA = {17"name": "cg_open_interest",18"title": "Coinglass Open Interest",19"description": (20"Get aggregate open interest across exchanges for a symbol."21),22"inputSchema": {23"type": "object",24"properties": {25"symbol": {26"type": "string",27"description": "Symbol (BTC, ETH, SOL, etc.)"28},29"interval": {30"type": "string",31"description": "Time interval: 0 (all), h1, h4, h12, h24",32"default": "0",33"enum": ["0", "h1", "h4", "h12", "h24"]34}35},36"required": ["symbol"],37"additionalProperties": False38}39}404142def get_open_interest(43symbol: str = "BTC",44interval: str = "0"45) -> Optional[Dict[str, Any]]:46"""47Get aggregate open interest across exchanges for a symbol.4849Uses v2 API for basic OI data.5051Args:52symbol: Coin symbol (BTC, ETH, SOL, etc.)53interval: Time interval (0=all, h1, h4, h12, h24).5455Returns:56Dict with open interest data by exchange.5758Raises:59CoinglassError: On API failure.60"""61return cg_request(62"open_interest",63params={"symbol": symbol, "interval": interval},64version="v2"65)666768def get_open_interest_history(69symbol: str = "BTC",70interval: str = "h4",71exchange: Optional[str] = None72) -> Optional[List[Dict[str, Any]]]:73"""74Get open interest history (aggregated across exchanges).7576Uses v4 API for historical data.7778Args:79symbol: Coin symbol.80interval: Time interval (h1, h4, h12, h24).81exchange: Optional exchange filter.8283Returns:84List of historical OI data points.85"""86params = {"symbol": symbol, "interval": interval}87if exchange:88params["exchange"] = exchange89return cg_request(90"api/futures/open-interest/aggregated-history",91params=params92)939495def main():96"""CLI entry point."""97parser = argparse.ArgumentParser(98description="Coinglass Open Interest Tools"99)100parser.add_argument("--symbol", "-s", default="BTC")101parser.add_argument("--interval", "-i", default="h4")102parser.add_argument("--exchange", "-e", default=None)103parser.add_argument("--history", action="store_true",104help="Show OI history")105parser.add_argument("--json", "-j", action="store_true")106args = parser.parse_args()107108try:109if args.history:110result = get_open_interest_history(111args.symbol, args.interval, args.exchange112)113else:114result = get_open_interest(args.symbol, args.interval)115116if result:117print(json.dumps(result, indent=2))118else:119print("No data found", file=sys.stderr)120except Exception as e:121print(f"Error: {e}", file=sys.stderr)122sys.exit(1)123124125if __name__ == "__main__":126main()127