# 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)                        | Sender account info                                                                                                                                                                                                     |
| `sender_centralized_account_info` | [`CentralizedAccountInfo`](https://docs.cspr.cloud/rest-api/centralized-account-info) | Sender account information available for known accounts provided by CSPR.cloud team                                                                                                                                     |
| `pair_contract_package`           | [`ContractPackage`](https://docs.cspr.cloud/rest-api/contract-package)                | Pair contract package details                                                                                                                                                                                           |
| `token0_contract_package`         | [`ContractPackage`](https://docs.cspr.cloud/rest-api/contract-package)                | Token0 contract package details                                                                                                                                                                                         |
| `token1_contract_package`         | [`ContractPackage`](https://docs.cspr.cloud/rest-api/contract-package)                | 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#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#functions) that accepts `currency_id` and `dex_id` arguments |

## Response

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

## 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
}
```
