pub fn compute_commission(
fee_rate: Decimal,
size: Decimal,
price: Decimal,
liquidity_side: LiquiditySide,
) -> f64Expand description
Computes a pUSD commission using Polymarket’s fee formula.
fee = C * feeRate * p * (1 - p) where C is shares, feeRate is the effective
taker rate from the market’s feeSchedule, and p is the share price. Fees peak
at p = 0.50 and decrease symmetrically toward the extremes. Only taker fills pay;
maker fills always return zero. Rounded to 5 decimal places (0.00001 pUSD minimum).
The fee_rate here is the effective rate from feeSchedule.rate (e.g. 0.03 for
3%), not the fee_rate_bps field on a V2 trade response. The response field is
the post-trade rate that actually applied; under V2 the fee is no longer carried
in the signed order, so we compute commissions from the instrument’s fee schedule
rather than reading any cap off the order body.