# Create order

To place an order, grab the nonce and msg hash from the nonce api <mark style="background-color:purple;">orders/nonce/</mark> and provide them to the create order api <mark style="background-color:purple;">/orders/create/</mark>.

> Note: You will need to include the JWT Auth token to request headers to access this endpoint. To get the JWT Auth Token, refer the [login](https://docs.brine.fi/tech/api-documentation/account/login) section of this document.

{% hint style="info" %}
If you are affiliated with the Brine organization, please ensure that you add the organization\_key and api\_key to the request body in both the nonce and create endpoints. This field is entirely optional. To obtain these keys, please reach out to Brine at <support@brine.fi>.
{% endhint %}

## New order nonce <a href="#new-order-nonce" id="new-order-nonce"></a>

Before creating a new order, you’d be required to obtain a nonce and a msg hash by making use of this endpoint. Please note that this is a Private 🔒 route which means it needs to be authorized by the account initiating this request.

#### Endpoint <a href="#endpoint" id="endpoint"></a>

```bash
POST /sapi/v1/orders/nonce/
```

#### Request Headers <a href="#request-headers" id="request-headers"></a>

```json
{
  "Authorization": "JWT ***"
}
```

#### Request Body <a href="#request-body" id="request-body"></a>

| Field     | Type   | Mandatory | Description                             |
| --------- | ------ | --------- | --------------------------------------- |
| market    | STRING | YES       |                                         |
| ord\_type | STRING | YES       | allowed values \[limit, market]         |
| price     | FLOAT  | OPTIONAL  | It is required for creating limit order |
| side      | STRING | YES       | allowed values \[buy, sell]             |
| volume    | FLOAT  | YES       |                                         |

#### Example

```json
{
  "market": "btcusdt",
  "ord_type": "limit",
  "price": 29580.51,
  "side": "sell",
  "volume": 0.015
}
```

#### Response <a href="#response" id="response"></a>

```json
{
  "status": "success",
  "message": "order nonce created successfully, please sign the msg_hash to place the order",
  "payload": {
    "nonce": 931,
    "msg_hash": "0x5f128faa6e96360629b1fcb4f24fe9bc547f0d79c7a3aed056d824baa786755"
  }
}
```

### New order <a href="#new-order" id="new-order"></a>

Create a new order. (Private 🔒)

Before creating a new order, you’d be required to obtain a nonce by making use of this endpoint. Please note that this is a <mark style="background-color:purple;">Private 🔒</mark> route which means it needs to be authorized by the account initiating this request.

#### Endpoint <a href="#endpoint-1" id="endpoint-1"></a>

```bash
POST /sapi/v1/orders/create/
```

#### Request Headers <a href="#request-headers-1" id="request-headers-1"></a>

```json
{
  "Authorization": "JWT ***"
}
```

#### Request Body <a href="#request-body-1" id="request-body-1"></a>

| Field                  | Type    | Mandatory |
| ---------------------- | ------- | --------- |
| msg\_hash              | STRING  | YES       |
| signature (both r & s) | STRING  | YES       |
| nonce                  | INTEGER | YES       |

> To sign the msg hash obtained after accessing the nonce API, use the [NodeJs SDK signMsgHash](https://github.com/Brine-Finance-Libs/brine-connector-nodejs/blob/5643daec485b13a118413ebeb6893dd8eb3f075b/src/utils.ts#L17) function.

```javascript
import { signMsgHash } from '@brine-fi/brine-connector'

const sign = signMsgHash(createOrderNoncePayload, privateKey); 
```

After successfully generating the signature, you may send it together with additional parameters to create the order, as shown below.

#### Example

```json
{
  "msg_hash": "0x5f128faa6e96360629b1fcb4f24fe9bc547f0d79c7a3aed056d824baa786755",
  "signature": {
    "r": "",
    "s": ""
  },
  "nonce": 931
}
```

#### Response <a href="#response-1" id="response-1"></a>

```json
{
  "status": "success",
  "message": "Created Order Successfully",
  "payload": {
    "id": 904,
    "uuid": "6c79cde4-1e8f-4446-9b4a-ba176d50f08b",
    "side": "sell",
    "ord_type": "limit",
    "price": "29580.51",
    "avg_price": "0.0",
    "state": "pending",
    "market": "btcusdt",
    "created_at": "2022-05-27T12:36:57+02:00",
    "updated_at": "2022-05-27T12:36:57+02:00",
    "origin_volume": "0.015",
    "remaining_volume": "0.015",
    "executed_volume": "0.0",
    "maker_fee": "0.0",
    "taker_fee": "0.0",
    "trades_count": 0
  }
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.brine.fi/tech/api-documentation/trading/create-order.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
