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

# Delegated Orders

> Place orders on behalf of sub-accounts with the TypeScript SDK

The `DelegatedOrderService` enables partners with the `delegated_signing` scope to place and cancel orders on behalf of their sub-accounts. The server signs orders using the sub-account's managed Privy wallet — no private key management is needed on the partner side.

<Warning>
  Delegated signing requires a sub-account created with `createServerWallet: true`. EOA sub-accounts sign their own orders.
</Warning>

<Info>
  **Recommended setup:** Store your HMAC credentials (`tokenId` / `secret`) on your backend. Use this SDK server-side to sign partner-authenticated requests. Expose only your own app-specific endpoints to the frontend. Never expose HMAC secrets in browser bundles or client-side storage.
</Info>

## Access

```typescript theme={null}
import { Client } from '@limitless-exchange/sdk';

const client = new Client({
  baseURL: 'https://api.limitless.exchange',
  hmacCredentials: { tokenId, secret },
});

// Use client.delegatedOrders.*
```

## Create a GTC delegated order

Builds an unsigned GTC (Good-Til-Cancelled) limit order locally and submits it to `POST /orders` with the `onBehalfOf` profile ID. The server signs the order via the sub-account's managed wallet. GTC orders remain on the orderbook until filled or explicitly cancelled.

```typescript theme={null}
import { OrderType, Side } from '@limitless-exchange/sdk';

const response = await client.delegatedOrders.createOrder({
  marketSlug: 'btc-100k',
  orderType: OrderType.GTC,
  onBehalfOf: partnerAccount.profileId,
  args: {
    tokenId: market.tokens.yes,
    side: Side.BUY,
    price: 0.55,
    size: 10,
  },
});

console.log(response.order.id);
```

Use `postOnly: true` in the args to ensure the order only rests on the book and is never filled immediately as a taker:

```typescript theme={null}
const response = await client.delegatedOrders.createOrder({
  marketSlug: 'btc-100k',
  orderType: OrderType.GTC,
  onBehalfOf: partnerAccount.profileId,
  args: {
    tokenId: market.tokens.yes,
    side: Side.BUY,
    price: 0.55,
    size: 10,
    postOnly: true,
  },
});
```

## Create a FAK delegated order

FAK (Fill-And-Kill) orders use the same `price` and `size` inputs as GTC, but they only consume immediately available liquidity and cancel any unmatched remainder.

`postOnly` is not supported for FAK orders.

```typescript theme={null}
import { OrderType, Side } from '@limitless-exchange/sdk';

const response = await client.delegatedOrders.createOrder({
  marketSlug: 'btc-100k',
  orderType: OrderType.FAK,
  onBehalfOf: partnerAccount.profileId,
  args: {
    tokenId: market.tokens.yes,
    side: Side.BUY,
    price: 0.45,
    size: 10,
  },
});

if (response.makerMatches?.length) {
  console.log(`FAK order matched immediately with ${response.makerMatches.length} fill(s)`);
} else {
  console.log('FAK remainder was cancelled.');
}
```

## Create a FOK delegated order

FOK (Fill-Or-Kill) orders execute immediately at the best available price or are cancelled entirely — there are no partial fills. Instead of `price` and `size`, FOK orders use `makerAmount`:

* **BUY**: `makerAmount` is the USDC amount to spend (e.g., `50` = spend \$50 USDC)
* **SELL**: `makerAmount` is the number of shares to sell (e.g., `18.64` = sell 18.64 shares)

```typescript theme={null}
import { OrderType, Side } from '@limitless-exchange/sdk';

// BUY FOK — spend 1 USDC at market price
const buyResponse = await client.delegatedOrders.createOrder({
  marketSlug: 'btc-100k',
  orderType: OrderType.FOK,
  onBehalfOf: partnerAccount.profileId,
  feeRateBps: 300,
  args: {
    tokenId: market.tokens.yes,
    side: Side.BUY,
    makerAmount: 1,
  },
});

if (buyResponse.makerMatches?.length) {
  console.log(`FOK order matched with ${buyResponse.makerMatches.length} fill(s)`);
} else {
  console.log('FOK order was not matched — cancelled automatically');
}

// SELL FOK — sell 10 shares at market price
const sellResponse = await client.delegatedOrders.createOrder({
  marketSlug: 'btc-100k',
  orderType: OrderType.FOK,
  onBehalfOf: partnerAccount.profileId,
  args: {
    tokenId: market.tokens.yes,
    side: Side.SELL,
    makerAmount: 10,
  },
});
```

