Skip to main content

Official Python SDK for the EDGE by Predigy prediction market API (retail, parlay, compliance/MICS, LP)

Project description

EDGE Python SDK

Official Python SDK for the EDGE by Predigy prediction market API.

EDGE is a prediction market pricing engine that integrates with sportsbook platforms. This SDK provides a fully-typed async client for all API operations.


Installation

pip install edge-sdk

Requirements: Python 3.11+


Quick Start

import asyncio
from edge_sdk import EdgeClient

async def main():
    async with EdgeClient(
        base_url="https://edge-production-7b77.up.railway.app",
        api_key="your-api-key",
    ) as client:
        # List open markets
        result = await client.list_markets(status="OPEN")
        for market in result.markets:
            print(f"{market.title}: YES={market.prices.yes:.1%}, NO={market.prices.no:.1%}")

        # Get a quote before trading
        quote = await client.get_quote("mkt_abc123", side="YES", amount=50.0)
        print(f"Cost: ${quote.total_cost:.2f} for {quote.contracts:.1f} contracts")

        # Execute the trade
        trade = await client.execute_trade("mkt_abc123", side="YES", amount=50.0)
        print(f"Trade {trade.trade_id} executed! New balance: ${trade.new_balance:.2f}")

asyncio.run(main())

Authentication

Every request requires an API key passed in the X-API-Key header. The SDK handles this automatically:

client = EdgeClient(
    base_url="https://edge-production-7b77.up.railway.app",
    api_key="your-api-key",
)

You receive your API key when your operator account is created by the Predigy team.


API Reference

Markets

# List markets with optional filters
markets = await client.list_markets(status="OPEN", category="NBA", limit=10)

# Get a single market by external ID
market = await client.get_market("mkt_abc123")

# Create a new market (admin)
market = await client.create_market(
    title="Lakers vs Celtics — Lakers Win",
    category="NBA",
    description="Will the Lakers win tonight's game?",
    b_base=5000.0,
    initial_price_yes=0.55,
)

Quotes and Trades

# Get a price quote (does not execute a trade)
quote = await client.get_quote("mkt_abc123", side="YES", amount=100.0)
print(f"Contracts: {quote.contracts}")
print(f"Avg price: ${quote.avg_fill_price:.4f}")
print(f"Fee: ${quote.fee:.2f} ({quote.fee_rate:.2%})")
print(f"Total cost: ${quote.total_cost:.2f}")

# Execute a trade
trade = await client.execute_trade("mkt_abc123", side="YES", amount=100.0)

# Execute with slippage protection
trade = await client.execute_trade(
    "mkt_abc123", side="YES", amount=100.0,
    max_avg_price=0.60,  # Reject if avg price exceeds $0.60
)

# Sell (cash out) contracts from an existing position
sell = await client.sell_position("mkt_abc123", side="YES", contracts=50.0)
print(f"Net payout: ${sell.net_payout:.2f}")

Portfolio

portfolio = await client.get_portfolio()
print(f"Balance: ${portfolio.balance:.2f}")
print(f"Unrealized P&L: ${portfolio.total_unrealized_pnl:.2f}")

for pos in portfolio.positions:
    print(f"  {pos.market_title} ({pos.side}): {pos.contracts} contracts, P&L: ${pos.unrealized_pnl:.2f}")

Admin Operations

# Get platform statistics
stats = await client.get_stats()
print(f"Total markets: {stats.total_markets}")
print(f"Total volume: ${stats.total_volume:,.2f}")

# Settle a market
result = await client.settle_market("mkt_abc123", outcome="YES")

# Reset sandbox data
await client.reset_sandbox()

Webhooks

# Register a webhook endpoint
webhook = await client.create_webhook(
    url="https://your-app.com/webhook",
    events=["trade.executed", "market.settled"],
    description="Production trade notifications",
)
print(f"Webhook ID: {webhook.webhook.external_id}")
print(f"Secret: {webhook.secret}")  # Store this — shown only once!

# List webhooks
webhooks = await client.list_webhooks()

# Delete a webhook
await client.delete_webhook("whk_abc123")

