> For the complete documentation index, see [llms.txt](https://docs.cspr.cloud/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.cspr.cloud/rest-api/swap/get-swaps.md).

# Get swaps

Get a paginated list of fungible token trades.

```
GET /swaps
```

This endpoint returns fungible token trades and supports filtering by token, pair, sender, and DEX. Results are paginated and sorted by timestamp by default.

Swap amounts are returned in raw on-chain units and are not normalized by token decimals.

## Query params

| Query param                   | Description                                                                                                                                                                                                                                |
| ----------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `token_contract_package_hash` | Filter swaps where any of the provided token hashes appear in the swap (comma-separated)                                                                                                                                                   |
| `pair_contract_package_hash`  | Filter by pair contract package hash (comma-separated)                                                                                                                                                                                     |
| `sender_account_hash`         | Filter by sender account hash (comma-separated)                                                                                                                                                                                            |
| `dex_id`                      | Filter by DEX ids (comma-separated)                                                                                                                                                                                                        |
| `includes`                    | Optional fields schema. Supports `sender_public_key`, `sender_account_info{}`, `sender_centralized_account_info{}`, `pair_contract_package{}`, `token0_contract_package{}`, `token1_contract_package{}`, and `ft_rate(currency_id,dex_id)` |

## Sorting

| Property    | Description              |
| ----------- | ------------------------ |
| `timestamp` | Sort swaps by timestamp. |

Default sorting is `timestamp DESC`

## Optional properties

| Property                          | Type                                                                                     | Description                                                                                                                                                                                                                |
| --------------------------------- | ---------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `sender_public_key`               | `string(68)`                                                                             | Sender public key represented as a hexadecimal string                                                                                                                                                                      |
| `sender_account_info`             | [`AccountInfo`](https://docs.cspr.cloud/rest-api/account-info.md)                        | Sender account info                                                                                                                                                                                                        |
| `sender_centralized_account_info` | [`CentralizedAccountInfo`](https://docs.cspr.cloud/rest-api/centralized-account-info.md) | Sender account information available for known accounts provided by CSPR.cloud team                                                                                                                                        |
| `pair_contract_package`           | [`ContractPackage`](https://docs.cspr.cloud/rest-api/contract-package.md)                | Pair contract package details                                                                                                                                                                                              |
| `token0_contract_package`         | [`ContractPackage`](https://docs.cspr.cloud/rest-api/contract-package.md)                | Token0 contract package details                                                                                                                                                                                            |
| `token1_contract_package`         | [`ContractPackage`](https://docs.cspr.cloud/rest-api/contract-package.md)                | Token1 contract package details                                                                                                                                                                                            |
| `token0_ft_rate`                  | `float64`                                                                                | Token0 rate in the specified currency at the swap timestamp. It's a [function includer](https://docs.cspr.cloud/documentation/overview/optional-properties.md#functions) that accepts `currency_id` and `dex_id` arguments |
| `token1_ft_rate`                  | `float64`                                                                                | Token1 rate in the specified currency at the swap timestamp. It's a [function includer](https://docs.cspr.cloud/documentation/overview/optional-properties.md#functions) that accepts `currency_id` and `dex_id` arguments |

## Response

[`PaginatedResponse`](https://docs.cspr.cloud/documentation/overview/pagination.md)[`<Swap>`](https://docs.cspr.cloud/rest-api/swap.md)

## Example

```bash
curl -X 'GET' \
  'https://api.testnet.cspr.cloud/swaps?token_contract_package_hash=3d80df21ba4ee4d66a2a1f60c32570dd5685e4b279f6538162a5fd1314847c1e&page=1&page_size=10&includes=sender_public_key,ft_rate(1,1)' \
  -H 'Accept: application/json' \
  -H 'Authorization: 55f79117-fc4d-4d60-9956-65423f39a06a'
```

```json
{
  "data": [
    {
      "pair_contract_package_hash": "0f6b7e1a8d6e4f1b5a2c3d4e5f60718293a4b5c6d7e8f90123456789abcdef12",
      "transaction_hash": "9c1b7f2a5d6e4f1b2c3d4e5f60718293a4b5c6d7e8f90123456789abcdef1234",
      "transform_id": 42,
      "block_height": 2404577,
      "sender_hash": "2a1d7f6c8b9e0f1a2b3c4d5e6f708192a3b4c5d6e7f8091a2b3c4d5e6f70819",
      "dex_id": 1,
      "token0_contract_package_hash": "ad0cd4ef3cfd9e7222706786e51773af771f063ecce4606282999a7a6d6ac495",
      "token1_contract_package_hash": "3b7f9c2d4e5f60718293a4b5c6d7e8f90123456789abcdef0123456789abcdef",
      "decimals0": 9,
      "decimals1": 6,
      "amount0_in": "1000000000",
      "amount1_in": "0",
      "amount0_out": "0",
      "amount1_out": "2500000",
      "timestamp": "2024-02-01T10:00:00Z",
      "sender_public_key": "01b9c4d8e2f3a4b5c6d7e8f90123456789abcdef0123456789abcdef0123456789",
      "token0_ft_rate": 2.5,
      "token1_ft_rate": 3.5
    }
  ],
  "item_count": 1,
  "page_count": 1
}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

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

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.cspr.cloud/rest-api/swap/get-swaps.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
