OrderBookClient is your primary interface for interacting with the T+ order-management system. It wraps every order lifecycle operation — placing limit and market orders, cancelling and replacing existing orders, batch submissions, and querying your positions, inventory, and trade history — as async Python methods backed by the tplus-core REST API.
Initialization
OrderBookClient is an async context manager. Always use it inside async with to ensure underlying HTTP connections are cleaned up properly.
load_user("name") reads a local keyfile and prompts for the password if required. For ephemeral/test usage, call User() from tplus.utils.user to mint a temporary keypair without storing it.User object you pass. You do not need a separate API key.
Fetching Market and Book Data
Get Market Details
Retrieve the decimal precision for price and quantity on a given asset’s book. This is needed to correctly interpret integer prices and quantities returned by the API.Get Order Book Snapshot
Fetch the current state of the order book for an asset, including the sequence number, all ask levels, and all bid levels.Get User Orders
Returns all orders associated with the authenticated user, along with the raw response payload.Get Open Orders for a Book
Fetch only the currently open orders for a specific asset.Get User Inventory
Returns your current inventory holdings across all assets.Get User Margin Info
Returns a breakdown of your margin usage. Passinclude_positions=True to include open position details.
Placing Orders
All prices and quantities are integers in the book’s native units. Fetch the asset’s
book_price_decimals and book_quantity_decimals from get_market() to convert human-readable values into the correct integer representation.Limit Orders
Usecreate_limit_order to place a resting limit order. Pass a time_in_force instance to control order lifetime.
The asset to trade. Use
AssetIdentifier(index) for registry-index form.Integer quantity in book units.
Integer price in book units.
Direction of the order.
Import from
tplus.model.limit_order. Pass an instance, not the class itself.Market Orders
Usecreate_market_order to execute immediately at the best available price. Set fill_or_kill=True to reject partial fills.
base_quantity instead of quantity for quantity expressed in the base asset:
Batch Orders
Submit multiple orders atomically usingsend_multiple_orders. Build each request object individually, then pass them as a list.
Managing Existing Orders
Cancel an Order
Cancel any open order by its ID and asset.Replace an Order
Atomically amend an open order’s price or quantity. You only need to pass the fields you want to change.User Trade and Position Data
Get Trades
Retrieve your complete trade history, or filter by a specific asset.Check Solvency
Query your account’s current solvency status.Preview Closing All Positions
Get a preview of what would happen if all positions in a sub-account were closed, without actually submitting any orders.Sub-Accounts
Transfer assets between sub-accounts on your user. Specify the source and target by their integer index.Create a Market (Idempotent)
Register a new trading market for an asset. This call is idempotent — it’s safe to call multiple times; it only creates the market if it doesn’t already exist.Error Handling
OrderBookClient raises typed exceptions from tplus.exceptions for all error conditions. Catch the most specific exception that applies to your use case.
| Exception | When it’s raised |
|---|---|
AuthError | Request signature is invalid, or the user is not recognised |
NotFoundError | The requested resource (order, asset, user) does not exist |
OmsError | The order-management system rejected the operation for a business-logic reason |
OrderRejected | The matching engine explicitly rejected the order (e.g. self-trade, invalid price) |
RateLimitError | Too many requests in a short window; back off and retry |
ServerError | An unexpected 5xx error occurred on the server |