Health Check

health = await client.health_check()
print(health)  # {"status": "healthy"}

Error Handling

The SDK raises typed exceptions for different error scenarios:

from edge_sdk.exceptions import (
    EdgeAPIError,       # Base class for all API errors
    EdgeAuthError,      # 401 — Invalid or missing API key
    EdgeRateLimitError, # 429 — Too many requests
    EdgeValidationError,# 422 — Invalid request data
)

try:
    trade = await client.execute_trade("mkt_abc123", side="YES", amount=100.0)
except EdgeAuthError as e:
    print(f"Authentication failed: {e.detail}")
except EdgeRateLimitError as e:
    print(f"Rate limited. Retry after {e.retry_after} seconds")
except EdgeValidationError as e:
    print(f"Invalid request: {e.detail}")
except EdgeAPIError as e:
    print(f"API error {e.status_code}: {e.detail}")
    print(f"Request ID: {e.request_id}")  # Useful for support

All exceptions include a request_id field that you can reference when contacting support.


Webhook Verification

When receiving webhook deliveries, verify the HMAC-SHA256 signature to ensure the payload is authentic:

from edge_sdk import verify_signature

# In your webhook handler (e.g., FastAPI)
@app.post("/webhook")
async def handle_webhook(request: Request):
    body = await request.body()
    signature = request.headers.get("X-Edge-Signature", "")

    if not verify_signature(body, signature, WEBHOOK_SECRET):
        raise HTTPException(401, "Invalid signature")

    event = json.loads(body)
    print(f"Received event: {event['event_type']}")
    # Process event...

The X-Edge-Signature header format is sha256=<hex_digest>.

Webhook event types:

  • trade.executed — A trade was placed
  • market.created — A new market was created
  • market.settled — A market was settled with an outcome
  • market.suspended — A market was suspended
  • surge.activated — Surge pricing was triggered
  • liquidity.adjusted — Dynamic liquidity parameter changed

Advanced Usage

Custom HTTP Client

You can provide your own httpx.AsyncClient for custom timeouts, proxies, or connection pooling:

import httpx

custom_client = httpx.AsyncClient(
    base_url="https://edge-production-7b77.up.railway.app",
    timeout=60.0,
    headers={"X-API-Key": "your-api-key", "Content-Type": "application/json"},
    limits=httpx.Limits(max_connections=20),
)

client = EdgeClient(
    base_url="https://edge-production-7b77.up.railway.app",
    api_key="your-api-key",
    http_client=custom_client,
)

Type Safety

The SDK is fully typed with Pydantic models. All responses are validated and provide IDE autocompletion. The py.typed marker (PEP 561) enables type checking in tools like mypy and pyright.


Links


License

Proprietary. Copyright Predigy LLC. All rights reserved.

Project details


Download files

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

Source Distribution

predigy_edge_sdk-2.0.1.tar.gz (21.2 kB view details)

Uploaded Source

Built Distribution

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

predigy_edge_sdk-2.0.1-py3-none-any.whl (16.2 kB view details)

Uploaded Python 3

File details

Details for the file predigy_edge_sdk-2.0.1.tar.gz.

File metadata

  • Download URL: predigy_edge_sdk-2.0.1.tar.gz
  • Upload date:
  • Size: 21.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for predigy_edge_sdk-2.0.1.tar.gz
Algorithm Hash digest
SHA256 5017171d83f19f71dc52bca2bda463069f95ce1b1def676780f9078c05ac0dee
MD5 08629c89e6b390b9b5bb82227f4481fd
BLAKE2b-256 864d738e420b71db1b1fee4c0ff2f16212b3bb574dceb29d74b67da81eefdba5

See more details on using hashes here.

File details

Details for the file predigy_edge_sdk-2.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for predigy_edge_sdk-2.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 fb67acceaf58e4c00d561fd9357de3af7e2749f298ae3fdbffe026b485a6d5a4
MD5 4c12281df40c1e1cd940cf07eae64e9f
BLAKE2b-256 739835b8f1a46f5be199767aa098a53a87e5e64083a515ce2a085238dfcf7fa2

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page