> For the complete documentation index, see [llms.txt](https://docs.opinion.trade/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.opinion.trade/developer-guide/opinion-clob-python-sdk/builder-mode/build-order.md).

# Build Order

> Build an EIP-712 order structure for a user to sign.

## Usage

```python
from opinion_clob_sdk.chain.py_order_utils.model.sides import BUY, SELL
from opinion_clob_sdk.chain.py_order_utils.model.order_type import LIMIT_ORDER, MARKET_ORDER

build_result = builder.build_order_for_signing(
    market_id=123,
    token_id="outcome_token_id",
    user_wallet_address="0xSafeAddress...",    # Maker (Safe wallet)
    side=BUY,
    order_type=LIMIT_ORDER,
    amount=10.0,
    price="0.5",
    signer_address="0xUserEOAAddress...",      # Signer (EOA)
)

print(build_result["order"])           # Order struct dict
print(build_result["struct_hash"])     # Hash for the user to sign
print(build_result["typed_data"])      # Full EIP-712 typed data (for reference)
```

## Parameters

| Parameter             | Type      | Required   | Description                                                                                       |
| --------------------- | --------- | ---------- | ------------------------------------------------------------------------------------------------- |
| `market_id`           | int       | Yes        | Market ID                                                                                         |
| `token_id`            | str       | Yes        | Outcome token ID to trade                                                                         |
| `user_wallet_address` | str       | Yes        | Safe address (maker, where funds are held)                                                        |
| `side`                | OrderSide | Yes        | `BUY` or `SELL`                                                                                   |
| `order_type`          | int       | Yes        | `LIMIT_ORDER` (2) or `MARKET_ORDER` (1)                                                           |
| `amount`              | float     | Yes        | Amount in human-readable units                                                                    |
| `price`               | str       | Limit only | Price per share (e.g., `"0.5"` for 50 cents). Required for `LIMIT_ORDER`.                         |
| `amount_type`         | str       | No         | `"quote"` (default) or `"base"`                                                                   |
| `signer_address`      | str       | No         | EOA signer address. If different from `user_wallet_address`, Safe mode (signatureType=2) is used. |

## Response

```python
{
    "order": {                        # Order struct for submission
        "salt": "123...",
        "maker": "0xSafeAddress...",
        "signer": "0xEOAAddress...",
        "taker": "0x0000...0000",
        "tokenId": "...",
        "makerAmount": "10000000",
        "takerAmount": "20000000",
        "expiration": "...",
        "nonce": "0",
        "feeRateBps": "0",
        "side": "0",
        "signatureType": "2",
    },
    "struct_hash": "0xabcdef...",     # Hash for user to sign
    "typed_data": { ... },            # Full EIP-712 typed data
    "domain": { ... },                # EIP-712 domain
    "exchange_address": "0x...",
    "currency_address": "0x...",
    "currency_decimal": 6,
    "market_id": 123,
    "order_type": 2,
    "price": "0.5",
}
```

## Market Order Restrictions

* Market BUY: `amount_type` must be `"quote"` (how much to spend)
* Market SELL: `amount_type` must be `"base"` (how many tokens to sell)
* Market orders set `price` to `"0"` internally.

## Signing the Order

Order signing uses `sign_hash(struct_hash)`, **not** `sign_typed_data`. This is different from Safe TX signing.

```python
# Using UserClient (testing helper)
from opinion_clob_sdk.user_client import UserClient

user = UserClient("0xPrivateKey...")
signature = user.sign_hash(build_result["struct_hash"])
```

For testing, you can also use the static helper method:

```python
signature = BuilderClient.sign_order_with_private_key(
    build_result["typed_data"],
    "0xPrivateKey...",
)
```

## Notes

* In production, users sign the `struct_hash` using their wallet (e.g., `personal_sign` or equivalent).
* The `sign_order_with_private_key()` static method signs the full `typed_data` (EIP-712). This is for testing convenience only.
* Orders expire after 30 days by default.
* The signature type (EOA=0 or Safe=2) is set automatically based on whether `signer_address` differs from `user_wallet_address`.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://docs.opinion.trade/developer-guide/opinion-clob-python-sdk/builder-mode/build-order.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
