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.
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.
client.host # API base URL
client.chain_id # Chain ID
client.address # Wallet address (None if no signer)
client.can_sign # True if private key is set
client.has_auth # True if API credentials are set
with TurbineClient(host="https://api.turbinefi.com", chain_id=137) as client:
markets = client.get_markets()
# client.close() called automatically
from turbine_client.exceptions import (
TurbineError, # Base exception
TurbineApiError, # HTTP API errors (has status_code)
OrderValidationError, # Invalid order parameters (has field)
SignatureError, # EIP-712 signing failures
AuthenticationError, # Missing credentials (has required_level)
ConfigurationError, # Invalid chain/config
WebSocketError, # WebSocket connection issues
)
try:
result = client.post_order(signed_order)
except AuthenticationError as e:
print(f"Auth failed (requires {e.required_level}): {e.message}")
except TurbineApiError as e:
print(f"API error {e.status_code}: {e.message}")
except OrderValidationError as e:
print(f"Invalid order ({e.field}): {e.message}")