# Place an order (previously quoted)

## Goal

Place a previously quoted order and query its progress through the order workflow.

This guide uses the *previously quoted* (PQ) order type: you submit the order with a reference to a tradable rate you requested and received.

Also, this guide uses the [Get spot prices](/developer-portal/tutorials/tutorialgetesp) workflow for tradable rates, but you can substitute the [Get fixed-period market data](/developer-portal/tutorials/tutorialfixedperiodmds) workflow in Step 2.

## Prerequisites

- Your REST API app.
- Integral API login with trading permission.
- Your organization provisioned with at least one provider who streams ESP spot prices.


## Steps

```mermaid
flowchart TD
  LOGIN(Step 1: Login) --> GETRATE(Step 2: Get rate) --> PLACEORDER(Step 3: Place order) --> QUERY(Step 4: Query order)
  click LOGIN "#step-1-login"
  click GETRATE "#step-2-get-spot-prices"
  click PLACEORDER "#step-3-place-order"
  click QUERY "#step-4-query-order"
```

### 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.

```json Payload application/json
{
  "user": "apiUserId",
  "pass": "This is a long password!",
  "org": "apiOrganizationId"
}
```

### Step 2: Get spot prices

Use the [Get spot rate by symbol](/openapi/integral-api-reference/rest/market-data/getspotrate) endpoint.

See the related [Get spot prices](/developer-portal/tutorials/tutorialgetesp) tutorial.

Use the `rateId` attribute of the JSON response in the next step.

```javascript JavaScript
const query = new URLSearchParams({symbol: 'EUR/USD'}).toString();

const resp = await fetch(
  `/v2/rates/spot?${query}`,
  {method: 'GET'}
);

const data = await resp.text();
console.log(data);
```

### Step 3: Place order

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

Send the `rateId` from the ESP rate 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.

```json Payload application/json
{
  "coId": "pq11233",
  "rateId": "4HProduct|2022-11-14|0800-1200|EURUSD|SPOT",
  "currency": "EUR",
  "size": 9000000,
  "type": "PQ",
  "price": 1.1652,
  "side": "Buy",
  "symbol": "EUR/USD",
  "timeInForce": "FOK"
}
```

### 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 one of the following endpoints:

* Query order (server ID)
* Query order (client ID or all active orders)


The diagram shows the values returned in the `status` field in the response and their context in the order workflow.

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 --> [*]
```

```javascript JavaScript
const id = '4820276016';
const resp = await fetch(
  `/v2/orders/${id}`,
  {method: 'GET'}
);

const data = await resp.text();
console.log(data);
```