# Get done trades

## Goal

Download new trades.

## Prerequisites

- Your REST API app.
- Integral API login with trading permission.
- Your organization provisioned to trade with at least one counterparty.
- Done trades that have not yet been downloaded.


## Steps

```mermaid
flowchart TD
  LOGIN(Step 1: Login) --> REQUEST(Step 2: Get done trades) --> RESPONSE(Step 3: Handle response) --> TRADE(List of trades returned) -->|Request until empty list returned| REQUEST
  RESPONSE --> EMPTY(Empty list, no trades to download)
  click LOGIN "#step-1-login"
  click REQUEST "#step-2-get-done-trades"
  click RESPONSE "#step-3-handle-response"
```

### Step 1: Login

Use the [Login and get token](/openapi/integral-api-reference/rest/authentication-api/login) endpoint.

See the related [Login](/developer-portal/tutorials/tutorialauth/) tutorial.

Your access token is in `SSO_TOKEN` of the response header. Your token is valid for limited time.

Pass the `SSO_TOKEN` cookie value with all of your subsequent API requests.

### Step 2: Get done trades

Use the [Get trades](/openapi/integral-api-reference/rest/stp-download/gettrades) endpoint.

You get executed trades that have not been downloaded before. The default maximum number of trades returned is determined by the server. You should poll this endpoint until you receive an empty response indicating that there are no more executed trades available for download.

To get trades that have been previously downloaded, you must first call the [Prepare trades to resend](/openapi/integral-api-reference/rest/stp-download/resend) endpoint.

### Step 3: Handle response

If the response contains a list of trades, you should call the endpoint until you get an empty list.

When the response contains an empty list, there are no new done trades to download.