Before you start
You need:- Node.js with built-in
fetch - a wallet that has accepted the current Terms of Use
- an
ss_...API token stored outside source control - exact-integer handling for token amounts and field identifiers
1. Create an API client
2. Discover tokens and pools
data is empty or pagination shows that all rows have been returned. Keep the exact pool key, token IDs, fee fields, and scale values. The fee_percent field records the creation fee. Use current_fee_percent for the live fee before Pricing Terms reductions, when available. Both fields use basis points.
3. Load the data your strategy uses
Do not fetch every endpoint for every pool. Request only the resources needed by the strategy:GET /pools/{key}for public pool metadataGET /pools/{key}/statsfor current indexed statisticsGET /pools/{key}/tradesfor trade historyGET /pools/{key}/ohlcvfor candlesGET /explore/transactionsfor the public market transaction feed
getJson with { publicEndpoint: true } for each one. Use GET /pools/{key}/oracle for an indexed oracle snapshot. See Pool oracle for supported windows and unavailable-data states.
Use offset pagination for Explore token and pool lists. Use the returned nextCursor for Explore transactions. See Pagination and errors.
When the API encodes an integer amount as a JSON string, parse it with an arbitrary-precision integer type. Never pass it through JavaScript number.
4. Request a route
5. Refresh state safely
Use request timeouts, bounded exponential backoff, jitter, and a maximum retry count.
The bot can request a short-lived WebSocket ticket with its API token or a browser wallet session. Follow the WebSocket feed. After any disconnect, reload REST state before acting on new events.
Transaction boundary
The API supplies indexed data and routes. Authenticated clients can readGET /pools/{key}/initialized-ticks when constructing transactions. Each tick includes its exact mapping_key; preserve that value for mapping reads and transaction inputs. Do not use the tick number as its mapping key. Your wallet or proving client still owns:
- token-record selection and reservation
- transaction construction and signing
- proof generation and submission
- swap-output claim handling
- accepted, rejected, and unknown transaction states
- final public-state and record reconciliation