# Place Order

> Submit a signed order on behalf of a user.

## Usage (Recommended)

Use `placeOrderForUserFromBuildResult()` with the output from `buildOrderForSigning()`:

```typescript
import { BuilderClient, OrderSide, OrderType } from '@opinion-labs/opinion-clob-sdk';

const builder = new BuilderClient({
  host: 'https://openapi.opinion.trade/openapi',
  builderApiKey: 'YOUR_BUILDER_KEY',
  chainId: 56,
});

// Step 1: Build the order
const orderData = await builder.buildOrderForSigning({
  marketId: 123,
  tokenId: 'token_id',
  userWalletAddress: safeAddress,
  side: OrderSide.BUY,
  orderType: OrderType.LIMIT_ORDER,
  amount: 10,
  price: '0.5',
  signerAddress: userEOA,
});

// Step 2: User signs the struct hash
const signature = await user.signHash(orderData.structHash);

// Step 3: Place the order (convenience method)
const result = await builder.placeOrderForUserFromBuildResult(
  orderData,
  signature,
  safeAddress,
);
```

## Convenience Method

```typescript
async placeOrderForUserFromBuildResult(
  buildResult: BuildOrderResult,
  signature: string,
  userWalletAddress: string,
): Promise<Record<string, unknown>>
```

| Parameter           | Type             | Required | Description                                           |
| ------------------- | ---------------- | -------- | ----------------------------------------------------- |
| `buildResult`       | BuildOrderResult | Yes      | Result from `buildOrderForSigning()`                  |
| `signature`         | string           | Yes      | User's signature (0x-prefixed hex string)             |
| `userWalletAddress` | string           | Yes      | User's Safe wallet address (must match `order.maker`) |

## Full Method

For advanced use cases, you can call `placeOrderForUser()` directly:

```typescript
const result = await builder.placeOrderForUser({
  order: orderData.order,
  signature: signature,
  userWalletAddress: safeAddress,
  marketId: orderData.marketId,
  orderType: orderData.orderType,
  price: orderData.price,
  currencyAddress: orderData.currencyAddress,
});
```

| Parameter           | Type                    | Required | Description                                           |
| ------------------- | ----------------------- | -------- | ----------------------------------------------------- |
| `order`             | Record\<string, string> | Yes      | Order struct from `buildOrderForSigning()`            |
| `signature`         | string                  | Yes      | User's signature (0x-prefixed hex string)             |
| `userWalletAddress` | string                  | Yes      | User's Safe wallet address (must match `order.maker`) |
| `marketId`          | number                  | No       | Market ID                                             |
| `orderType`         | number                  | No       | Order type (1=market, 2=limit)                        |
| `price`             | string                  | No       | Order price                                           |
| `currencyAddress`   | string                  | No       | Quote token address                                   |

## Notes

* The convenience method `placeOrderForUserFromBuildResult()` is recommended. It automatically extracts `marketId`, `orderType`, `price`, and `currencyAddress` from the build result.
* The `order.maker` must match `userWalletAddress` or the request will be rejected.
* The signature must be a hex string starting with `0x`.
* Order placement is gasless (counts toward the 2,000/day limit).
