Featured recipe
Place Your First Order
Authenticate, confirm credentials, check buying power, place a market order, and verify the status - your first end-to-end TradeZero integration.
- Authenticate
- Confirm credentials
- Check buying power
Getting Started
Stand up your first authenticated TradeZero integration and learn the request shape every other recipe builds on.
Place Your First Order
Authenticate, confirm credentials, check buying power, place a market order, and verify the status - your first end-to-end TradeZero integration.
Authenticate & Discover Account
Validate credentials against the live API, identify whether you are pointed at a paper or live account, and enumerate the routes your account is authorized to use.
List All Your Accounts
Use GET /v1/api/accounts as the entry point for any tool that operates across multiple TradeZero accounts. The list response already carries full account data; call the per-account detail endpoint in parallel only if you need the bp field (the list uses buyingPower). Partition paper vs live by the accountType field returned on each row.
Encoding Trader Actions
TradeZero accepts only side: "Buy" | "Sell" on order requests; the trader's real intent (Buy / Sell / Short / Cover) is encoded by pairing side with openClose. This recipe maps trader actions to wire fields in both directions.
Account & Monitoring
Real-time dashboards, parallel data fetching, and order-status notifications - integration patterns for keeping your application in sync with account data.
Live Account Dashboard
Fan out four parallel reads (/account, /pnl, /positions, /orders), compose the headline metrics into a flat snapshot, and poll on an exponential-backoff timer so the dashboard stays cheap when idle and responsive when active.
End-of-Day Trade Recap
Pull today's historical orders from GET /orders/start-date/{date} (one row per fill - tradeId, qty, price, commission, totalFees, netProceeds), summarise headline activity (fills, share volume, gross/net flow, fees), and print a per-symbol VWAP and net-share breakdown - with a fallback to GET /orders for paper accounts (paper has no order history available).
Closed Positions Recap
Read GET /positions/closed, parse lifecycle rows with safe positionId handling, aggregate cumulative realized P&L by symbol (or tradedSymbol for options), print a closed-trades recap, and poll for async lifecycle updates after a flat close.
Poll Orders & Detect Fills
Monitor the orders your application submits: track a working set of clientOrderIds, detect each status transition once, prune terminal orders, and stay within rate limits.
Short Selling & Locates
Borrow availability, locate quotes, and inventory management - the workflows specific to short selling on TradeZero.
Locate Shares & Sell Short
Check Easy-To-Borrow, request and accept a locate quote for hard-to-borrow symbols, confirm the inventory landed, then open the short with side: "Sell" / openClose: "Open".
Cancel a Pending Locate
Locate quotes are not free - every offer ties up inventory. When the offered rate exceeds your threshold, cancel cleanly via DELETE /locates/cancel/accounts/{id}/quoteReqID/{q} and confirm the cancel landed in /locates/history before moving on.
Handle Locate Rejections
Every locate rejection lands in /locates/history with locateStatus: 56. The text field tells you why. This recipe shows how to classify each rejection code and build the appropriate recovery path - skip ETB symbols, back off on "no inventory", and reuse live quotes instead of re-quoting when already pending.
Reuse Locate Inventory
Check existing locate inventory before requesting a new quote. Pre-Borrow locates survive multiple short/cover cycles intraday - no re-quoting needed. Sell back unused inventory end-of-day to stop the billing clock.
Select Between Pre-Borrow and Single Use
When a Reg SHO threshold symbol returns two locate offers - Pre-Borrow (locateType: 3) and Single Use (locateType: 4) - pick the one that minimises your borrow cost for your planned trade count.
Cancel a Pending Sell-Back
After queuing a locate sell-back with POST /locates/sell, you can reverse the decision using the same DELETE /locates/cancel endpoint before the sell settles. The shares return to your available inventory.
Locate a Basket of Symbols
Fan-out ETB checks across a list of symbols you select, request locate quotes for the hard-to-borrow names in parallel, poll a single history response to classify all outcomes at once, then accept the offers that meet your rate criteria.
Pre-Market Short Setup
A morning checklist for short sellers: check existing inventory for reuse, ETB-filter the entire watchlist in one parallel pass, request locate quotes in parallel for hard-to-borrow names, accept or cancel offers against a rate threshold you set, then confirm a clean inventory snapshot before market open.
Equity Orders
Submit, cancel, and cancel-and-replace single-leg stock orders - market, limit, stop, and stop-limit - with safe cleanup patterns.
Place a Limit Order & Cancel It
Submit a resting limit buy far below the market, confirm it is on the book, cancel by clientOrderId, and poll until the order reaches a terminal state.
Watch a Single Order to Completion
Place one order then poll GET /order/{clientOrderId} - a lightweight single-order endpoint that returns the result directly, without scanning all of today's orders or parsing userOrderId.
Pre-Trade Validation
Validate account status, available cash, route capability, existing position, and option trading level - *before* you submit POST /order. Catches the primary 4xx rejections upfront and gives users every failure at once instead of one per retry.
Route-Aware Order Submission
Query GET /routes to discover available execution venues, select the best one for your order characteristics, and pass the route field in POST /order to direct the order precisely.
Stop-Loss On a Long Position
Look up an existing long position, size a stop relative to the average entry price, submit a Sell/Close stop order with timeInForce: GoodTillCancel, and verify it parks on the book.
Use clientOrderId for Idempotency
Never submit the same order twice. Generate a stable clientOrderId before the first attempt, check GET /order/{clientOrderId} to dedupe client-side, and reconcile through the same key after any transport failure.
Cancel All Open Orders
Use DELETE /v1/api/accounts/orders to flatten every working order in one call (optionally scoped by symbol), poll until terminal, and fall back to per-order cancellation when you need finer-grained subsets.
Flatten All Positions
Close every open position when you choose to. Walk each row of /positions, build the inverse market order (longs → Sell/Close, shorts → Buy/Close, options use tradedSymbol), submit sequentially, and poll until the account is fully flat.
Options
OCC symbol construction, single-leg lifecycles, and multi-leg spreads against the TradeZero options API.
Build & Parse OCC Option Symbols
Master the 13-21-character OCC symbol format the TradeZero API uses for every option order - construct it from human inputs, parse it back from positions, and submit a single-leg buy with it.
Close an Option Position
Look up an existing short option in /positions, submit a Buy/Close limit at the mid + a tick, then poll positions until the row disappears - the inverse of opening a short.
Multi-Leg Options: Bull Call Spread
Define a vertical spread as two OCC legs, sort by strike ascending, and submit as a single securityType: "Mleg" ticket. The venue prices and fills both legs together at the net debit, so you never carry one-sided risk during the fill.
Options Strategy Cookbook
A single recipe for every documented multi-leg strategy - Covered Call, Married Put, Straddle, Strangle, Bull Call / Bear Put, Butterfly, Iron Butterfly, Condor, Iron Condor. Build the OCC + submit scaffolding once; plug in the right legs[] per strategy. The wire format never changes - only the legs do.
WebSocket Streams (Beta)
Real-time P&L and portfolio updates over persistent WebSocket connections. Beta — breaking improvements are in progress; message schemas are not finalized.
P&L Stream Dashboard
Connect to the P&L WebSocket stream, complete the two-step auth handshake, subscribe with {"account": accountId}, then maintain a live in-memory state of account equity and per-position unrealized P&L - with correct snapshot seeding, aggCalcs merging, and nested pnlCalc updates.
Portfolio Stream
Bootstrap your order and position state from REST, then stream live incremental updates from the Portfolio WebSocket. Orders key on clientOrderId; position updates arrive with id (the WebSocket name for positionId). Buffer messages during the REST fetch so no event is ever lost.