Getting Started

The Turbine Python SDK (turbine-py-client) provides EIP-712 order signing, Ed25519 bearer token authentication, HTTP API access, WebSocket streaming, and gasless on-chain operations for the Turbine prediction market platform.

Installation

pip install turbine-py-client

Requires Python 3.9+. Dependencies: eth-account, eth-utils, httpx, web3, websockets, pynacl, python-dotenv.

Quick Start

from turbine_client import TurbineClient, Outcome, Side, OrderArgs

# Read-only client (public data only)
client = TurbineClient(
    host="https://api.turbinefi.com",
    chain_id=137,
)

# Fetch markets
markets = client.get_markets()
for market in markets:
    print(f"{market.question} (volume: {market.volume / 1e6:.2f} USDC)")

Authentication Levels

The client supports three access levels. Each level unlocks additional functionality.

1

Public (Read-Only)

What you need:

  • host + chain_id

What you can do:

  • Read markets, orderbooks, trades, prices

Example:

2

Signing (Order Creation)

What you need:

  • private_key (wallet private key)

What you can do:

  • Sign orders locally (create SignedOrder objects). Cannot submit to API.

Example:

3

Full Access

What you need:

  • private_key + api_key_id + api_private_key (Ed25519)

What you can do:

  • Submit orders, cancel, get positions, gasless operations, and all authenticated endpoints.

Example:

Getting API Credentials

API credentials are Ed25519 key pairs used to generate bearer tokens for authenticated endpoints. Register them by proving wallet ownership:

This signs a message with your wallet ("Register API key for Turbine: <address>") and sends it to POST /api/v1/api-keys. The server returns a new Ed25519 key pair. Save both values — the private key is not recoverable.

If your wallet already has a registered key, this raises TurbineApiError with status code 409.

Configuration

Constructor Parameters

Parameter
Type
Required
Description

host

str

Yes

API base URL (e.g., https://api.turbinefi.com)

chain_id

int

Yes

Blockchain chain ID

private_key

str

No

Wallet private key for EIP-712 signing

api_key_id

str

No

Ed25519 API key ID for bearer tokens

api_private_key

str

No

Ed25519 private key (hex) for bearer tokens

timeout

float

No

HTTP timeout in seconds (default: 30.0)

Using Environment Variables

Supported Chains

Chain
Chain ID
Settlement Address
USDC Address

Polygon

137

0xdB96C91d9e5930fE3Ed1604603CfA4ece454725c

0x3c499c542cEF5E3811e1192ce70d8cC03d5c3359

Avalanche

43114

0x893ca652525B1F9DC25189ED9c3AD0543ACfb989

0xB97EF9Ef8734C71904D8002F8b6Bc66Dd9c48a6E

Base Sepolia

84532

0xF37B881F236033E55bF1cdAB628c7Cd88aAd89D4

0xf9065CCFF7025649F16D547DC341DAffF0C7F7f6

Chain configs are loaded automatically based on chain_id. Access them via:

Client Properties

Context Manager

The client implements the context manager protocol for automatic resource cleanup:

Price and Size Encoding

All prices and sizes use integer encoding with 6 decimal places:

Concept
Raw Value
Meaning

Price

500000

$0.50 (50% probability)

Price

1

$0.000001 (minimum)

Price

999999

$0.999999 (maximum)

Size

1000000

1 share

Size

10000000

10 shares

Prices range from 1 to 999999 (exclusive of 0 and 1,000,000). A price of 500000 means $0.50 = 50% implied probability.

Error Handling

Last updated