Skip to content

Pricing API

Price calculations and estimations.

Mark Price

mark_price

mark_price

mark_price(
    orderbook: OrderBook | None = None,
    index_price: Price | None = None,
) -> Price

Return a mark price using mid from the orderbook or fallback to index price.

Mid Price

mid_price

mid_price

mid_price(orderbook: OrderBook) -> Price | None

Return mid price from an orderbook snapshot.

VWAP

vwap

vwap

VWAP calculation.

vwap

vwap(data: Iterable[Tuple[Price, Quantity]]) -> Price

Calculate Volume-Weighted Average Price.

VWAP is the average price weighted by volume, commonly used as a trading benchmark.

Parameters:

Name Type Description Default
data Iterable[Tuple[Price, Quantity]]

Iterable of (price, quantity) tuples

required

Returns:

Type Description
Price

Volume-weighted average price

Raises:

Type Description
ValueError

If total quantity is zero

Example

from decimal import Decimal trades = [ ... (Decimal("100"), Decimal("10")), # 10 @ $100 ... (Decimal("102"), Decimal("20")), # 20 @ $102 ... (Decimal("99"), Decimal("5")), # 5 @ $99 ... ] price = vwap(trades) float(price) 101.0

VWAP is weighted toward larger trades

(10100 + 20102 + 5*99) / 35 = 101.0

Slippage

estimate_slippage

estimate_slippage

estimate_slippage(
    orderbook: OrderBook,
    side: OrderSide,
    quantity: Quantity,
    impact_bps: Decimal | None = None,
) -> Price

Estimate volume-weighted execution price for a market order. Optionally add a linear market impact in basis points on the notional.

Rate Annualization

annualize_rate

annualize_rate

annualize_rate(
    period_rate: Decimal, periods_per_year: int = 365 * 3
) -> Decimal

Approximate annualized funding given a per-period rate.