Metadata-Version: 2.4
Name: pmfees
Version: 0.3.0
Summary: Exact trading fees for Kalshi, Polymarket US and polymarket.com, with a CLI and break-even helper.
Author-email: SwapHunt <github@swaphunt.dev>
License-Expression: MIT
Project-URL: Homepage, https://github.com/swaphunt/pmfees
Project-URL: Source, https://github.com/swaphunt/pmfees
Project-URL: Issues, https://github.com/swaphunt/pmfees/issues
Project-URL: Changelog, https://github.com/swaphunt/pmfees/blob/main/CHANGELOG.md
Project-URL: Fee calculator, https://swaphunt.dev/tools/kalshi-vs-polymarket-fee-calculator
Keywords: kalshi,polymarket,prediction markets,fees,trading
Classifier: Programming Language :: Python :: 3
Classifier: Operating System :: OS Independent
Classifier: Typing :: Typed
Classifier: Development Status :: 4 - Beta
Classifier: Topic :: Office/Business :: Financial
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Dynamic: license-file

# pmfees

[![Listed on Awesome Prediction Market Toolkit](https://img.shields.io/badge/listed%20on-Prediction%20Market%20Toolkit-blue)](https://github.com/talhareltal/awesome-prediction-market-toolkit)

Exact trading fees for the prediction market platforms **Kalshi**, **Polymarket US** and
**polymarket.com** (international), as a small Python library and a command line tool.

- The platforms' own formulas and rounding rules: Kalshi rounds up so that fee + position cost
  is a whole centicent ($0.0001), Polymarket US rounds to the cent with banker's rounding,
  polymarket.com rounds to 5 decimals.
- Exact decimal arithmetic (`decimal.Decimal`), so $1.75 is $1.75 and not $1.7500000000000002.
- A break-even helper: how far the price has to move before a round trip is in profit after
  the fee on both orders.
- Fees for a list of fills: Kalshi's per-order fee accumulator by default, or each fill rounded on
  its own for fills from different orders.
- Kalshi's per-series fee structure (multiplier M and maker fees) for the 195 series that differ
  from the standard, looked up by series, event or market ticker.
- polymarket.com's fee and rebate changes from 2026-11-20 23:59 UTC: every fill is priced with the
  rates in force at its own time, plus the new taker and maker rebate tiers on weighted volume.
- No dependencies outside the Python standard library. Typed (`py.typed`).

Rates current as of: Kalshi 2026-11-10 (fee schedule 7.7.26), Polymarket US 2026-11-15,
polymarket.com 2026-11-08. Each platform's date and source are in the rates file and in every result.
Kalshi series list as of 2026-11-14.

Other ways to get the same numbers, from the same rates file:

- In a browser: the [SwapHunt Kalshi vs Polymarket fee calculator](https://swaphunt.dev/tools/kalshi-vs-polymarket-fee-calculator).
- Over HTTP, for agents: [`GET https://x402.swaphunt.dev/v1/pm/fees`](https://swaphunt.dev/api), paid per call
  with [x402](https://www.x402.org/) in USDC. This package is free; the endpoint exists for agents that
  cannot install a library.

## Install

```bash
pip install pmfees
```

Python 3.10 or newer.

## Command line

```bash
pmfees kalshi --price 0.50 --contracts 100
```

```text
Kalshi taker fee: $1.75 (3.50% of trade value at 50¢)
  buy 100 contracts at $0.50 = $50.00 trade value
  base rate: 0.07
  multiplier: 1
  fee schedule version: 7.7.26
  0.07 × 100 × 0.5 × (1 − 0.5) = 1.75, rounded up so that fee + position cost is a whole centicent ($0.0001): $1.75
  rates as of 2026-11-10 · source: https://kalshi.com/docs/kalshi-fee-schedule.pdf
```

More examples:

```bash
# Polymarket US, Tier 1 (under $10,000 of 30-day taker volume, the default)
pmfees polymarket-us --price 0.50 --contracts 100
# -> Polymarket US taker fee: $2.38 (4.76% of trade value at 50¢)   [0.095 × 100 × 0.5 × 0.5 = 2.375]

# polymarket.com, Crypto category, a fill before the change on 2026-11-20 23:59 UTC
pmfees polymarket --price 0.25 --contracts 100 --category Crypto --at 2026-11-20T12:00Z
# -> polymarket.com taker fee: $1.3125 (5.25% of trade value at 25¢)

# The same fill after the change (Crypto 0.07 -> 0.01); without --at the time is now
pmfees polymarket --price 0.25 --contracts 100 --category Crypto --at 2026-11-21T00:00Z
# -> polymarket.com taker fee: $0.1875 (0.75% of trade value at 25¢)

# polymarket.com maker rebate from 2026-11-20 23:59 UTC: Tier 4, fills that generated $100 in taker fees
pmfees polymarket-rebate --role maker --taker-fees 100 --tier Tier4 --at 2026-11-21T00:00Z
# -> polymarket.com maker rebate: $15.00

# Break-even: buy 100 on Kalshi at 50¢, when is selling in profit?
pmfees kalshi --price 0.50 --contracts 100 --break-even
# -> Break-even: the price must rise 4¢ to 54¢ (tick 1¢); entry fee $1.75 + exit fee $1.7388, profit at that price $0.5112
```

Options:

| Option | Platforms | Meaning |
|---|---|---|
| `--price` | all | Price of the contract you trade, in dollars (0 < price < 1) |
| `--contracts` | all | Number of contracts (shares on polymarket.com): whole contracts on Kalshi, steps of 0.01 on Polymarket US, up to 6 decimals on polymarket.com |
| `--side buy\|sell` | all | Changes the cash flow only; the fee formulas are symmetric |
| `--maker` | all | Maker order. Kalshi: maker rate 0.0175 with M default 0, so pass `--multiplier 1` (or `--series`) on markets with maker fees. Polymarket US and polymarket.com: makers pay no fee |
| `--multiplier` | kalshi | Fee multiplier M (default 1 for takers, 0 for makers) |
| `--series` | kalshi | Series, event or market ticker (e.g. `KXMLBGAME`): M and maker fees from the series list. Instead of `--multiplier` |
| `--tier 1-4\|new` | polymarket-us | Taker tier, or `new` for the first 7 days of a new account (default 1) |
| `--volume` | polymarket-us | Trailing 30-day taker volume in USD; picks the tier for you |
| `--category` | polymarket | Market category, e.g. `Crypto`, `Sports`, `Politics`, from 2026-11-20 23:59 UTC also `Politics (elections)` and `Crypto (BTC 5m/15m up/down)` (required) |
| `--at` | polymarket | Fill time, ISO 8601 with an offset (`2026-11-21T08:00Z`); picks the rates in force then (default: now) |
| `--break-even`, `--tick` | all | Also print the break-even move (price step, default 0.01) |
| `--json` | all | Machine-readable output |
| `--rates PATH` | all | Use an updated rates file |

`pmfees rates` prints the loaded rates and their date, including dated changes.

`pmfees polymarket-rebate --role maker|taker --taker-fees USD (--tier NAME | --weighted-volume USD)
[--category C] [--at TIME]` prints a polymarket.com rebate from 2026-11-20 23:59 UTC (see below).

## Library

```python
from pmfees import fee, break_even

r = fee("kalshi", 0.50, 100)
r.fee  # Decimal('1.7500')  what you pay, in USD
r.raw_fee  # Decimal('1.7500') before rounding
r.fee_pct_of_trade_value  # Decimal('3.500')
r.breakdown()  # dict of strings: coefficient, rounding, formula, source_url, rates_as_of, ...

fee("polymarket-us", 0.10, 1000, "buy", tier=4).fee  # Decimal('6.26')
fee("polymarket-us", 0.10, 1000, volume_30d=12_500).fee  # Tier 2
fee("polymarket", 0.25, 100, category="Crypto", at="2026-11-20T12:00Z").fee  # Decimal('1.31250')
fee("polymarket", 0.25, 100, category="Crypto", at="2026-11-21T00:00Z").fee  # Decimal('0.18750')
fee("kalshi", 0.50, 1).fee  # Decimal('0.0175')  centicent rounding, not $0.02
fee("kalshi", 0.50, 100, maker=True).fee  # Decimal('0.0000')  maker M defaults to 0
fee("kalshi", 0.50, 100, maker=True, multiplier=1).fee  # Decimal('0.4375')
fee("kalshi", 0.50, 100, multiplier=0.5).fee  # Decimal('0.8750')

b = break_even("polymarket-us", 0.40, 500, tier=2)
b.exit_price, b.move_cents  # (Decimal('0.45'), Decimal('5.00'))
```

Signature: `fee(platform, price, contracts, side="buy", tier=None, maker=False, *, category=None,
multiplier=None, series=None, volume_30d=None, at=None, rates=None) -> FeeResult`. Platform names: `kalshi`,
`polymarket-us`, `polymarket` (also `polymarket.com`). Prices and counts can be `str`, `int`,
`float` or `Decimal`; floats are converted through `str`, so `0.1` means exactly 0.1.

`break_even(...)` takes the same arguments plus `tick`. It opens the position at `price`, then
walks the price in `tick` steps (up for a buy, down for a sell) and returns the first exit price
where proceeds − cost − entry fee − exit fee > 0, or `exit_price=None` if no price before $1 (or
$0) works.

## polymarket.com from 2026-11-20 23:59 UTC

Polymarket changes its fees and rebates on polymarket.com at **2026-11-20 23:59 UTC**
([Upcoming Fee and Rebate Changes](https://docs.polymarket.com/programs/fee-and-rebate-changes-november-2026)).
The formula stays `shares × feeRate × price × (1 − price)`; the category coefficients change, and
rebates move to tiers on 30-day weighted volume.

The rates file holds both sets (`polymarket_global.schedule`). `fee()`, `fill_fees()` and
`break_even()` take `at=` (a timezone-aware `datetime` or an ISO 8601 string with an offset; default
now): a fill before the effective time uses the old rates, a fill at or after it the new ones. In
`fill_fees()` each fill can carry its own `at`, so fills of one order on both sides of the change are
each priced with their own rates. Naive times are rejected. A subcategory that only exists after the
change (`Politics (elections)`) uses its parent category's rate before it.

| Category | Before | From 2026-11-20 23:59 UTC |
|---|---|---|
| Crypto, BTC 5- and 15-minute up/down (`Crypto (BTC 5m/15m up/down)`) | 0.07 | 0.05 |
| Crypto, all other markets | 0.07 | 0.01 |
| Sports (all, including NFL and college football) | 0.05 | 0.05 |
| Finance, Tech | 0.04 | 0.05 |
| Politics, elections (`Politics (elections)`) | 0.04 | 0.05 |
| Politics, excluding elections and geopolitics | 0.04 | 0.01 |
| Economics, Culture, Weather | 0.05 | 0.01 |
| Mentions | 0.04 | 0.01 |
| Geopolitics | 0 | 0 |
| Combos, Other / General | 0.05 | 0.05 |

Rebates from the same time, as a share of taker fees: **taker** tiers by the fees you paid (None
under $200K, Gold 10%, Platinum 25% from $1M, Diamond 40% from $4M, Obsidian 50% from $10M, Onyx 60%
from $75M), **maker** tiers by the taker fees your eligible maker fills generated (None under $200K,
Tier 1 3%, Tier 2 7% from $1M, Tier 3 10% from $4M, Tier 4 15% from $10M). The volumes are
**weighted volume**: each fill adds shares × price × (1 − price), summed over 30 days, maker and
taker fills separately. Combos and fee-free fills earn no maker rebate.

```python
from pmfees import polymarket_rebate, polymarket_rebate_tier, weighted_volume

weighted_volume([(0.40, 1000)])  # Decimal('240.00')  not dollar volume ($400)
polymarket_rebate_tier("taker", 1_500_000, at="2026-11-21T00:00Z").name  # 'Platinum'
t = "2026-11-21T00:00Z"
r = polymarket_rebate("maker", 100, tier="Tier 4", at="2026-11-21T00:00Z")
r.rebate  # Decimal('15.00')  Polymarket's own example
polymarket_rebate("maker", 100, weighted_volume_30d=2_500_000, at=t).rebate  # Decimal('7.00')
```

Rebates before the change (category multipliers, Bronze/Silver, daily maker rebate pools) are not
modelled: `polymarket_rebate()` raises for an earlier `at`. Polymarket documents no rounding for
rebates, so the amount is exact.

## Kalshi: centicent rounding and the multiplier

Kalshi does not round the fee on its own. It rounds **fee + position cost** (contracts × price) up to
a whole centicent ($0.0001), per the fee schedule (version 7.7.26, page 2). Most of the time that
looks like rounding the fee up to four decimals, but the fee alone is what you see change:

```python
from pmfees import fee

fee("kalshi", 0.50, 1).fee  # Decimal('0.0175')  0.07 × 1 × 0.5 × 0.5 = 0.0175 exactly; not $0.02
fee("kalshi", 0.33, 7).fee  # Decimal('0.1084')  raw 0.108339; 2.31 + 0.108339 = 2.418339 -> 2.4184
```

Accounts cleared through a broker (FCM) keep balances in whole cents, so there the fee rounds to the
cent ([Kalshi docs](https://docs.kalshi.com/getting_started/fee_rounding.md)). pmfees models
kalshi.com accounts (direct members).

Each Kalshi series has a fee multiplier M: 1 (standard), 0.5 or 0. Takers default to M = 1, makers
to M = 0, because Kalshi charges makers only on series listed with maker fees:

```python
fee("kalshi", 0.25, 100).fee  # Decimal('1.3125')  M = 1
fee("kalshi", 0.25, 100, multiplier=0.5).fee  # Decimal('0.6563')  raw 0.65625, rounded up
fee("kalshi", 0.50, 100, maker=True).fee  # Decimal('0.0000')  maker, M defaults to 0
fee("kalshi", 0.50, 100, maker=True, multiplier=1).fee  # Decimal('0.4375')  0.0175 × 100 × 0.25
```

```bash
pmfees kalshi --price 0.25 --contracts 100 --multiplier 0.5
# -> Kalshi taker fee: $0.6563 (2.63% of trade value at 25¢)
```

### Per-series fees

Kalshi publishes a `fee_type` and `fee_multiplier` for every series in its Trade API
([Get Series List](https://docs.kalshi.com/api-reference/market/get-series)). The `fee_type` points
to a table in the [fee schedule](https://kalshi.com/docs/kalshi-fee-schedule.pdf) (version 7.7.26,
2026-07-07): `quadratic` (no maker fees), `quadratic_with_maker_fees` (makers pay 0.25 × the taker
fee, i.e. 0.0175) and `quadratic_with_combo_maker_fees` (makers pay 0.5 × the taker fee). On
2026-11-14, 16,247 of 16,442 series were standard (`quadratic`, M = 1). The other 195 are in
`src/pmfees/data/kalshi_series.json`, with that date and the source links. Some examples: MLB
first-innings and player-prop series have M = 0.5, a few long-dated political and economic series
have M = 0, and about 160 series charge makers.

Pass `series=` instead of `multiplier=`, with a series, event or market ticker:

```python
fee("kalshi", 0.50, 100, series="KXMLBF5").fee  # Decimal('0.8750')  M = 0.5
fee("kalshi", 0.50, 100, series="KXMLBGAME-26NOV14NYYBOS-NYY").fee  # Decimal('0.8750')  series KXMLBGAME
fee("kalshi", 0.50, 100, maker=True, series="KXMLBGAME").fee  # Decimal('0.2188')  0.5 × 0.0175 × 100 × 0.25
fee("kalshi", 0.50, 100, maker=True, series="KXMLBF5").fee  # Decimal('0.0000')  no maker fees
fee("kalshi", 0.50, 100, series="KXHIGHNY").fee  # Decimal('1.7500')  not listed, so standard
```

A ticker that is not in the file gets the standard structure, with a note in `FeeResult.notes`.
`kalshi_series("KXMLBGAME")` returns the entry itself. Kalshi can change a series' fees at any time;
`python3 scripts/update_kalshi_series.py` rebuilds the file from the API (`--check` only compares),
and `load_kalshi_series(path)` or `PMFEES_KALSHI_SERIES_FILE` reads an updated copy.

```bash
pmfees kalshi --price 0.50 --contracts 100 --series KXMLBGAME
# -> Kalshi taker fee: $0.875 (1.75% of trade value at 50¢)
```

## Fees per fill

An order that fills at several prices pays a fee on every fill. `fill_fees()` prices each fill with
`fee()` and adds them up. Fills are `(price, contracts)` pairs or dicts with `price`, `contracts` and
optionally `maker`; the other arguments are the same as `fee()`.

On Kalshi, each fill is rounded up to a whole centicent, but the rounding does not add up within an
order. Kalshi's [Fee Rounding](https://docs.kalshi.com/getting_started/fee_rounding.md) page:

> The **fee accumulator** applies across all fills of an order so that the total fee converges to
> what a single equivalent fill would cost.

> The fee accumulator is maintained per order across all fills regardless of whether the fills are
> taker or maker.

The accumulator collects each fill's rounding and refunds it in steps of the balance precision
($0.0001 for direct members), never more than the fill's own fee. That is the default
(`same_order=True`): the fills are treated as one order.

```python
from pmfees import fill_fees

fills = [(0.33, 1)] * 5  # one order, filled 1 contract at a time
r = fill_fees("kalshi", fills)
r.rebates  # 0.0001 refunded on the fifth fill
fill_fees("kalshi", fills).fee  # Decimal('0.0774')  the same as one fill of 5
fee("kalshi", 0.33, 5).fee  # Decimal('0.0774')
fill_fees("kalshi", [(0.33, 7), (0.34, 3)], series="KXMLBGAME").fee  # Decimal('0.0778')  0.0542 + 0.0236
```

For fills from different orders, pass `same_order=False`. Each fill is then rounded on its own and
nothing is refunded:

```python
fill_fees("kalshi", fills, same_order=False).fee  # Decimal('0.0775')  5 × 0.0155 (0.015477 rounded up)
```

Polymarket US and polymarket.com document no such refund, so there every fill is always rounded on
its own and `same_order` has no effect. `r.breakdown()` gives every fill's raw fee, rounded fee,
rebate and net fee as strings, ready for JSON.

## The formulas

| Platform | Taker fee | Rounding |
|---|---|---|
| Kalshi | M × 0.07 × C × P × (1 − P), M default 1; maker M × 0.0175 × C × P × (1 − P), M default 0 | Up, so that fee + position cost is a whole centicent ($0.0001) |
| Polymarket US | Θ × C × p × (1 − p), Θ by 30-day taker volume: 0.095 (< $10K), 0.085 (< $50K), 0.075 (< $250K), 0.0695 ($250K+); new accounts 0.0695 for the first 7 days | Nearest cent, half to even |
| polymarket.com | C × rate × p × (1 − p), rate by category (Crypto 0.07; Sports, Economics, Culture, Weather, Other, Combos 0.05; Finance, Politics, Mentions, Tech 0.04; Geopolitics 0) | 5 decimals |
| polymarket.com from 2026-11-20 23:59 UTC | C × rate × p × (1 − p) (Sports, Finance, Tech, Politics elections, Combos, Other, Crypto BTC 5m/15m up/down 0.05; Crypto, Politics, Economics, Culture, Weather, Mentions 0.01; Geopolitics 0) | 5 decimals |

The numbers in this table are for reading only. The code takes every rate, tier, multiplier and
rounding rule (including Kalshi's fee + position cost basis) from `prediction_market_fees.json`.

Not modelled: Polymarket US combo fees and maker rebates, polymarket.com rebate programs before
2026-11-20 23:59 UTC, polymarket.com per-market `feeSchedule` exceptions, and Kalshi's `flat` fee type
(Specific Trading Fees Table; no series used it on 2026-11-14). Kalshi's per-series multipliers
are in `kalshi_series.json` (see above). Check the market when it matters.

## Sources

| Platform | Source | Rates current as of |
|---|---|---|
| Kalshi | <https://kalshi.com/docs/kalshi-fee-schedule.pdf> (version 7.7.26) | 2026-11-10 |
| Kalshi series | <https://external-api.kalshi.com/trade-api/v2/series> (`fee_type`, `fee_multiplier`) | 2026-11-14 |
| Polymarket US | <https://docs.polymarket.us/fees> | 2026-11-15 |
| polymarket.com | <https://docs.polymarket.com/trading/fees> | 2026-11-08 |
| polymarket.com from 2026-11-20 23:59 UTC | <https://docs.polymarket.com/programs/fee-and-rebate-changes-november-2026> | 2026-11-17 |

The tests lock the formulas to the worked examples and fee tables on these pages, with a link
to the source in each test.

## Updating the rates

All rates live in `src/pmfees/data/prediction_market_fees.json`. Each platform has its own `as_of`
(the date its rates were last checked against `source_url`). SwapHunt checks the official fee pages
every week; when a rate changes, the updated file arrives here as a pull request, and a new release
follows after review. To use newer rates without waiting for a release:

```python
from pmfees import fee, load_rates

rates = load_rates("prediction_market_fees.json")
fee("kalshi", 0.50, 100, rates=rates)
```

or set `PMFEES_RATES_FILE=/path/to/prediction_market_fees.json`, or pass `--rates` on the
command line. A file with a missing field or an unknown rounding mode is rejected with a
`RatesError` that names the field.

## Development

```bash
pip install -e . pytest ruff mypy
pytest
ruff check . && ruff format --check .
mypy
```

Releases go to PyPI from GitHub Actions with trusted publishing: bump `__version__`, add a
CHANGELOG entry, and push a `v<version>` tag. The publish job waits for approval.

## Limitations

- pmfees checks `contracts` against each platform's general order size step, not the step of a single
  market. Most Polymarket US markets trade in steps of 0.01 contracts, but a few, mostly futures, trade
  whole contracts only ([Fractional Contracts](https://docs.polymarket.us/learn/trading/basics/fractional-shares.md)).
  pmfees cannot see which market an order is for, so it accepts 0.01 steps on those markets too. Check the
  market's step yourself for Polymarket US futures.

## Disclaimer

Fee estimates for information only. The platform's own confirmation is what you pay.

## License

MIT. See [LICENSE](LICENSE).
