settlerisk 0.1.0
Python SDK for the SettleRisk API — resolution risk scoring for prediction markets
Requires Python: >=3.10
Keywords: api-client, kalshi, polymarket, prediction-markets, risk-scoring, trading

# SettleRisk Python SDK

Python client for the [SettleRisk API](https://settlerisk.com) — resolution risk scoring, dispute pricing, and settlement delay modeling for prediction markets.

## Install

```bash
pip install settlerisk
```

## Quick Start

```python
from settlerisk import SettleRiskClient

client = SettleRiskClient(
    key_id="vx_yourkey_123",
    secret="your-base64-secret",
)

# Get risk score for a market
score = client.get_risk_score("polymarket", "0xabc123")
print(f"Risk: {score['aggregate_risk_score']} ({score['risk_tier']})")
print(f"P(dispute): {score['p_dispute']:.1%}")

# Get settlement delay estimate
delay = client.get_expected_delay("polymarket", "0xabc123")
print(f"Median delay: {delay['delay_distribution']['p50_hours']}h")

# Evaluate custom rules (no market required)
result = client.evaluate_rules({
    "platform": "polymarket",
    "rules_text": "This market resolves YES if BTC reaches $100,000 by Dec 31.",
    "resolution_sources": ["https://coingecko.com"],
})
print(f"Score: {result['aggregate_risk_score']}")

# Get dispute-adjusted pricing
pricing = client.price({
    "platform": "polymarket",
    "platform_market_id": "0xabc123",
    "mid_price": 0.65,
    "position_side": "YES",
    "position_notional_usd": 10000,
    "annual_capital_cost_apr": 0.12,
})
print(f"Fair price: {pricing['adjusted_fair_price']:.4f}")
print(f"Risk premium: {pricing['risk_premium']:.4f}")
print(f"Fair spread: {pricing['fair_spread_bps']} bps")
```

## Authentication

All requests are signed with HMAC-SHA256. The SDK handles signing automatically — just provide your `key_id` and `secret` from the SettleRisk dashboard.

## Context Manager

```python
with SettleRiskClient(key_id="...", secret="...") as client:
    score = client.get_risk_score("polymarket", "0xabc")
```

## Retry Behavior

The client automatically retries on 429 (rate limit) and 5xx errors with exponential backoff. Each retry uses a fresh timestamp and nonce. Idempotency keys are preserved across retries.

## API Reference

| Method | Endpoint |
|--------|----------|
| `get_risk_score(platform, market_id)` | `GET /v1/markets/{platform}/{market_id}/risk-score` |
| `get_expected_delay(platform, market_id)` | `GET /v1/markets/{platform}/{market_id}/expected-delay` |
| `evaluate_rules(request)` | `POST /v1/evaluate-rules` |
| `batch_risk_scores(markets)` | `POST /v1/risk-scores:batch` |
| `batch_expected_delays(markets)` | `POST /v1/expected-delays:batch` |
| `price(request)` | `POST /v1/pricing` |
| `batch_price(items)` | `POST /v1/pricing:batch` |
| `create_webhook(url, events)` | `POST /v1/webhooks` |
| `list_webhooks()` | `GET /v1/webhooks` |
| `delete_webhook(webhook_id)` | `DELETE /v1/webhooks/{webhook_id}` |
| `rotate_webhook_secret(webhook_id)` | `POST /v1/webhooks/{webhook_id}/rotate-secret` |
| `list_webhook_deliveries()` | `GET /v1/webhook-deliveries` |
| `replay_webhook_delivery(delivery_id)` | `POST /v1/webhook-deliveries/{delivery_id}/replay` |
| `status()` | `GET /v1/status` |

## Development

```bash
pip install -e ".[dev]"
pytest tests/ -v
```