> ## Documentation Index
> Fetch the complete documentation index at: https://build.flashnet.xyz/llms.txt
> Use this file to discover all available pages before exploring further.

# Swap History

> Query historical swap data for pools, users, or the entire AMM

The Flashnet SDK provides methods to query historical swap data, allowing you to track trading activity across the AMM, for specific pools, or for individual users.

## Get Global Swaps

Retrieve a list of the latest swaps across all pools on the AMM.

```typescript theme={null}
async function getGlobalSwaps() {
  try {
    const history = await client.getGlobalSwaps({
      limit: 50, //
    });

    console.log(`Found ${history.totalCount} swaps globally.`);
    history.swaps.forEach(swap => {
      console.log(`- Pool ${swap.poolLpPublicKey}: ${swap.amountIn} -> ${swap.amountOut}`);
    });

    return history;
  } catch (error) {
    console.error('Failed to get global swaps:', error);
  }
}
```

## Get Pool Swaps

Fetch the swap history for a single, specific pool.

```typescript theme={null}
async function getPoolSwaps(poolId: string) {
  try {
    const history = await client.getPoolSwaps(poolId, {
      limit: 100,
      startTime: new Date(Date.now() - 24 * 60 * 60 * 1000).toISOString(), // Last 24 hours
    });

    console.log(`Found ${history.totalCount} swaps for pool ${poolId}.`);
    history.swaps.forEach(swap => {
      console.log(`- User ${swap.swapperPublicKey} swapped ${swap.amountIn} for ${swap.amountOut}`);
    });

  } catch (error) {
    console.error(`Failed to get swaps for pool ${poolId}:`, error);
  }
}
```

## Get User Swaps

Retrieve the trading history for a specific user. If no user public key is provided, it defaults to the client's wallet public key.

```typescript theme={null}
async function getMySwapHistory() {
  try {
    // Gets history for the client's own wallet
    const history = await client.getUserSwaps();

    console.log('My swap history:', history.swaps);

  } catch (error) {
    console.error('Failed to get my swap history:', error);
  }
}

async function getAnyUserSwapHistory(userPublicKey: string) {
  try {
    const history = await client.getUserSwaps(userPublicKey, {
        limit: 50,
        sort: "timestampDesc",
    });

    console.log(`History for ${userPublicKey}:`, history.swaps);
    
  } catch(error) {
    console.error('Failed to get user swap history:', error);
  }
}
```

## Filtering and Pagination

All history methods support `limit` and `offset` for pagination, as well as other filters like `startTime` and `endTime`. Refer to the `ListPoolSwapsQuery`, `ListGlobalSwapsQuery`, and `ListUserSwapsQuery` types in `src/types/index.ts` for a full list of available filters.

## Next Steps

* [Execute Swaps](/products/flashnet-amm/swaps)
* [Explore Pools](/products/flashnet-amm/creation)
