Build Order

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

Usage

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

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.

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

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.