Clarify get_fee_rate_bps semantics; add get_fee_rate for the real per-market rate (#107) - #110
Open
erik-polymarket wants to merge 1 commit into
Open
Clarify get_fee_rate_bps semantics; add get_fee_rate for the real per-market rate (#107)#110erik-polymarket wants to merge 1 commit into
erik-polymarket wants to merge 1 commit into
Conversation
…-market rate get_fee_rate_bps returns the /fee-rate base_fee, a constant fee-authorization value (1000 bps for every fee-bearing market, 0 for fee-free) that is signed into v1 orders as feeRateBps and capped on-chain by the exchange max fee rate. It is not the effective per-market rate, which is confusing for integrators using it to estimate fees (GH #107). Document that on get_fee_rate_bps and add get_fee_rate(token_id), a public getter for the real per-category rate (fd.r) mirroring get_fee_exponent, so integrators have an actionable path to the value the charged fee derives from. No change to what gets signed into orders.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Addresses the SDK-observable half of #107.
get_fee_rate_bps()returns/fee-rate'sbase_fee, which is a constant (1000bps for every fee-bearing market,0for fee-free) — it is the fee authorization value signed into v1 orders asfeeRateBps(capped on-chain by the exchange's global max fee rate in_validateFeeRate), not the effective per-market rate. Integrators reading it as "the fee rate in bps" compute wrong fees (the reporter's core finding:1000never matched any market's real 400/500/700 bps).The real per-category rate already lives in the SDK as
FeeInfo.rate(fd.r), populated fromGET /clob-markets/{condition_id}and used by the fee-estimation helpers — but there was no public getter for it (onlyget_fee_exponent).Changes
get_fee_rate_bps()documenting thatbase_feeis an authorization/ceiling value, not the effective rate, and pointing to the real one.get_fee_rate(token_id) -> floatreturning the real per-market rate (fd.r), mirroring the existingget_fee_exponent.TestGetFeeRate(cache hit, lazy fetch, no-refetch, and distinctness fromget_fee_rate_bps).What this deliberately does NOT change
The reporter asked (#107 Q2) whether
__resolve_fee_rate_bps()should signfd.rinstead ofbase_fee. No — that would be a regression. The canonical TS SDK (clob-client-v2) signsbase_feeidentically, and the signedfeeRateBpsis a max-fee authorization the operator charges under, not the applied rate. Lowering it tofd.rwould reduce the on-chain ceiling and diverge from the TS SDK / server expectations. Production trades daily withbase_fee=1000, so it is the correct value to sign. This PR leaves signing untouched and only removes the ambiguity.The remaining items in #107 (documenting
base_feeas a flag in the public API reference,fd.esemantics, USDC-side vs share-side collection, andfee_rate_bps: 0on charged trade records) are backend/docs-owned and are being triaged separately.Test plan
pytest tests/test_client_fee_cache.py tests/test_fee_calculations.py→ 69 passed (public deps only; privatepoly_eip712_structsnot required for these).Note
Low Risk
Read-only API and documentation only; no changes to order signing or fee calculation paths.
Overview
Clarifies that
get_fee_rate_bpsreturns/fee-rate'sbase_fee—the constant fee authorization signed into v1 orders—not the rate used to compute charged fees. The docstring directs integrators to the new API for the effective rate.Adds
get_fee_rate(token_id), returning the per-marketfd.rfraction (same cache path asget_fee_exponent). Order signing via__resolve_fee_rate_bpsis unchanged.Includes
TestGetFeeRatecoverage for cache behavior and distinction fromget_fee_rate_bps.Reviewed by Cursor Bugbot for commit 3e3bfc3. Bugbot is set up for automated code reviews on this repo. Configure here.