# Create Order

<mark style="color:blue;">**`POST`**</mark> `https://api.sfox.com/v1/orders/:side`

Create an order.

{% hint style="info" %}
Create order requests are rate limited to **60 requests per second** per account.
{% endhint %}

### **Path Parameters**

<table><thead><tr><th width="240">Parameter</th><th width="92">Type</th><th>Description</th></tr></thead><tbody><tr><td><strong><code>side</code></strong> <mark style="color:red;">required</mark></td><td>string</td><td>Possible values: <code>buy</code> (buy order), <code>sell</code> (sell order)</td></tr></tbody></table>

### Body Parameters

<table data-full-width="false"><thead><tr><th width="274">Parameter</th><th width="100">Type</th><th width="665">Description</th></tr></thead><tbody><tr><td><strong><code>currency_pair</code></strong> <mark style="color:red;">required</mark></td><td>string</td><td>Pair or product to trade in the format <code>basequote</code> . e.g. <code>btcusd</code>, <code>ethbtc</code>, <code>ethusdc</code></td></tr><tr><td><strong><code>algorithm_id</code></strong> <mark style="color:red;">required</mark></td><td>int</td><td><p>Order type / algorithm.</p><ul><li>For more info, see <a href="/pages/-MksB3OWKUp0-RnwDoxN"><strong>Order Types &#x26; Algorithms</strong></a></li><li>Default: Limit (<code>200</code>)</li></ul></td></tr><tr><td><strong><code>price</code></strong> <mark style="color:red;">required</mark></td><td>string</td><td><p>Order limit price.</p><ul><li>Precision: 8 decimal places for crypto, 2 decimal places for fiat</li><li>NOT required for Market (<code>100</code>) orders</li><li><strong>Order fill price will always be better than or equal to this price.</strong> If market conditions do not allow it, the order will not execute.</li></ul></td></tr><tr><td><strong><code>quantity</code></strong> <mark style="color:red;">required</mark></td><td>string</td><td><p>Order size in base currency quantity.</p><ul><li>NOT required for Market (<code>100</code>) orders</li><li><p>Minimum quantity: </p><ul><li>Crypto Quote Pairs:<code>0.001</code></li><li>USD Quote Pairs: <code>price</code>*<code>quantity</code> must be >= $5</li></ul></li></ul></td></tr><tr><td><strong><code>amount</code></strong></td><td>string</td><td><p>The amount (quote currency) to spend when buying.</p><p><strong>Required when placing BUY orders using:</strong> Market (<code>100</code>), Stop (<code>304</code>) or Trailing Stop (<code>308</code>) order types.</p></td></tr><tr><td><strong><code>client_order_id</code></strong></td><td>string</td><td><p>Optional field for a user-specified ID.</p><p><code>client_order_id</code> serves as an idempotency key. <strong>Orders will be rejected if the</strong> <code>client_order_id</code> <strong>has been specified in a previous order placed in the last 24 hours.</strong></p></td></tr><tr><td><strong><code>quote_id</code></strong></td><td>string</td><td>For executing on an <a href="/pages/nEOyHVWWrh7jJmuSU6Sx"><strong>RFQ</strong></a>, the <code>quote_id</code> received in the RFQ request.</td></tr><tr><td><strong><code>time_in_force</code></strong></td><td>string</td><td><p>Time in force (TIF) specifies how the lifetime of your order will be handled. Possible values:</p><ul><li><code>GTC</code>: Good 'til canceled orders remain open until canceled. This is the default TIF option. (Default)</li><li><code>IOC</code>: Immediate or cancel orders instantly cancel the remaining unfilled size of an order leaving it open. Smart (<code>200</code>) and Limit (<code>201</code>) orders only.</li><li><code>FOK</code>: Fill or kill orders are either instantly filled for the full order size or instantly rejected if the entire size cannot be matched. Market (<code>100</code>) and Limit (<code>201</code>) orders only.</li><li><code>GTD</code>: Good 'til date orders are automatically canceled at your specified <code>expires</code> date time.</li></ul></td></tr><tr><td><strong><code>max_slippage</code></strong></td><td>number</td><td>A risk management parameter that will limit the slippage of an order in basis points (e.g. setting <code>max_slippage</code> to <code>5</code> = 0.05%). Market (<code>100</code>), Stop (<code>304</code>), Trailing Stop (<code>308</code>) only.</td></tr><tr><td><strong><code>expires</code></strong></td><td>date-time</td><td><p>Specify the expiration date time of your order (UNIX timestamp in ms). </p><p><strong>Required for orders with</strong> <code>time_in_force</code> <strong>=</strong> <code>GTD</code></p></td></tr><tr><td><strong><code>destination</code></strong></td><td>string</td><td><p>Route the order to a specific destination.</p><p></p><p>Possible values:</p><ul><li><code>ox</code> for the sFOX Ox order book</li><li><code>darkpool</code> for the sFOX Dark Pool</li></ul></td></tr><tr><td><strong><code>total_time</code></strong></td><td>int</td><td>The time, in seconds, that a TWAP (<code>307</code>) order will stay active from the time the TWAP order is placed.</td></tr><tr><td><strong><code>interval</code></strong></td><td>int</td><td>The frequency, in seconds, that slices of a TWAP (<code>307</code>) order will be executed. Default: <code>900</code></td></tr><tr><td><strong><code>continuous</code></strong></td><td>boolean</td><td>TWAP (<code>307</code>) orders will execute slices as small as possible and frequently as possible over the <code>total_time</code>. <code>interval</code> will be ignored If <code>continuous</code> = <code>true.</code></td></tr><tr><td><strong><code>post_only</code></strong></td><td>boolean</td><td>TWAP (<code>307</code>) orders will execute in "post-only" mode. The order will not take and will only execute slices as make orders.<code>post_only</code> means <strong>it is possible the TWAP order will not fill completely</strong> by the end of the <code>total_time</code></td></tr><tr><td><strong><code>stop_amount</code></strong></td><td>number</td><td>Set the amount (quote currency) that the trigger price of a trailing stop order will trail the price of an asset. Trailing Stop (<code>308</code>) only.</td></tr><tr><td><strong><code>stop_percent</code></strong></td><td>number</td><td>Percentage that the trigger price of a trailing stop order will trail the price of an asset (e.g. <code>0.1</code> = 10%). Trailing Stop (<code>308</code>) only.</td></tr><tr><td><strong><code>stop_any_id</code></strong></td><td>int</td><td><p>Turn your order into an STO (Stop-Triggers-Other) or TSTO (Trailing-Stop-Triggers-Other) order: Trigger placement of an order type of your choosing at a certain price or based on a trailing amount/percent. e.g. when price reaches $100 trigger a 1-hour TWAP. Possible values:</p><ul><li><code>310</code> : STO (Stop-Triggers-Other)</li><li><code>311</code> : TSTO (Trailing-Stop-Triggers-Other)</li></ul></td></tr><tr><td><strong><code>stop_any_price</code></strong></td><td>number</td><td>Trigger price of an STO (Stop-Triggers-Other) order. <strong>Required if</strong> <code>stop_any_id</code> <strong>=</strong> <code>310</code>.</td></tr><tr><td><strong><code>stop_any_trail_amount</code></strong></td><td>number</td><td>Trailing amount (quote currency) of a TSTO (Trailing-Stop-Triggers-Other) order. <strong>Required if</strong> <code>stop_any_id</code> <strong>=</strong> <code>311</code> and <code>stop_any_trail_percent</code> <strong>is not used.</strong></td></tr><tr><td><strong><code>stop_any_trail_percent</code></strong></td><td>number</td><td>Specify the trailing percent of a TSTO (Trailing-Stop-Triggers-Other) order (e.g. <code>0.1</code> = 10%). <strong>Required if</strong> <code>stop_any_id</code> <strong>=</strong> <code>311</code> and <code>stop_any_trail_amount</code> <strong>is not used.</strong></td></tr><tr><td><strong><code>routing_option</code></strong></td><td>string</td><td><p>Specify how sFOX will trade your order. Routing Options: </p><ul><li><code>BestPrice</code>: Prioritize price improvement. Hare (<code>303</code>) and Gorilla (<code>301</code>) only.</li><li><code>Fast</code>: Prioritize speed of execution. Hare (<code>303</code>) and Gorilla (<code>301</code>) only.</li><li><code>WeightedExchange</code>: Prioritize routing based on the best combination of price and speed of execution. Smart (<code>200</code>), Limit (<code>201</code>) and Hare (<code>303</code>) only.</li></ul></td></tr><tr><td><strong><code>last_published</code></strong></td><td>date-time</td><td>Specify the last/latest order book update you are attempting to execute on for analysis purposes. Use the <a href="/pages/4CQgv3BxIh9W9BbKsZnF#order-book-message"><code>lastpublished</code> key from the order book message.</a> (UNIX timestamp in ms)</td></tr></tbody></table>