## Parameters

### GTC order args

| Field           | Type        | Description                                                                        |
| --------------- | ----------- | ---------------------------------------------------------------------------------- |
| `marketSlug`    | `string`    | Market identifier                                                                  |
| `orderType`     | `OrderType` | `OrderType.GTC`                                                                    |
| `onBehalfOf`    | `number`    | Profile ID of the sub-account                                                      |
| `args.tokenId`  | `string`    | Position token ID (YES or NO) from market data                                     |
| `args.side`     | `Side`      | `BUY` (0) or `SELL` (1)                                                            |
| `args.price`    | `number`    | Price between 0 and 1                                                              |
| `args.size`     | `number`    | Number of contracts                                                                |
| `args.postOnly` | `boolean`   | Optional. `true` rejects the order if it would immediately match. Default `false`. |
| `feeRateBps`    | `number`    | Fee rate in basis points (defaults to 300 if omitted)                              |

### FAK order args

| Field          | Type        | Description                                           |
| -------------- | ----------- | ----------------------------------------------------- |
| `marketSlug`   | `string`    | Market identifier                                     |
| `orderType`    | `OrderType` | `OrderType.FAK`                                       |
| `onBehalfOf`   | `number`    | Profile ID of the sub-account                         |
| `args.tokenId` | `string`    | Position token ID (YES or NO) from market data        |
| `args.side`    | `Side`      | `BUY` (0) or `SELL` (1)                               |
| `args.price`   | `number`    | Price between 0 and 1                                 |
| `args.size`    | `number`    | Number of contracts                                   |
| `feeRateBps`   | `number`    | Fee rate in basis points (defaults to 300 if omitted) |

### FOK order args

| Field              | Type        | Description                                               |
| ------------------ | ----------- | --------------------------------------------------------- |
| `marketSlug`       | `string`    | Market identifier                                         |
| `orderType`        | `OrderType` | `OrderType.FOK`                                           |
| `onBehalfOf`       | `number`    | Profile ID of the sub-account                             |
| `args.tokenId`     | `string`    | Position token ID (YES or NO) from market data            |
| `args.side`        | `Side`      | `BUY` (0) or `SELL` (1)                                   |
| `args.makerAmount` | `number`    | BUY: USDC to spend. SELL: shares to sell. Max 6 decimals. |
| `feeRateBps`       | `number`    | Fee rate in basis points (defaults to 300 if omitted)     |

## Cancel an order

Cancel an order placed by the partner or on behalf of a sub-account.

```typescript theme={null}
await client.delegatedOrders.cancel(orderId);
```

### Cancel on behalf of a sub-account

```typescript theme={null}
await client.delegatedOrders.cancelOnBehalfOf(orderId, partnerAccount.profileId);
```

## Cancel all orders in a market

```typescript theme={null}
await client.delegatedOrders.cancelAll(marketSlug);
```

### Cancel all on behalf of a sub-account

```typescript theme={null}
await client.delegatedOrders.cancelAllOnBehalfOf(marketSlug, partnerAccount.profileId);
```

## How it works

1. The SDK builds an unsigned order locally using `OrderBuilder` with a zero verifying address
2. For GTC and FAK orders, `price` and `size` are used; for FOK orders, `makerAmount` is used (with `takerAmount` always set to 1)
3. The order is posted to `POST /orders` with `onBehalfOf` and `ownerId` set to the sub-account's profile ID
4. The server detects the `delegated_signing` scope and missing signature
5. The server looks up the sub-account's server wallet, builds EIP-712 typed data, and signs via Privy
6. The signed order is submitted to the CLOB engine — GTC orders can rest on the book, FAK orders cancel unmatched remainder, and FOK orders either fully fill or cancel
