# 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.tanx.fi/tech/api-documentation/account/login) section of this document.

{% hint style="info" %}
If you are affiliated with the tanX 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 tanX at <support@tanx.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       | <p>allowed values: \[limit, market, stop\_limit, limit\_maker(post-only order) ]. </p><p></p><p>To place a post-only order, send limit\_maker as the order type.</p> |
| price       | FLOAT  | OPTIONAL  | It is required for creating limit order                                                                                                                              |
| side        | STRING | YES       | allowed values \[buy, sell]                                                                                                                                          |
| volume      | FLOAT  | YES       |                                                                                                                                                                      |
| stop\_price | FLOAT  | OPTIONAL  | It is required for creating stop limit order                                                                                                                         |

#### 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 '@tanx-libs/tanx-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
  }
}
```
