Skip to main content
The T+ Python SDK (tpluspy) lets you place and manage orders on the T+ exchange through a fully async client. This guide walks you through every step — installing the library, creating an account, connecting to the exchange, and submitting your first limit or market order — so you have a working script you can build on.
1
Install tpluspy
2
Install the core package with pip. You do not need the [evm] extra just to place orders.
3
pip install tpluspy
4
Verify the install by checking the CLI:
5
tplus --help
6
7
Create or load an account
8
T+ signs every request with an Ed25519 key. You can create an ephemeral key for quick testing or load a stored, password-protected keyfile for persistent use.
9
Ephemeral (testing)
from tplus.utils.user import User

# Mints a fresh key pair in memory — gone when the process exits.
user = User()
print("Public key:", user.public_key)
Stored account (production)
from tplus.utils.user import load_user

# Loads ~/.tplus/users/alice — prompts for password if needed.
user = load_user("alice")
print("Public key:", user.public_key)
Generate account via CLI
# Create and persist a new Ed25519 key named "alice".
tplus accounts generate alice
10
Use load_user("alice") (or tplus accounts generate alice) for any workflow where you need the same key across sessions — for example, if you have an on-chain deposit linked to that public key.
11
12
Connect to T+ with OrderBookClient
13
OrderBookClient is the async client for order placement, cancellations, and user data. Always use it as an async context manager so connections are cleaned up automatically.
14
import asyncio
from tplus.client import OrderBookClient
from tplus.utils.user import load_user

API_BASE_URL = "http://127.0.0.1:8000"  # Replace with your T+ endpoint

async def main():
    user = load_user("alice")

    async with OrderBookClient(API_BASE_URL, default_user=user) as client:
        print("Connected to T+")
        # All order calls go inside this block.

asyncio.run(main())
15
16
Check the market exists and get decimals
17
Before placing an order, confirm the market is live and note the price and quantity decimal precision. All prices and quantities are integers in book-native units — the decimals tell you how to convert from human-readable amounts.
18
from tplus.model.asset_identifier import AssetIdentifier

async def main():
    user = load_user("alice")
    example_asset = AssetIdentifier(200)  # registry index form

    async with OrderBookClient(API_BASE_URL, default_user=user) as client:
        market = await client.get_market(example_asset)
        print(f"Price decimals:    {market.book_price_decimals}")
        print(f"Quantity decimals: {market.book_quantity_decimals}")
19
Prices and quantities are integers. If book_price_decimals is 2, then a price of 1000 represents 10.00 in human terms. Always convert your human-readable values before sending them to the API.
20
21
Place a limit order
22
Use create_limit_order with a GTC (Good-Till-Cancelled) time-in-force to post a resting order on the book.
23
import asyncio
from tplus.client import OrderBookClient
from tplus.model.asset_identifier import AssetIdentifier
from tplus.model.limit_order import GTC
from tplus.utils.user import load_user

API_BASE_URL = "http://127.0.0.1:8000"

async def main():
    user = load_user("alice")
    asset = AssetIdentifier(200)

    async with OrderBookClient(API_BASE_URL, default_user=user) as client:
        # Confirm the market is open.
        market = await client.get_market(asset)
        print(f"Market ready — price decimals: {market.book_price_decimals}")

        # Place a GTC sell limit order: 5 units @ price 1000.
        response = await client.create_limit_order(
            asset_id=asset,
            quantity=5,       # integer in book-native units
            price=1_000,      # integer in book-native units
            side="Sell",
            time_in_force=GTC(),
        )
        print("Limit order placed:", response)

asyncio.run(main())
24
Besides GTC, you can import GTD (Good-Till-Date) and IOC (Immediate-Or-Cancel) from tplus.model.limit_order.
25
You can also place a market order that fills immediately at the best available price:
26
# Market buy: 10 units, partial fills allowed.
response = await client.create_market_order(
    asset_id=asset,
    quantity=10,
    side="Buy",
    fill_or_kill=False,   # set True to require a full fill or cancel
)
print("Market order placed:", response)
27
28
Confirm the order was placed
29
Fetch your open orders to verify the order is on the book and inspect its status.
30
async with OrderBookClient(API_BASE_URL, default_user=user) as client:
    orders, _raw = await client.get_user_orders()

    for order in orders:
        print(f"Order ID: {order.order_id}  Side: {order.side}  Status: {order.status}")

Cancel and replace orders

Once you have an order ID from the placement response or from get_user_orders, you can cancel or modify it.

Cancel an order

cancel_response = await client.cancel_order(
    order_id="your-order-id-here",
    asset_id=asset,
)
print("Cancelled:", cancel_response)

Replace an order

Replace lets you atomically update the price and/or quantity of a resting order without cancelling and re-submitting.
replace_response = await client.replace_order(
    original_order_id="your-order-id-here",
    asset_id=asset,
    new_quantity=6,    # optional — omit to keep the existing quantity
    new_price=1_050,   # optional — omit to keep the existing price
)
print("Replaced:", replace_response)

Putting it all together

Here is a complete, copy-paste-ready script that runs the full flow end-to-end:
import asyncio
from tplus.client import OrderBookClient
from tplus.model.asset_identifier import AssetIdentifier
from tplus.model.limit_order import GTC
from tplus.utils.user import load_user

API_BASE_URL = "http://127.0.0.1:8000"

async def main():
    user = load_user("alice")
    asset = AssetIdentifier(200)

    async with OrderBookClient(API_BASE_URL, default_user=user) as client:
        # 1. Check the market.
        market = await client.get_market(asset)
        print(f"Price decimals: {market.book_price_decimals}")

        # 2. Place a limit order.
        limit = await client.create_limit_order(
            asset_id=asset,
            quantity=5,
            price=1_000,
            side="Sell",
            time_in_force=GTC(),
        )
        print("Limit order:", limit)

        # 3. Place a market order.
        market_order = await client.create_market_order(
            asset_id=asset,
            quantity=10,
            side="Buy",
            fill_or_kill=False,
        )
        print("Market order:", market_order)

        # 4. Check your orders.
        orders, _ = await client.get_user_orders()
        for o in orders:
            print(f"  {o.order_id}: {o.side} {o.status}")

asyncio.run(main())

OrderBookClient Reference

Full API reference for all order, market, and inventory methods.

Orders Concept Guide

Learn about order types, time-in-force options, and the order lifecycle.