betting_combat.providers.base
base.py — what every provider shares: one paced, counted, retried HTTP client that never shows its secrets.
Pacer at most ``calls`` in any ``window_s``; ``defer`` holds everyone back (a 429)Budget the calls a process made, by endpoint family, and the vendor's own remainderProviderError a call that failed for good: provider, status, endpoint, body (scrubbed)Provider the base: ``get`` (JSON) and ``request`` (any method, raw response), the retries (timeouts, 429 with ``Retry-After``, 5xx), the auth hook (``_auth``: static secret headers by default, Kalshi signs per request)retry_after_seconds a ``Retry-After`` header (seconds or an HTTP-date) as secondsA provider speaks only its source: its endpoints and its payloads as typed vendor rows (values parsed, times in UTC), never our ids. The feeds turn those rows into ours.
Classes
Budget
The calls a process made (every attempt counts: a vendor bills attempts), by endpoint
family; the vendor’s own remainder from its answers’ headers (remaining_header); none
once that remainder is spent, or once cap calls are made.
observe
observe(headers: Mapping[str, str]) -> Nonespend
spend(family: str) -> NoneCount one attempt, or raise ProviderError (nothing counted, nothing sent).
Pacer
At most calls starts in any window_s: a caller over the limit waits for the oldest
start to age out. defer holds every caller back (a 429’s Retry-After). Adaptive: a
429 cuts the rate by a third (slower: the vendor’s budget is shared, with whatever else
spends it), every calls answers since win a call back (faster) up to the ceiling.
acquire
acquire() -> floatWait for a slot; returns the seconds waited.
defer
defer(seconds: float) -> NoneNo call starts before seconds from now.
faster
faster() -> Noneslower
slower() -> NoneOne cut per back-off: the 429s of the calls already in flight are the same news.
Provider
One source’s HTTP client. Subclasses set NAME and BASE_URL and add one method per
endpoint; _auth adds the headers a request needs (static secrets by default).
aclose
aclose() -> Noneget
get(path: str, params: Mapping[str, Any] | None = None, signed: bool = False) -> AnyGET path and its JSON body.
request
request(method: str, path: str, params: Mapping[str, Any] | None = None, json: Any = None, retry: bool = True, signed: bool = False) -> httpx.ResponseOne call, paced and counted, retried on timeouts, 429 and 5xx (unless retry is
False: an order is never sent twice). Any other error raises ProviderError. A full
https:// path is called as it is (a vendor with several hosts).
text
text(path: str, params: Mapping[str, Any] | None = None) -> strGET path and its body as text (UTF-8, unreadable bytes replaced).
ProviderError
Bases: RuntimeError
A call that failed for good (its retries spent, or an error not worth retrying).
Functions
retry_after_seconds
retry_after_seconds(value: str | None, now: dt.datetime | None = None) -> float | NoneA Retry-After header as seconds to wait: delay-seconds, or an HTTP-date (the time left
until it, never negative). None when absent or unreadable.