GET Open Interest

/open-interest

/open-interest

Example Query:

https://base-hedger82.rasa.capital/open-interest

Example Response:

{
  "total_cap": "2438560.667955634347925220",
  "used": "111969.991183710650000000"
}

Data Source

All values are configured and managed exclusively by the hedger. This data reflects the hedger’s internal risk management settings and is not derived from on-chain contracts or user positions.

Response Fields

  • total_cap: The maximum total open interest across all assets (in collateral, e.g., USDT).

  • used: The portion of the total capacity currently utilized by open positions across all assets.

Open Interest Implementation (Rasa)


Router

  • Path: GET /open-interest

  • Rate‐limits: 1 req/sec, 40 req/min, 1 500 req/hr

  • DB session: injected via @with_context_db_session (in case the capacity engine reads from SQL)


Logic

  1. Call Capacity Engine

    • Invokes your hedger’s internal risk‐management component to compute:

      • total_cap: how much notional collateral the hedger is willing to allow in aggregate.

      • used: how much of that allowance is currently locked up by open positions.

  2. Instrumentation

    • Sends metrics (via your APM/tracing tool) for observability.

  3. Return Payload

    • FastAPI serializes this to JSON matching OpenInterestResponseSchema.


Steps to Implement Your Own Version

  1. Define the Response Schema

  2. Build or Wire Up Your Capacity Engine

    • Implement OpenCapEngine.get_total_cap_and_used_amount_async(from_stats: bool) → Tuple[Decimal, Decimal].

    • Internally, read from your own data sources:

      • Configuration table (max capacities per asset or global).

      • Positions table (sum up open positions’ collateral needs).

    • Return (total_cap, used).

  3. Add the FastAPI Route

    • In your common_router, add the @common_router.get("/open-interest") handler shown above.

    • Import OpenInterestResponseSchema and OpenCapEngine.

    • Include your rate‐limiting dependencies and @with_context_db_session if your engine needs DB access.

  4. Instrumentation (Optional)

    • If you have an APM or metrics library, record these values on each call.


Last updated