> For the complete documentation index, see [llms.txt](https://dexhunter.gitbook.io/dexhunter-partners/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://dexhunter.gitbook.io/dexhunter-partners/trading/limit.md).

# Limit Orders

Place orders at a specific price.

{% hint style="warning" %}
**Required:** Include `X-Partner-Id` header with your API key on all requests.

**Base URL:** `https://api-us.dexhunterv3.app`
{% endhint %}

***

## Build Limit Order

Build a limit order transaction.

**Endpoint**

`POST /swap/limit/build`

**Payload**

| Field               | Type   | Required | Description                     |
| ------------------- | ------ | -------- | ------------------------------- |
| `buyer_address`     | string | ✓        | User's Cardano address          |
| `token_in`          | string | ✓        | Token to sell (`""` for ADA)    |
| `token_out`         | string | ✓        | Token to buy                    |
| `amount_in`         | number | ✓        | Amount in ADA (or token units)  |
| `wanted_price`      | number | ✓        | Target price (in ADA per token) |
| `multiples`         | number |          | Split into N orders             |
| `dex`               | string |          | Preferred DEX                   |
| `blacklisted_dexes` | array  |          | DEXes to exclude                |

**Response**

| Field    | Type   | Description              |
| -------- | ------ | ------------------------ |
| `cbor`   | string | Transaction CBOR to sign |
| `splits` | array  | Order breakdown          |

**Split Object**

| Field             | Type   | Description     |
| ----------------- | ------ | --------------- |
| `dex`             | string | DEX identifier  |
| `amount_in`       | number | Input amount    |
| `expected_output` | number | Expected output |

{% tabs %}
{% tab title="Example: Limit buy at 0.5 ADA" %}

```javascript
const API_KEY = 'YOUR_API_KEY';
const BASE_URL = 'https://api-us.dexhunterv3.app';
const headers = { 'X-Partner-Id': API_KEY };

const payload = {
  buyer_address: 'addr1qx2kd28nq8ac5pr...',
  token_in: '',
  token_out:
    '0691b2fecca1ac4f53cb6dfb00b7013e561d1f34403b957cbb5af1fa4e49474854',
  amount_in: 100,
  wanted_price: 0.5,
  multiples: 1,
  dex: 'MINSWAP',
  blacklisted_dexes: [],
};

const { data: swap } = await axios.post(
  `${BASE_URL}/swap/limit/build`,
  payload,
  { headers }
);
const signatures = await wallet.signTx(swap.cbor, true);
const { data: signed } = await axios.post(
  `${BASE_URL}/swap/sign`,
  { txCbor: swap.cbor, signatures },
  { headers }
);
const txHash = await wallet.submitTx(signed.cbor);
```

{% endtab %}

{% tab title="Example: Split into 5 orders" %}

```javascript
const payload = {
  buyer_address: 'addr1qx2kd28nq8ac5pr...',
  token_in: '',
  token_out:
    '0691b2fecca1ac4f53cb6dfb00b7013e561d1f34403b957cbb5af1fa4e49474854',
  amount_in: 500,
  wanted_price: 0.5,
  multiples: 5,
  dex: 'MINSWAP',
  blacklisted_dexes: [],
};
```

{% endtab %}
{% endtabs %}

***

## Estimate Limit Order

Get expected output without building a transaction.

**Endpoint**

`POST /swap/limit/estimate`

**Payload**

| Field               | Type   | Required | Description                     |
| ------------------- | ------ | -------- | ------------------------------- |
| `token_in`          | string | ✓        | Token to sell (`""` for ADA)    |
| `token_out`         | string | ✓        | Token to buy                    |
| `amount_in`         | number | ✓        | Amount in ADA (or token units)  |
| `wanted_price`      | number | ✓        | Target price (in ADA per token) |
| `multiples`         | number |          | Split into N orders             |
| `dex`               | string |          | Preferred DEX                   |
| `blacklisted_dexes` | array  |          | DEXes to exclude                |

**Response**

| Field             | Type   | Description          |
| ----------------- | ------ | -------------------- |
| `total_output`    | number | Expected output      |
| `possible_routes` | array  | Available DEX routes |

**Route Object**

| Field             | Type   | Description     |
| ----------------- | ------ | --------------- |
| `dex`             | string | DEX identifier  |
| `amount_in`       | number | Input amount    |
| `expected_output` | number | Expected output |

{% tabs %}
{% tab title="Example" %}

```javascript
const { data: quote } = await axios.post(
  `${BASE_URL}/swap/limit/estimate`,
  {
    token_in: '',
    token_out:
      '0691b2fecca1ac4f53cb6dfb00b7013e561d1f34403b957cbb5af1fa4e49474854',
    amount_in: 100,
    wanted_price: 0.5,
    multiples: 1,
    dex: 'MINSWAP',
    blacklisted_dexes: [],
  },
  { headers }
);

console.log(`Expected output: ${quote.total_output} NIGHT`);
```

{% endtab %}
{% endtabs %}

***

## Get Orderbook

Fetch limit orders for a trading pair.

**Endpoint**

`GET /swap/limit_orders/ADA/{token_id}`

{% tabs %}
{% tab title="Example" %}

```javascript
const { data } = await axios.get(
  `${BASE_URL}/swap/limit_orders/ADA/0691b2fecca1ac4f53cb6dfb00b7013e561d1f34403b957cbb5af1fa4e49474854`,
  { headers }
);
```

{% endtab %}
{% endtabs %}
