Skip to main content
Glama
ymylive
by ymylive

get_open_interest

Retrieve current open interest for any perpetual contract. Use OI with price to assess trend strength: rising OI with rising price confirms new longs, falling OI with falling price signals capitulation. Essential for market analysis.

Instructions

Get the current open interest (OI) for a perpetual contract on one exchange.

Open interest is the total notional/contract count of outstanding positions on a venue. Reading OI alongside price:

  • OI rising with price rising -> new longs entering, trend has fuel

  • OI rising with price falling -> new shorts loading up

  • OI falling with price rising -> short squeeze / covering rally

  • OI falling with price falling -> longs capitulating This is descriptive, not advice. For funding-rate context use get_funding_rate (snapshot) or get_funding_rate_history (series).

Falls back to fetch_open_interest_history(timeframe="1h", limit=1) when the exchange exposes only the historical endpoint.

Args: exchange_id: CCXT exchange ID supporting perps. symbol: Perp symbol with settle suffix, e.g. "BTC/USDT:USDT" or "BTC/USD:BTC" for inverse.

Returns: Object with symbol, openInterestAmount (in base units / contracts), openInterestValue (notional in quote), timestamp, datetime, and exchange-specific info. On unsupported exchanges returns {"error": "..."}.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
exchange_idYes
symbolYes

Implementation Reference

  • The `get_open_interest` async tool handler — decorated with @mcp.tool(), prewarms the exchange, then calls either `fetchOpenInterest` or falls back to `fetchOpenInterestHistory` via CCXT inside a `_ccxt_call` thread runner.
    @mcp.tool()
    async def get_open_interest(exchange_id: str, symbol: str) -> Any:
        """Get the current open interest (OI) for a perpetual contract on one exchange.
    
        Open interest is the total notional/contract count of outstanding positions
        on a venue. Reading OI alongside price:
          - OI rising with price rising  -> new longs entering, trend has fuel
          - OI rising with price falling -> new shorts loading up
          - OI falling with price rising -> short squeeze / covering rally
          - OI falling with price falling -> longs capitulating
        This is descriptive, not advice. For funding-rate context use
        `get_funding_rate` (snapshot) or `get_funding_rate_history` (series).
    
        Falls back to `fetch_open_interest_history(timeframe="1h", limit=1)` when
        the exchange exposes only the historical endpoint.
    
        Args:
            exchange_id: CCXT exchange ID supporting perps.
            symbol: Perp symbol with settle suffix, e.g. "BTC/USDT:USDT" or
                "BTC/USD:BTC" for inverse.
    
        Returns:
            Object with `symbol`, `openInterestAmount` (in base units / contracts),
            `openInterestValue` (notional in quote), `timestamp`, `datetime`, and
            exchange-specific `info`. On unsupported exchanges returns
            `{"error": "..."}`.
        """
        err = await _prewarm_exchange(exchange_id)
        if err is not None:
            return err
    
        def _do() -> Any:
            ex = _get_ccxt_exchange(exchange_id)
            if ex.has.get("fetchOpenInterest"):
                return ex.fetch_open_interest(symbol)
            if ex.has.get("fetchOpenInterestHistory"):
                rows = ex.fetch_open_interest_history(symbol, timeframe="1h", limit=1)
                if isinstance(rows, list) and rows:
                    return rows[-1]
                return {
                    "error": f"{exchange_id} fetchOpenInterestHistory returned no rows for {symbol}"
                }
            return {
                "error": (
                    f"{exchange_id} supports neither fetchOpenInterest nor "
                    f"fetchOpenInterestHistory via CCXT"
                )
            }
    
        return await _ccxt_call(_do, exchange_id=exchange_id)
  • Registration/listing of `get_open_interest` in the MCP instructions table mapping tool names to descriptions.
    | Current open interest for a perp | get_open_interest |
    | Compare funding rates across exchanges | compare_funding_rates |
  • The @mcp.tool() decorator on line 87 registers the tool on the shared FastMCP instance imported from core.py.
    @mcp.tool()
  • Calls `_prewarm_exchange` helper to build/cache the CCXT exchange instance outside the per-id lock to avoid deadlocks.
    err = await _prewarm_exchange(exchange_id)
    if err is not None:
        return err
  • Delegates execution to `_ccxt_call` (from core.py) which runs the blocking CCXT call in a thread with per-exchange locking.
    return await _ccxt_call(_do, exchange_id=exchange_id)
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations, the description discloses fallback behavior to fetch_open_interest_history, explains the return object format, and mentions error handling for unsupported exchanges. This adds significant behavioral context beyond just the tool name.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is well-structured: definition, interpretive guideline, fallback note, parameter docs, return description. It is slightly long but each sentence adds value, and the structure is logical.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given no output schema, the description covers return fields, fallback, and error handling. It is complete enough for an agent to invoke correctly without additional context.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema coverage is 0%, but the description explains each parameter: exchange_id as 'CCXT exchange ID supporting perps' and symbol with example suffix. It also details the return object structure, compensating for the lack of schema details.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description starts with a clear verb+resource: 'Get the current open interest (OI) for a perpetual contract on one exchange.' It distinguishes itself from sibling tools like get_funding_rate and get_funding_rate_history by explicitly mentioning them as alternatives for funding-rate context.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides interpretive guidance on reading OI with price action and explicitly names alternative tools for funding-rate context. It lacks explicit when-not-to-use guidance but the context is clear.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/ymylive/coin-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server