I got tired of eyeballing exchange fee pages every time I wanted to know what a month of trading would roughly cost. So I wrote a small script: you give it a config of fee schedules and a CSV of fills (or planned turnover), and it writes a fees.csv plus a printed summary. No API keys, no account endpoints, no network calls at all. Just arithmetic you control.
The important design decision is that fees live in config, not in code. The script never claims to know your real rate. Your billed fee depends on VIP tier, region, pair category, promotions, and whether a given trade was maker or taker. The script only multiplies what you tell it.
The data model
Each fee row in the config describes one exchange schedule:
-
exchange: free-text name -
label: a short tag for the schedule (this is what fills reference) -
maker_rate/taker_rate: percentages, as you'd read them on a fee page (0.1 means 0.1%) -
tier: optional label like "regular" or "VIP1". It is just a string; I'm not inventing thresholds -
discount_percent: optional, you set it (20 for a rebate, 10 for a discount, 0 if none) -
notes: free text, e.g. region and source
Each fill row in the CSV has label, side (maker or taker), and notional (quote-currency value, e.g. USDT). For planned turnover, just write one row per label and side with the total volume.
The effective rate is listed_rate * (1 - discount_percent / 100), and the fee is notional * effective_rate / 100.
One honest caveat on that formula: a "20% rebate on fees paid" and a "10% fee discount" are not necessarily mechanically identical in how they're credited, and which products a discount covers varies. I model both as a simple percentage reduction. Check the exchange's own terms for scope.
Sample config
Here is a config.json. Every number below is an example, replace with your schedule. I took them from public fee pages I checked, but regions and tiers change fees, so treat them as placeholders.
{
"schedules": [
{
"exchange": "OKX",
"label": "okx_eea_regular_no_xperps",
"tier": "regular",
"maker_rate": 0.200,
"taker_rate": 0.350,
"discount_percent": 0,
"notes": "example, replace with your schedule. EEA regular spot without X-Perps account. Source: https://www.okx.com/en-us/help/eea-xperp-spot-trading-fees-comparison"
},
{
"exchange": "OKX",
"label": "okx_eea_regular_with_xperps",
"tier": "regular",
"maker_rate": 0.0800,
"taker_rate": 0.1000,
"discount_percent": 0,
"notes": "example, replace with your schedule. EEA regular spot with an X-Perps account. Source: https://www.okx.com/en-us/help/eea-xperp-spot-trading-fees-comparison"
},
{
"exchange": "MEXC",
"label": "mexc_standard_spot",
"tier": "standard",
"maker_rate": 0.0,
"taker_rate": 0.05,
"discount_percent": 0,
"notes": "example, replace with your schedule. Standard spot pairs; rates can vary by region and pair type."
},
{
"exchange": "Bitget",
"label": "bitget_standard_spot",
"tier": "standard",
"maker_rate": 0.1,
"taker_rate": 0.1,
"discount_percent": 0,
"notes": "example, replace with your schedule. Standard spot. Set discount_percent yourself if you have a promo; check the official terms for which products it covers."
},
{
"exchange": "Bybit",
"label": "bybit_global_spot",
"tier": "standard",
"maker_rate": 0.1,
"taker_rate": 0.1,
"discount_percent": 0,
"notes": "example, replace with your schedule. Bybit Global spot."
},
{
"exchange": "Binance",
"label": "binance_spot",
"tier": "",
"maker_rate": null,
"taker_rate": null,
"discount_percent": 0,
"notes": "Fill maker_rate and taker_rate from the official Binance fee schedule for your account."
}
]
}
Notice the Binance row has null rates on purpose. I don't have a verified Binance figure to put there, so the script will refuse to compute for that label until you fill it in. I'd rather it fail loudly than silently charge 0%.
Sample fills
fills.csv:
label,side,notional
okx_eea_regular_no_xperps,taker,50000
okx_eea_regular_with_xperps,taker,50000
mexc_standard_spot,taker,50000
mexc_standard_spot,maker,50000
bitget_standard_spot,taker,20000
bybit_global_spot,maker,20000
These are hypothetical volumes, not anyone's real trading.
The script
Standard library only. Python 3.11.
#!/usr/bin/env python3
"""Estimate maker/taker fees from a local config and a CSV of fills."""
from __future__ import annotations
import argparse
import csv
import json
import sys
from dataclasses import dataclass
from pathlib import Path
@dataclass
class Schedule:
exchange: str
label: str
tier: str
maker_rate: float | None
taker_rate: float | None
discount_percent: float
notes: str
def load_schedules(path: Path) -> dict[str, Schedule]:
data = json.loads(path.read_text(encoding="utf-8"))
out: dict[str, Schedule] = {}
for row in data["schedules"]:
label = row["label"]
if label in out:
raise ValueError(f"duplicate label in config: {label}")
out[label] = Schedule(
exchange=row.get("exchange", ""),
label=label,
tier=row.get("tier", "") or "",
maker_rate=row.get("maker_rate"),
taker_rate=row.get("taker_rate"),
discount_percent=float(row.get("discount_percent") or 0),
notes=row.get("notes", "") or "",
)
return out
def effective_rate(listed: float, discount_percent: float) -> float:
if not 0 <= discount_percent <= 100:
raise ValueError("discount_percent must be between 0 and 100")
return listed * (1 - discount_percent / 100)
def compute_rows(schedules: dict[str, Schedule], fills_path: Path):
rows = []
with fills_path.open(newline="", encoding="utf-8") as f:
for i, fill in enumerate(csv.DictReader(f), start=2):
label = fill["label"].strip()
side = fill["side"].strip().lower()
notional = float(fill["notional"])
if label not in schedules:
raise KeyError(f"line {i}: unknown label '{label}'")
if side not in ("maker", "taker"):
raise ValueError(f"line {i}: side must be maker or taker")
s = schedules[label]
listed = s.maker_rate if side == "maker" else s.taker_rate
if listed is None:
raise ValueError(
f"line {i}: {side} rate for '{label}' is blank; "
"fill it in from the official fee schedule"
)
eff = effective_rate(listed, s.discount_percent)
fee = notional * eff / 100
rows.append({
"exchange": s.exchange,
"label": label,
"tier": s.tier,
"notional": f"{notional:.2f}",
"side": side,
"listed_rate": f"{listed:.4f}",
"discount_percent": f"{s.discount_percent:g}",
"effective_rate": f"{eff:.4f}",
"fee": f"{fee:.4f}",
"notes": s.notes,
})
return rows
def write_csv(rows, out_path: Path) -> None:
fields = ["exchange", "label", "tier", "notional", "side",
"listed_rate", "discount_percent", "effective_rate",
"fee", "notes"]
with out_path.open("w", newline="", encoding="utf-8") as f:
w = csv.DictWriter(f, fieldnames=fields)
w.writeheader()
w.writerows(rows)
def print_summary(rows) -> None:
totals: dict[str, tuple[float, float]] = {}
for r in rows:
n, fee = totals.get(r["label"], (0.0, 0.0))
totals[r["label"]] = (n + float(r["notional"]), fee + float(r["fee"]))
print(f"{'label':34} {'notional':>12} {'fee':>10} {'blended %':>10}")
for label, (n, fee) in totals.items():
blended = (fee / n * 100) if n else 0.0
print(f"{label:34} {n:12.2f} {fee:10.4f} {blended:10.4f}")
def main() -> int:
p = argparse.ArgumentParser(description=__doc__)
p.add_argument("--config", required=True, type=Path)
p.add_argument("--fills", required=True, type=Path)
p.add_argument("--out", default=Path("fees.csv"), type=Path)
args = p.parse_args()
try:
schedules = load_schedules(args.config)
rows = compute_rows(schedules, args.fills)
except (KeyError, ValueError, OSError) as e:
print(f"error: {e}", file=sys.stderr)
return 1
write_csv(rows, args.out)
print_summary(rows)
print(f"\nwrote {len(rows)} rows to {args.out}")
return 0
if __name__ == "__main__":
sys.exit(main())
Run it:
python fees.py --config config.json --fills fills.csv --out fees.csv
A worked example, with hypothetical volume
Say you traded 50,000 USDT as taker this month (a made-up number). Using the example rows above:
- OKX EEA regular spot without X-Perps, taker 0.350%: 50,000 x 0.0035 = 175 USDT
- OKX EEA regular spot with an X-Perps account, taker 0.1000%: 50,000 x 0.001 = 50 USDT
- MEXC standard spot, taker 0.05%: 50,000 x 0.0005 = 25 USDT
Same volume, very different cost, and that gap on OKX comes purely from whether the account has an X-Perps (derivatives) account, according to the OKX page linked in the config. Whether that's relevant to you depends on your region and what you actually trade. I deliberately did not build a worked saving example for Bybit, because I don't have verified discount figures to support one.
Where this will be wrong
I'd rather be upfront about the limits than have you trust the CSV blindly:
- It isn't your bill. Actual fees depend on VIP level, region, pair category, promotions, and maker vs. taker status of each fill. If your fill export doesn't tell you maker or taker, you're guessing the split.
- Rates change. The example numbers were accurate when I looked at the linked pages. Re-check them before relying on the output.
-
Discount scope.
discount_percentapplies uniformly to whatever rows you apply it to. Some promotions exclude certain products or regions; the script can't know. For example, Bitget advertises a "10% Off Trading Fees" offer but I'm not going to claim which products it covers. Read the official terms. - No account access. The script doesn't call any private endpoint, doesn't need API keys, and can't fetch your real fee tier. That's a feature for safety, and a limitation for accuracy.
- Not advice. This is a calculator, not tax, accounting, or investment advice.
Extending it
A few easy next steps: accept a CSV config as well as JSON, add a --by-exchange rollup, or add a fee_asset column if you pay fees in a native token at a different rate. If you do wire up real fills, most exchanges let you export trade history as CSV, so a small adapter that maps their columns to label,side,notional is usually all you need.
If you want an account to test fee tiers against your own numbers, I use the code UNLOCK20 on OKX (https://okx.com/join/UNLOCK20).
Top comments (0)