GET Notional Cap

/notional_cap

/notional_cap/{symbol_id}

Example Query:

https://base-hedger82.rasa.capital/notional_cap/1

Example Response:

{
  "total_cap": "2344336.83177192369792522000000000",
  "used": "17746.15500000000000000000000000"
}

Data Source

Values are configured and managed exclusively by the hedger. These caps are set per trading pair and reflect the hedger’s risk management strategy for individual assets.

Notional Cap Implementation (Rasa)

Router

@common_router.get(
    '/notional_cap/{symbol_id}',
    responses={status.HTTP_200_OK: {"model": OpenInterestResponseSchema}},
    response_model=OpenInterestResponseSchema,
    dependencies=[
        Depends(CustomRateLimiter(times=1, seconds=1)),
        Depends(CustomRateLimiter(times=40, minutes=1)),
        Depends(CustomRateLimiter(times=1500, hours=1)),
    ]
)
@with_context_db_session
async def get_notional_cap(symbol_id: int):
    symbol_id_validator(symbol_id)
    total_cap, used = await OpenCapEngine.get_cap_and_used_amount_async(symbol_id, from_stats=True)
    apm.label(total_cap=total_cap, used=used)
    return {"total_cap": total_cap, "used": used}

Logic

  • Ensures the provided symbol_id exists and is well-formed; raises a 400/422 if not.

  • Queries the hedger’s capacity engine for the per-symbol maximum notional cap and current usage.

  • Emits metrics for monitoring and alerting.

  • FastAPI serializes this to JSON matching OpenInterestResponseSchema:

class OpenInterestResponseSchema(BaseModel):
    total_cap: Decimal
    used: Decimal

Steps to Implement Your Own Version

Define the Response Schema

class OpenInterestResponseSchema(BaseModel):
    total_cap: Decimal
    used: Decimal

Implement Symbol Validation

  • Write symbol_id_validator(symbol_id: int) that checks against your Symbol table or whitelist.

Build The Capacity Engine

  • In OpenCapEngine, implement get_cap_and_used_amount_async(symbol_id, from_stats=True) to return (Decimal total_cap, Decimal used), using:

    • Per-symbol config table for maximum caps.

    • Positions table to sum currently open notional on that symbol.

Add the FastAPI Route

  • In your common_router, add the GET /notional_cap/{symbol_id} handler as shown, importing the schema, validator, and engine.

  • Attach the same rate-limiting and @with_context_db_session decorators.

Last updated