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; fan out to the per-account detail endpoint 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 gives you the single source of truth for the mapping in both directions, so the wire format never bites you again.
Account & Monitoring
Real-time dashboards, parallel data fetching, and order-status notifications - production patterns for keeping your app in sync with the broker.
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).
Track Orders Across Sessions
`GET /orders` already covers every currently working order, including multi-day GTCs placed in earlier sessions. To complete the picture you also need post-trade history from `GET /orders/start-date/{date}` - up to one week of historical orders at the **fill level**, which powers reconciliation, daily P&L checks, and audit trails.
Poll Orders & Detect Fills
Build a deduplicated order poller that watches a working set of `clientOrderIds`, fires a callback once per transition, prunes terminal orders, and gracefully bounds rate-limit usage.
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 short candidates, fire locate quotes for all hard-to-borrow names in parallel, poll a single history response to classify all outcomes at once, then accept only the offers that fit within your rate budget.
Pre-Market Short Setup
A morning checklist for short sellers: check existing inventory for reuse, ETB-filter the entire watchlist in one parallel pass, fan out locate quotes for hard-to-borrow names, auto-accept or cancel on price, 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
Run five guard rails - account status, available cash, route capability, existing position, option trading level - *before* `POST /order`. Eliminates the most common 4xx rejections 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
Emergency exit. Walk every 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
Real-time P&L and portfolio updates over persistent WebSocket connections - live account dashboards and order-state tracking without polling.
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.