> ## Documentation Index
> Fetch the complete documentation index at: https://docs.pacifica.fi/llms.txt
> Use this file to discover all available pages before exploring further.

# Create Order Strategy

> This endpoint allows users to create an order strategy.

```http theme={null}
POST /api/v1/order_strategies/create
```

Creates a server-side [order strategy](https://docs.pacifica.fi/api-documentation/api/rest-api/order-strategies). Pacifica runs it on your account until it completes, is cancelled, or expires.

#### Operation Type (for Signing)

| Header Field | Type | Content |
| - | - | - |
| `"type"` | string | `"create_order_strategy"` |

#### Request Body

<table><thead><tr><th width="200">Field</th><th width="98">Type</th><th width="95">Need</th><th>Description</th><th>Example</th></tr></thead><tbody><tr><td>`"account"`</td><td>string</td><td>required</td><td>User's wallet address</td><td>`42trU9A5...`</td></tr><tr><td>`"signature"`</td><td>string</td><td>required</td><td>Cryptographic signature</td><td>`5j1Vy9Uq...`</td></tr><tr><td>`"timestamp"`</td><td>integer</td><td>required</td><td>Current timestamp in milliseconds</td><td>`1716200000000`</td></tr><tr><td>`"strategy_type"`</td><td>string</td><td>required</td><td>Strategy type. See [Strategy parameters](https://docs.pacifica.fi/api-documentation/api/rest-api/order-strategies/strategy-parameters.md)</td><td>`conditional`</td></tr><tr><td>`"params"`</td><td>object</td><td>required</td><td>Parameters for the strategy type. See [Strategy parameters](https://docs.pacifica.fi/api-documentation/api/rest-api/order-strategies/strategy-parameters.md)</td><td>See below</td></tr><tr><td>`"scheduled_start_at"`</td><td>integer</td><td>optional</td><td>Start time in milliseconds. Until then, the strategy is `pending`</td><td>`1716203600000`</td></tr><tr><td>`"scheduled_end_at"`</td><td>integer</td><td>optional</td><td>End time in milliseconds. Must be after `scheduled_start_at`. At this time the strategy expires</td><td>`1716207200000`</td></tr><tr><td>`"expires_at"`</td><td>integer</td><td>optional</td><td>Expiry time in milliseconds. At this time the strategy expires</td><td>`1716207200000`</td></tr><tr><td>`"agent_wallet"`</td><td>string</td><td>optional</td><td>Agent wallet address</td><td>`69trU9A5...`</td></tr><tr><td>`"expiry_window"`</td><td>integer</td><td>optional</td><td>Signature expiry in milliseconds</td><td>`30000`</td></tr></tbody></table>

When a strategy expires, Pacifica cancels the orders it still has open.

```json theme={null}
{
  "account": "42trU9A5...",
  "signature": "5j1Vy9Uq...",
  "timestamp": 1716200000000,
  "strategy_type": "conditional",
  "params": {
    "trigger_symbol": "BTC",
    "trigger_price_type": "mark",
    "trigger_direction": "gte",
    "trigger_price": "66000",
    "execution_symbol": "BTC",
    "side": "bid",
    "amount": "0.01",
    "order_type": "market",
    "reduce_only": false
  },
  "expires_at": 1716286400000,
  "expiry_window": 30000
}
```

#### Signing

Sign `strategy_type`, `params`, and any schedule fields as the `data` object, like any other request. See [Signing](https://docs.pacifica.fi/api-documentation/api/signing/implementation.md). Keys inside `params` are sorted too. For the request above, the message to sign is:

```json theme={null}
{"data":{"expires_at":1716286400000,"params":{"amount":"0.01","execution_symbol":"BTC","order_type":"market","reduce_only":false,"side":"bid","trigger_direction":"gte","trigger_price":"66000","trigger_price_type":"mark","trigger_symbol":"BTC"},"strategy_type":"conditional"},"expiry_window":30000,"timestamp":1716200000000,"type":"create_order_strategy"}
```

#### Response

* Status 200: Strategy created

```json theme={null}
{
  "success": true,
  "data": {
    "strategy_id": "0f8e7c2a-4b1d-4e5f-9a3b-2c1d0e9f8a7b",
    "revision": 1
  },
  "error": null,
  "code": null
}
```

| Field | Type | Description |
| - | - | - |
| `'strategy_id'` | string | Strategy ID (UUID) |
| `'revision'` | integer | Revision of the strategy definition. Send it as `expected_revision` to [edit](https://docs.pacifica.fi/api-documentation/api/rest-api/order-strategies/edit-order-strategy.md) the strategy |

* Status 400: Invalid parameters, or the account cannot run the strategy. The `error` field says why, for example `invalid strategy definition: clip count must be between 2 and 100` or `STRATEGIST_INSUFFICIENT_BALANCE`

```json theme={null}
{
  "success": false,
  "data": null,
  "error": "invalid strategy definition: exactly two OCO legs are required",
  "code": 400
}
```

* Status 429: The account already has 100 strategies that have not finished (`STRATEGIST_ORDER_STRATEGY_LIMIT_REACHED`), or the rate limit is exceeded
* Status 500: Internal server error
* Status 503: The strategy service is not ready. Retry later

Other `error` values with status 400:

| `error` | Meaning |
| - | - |
| `STRATEGIST_BELOW_MIN_NOTIONAL` | An order or clip would be below the market's minimum order size |
| `STRATEGIST_INSUFFICIENT_BALANCE` | The account cannot afford the strategy |
| `STRATEGIST_BOUNDARY_ALREADY_CROSSED` | The swarm boundary is already crossed |
| `STRATEGIST_NO_POSITION` | A position exit has no open position |
| `STRATEGIST_POSITION_ID_MISMATCH` | `position_id` does not match the current position |
| `STRATEGIST_INVALID_POSITION_EXIT` | The position exit side or amount does not fit the position |
| `STRATEGIST_UNSUPPORTED_SIZING` | The `size_mode` is not supported for this strategy |
| `STRATEGIST_STRATEGY_TYPE_DISABLED` | The strategy type is turned off |

#### Code Example (Python)

```python theme={null}
import requests

payload = {
    "account": "42trU9A5...",
    "signature": "5j1Vy9Uq...",
    "timestamp": 1716200000000,
    "strategy_type": "twap",
    "params": {
        "symbol": "BTC",
        "side": "ask",
        "amount": "1",
        "reduce_only": False,
        "duration_seconds": 3600,
        "randomize": False
    }
}

response = requests.post(
    "/api/v1/order_strategies/create",
    json=payload,
    headers={"Content-Type": "application/json"}
)

data = response.json()
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.