### Responses

<details>

<summary><mark style="color:green;">201</mark> Accepted &#x26; Created</summary>

```json
{
    "id": 2010135,
    "side_id": 500,
    "action": "Buy",
    "algorithm_id": 201,
    "algorithm": "Limit",
    "type": "Limit",
    "pair": "btcusd",
    "quantity": 0.1,
    "price": 36431,
    "amount": 0,
    "net_market_amount": 0,
    "filled": 0,
    "vwap": 0,
    "filled_amount": 0,
    "fees": 0,
    "net_proceeds": 0,
    "status": "Started",
    "status_code": 100,
    "routing_option": "WeightedExchange",
    "routing_type": "NetPrice",
    "time_in_force": "GTC",
    "expires": null,
    "dateupdated": "2023-11-17T20:52:40.000Z",
    "date_added": "2023-11-17T20:52:40.000Z",
    "client_order_id": "ea5c8afc-419a-447d-8188-659dce1a782a",
    "user_tx_id": "ea5c8afc-419a-447d-8188-659dce1a782a",
    "o_action": "Buy",
    "algo_id": 201,
    "algorithm_options": null,
    "destination": ""
}
```

</details>

<details>

<summary><mark style="color:red;">422</mark> Rejected</summary>

```json
// currency_pair not specified
{
    "error": "invalid currency_pair: undefined"
}

// currency_pair speficied but not supported or does not exist
{
    "error": "invalid currency_pair: btcusda"
}
```

