Overview
TheTurbineClient class is the main interface for interacting with the Turbine CLOB API. It provides three access levels:
- Level 0 (Public): No authentication, read-only market data
- Level 1 (Signing): Private key for order signing
- Level 2 (Full): Private key + API credentials for all endpoints
api.turbinefi.com - no direct RPC or blockchain node access required.
Constructor
The API host URL (e.g.,
https://api.turbinefi.com)The blockchain chain ID:
137- Polygon mainnet (recommended)43114- Avalanche mainnet84532- Base Sepolia testnet (currently non-operational)
Optional wallet private key (hex string with
0x prefix) for order signing. Required for Level 1+ access.Optional API key ID for bearer token authentication. Required for Level 2 access.
Optional Ed25519 private key for bearer token signing. Required for Level 2 access.
HTTP request timeout in seconds.
Properties
host
chain_id
address
None.
can_sign
has_auth
Context Manager
The client can be used as a context manager to ensure proper cleanup:Public Endpoints
These methods require no authentication (Level 0 access).get_health
Health status (e.g., “ok”)
get_markets
Optional chain ID to filter markets
List of Market objects with fields:
market_id(str): Unique market identifierquestion(str): Market questionsettlement_address(str): Settlement contract addressstart_time(int): Market start timestampend_time(int): Market end timestampresolved(bool): Whether the market is resolved
get_market
The market ID (hex string)
Market statistics including volume, liquidity, and price data
get_orderbook
The market ID
Optional outcome filter (
Outcome.YES or Outcome.NO)Orderbook with bids and asks:
market_id(str): Market identifierbids(List[PriceLevel]): Buy ordersasks(List[PriceLevel]): Sell orderslast_update(int): Last update timestamp
get_trades
The market ID
Maximum number of trades to return
List of Trade objects
get_stats
get_market).
get_platform_stats
Platform statistics including total volume, markets, and users
get_holders
The market ID
Maximum number of holders to return
List of top holders with addresses and position sizes
get_quick_market
The asset symbol (e.g.,
"BTC", "ETH")Active quick market with:
market_id(str): Market identifierasset(str): Asset symbolstart_price(int): Strike price (6 decimals)start_time(int): Market start timestampend_time(int): Market end timestampsettlement_address(str): Settlement contract
get_quick_market_history
The asset symbol
Maximum number of markets to return
List of historical quick markets
get_quick_market_price
The asset symbol (e.g.,
"BTC", "ETH")Current asset price with timestamp
get_quick_market_price_history
The asset symbol
Maximum number of prices to return
List of historical prices
get_resolution
The market ID
Resolution status:
resolved(bool): Whether the market is resolvedwinning_outcome(int): Winning outcome (0=YES, 1=NO)resolution_time(int): Resolution timestamp
get_failed_trades
List of failed trade records
get_pending_trades
List of pending trade records
get_failed_claims
List of failed claim records
get_pending_claims
List of pending claim records
get_settlement_status
The transaction hash
Settlement status with confirmation details
Order Management
These methods require a private key (Level 1 access).create_order
Order arguments:
market_id(str): Market identifierside(Side):Side.BUYorSide.SELLoutcome(Outcome):Outcome.YESorOutcome.NOprice(int): Price scaled by 1e6 (0-1,000,000)size(int): Size with 6 decimalsexpiration(int): Unix timestamp
Optional settlement contract address. If not provided, fetched from market.
A signed order ready for submission
create_limit_buy
The market ID
Outcome.YES or Outcome.NOPrice scaled by 1e6 (1 to 999,999)
Size with 6 decimals
Optional expiration timestamp. Defaults to 1 hour from now.
Optional settlement contract address
A signed buy order
create_limit_sell
The market ID
Outcome.YES or Outcome.NOPrice scaled by 1e6 (1 to 999,999)
Size with 6 decimals
Optional expiration timestamp
Optional settlement contract address
A signed sell order
Authenticated Endpoints
These methods require both a private key and API credentials (Level 2 access).post_order
The signed order from
create_order, create_limit_buy, or create_limit_sellOrder submission response:
order_hash(str): Unique order identifierstatus(str): Order status
get_orders
Optional trader address to filter
Optional market ID to filter
Optional status filter:
"open", "filled", or "cancelled"List of Order objects
get_order
The order hash
Order details
cancel_order
The order hash to cancel
Optional market ID for validation
Optional side for validation
Cancellation response
cancel_market_orders
The market ID
Cancellation response with count of cancelled orders
get_positions
The market ID
Optional user address to filter
List of Position objects with:
yes_shares(int): YES token balanceno_shares(int): NO token balancetotal_cost(int): Total cost basistotal_revenue(int): Total revenue from sales
get_user_positions
The user’s address
Optional chain ID to filter
List of all positions for the user
get_user_orders
The user’s address
Optional status filter
List of orders
get_user_activity
The user’s address
User activity summary with trade counts and volumes
get_user_stats
User statistics including:
total_cost(int): Total amount spenttotal_invested(int): Net amount investedposition_value(int): Current position valuepnl(int): Profit and loss
get_claimable_positions
User address. Defaults to the signer’s address.
If True, verify each position on-chain and backfill already-claimed ones. Slower but handles pre-fix data.
Dictionary with:
claimable(List[ClaimablePosition]): Claimable positionscount(int): Number of claimable positionstotalPayout(str): Total payout amount
Relayer Endpoints (Gasless Operations)
These methods use Turbine’s gasless relayer for zero-gas transactions.approve_usdc_for_settlement
The settlement contract to approve. If not provided, uses the default for the chain.
The relayer response with
tx_hash on successapprove_ctf_for_settlement
The settlement contract to approve
The relayer response with
tx_hash on successapprove_usdc
The amount to approve (with 6 decimals for USDC)
The spender address. Defaults to settlement contract.
The relayer response with
tx_hash on successclaim_winnings
The market’s contract address
The relayer response with
tx_hash on successbatch_claim_winnings
List of market contract addresses to claim from
The relayer response with
tx_hash on successclaim_all_winnings
The relayer response with
tx_hash on successPosition Discovery
discover_positions
Wallet address to check. Defaults to the signer’s address.
Discovery result with:
claimable(List[ClaimablePosition]): Claimable positionsmergeable(List[MergeablePosition]): Mergeable positionstotal_claimable_usdc(float): Total claimable valuetotal_mergeable_usdc(float): Total mergeable valuemarkets_scanned(int): Number of markets scanned
get_mergeable_positions
Wallet address to check. Defaults to the signer’s address.
List of MergeablePosition with merge amounts
Utility Methods
get_usdc_balance
The address to check. Defaults to signer address.
The USDC balance (raw, 6 decimals)
get_usdc_allowance
The token owner. Defaults to signer address.
The spender address. Defaults to settlement contract.
The current allowance (with 6 decimals)
sign_usdc_permit
The amount to approve (with 6 decimals for USDC)
The spender (settlement contract). Uses chain default if not provided.
Permit expiration timestamp. Defaults to 1 hour from now.
Permit signature that can be included with order submission
sync_permit_nonce
The token contract. Defaults to USDC.
The current on-chain nonce
API Credentials
request_api_credentials (static)
The API host URL (e.g.,
"https://api.turbinefi.com")The wallet private key (for signing the auth message)
Optional friendly name for the API key
Dictionary with:
api_key_id: The API key identifierapi_private_key: The Ed25519 private key (save this!)message: Success message
Error Handling
The client raises specific exceptions for different error conditions:AuthenticationError: Missing credentials for the requested operationTurbineApiError: API request failedOrderValidationError: Invalid order parametersSignatureError: Signature generation failed