Bot workflow: state, orders, errors, shutdown#
This page is the end-to-end map for an automated trader or market maker. It connects the pieces that other pages describe in depth and does not repeat them. Read it first, then follow the links for the procedure you need.
| Need | Page |
|---|---|
| Build and send one order | Quickstart, Building transactions |
| Read and decode accounts | Reading data |
| Reconcile balances, orders, and P&L | Monitor a trading bot |
| Unknown transaction result | Transaction recovery examples |
| Two-sided quoting | Market making |
| Reference bot (dry-run first) | Run the reference market maker |
| Lifecycle cranks and Pull keeper | Automation |
| Manual versions of the same actions | First trade and exit |
1. Required state#
Keep each item below in your process, and record its source and slot with every update. A hosted API response is a convenience view; the chain is the authority (Reading data).
| Item | Source | Refresh |
|---|---|---|
| Config (fee epoch, treasury recipients) | ConfigAccount through the generated reader, or GET /api/v1/config and /fee-config | At startup and before each placement batch. Governance can change it. |
| Market state, timing, halt flag | Market account, authenticated through its PDA | Before each placement. Stop quoting before t_end minus your safety margin. |
| Order book | Orderbook PDA through the deep-orderbook reader | Each quote cycle, and after every ambiguous submission. Subscriptions only invalidate. |
| Your open orders | Records in the book whose full owner equals your wallet | Startup, reconnect, each cycle, after every submission result. |
| Position (available and locked shares) | Position PDA | After each confirmed transaction. |
Free funds (quote_free, yes_free, no_free) | Trader ledger slot owned by your wallet | After each confirmed transaction. Rebates credit quote_free. |
| Wallet balances | Settlement, YES, and NO token accounts; SOL balance | Before funding or withdrawal, and when SOL for fees or recovery runs low. |
| Pending transaction attempts | Your durable attempt journal | Before every new signature (section 3). |
| Indexer freshness | GET /api/v1/status (synced, slotLag) | Each cycle if you read any indexed data. |
| Oracle price (strategy input only) | Pyth through Hermes | Per strategy. Not needed to place an order. |
There is no protocol-wide polling interval. Choose cadences from the stale
exposure your strategy tolerates and your RPC capacity. Use finalized
commitment for balances and settlement decisions; use a lower commitment for
live books only with an explicit slot and staleness indicator
(Reading data).
On disagreement between a stream and an account read, stop adding exposure and re-read. See Monitor a trading bot.
2. Fund the strategy#
A bot can pay from wallet token accounts on each order, or deposit into the
per-market trader ledger and use the *WithFreeFunds instructions to avoid a
token transfer per order. Both are described in
Automation and
Fund your trading balance. Ledger
funds belong to one market; withdraw them before you consider the strategy flat.
3. Order placement loop#
One iteration:
- Gate on pending attempts. Call
reconcileReplacementGatefor the action. Ifblockingis not empty, do not sign. Iflandedis not empty, use that result and refresh state (recovery examples). - Refresh state from the table above and run the pre-trade checks in Automation: market is trading, margin before close, balance, book capacity, price band.
- Build the unsigned instruction with
@seesaw/core. Pick the protocol treasury shard withpickTreasuryIndexand pass the matching recipient from config. Never add client-controlled creator or fee-recipient accounts (Building transactions). Bound IOC orders with a worst acceptable price and minimum fill. - Simulate the exact transaction and keep the simulation slot.
- Sign and journal. Record the signed bytes with
TransactionAttemptJournal.recordSignedbefore any network call, then send those exact bytes. - Reconcile. Check the signature status and block height
(
reconcileTransactionAttempt). Do not treat a successful submission as a fill. - Update local state from the confirmed result, then re-read the order book and position. Track orders by on-chain order ID, not by submission.
Batch quoting (PlaceMultiplePostOnly, BatchPostOnlyWithFreeFunds) and
cancel-before-requote are covered in Market making.
Hosted builders under POST /api/v1/tx/* return unsigned instructions only;
they do not submit or confirm anything
(endpoints).
4. Error taxonomy#
A failure happens in one of two stages. The stage tells you whether anything could have changed on chain.
Stage 1: rejected before the transaction lands#
Nothing executed. Fix the input or wait, then rebuild.
| Where | What you see | Action |
|---|---|---|
| SDK validation | SeesawValidationError or a failed account-decode check | Correct the argument or account. Do not send. |
Hosted builder, HTTP 400 INVALID_PARAMETER | message names the cause: resolved or halted market, responsible-trading cool-off or deposit limit, missing or out-of-range protocolTreasuryIndex, token account mismatch | Fix the request. Resolved and halted markets accept no new orders; cancel, withdraw, and redeem stay available. |
| Hosted API, HTTP 401 / 429 / 503 | Error body with code, source, retryable, userMessage | retryable is true for 429 and 5xx. Back off, then retry the request. |
| Wallet or RPC preflight, simulation | Program error returned by simulation | Same program codes as stage 2. Nothing landed. Re-read state, rebuild. |
API error bodies are described in the REST reference. A builder success is not execution.
Stage 2: landed and failed on chain#
The transaction was included and the program returned an error. State changes are rolled back, but the Solana network fee is spent.
- The program error appears as a custom code, for example
Custom(12306), which is0x3012,OrderPriceOutOfBand. Convert the decimal to hex and look it up in Error codes; the page also gives a user-facing message and recovery action for each code. - Treat a failure as final only when the status is
finalized. A failure seen at a lower commitment is provisional and keeps the replacement barrier up (classifySignatureStatus). - Common retry decisions are in Automation. Symptom-first fixes are in Troubleshooting.
Unknown: no stage yet#
A timeout, missing status, or expired blockhash does not prove failure. Keep the signature, keep the barrier, and follow Recover an unknown transaction and Follow a transaction (unavailable reference). Do not sign a replacement automatically.
5. Return to flat#
Run this on a clean shutdown, on a circuit-breaker trip, and before market close. Stop quoting first, then work in order. After each step, re-read state and confirm it before the next.
- Stop new orders and reconcile every pending attempt. Do not start the checklist while any attempt is unresolved.
- Cancel resting orders.
seesaw order cancel-allsubmits boundedCancelOwnerOrderspages and refunds released balances to the trader ledger. Continue an interrupted session with--resume. Re-read the book after completion to check for orders posted after the session began. Expired orders can also be reclaimed withReclaimExpiredOrder. - Close inventory before resolution. Sell shares, or merge equal YES and NO
amounts back to collateral with
MergeCompleteSet(funding page). Locked shares must be cancelled first. - Claim after resolution.
Redeempays winning shares and returns collateral under unfilled buy orders. Claim within seven days of resolution; after that, cleanup is permissionless but nobody is obligated to run it (Claiming winnings). Persist progress for multi-instruction redemptions (recovery examples). - Reclaim free funds. Withdraw
quote_freewithWithdrawFundsand any free YES or NO shares withWithdrawShares. Maker rebates and free-funds cancellations credit the ledger, not the wallet. - Close the position account with
ClosePositionto return its rent to the owner. This is housekeeping with no payout deadline. - Verify flat. Position shares are zero, the ledger slot is empty or you have recorded what remains, the book holds no owned orders, and the wallet balance matches your external cash-flow ledger (Monitor a trading bot).
If the process dies mid-checklist, restart from the journal and re-run section 1 before continuing. Do not re-send completed steps.
Not covered#
Operator and keeper duties (running cranks, the Pull keeper) are in Automation and Run a Pyth Pull keeper. Strategy design is outside this page.