# Trade fixed-period rates

## Goal

Execute a trade with rates from a fixed-period market data set, from login and requesting rates to downloading the done trade.

## Prerequisites

- Your REST API app.
- Integral API login with trading permission.
- Your organization provisioned with at least one provider who supports fixed-period market data sets.


## Steps


```mermaid
flowchart TD
  LOGIN(Step 1: Login) --> MARKETDATA(Step 2: Get fixed-period market data)
  MARKETDATA --> PLACEORDER(Step 3: Place order)
  QUERYORDER(Step 4: Query order) -->|Poll for order status| QUERYORDER
  PLACEORDER --> QUERYORDER
  QUERYORDER -->|Order status = FILLED| DOWNLOADTRADE(Step 5: Download trade)
  click LOGIN "#step-1-login"
  click MARKETDATA "#step-2-get-fixed-period-market-data"
  click PLACEORDER "#step-3-place-order"
  click QUERYORDER "#step-4-query-order"
  click DOWNLOADTRADE "#step-5-download-trade"
```

### 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 fixed-period market data

Use the [Get market data](/openapi/integral-api-reference/rest/market-data/getmarketdataset) endpoint.

See the related [Get fixed-period market data](/developer-portal/tutorials/tutorialfixedperiodmds) tutorial.

### Step 3: Place order

Use the [Place order](/openapi/integral-api-reference/rest/orders/placeorder) endpoint.

Send the `rateId` of the rate from the market data set in the `rateId` parameter of the request body.

To get your order status, you must query your order. After the initial success/fail response, status updates are not pushed to you.

### Step 4: Query order

To get your order status, you must query your order. After the initial success/fail response, status updates are not pushed to you.

Use the [Query order (server ID)](/openapi/integral-api-reference/rest/orders/queryorderbyserverid) endpoint.

The diagram shows the values returned in the `status` field in the response.

div
Order status transition (PQ order, success)

```mermaid
stateDiagram-v2
  direction LR
  RECEIVED: Status = RECEIVED\nHTTP code 202
  NEW: Status = NEW\n(Intermediate state)\nHTTP code 200
  FILLED: Status = FILLED\nHTTP code 200
  REJECTED: Status = REJECTED\nHTTP code 200
  [*] --> RECEIVED: Place order
  RECEIVED --> NEW: Query order
  RECEIVED --> REJECTED: Query order
  NEW --> FILLED: Query order
  NEW --> REJECTED: Query order
  FILLED --> [*]
  REJECTED --> [*]
```

div
Order status transition (failure)

```mermaid
stateDiagram-v2
  direction LR
  ERROR: Error object\nHTTP code 400/5xx
  [*] --> ERROR: Place order
  ERROR --> [*]
```

### Step 5: Download trade

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

The endpoint returns all executed trades that have not been downloaded before.

Use the `orderId` from the 202 response when you placed the order to find your trade in the list of returned trades.