Automation#
Automated trading on Seesaw means reading on-chain state, applying strategy logic, and submitting signed instructions programmatically — without a UI.
This page covers two related topics:
- Permissionless lifecycle cranks — anyone can run the market lifecycle (create, snapshot, resolve, expire) and earn SOL rewards for doing so.
- Automated trading bots — placing and cancelling orders, managing inventory, and handling settlement automatically.
Permissionless cranks#
Seesaw has no privileged keeper or operator. Every lifecycle step is a public instruction that anyone can call. Native markets use an off-chain cranker to fetch a signed Pyth update, post it through the pinned Pyth Receiver, and pass the resulting account into Seesaw. The protocol rewards timely execution with lamport payments:
Crank rewards#
Each successful lifecycle instruction earns a SOL reward paid directly from the market account:
| Operation | Trigger condition | Default reward |
|---|---|---|
CreateMarket | now >= t_start | 0.0002 SOL |
SnapshotEnd | now >= t_end AND Pyth has a valid post-boundary price | 0.0002 SOL |
ResolveMarket | End snapshot captured | 0.0002 SOL |
ExpireMarket | now >= t_end + expiration_window AND market unresolved | 0.0002 SOL |
The default reward is DEFAULT_CLOSER_REWARD_LAMPORTS = 200,000 lamports
(0.0002 SOL). Each market pre-funds up to 5 reward payouts at creation.
The reward is admin-tunable (via UpdateOperationalParams 0x2A) but only
for future markets — existing markets are funded at the rate in effect when
they were created.
Duplicate calls (e.g., two cranks racing to snapshot the same market) are safe — all lifecycle instructions are idempotent. The first successful call earns the reward; subsequent calls are no-ops and earn nothing.
ExpireMarket: committed evidence or neutral fallback#
ExpireMarket is only available after t_end + market_expiration_window
(default 7 days from the spec — see MARKET_EXPIRY_WINDOW = 604800 s
in program/src/constants.rs). It uses committed snapshots only.
| Condition | Result |
|---|---|
| Both snapshots committed | Apply the jump and strict confidence-interval rules |
| End snapshot missing | Neutral EXPIRED |
Expiry does not accept a transient price-update account. It does not fetch or capture a late price. A directional result remains possible from valid committed snapshots.
Minimal crank loop#
use solana_client::rpc_client::RpcClient;
async fn crank_loop(rpc: &RpcClient, expiration_window: i64) {
loop {
let clock = rpc.get_clock().unwrap();
let now = clock.unix_timestamp;
// Discover existing markets from an indexer or a program-account scan.
// `market_id` is a persisted identity and cannot enumerate time slots.
for (market_address, market_id) in list_existing_markets().await.unwrap() {
let account = rpc.get_account(&market_address).unwrap();
let market = MarketAccount::deserialize(&account.data).unwrap();
let t_end = market.t_end;
let expiry_deadline = t_end.checked_add(expiration_window).unwrap();
if market.outcome == 0 && market.end_price == 0 && now >= expiry_deadline {
// Expiry uses committed snapshots and the deadline.
// Do not fetch or post a new price-update account.
send_expire_market(market_id).await;
} else if market.end_price == 0 && now >= t_end {
send_snapshot_end(market_id).await;
} else if market.outcome == 0 && market.end_price != 0 {
send_resolve_market(market_id).await;
}
}
tokio::time::sleep(Duration::from_secs(1)).await;
}
}
Market discovery must enumerate existing accounts or use an indexer. Do not
derive IDs from the current time or create markets as a side effect of a crank;
each creation uses a distinct persisted preparation identity, while t_start
and t_end come from the landed market account.
Note: redeem is not a crank operation. Traders trigger their own Redeem
— this is by design so that payouts go to the position owner, not to whoever
happens to run a crank.
Pull-oracle markets#
For native markets, the SnapshotEnd crank requires an additional step:
fetching the exact first post-boundary price from Pyth's
Hermes API and posting it on-chain as a PriceUpdateV2 account. The SDK's
resolveSnapshotEnd helper bundles this automatically.
Pull makes Sampling Rule A firstness deterministic — Hermes can serve the exact first post-boundary print before the crank submits the lifecycle instruction.
Seesaw's default Pull keeper is open source in
services/pyth-keeper (unavailable reference), and a
public operator guide is available at Run A Pyth Pull Keeper.
It is not privileged: any caller with a funded Solana fee payer and a valid
Pyth update account can submit the same snapshot_end, resolve_market, or
expire_market instructions. Production operators should monitor both the
keeper process and indexed market state; a running process alone does not prove
markets are advancing.
Automated trading bots#
Architecture overview#
Reading market state#
| Data | Source | Refresh |
|---|---|---|
| Market state and prices | Solana RPC getAccountInfo | Poll or WebSocket |
| Order book (bids + asks) | Solana RPC getAccountInfo on orderbook PDA | Poll or WebSocket |
| Your position | Solana RPC getAccountInfo on position PDA | After each trade |
| Oracle price | Pyth WebSocket / Hermes | ~400 ms |
Use WebSocket subscriptions (accountSubscribe) for latency-sensitive
strategies. Use polling as a fallback or for lower-frequency strategies.
Free-funds trading#
For high-frequency strategies, use the *WithFreeFunds instruction variants.
These operate on an internal trader-ledger balance instead of performing
SPL token transfers on every order:
DepositFunds → deposit stablecoin into quote_free (your ledger balance)
SwapWithFreeFunds → IOC order settled against ledger (no per-order token CPI)
PlaceLimitOrderWithFreeFunds → Limit/PostOnly settled against ledger
CancelMultipleOrdersByIdWithFreeFunds → cancel + refund to ledger
WithdrawFunds → withdraw quote_free back to your wallet
Free-funds orders reduce transaction cost and latency for bots that cycle rapidly through the same capital.
Order lifecycle state tracking#
Order states:
Active → resting on the book, waiting to fill
PartiallyFilled → some quantity matched, remainder resting
Filled → fully matched, slot can be freed
Cancelled → you cancelled it
Expired → TTL elapsed; the next order that touches it reclaims it inline
(maker backing → trader-ledger free balance), or anyone may call
ReclaimExpiredOrder
Track your orders by order_id. After each transaction, re-read the
orderbook PDA to confirm actual state.
Pre-trade checks#
Always validate before sending:
| Check | How |
|---|---|
| Market in TRADING state | market.state == Trading |
Not too close to t_end | now < market.t_end − safety_margin |
| Sufficient USDT balance | Compare user_token_account.amount to required collateral |
| Book not full | Count active slots against the market's configured capacity |
| Price inside maker band | Compute band from best bid/ask before posting |
Retry and error handling#
| Error | Retryable | Recommended action |
|---|---|---|
OrderPriceOutOfBand | Yes (re-price) | Re-read book, recalculate quotes |
OrderbookFull | Yes (wait) | Back off, cancel a stale order |
TradingEnded | No | Stop placing orders; switch to settlement |
InsufficientBalance | No | Examine actual on-chain balance |
| Network / RPC timeout | Reconcile only | Examine the recorded signature; keep the replacement barrier |
| Blockhash expired | Reconcile only | Expiry does not prove failure; do not sign a new attempt automatically |
Settlement automation#
Bots should automate the claim step too, not just order placement:
Automate claims and keep their transaction journals. After seven days, cleanup can pay owners, but no keeper must submit it. Pending referral fees have a separate forfeiture rule. See Claiming Winnings and Risks.
Strategy patterns#
Momentum#
Track Pyth oracle price movements and trade in the direction of recent momentum:
Market making#
See Market Making for the full two-sided quoting strategy. The key loop for a maker bot:
- Read book → compute mid → compute bid/ask
- Cancel stale quotes
- Place new quotes via
PlaceMultiplePostOnlyOrders - Monitor fills → adjust inventory skew
- Cancel all before
t_end − safety_margin
Arbitrage#
When YES + NO < 10000 bps (both available cheaper than $1 total): buying both locks in a guaranteed profit at settlement. Always net against the taker fee before acting.
Priority fees#
During network congestion, add compute-budget priority fees:
| Congestion | Priority fee |
|---|---|
| Low | 0 |
| Medium | 10,000 µlam/CU |
| High | 100,000 µlam/CU |
Also prepend RequestHeapFrame(64 KiB) for PlaceOrder on a full book —
the place-order hot path can exceed Solana's default 32 KiB heap.
Operational considerations#
Key management#
| Risk | Mitigation |
|---|---|
| Key exposure | Store in environment variables or a hardware vault |
| Key compromise | Keep minimal SOL on the bot wallet; top up as needed |
| Unauthorized access | IP allowlisting; separate bot wallet from main wallet |
Uptime#
The Seesaw protocol operates continuously. Market lifecycles run 24/7 via permissionless cranks. Your bot should handle:
- RPC node downtime → failover endpoint
- Websocket disconnects → reconnect with state re-sync
- Program errors → circuit breaker to pause and alert
Testing#
- Devnet first. Run your strategy with devnet USDT before mainnet.
- Paper trading. Log intended orders without sending them to verify logic.
- Small capital. Ramp up gradually: 1% → 10% → full capital.
Next steps#
- Market Making — the two-sided quoting strategy in detail
- Placing Orders — all order types, free-funds variants, TTL
- Risks — admin controls (pause/post-only) that affect bots
- SDK Guide — TypeScript, Python, and Rust SDK references
Technical reference#
| Mechanism | Instruction |
|---|---|
| Create market + capture start price | CreateMarket (0x03) |
| Capture end price | SnapshotEnd (0x04) |
| Resolve outcome | ResolveMarket (0x05) |
| Oracle-outage fallback | ExpireMarket (0x06) |
| Deposit to ledger balance | DepositFunds (0x08) |
| Withdraw from ledger balance | WithdrawFunds (0x09) |
| IOC with free funds | SwapWithFreeFunds (0x0E) |
| Limit/PostOnly with free funds | PlaceLimitWithFreeFunds (0x0F) |
| Batch post-only with free funds | BatchPostOnlyWithFreeFunds (0x10) |
| Cancel with ledger refund | CancelMultipleOrdersByIdWithFreeFunds (0x14) |
| Reclaim expired order (+ optional bounty) | ReclaimExpiredOrder (0x16) |
| Claim winnings | Redeem (0x17) |
| Permissionless position settle | MarkPositionSettled (0x19) |
| Close position PDA | ClosePosition (0x1A) |
| Market teardown | CloseMarket (0x1B) |