The SDK exposes two fee calculation helpers: the simple
SatoshisPerKilobyte model and the new LivePolicy model that mirrors the
behaviour of the TypeScript SDK. This document focuses on LivePolicy, which
retrieves fee rates from the ARC policy API before computing the transaction
fee.
LivePolicy subclasses SatoshisPerKilobyte so it reuses the same byte-size
estimation logic while sourcing the sat/kB rate dynamically. A singleton helper
is provided so consumers can share the cached rate across transactions.
from bsv.fee_models.live_policy import LivePolicy
policy = LivePolicy.get_instance()
tx.fee(policy)LivePolicy(
cache_ttl_ms: int = 5 * 60 * 1000,
arc_policy_url: Optional[str] = "https://arc.gorillapool.io/v1/policy",
fallback_sat_per_kb: int = 1,
request_timeout: Optional[int] = 30,
api_key: Optional[str] = None,
)cache_ttl_ms: Milliseconds a fetched rate remains valid. Subsequent calls within the TTL reuse the cached value instead of re-querying ARC.arc_policy_url: Override the ARC policy endpoint. Defaults to GorillaPool's public service but honours theBSV_PY_SDK_ARC_POLICY_URLenvironment variable when set.fallback_sat_per_kb: Fee to use when the API response cannot be parsed or the network request fails. The default respects theTRANSACTION_FEE_RATEconstant via theTransaction.fee()helper.request_timeout: Timeout passed torequests.get. Defaults toHTTP_REQUEST_TIMEOUTfrombsv.constants(30 seconds by default).api_key: Optional token added as theAuthorizationheader. You can also supply it through theBSV_PY_SDK_ARC_POLICY_API_KEYenvironment variable.
- On a successful fetch,
LivePolicycaches the sat/kB rate for the configured TTL. - If ARC returns an error or an unexpected payload, the model logs a warning, falls back to the most recent cached value when available, otherwise uses the configured fallback rate.
- The singleton returned by
LivePolicy.get_instance()stores cache data in a process-wide shared instance, making it suitable for repeatedTransaction.fee()calls.
from bsv.transaction import Transaction
from bsv.fee_models.live_policy import LivePolicy
tx = Transaction(...)
# Use the shared singleton (default behaviour of Transaction.fee()).
tx.fee(LivePolicy.get_instance())
# Or create a custom policy with a shorter cache TTL and private endpoint.
policy = LivePolicy(
cache_ttl_ms=60_000,
arc_policy_url="https://arc.example.com/v1/policy",
api_key="Bearer <token>"
)
tx.fee(policy)