</details>

### Example Requests

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

<pre class="language-bash"><code class="lang-bash"><strong>curl -X POST \
</strong>  -H 'Content-type: application/json' \
  -H 'Authorization: Bearer &#x3C;API_TOKEN>' \
  --data '{ "quantity": 1,
            "currency_pair": "btcusd",
            "algorithm_id": 200,
            "price": 20000 }'  \
  'https://api.sfox.com/v1/orders/buy'
</code></pre>

{% endtab %}

{% tab title="NodeJS" %}

```javascript
const axios = require('axios');

axios({
  method: 'post',
  url: 'https://api.sfox.com/v1/orders/buy',
  headers: {
    'Authorization': 'Bearer <API_KEY>'
  },
  data: {
   quantity: 1,
   currency_pair: 'btcusd',
   algorithm_id: 200,
   price: 20000
  }
}).then(response => {
  console.log(response)
}).catch(err => {
  console.error(err)
});
```

{% endtab %}

{% tab title="Python" %}

```python
import requests

data = requests.post(
  "https://api.sfox.com/v1/orders/buy",
  headers={
    "Authorization": "Bearer <API_KEY>",
  },
  data={
    "quantity": 1,
    "currency_pair":"btcusd",
    "algorithm_id": 200,
    "price": 20000
  }
)
print(data)
```

{% endtab %}
{% endtabs %}


---

# 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.sfox.com/rest-api/orders/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.
