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.
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.
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.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.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())
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.
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}")
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.Use
create_limit_order with a GTC (Good-Till-Cancelled) time-in-force to post a resting order on the book.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())
Besides
GTC, you can import GTD (Good-Till-Date) and IOC
(Immediate-Or-Cancel) from tplus.model.limit_order.# 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)
Cancel and replace orders
Once you have an order ID from the placement response or fromget_user_orders, you can cancel or modify it.
Cancel an order
Replace an order
Replace lets you atomically update the price and/or quantity of a resting order without cancelling and re-submitting.Putting it all together
Here is a complete, copy-paste-ready script that runs the full flow end-to-end: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.