Creating Orders

Step-by-step guide for creating, signing, submitting, and managing orders programmatically with the Python SDK.

Prerequisites

Install the SDK and have your credentials ready:

pip install turbine-py-client

You need a wallet private key and API credentials. If you don't have API credentials yet, the SDK can register them for you (see Auto-Registration below).

Initialize the Client

import os
import time
from dotenv import load_dotenv
from turbine_client import TurbineClient, Outcome, Side, OrderArgs

load_dotenv()

client = TurbineClient(
    host=os.environ["TURBINE_HOST"],            # https://api.turbinefi.com
    chain_id=int(os.environ.get("CHAIN_ID", "137")),
    private_key=os.environ["TURBINE_PRIVATE_KEY"],
    api_key_id=os.environ["TURBINE_API_KEY_ID"],
    api_private_key=os.environ["TURBINE_API_PRIVATE_KEY"],
)

Auto-Registration

If you don't have TURBINE_API_KEY_ID and TURBINE_API_PRIVATE_KEY yet, register them first:

Check the Orderbook

Before placing an order, inspect the current orderbook to find appropriate prices:

Create and Submit an Order

Using create_limit_buy / create_limit_sell

The simplest approach. The client handles signing and nonce generation:

Using OrderArgs

For more control, construct OrderArgs explicitly:

Price and Size Encoding

All prices and sizes are integers with 6 decimal places:

Value
Raw
Meaning

Price

500000

$0.50 (50% probability)

Price

100000

$0.10 (10% probability)

Price

900000

$0.90 (90% probability)

Size

1000000

1 share

Size

10000000

10 shares

Size

500000

0.5 shares

Valid prices: 1 to 999999 (exclusive of 0 and 1,000,000).

Cost to buy: price * size / 1,000,000. For example, buying 10 shares at 450000 ($0.45) costs 450000 * 10000000 / 1000000 = 4500000 = $4.50 USDC.

Payout if you win: size. So 10 shares pay 10000000 = $10 USDC. Profit = $10 - $4.50 = $5.50.

USDC Approval

Before your first order can settle, the settlement contract needs USDC approval. Use the gasless max permit (one-time, no native gas needed):

This signs an EIP-2612 max permit and submits it to the relayer. All subsequent orders on that settlement contract reuse the existing allowance.

To check the current allowance:

Per-Order Permit (Alternative)

You can attach a permit to an individual order instead:

Order Lifecycle

1

Created

create_limit_buy() or create_order() signs the order locally and returns a SignedOrder.

2

Submitted

post_order() sends it to the API. The matching engine checks for compatible counter-orders.

3

Matched

If a compatible order exists, a trade is created. Both orders are matched at the maker's price.

4

Settled

The matched trade is settled on-chain via the settlement contract.

5

Failed / Pending

Check get_failed_trades() / get_pending_trades() for settlement status.

Cancel Orders

Cancel a Single Order

Cancel All Orders for a Market

Monitor Order Status

Check Your Open Orders

Check a Specific Order

Monitor Failed and Pending Trades

After orders match, trades go through on-chain settlement. Monitor the pipeline:

Complete Example

A script that checks the orderbook, places a buy order, and monitors it:

Last updated