Skip to main content

supagamma

Official Python SDK for the SupaGamma API — institutional-grade historical data for prediction markets.

pip install supagamma
from supagamma import SupaGamma

client = SupaGamma(api_key="sg_...")        # or set SUPAGAMMA_API_KEY

for market in client.markets.auto_paginate(limit=500):
    print(market["id"], market["question"])

Async works identically:

from supagamma import AsyncSupaGamma

async with AsyncSupaGamma() as client:
    bars = await client.trades.ohlcv(market_id="546814", timeframe="1d")

Getting a key

Create one in your dashboard. Keys look like sg_ followed by 32 hex characters, and carry scopes — read for browsing, download for anything that spends credits. The SDK validates the format locally so a typo fails immediately instead of costing a round trip.

What's here

Namespace What it does
client.markets Market catalogue, stats, cost estimates
client.trades Raw fills, OHLCV bars, recent trades
client.series The stream catalogue and its estimates
client.download Paid data delivery — see below
client.orders Cart checkout with idempotency
client.billing Balance, transactions, subscription
client.account Identity, usage, API keys, GDPR export
client.system /health, platform stats
client.public_markets Public market metadata (usually disabled)

Four things worth knowing

These are properties of the API, not of this library, and the SDK surfaces them rather than hiding them.

Downloads spend money, so they are never retried

Every client.download.* call except the two estimates debits your balance. The SDK sets a no-retry policy on those routes regardless of how you configure max_retries.

The reason is specific. The server debits after serialising your data but before the body finishes arriving, and the only protection against paying twice is a 7-day entitlement waiver matched on an exact parameter tuple. A retry that re-derives end=datetime.now() looks like a different request to that matcher and is charged again in full. If you retry a download yourself, freeze your parameters first and replay them byte-identically:

start, end = window()          # compute ONCE
try:
    result = client.download.trades(market_id="546814", start=start, end=end)
except supagamma.APITimeoutError:
    time.sleep(2)              # the entitlement row is written in the background
    result = client.download.trades(market_id="546814", start=start, end=end)

429 means two different things

try:
    client.download.orderbook(market_id="546814")
except supagamma.RateLimitError as e:
    time.sleep(e.retry_after)   # transient — the limiter
except supagamma.QuotaExceededError:
    ...                         # a billing cap; retrying can never succeed

RateLimitError clears after retry_after seconds. QuotaExceededError — your monthly fair-use or free-tier cap — clears on a billing-period boundary, carries no Retry-After, and retrying it just burns limiter budget on top. They share a status code and nothing else, which is why they are separate classes.

Truncation is silent

A download that hits its row cap looks exactly like a complete one: no flag, no header, no marker. When completeness matters, estimate first:

est = client.download.raw_estimate(data_type="polymarket_l2_deltas", start=start, end=end)
if est["capped_by_limit"]:
    ...   # narrow the window; paging cannot reach the rest

Downloads have no offset. A dataset larger than the cap is reachable only by narrowing start/end.

Orderbook data is expensive

At roughly 2 KB per row and $5/MB, the default 100,000-row orderbook pull is on the order of $990. The SDK warns above $25 and lets you gate it:

client.download.confirm_cost = lambda usd: usd < 50    # abort anything pricier

Errors

Everything derives from supagamma.SupaGammaError. The ones you will actually branch on:

Exception Meaning
InsufficientCreditsError 402 — .shortfall is exactly what to top up
SubscriptionRequiredError / UpgradeRequiredError 402 — plan doesn't cover this
RateLimitError 429 — transient, honour .retry_after
QuotaExceededError 429 — billing cap, do not retry
NoDataInRangeError 404 — the id is fine, the window is empty
OrderStatusUnknownError 502 on order creation — replay the same idempotency_key
OriginBlockedError 403 — you pointed base_url at the origin, not the API

Every exception carries .status_code, .code, .request_id and the raw .detail. Quote request_id to support; it is the only correlation handle.

Orders and idempotency

client.orders.create() is the one route with real idempotency protection, and it is a body field, not an Idempotency-Key header. The SDK generates a key for you and returns it:

order = client.orders.create([
    supagamma.resources.orders.OrderItem(data_type="trades", market_id="546814"),
])

# On an ambiguous failure, replay with the SAME key — the server returns the
# original order instead of charging again.
client.orders.create(items, idempotency_key=order["idempotency_key"])

Configuration

SupaGamma(
    api_key=None,               # env SUPAGAMMA_API_KEY
    jwt=None,                   # env SUPAGAMMA_JWT — mutually exclusive with api_key
    base_url="https://api.supagamma.com",
    timeout=httpx.Timeout(connect=10, read=300, write=30, pool=10),
    max_retries=3,              # applies only to safe reads
    max_retry_wait_seconds=60,  # refuse to block longer than this on a 429
)

Pass api_key or jwt, never both — sending both makes the server silently use the key and ignore the JWT, so the SDK refuses it up front.

Requirements

Python 3.9+. The only runtime dependency is httpx.

Licence

MIT — see LICENSE.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

supagamma-0.1.0.tar.gz (49.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

supagamma-0.1.0-py3-none-any.whl (55.3 kB view details)

Uploaded Python 3

File details

Details for the file supagamma-0.1.0.tar.gz.

File metadata

  • Download URL: supagamma-0.1.0.tar.gz
  • Upload date:
  • Size: 49.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for supagamma-0.1.0.tar.gz
Algorithm Hash digest
SHA256 705eb5e0e55d61486a90a2971cf6e366d07eb0e2de516bdee246c1f987f11438
MD5 594dffce0263766e0305c3ff3ec8b787
BLAKE2b-256 47bae2bda920c46451e8dd62436dd9d85f6b319e9ac668086bd37eaaaa681fa9

See more details on using hashes here.

Provenance

The following attestation bundles were made for supagamma-0.1.0.tar.gz:

Publisher: publish.yml on SuperGamma/supagamma-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file supagamma-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: supagamma-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 55.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for supagamma-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 51a993364398f7f3a1c479973fa02e573fb019a3337c7aea50aa6e0eb2a3ae9d
MD5 5e01412c8e5c169f3f195e62759d8b50
BLAKE2b-256 15d3ca508e7e6dcf883535751ffc8b7a0cb1eef0163669ed599738092032c79f

See more details on using hashes here.

Provenance

The following attestation bundles were made for supagamma-0.1.0-py3-none-any.whl:

Publisher: publish.yml on SuperGamma/supagamma-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page