# API Reference

Architecture

* **Historical State Archive**
  * Accounts, blocks, and deltas are stored in a proprietary format for fast deterministic queries.
* **Available Ranges**
  * Before creating a session, confirm the slot range of interest is available.
  * `curl https://<host>/available-ranges | jq`&#x20;
* **Session Control Channel**
  * Connect to create and drive a backtest session. All messages on this channel use a custom JSON protocol.
  * Endpoint: `ws(s)://<host>/backtest`
  * Methods: `createBacktestSession`, `attachBacktestSession`, `continue`, `continueTo`, `closeBacktestSession`
  * Responses: `sessionCreated`, `sessionAttached`, `readyForContinue`, `slotNotification`, `paused`, `discoveryBatch`, `status` (see variants below), `success`, `completed`, `error`&#x20;
* **Sequenced Responses**

  * When `disconnectTimeoutSecs > 0`, responses are wrapped with a sequence id so clients can resume a session after reconnecting.
  * `seqId` is a monotonically increasing sequence number. Clients can pass their last received sequence when calling `attachBacktestSession` to resume the stream without replaying earlier messages.

  ```json
  {
    "seqId": 123,
    "method": "status",
    "params": {
      "status": "decodedTransactions"
    }
  }
  ```
* **Discovery Filters**
  * Register filters at session creation to watch for specific events (e.g. a particular program executing). When an upcoming batch matches, the server emits `discoveryBatch` with the target slot and batch index.
  * Pass those values to `continueTo` to pause immediately before the batch executes.
* **Per-Session RPC Channel**
  * Once a session is created, interact with the simulated Solana environment. Most methods conform to the standard Solana JSON-RPC interface.
  * Endpoint: `http(s)://` or `ws(s)://` at `/backtest/{session_id}`
  * Account state: `getAccountInfo`, `getBalance`, `getMultipleAccounts`, `getProgramAccounts`
  * Chain state: `getLatestBlockhash`, `getFeeForMessage`, `getSlot`&#x20;
  * Transactions: `simulateTransaction`, `sendTransaction`, `getTransaction`
  * Subscriptions: `accountSubscribe`, `slotSubscribe`, `transactionSubscribe`

> Notes:
>
> * &#x20;`/backtest` is authenticated by API key in production. `/backtest/{session_id}` is unauthenticated for per-session access.
> * `ReadyToExecuteUserTransactions` is the main status typically requires to wait for before sending or executing user transactions.
> * If your client script does strict parsing, make sure it can handle above mentioned status variants.

#### API Table

| Method                  | Purpose                                                                                                                                                                           | Surface                        |
| ----------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------ |
| `createBacktestSession` | <p>Start a backtest session and receive <code>sessionId</code> + <code>rpcEndpoint</code>.<br>Use <code>parallel: true</code> to create sessions across all available bundles</p> | Session control (WS)           |
| `continue`              | Execute a batch and advance slots; supports `transactions` + `modifyAccountStates`.                                                                                               | Session control (WS)           |
| `closeBacktestSession`  | Close and clean up a session.                                                                                                                                                     | Session control (WS)           |
| `attachBacktestSession` | Reattach to an existing session and receive rpcEndpoint.                                                                                                                          | Session control (WS)           |
| `continueTo`            | Pause immediately before a specific slot and batch index                                                                                                                          | Session control (WS)           |
| `getAccountInfo`        | Fetch a single account at current slot.                                                                                                                                           | Per-session RPC (HTTP)         |
| `getBalance`            | Fetch lamport balance for an account.                                                                                                                                             | Per-session RPC (HTTP)         |
| `getMultipleAccounts`   | Fetch multiple accounts in one call.                                                                                                                                              | Per-session RPC (HTTP)         |
| `getProgramAccounts`    | Fetch accounts owned by a program.                                                                                                                                                | Per-session RPC (HTTP)         |
| `getLatestBlockhash`    | Get current slot blockhash.                                                                                                                                                       | Per-session RPC (HTTP)         |
| `getFeeForMessage`      | Get fee estimate for a message.                                                                                                                                                   | Per-session RPC (HTTP)         |
| `getSignatureStatuses`  | Fetch status for signatures.                                                                                                                                                      | Per-session RPC (HTTP)         |
| `getTransaction`        | Fetch transaction details (including logs).                                                                                                                                       | Per-session RPC (HTTP)         |
| `simulateTransaction`   | Simulate a transaction without committing state.                                                                                                                                  | Per-session RPC (HTTP)         |
| `sendTransaction`       | Execute a transaction immediately in the current slot.                                                                                                                            | Per-session RPC (HTTP)         |
| `getSlot`               | Get the current slot.                                                                                                                                                             | Per-session RPC (HTTP)         |
| `getAddressLookupTable` | Fetch an ALT account.                                                                                                                                                             | Per-session RPC (HTTP)         |
| `modifyAccounts`        | Apply account overrides via RPC.                                                                                                                                                  | Per-session RPC (HTTP)         |
| `accountSubscribe`      | Stream account changes.                                                                                                                                                           | Per-session subscriptions (WS) |
| `programSubscribe`      | Stream program-owned account changes.                                                                                                                                             | Per-session subscriptions (WS) |
| `signatureSubscribe`    | Stream signature status updates.                                                                                                                                                  | Per-session subscriptions (WS) |
| `slotSubscribe`         | Stream slot updates.                                                                                                                                                              | Per-session subscriptions (WS) |
| `logsSubscribe`         | Stream log updates.                                                                                                                                                               | Per-session subscriptions (WS) |


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.termina.technology/documentation/tech-setup-guide/api-reference.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
