> ## 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 Python 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 `create_server_wallet=True`. EOA sub-accounts sign their own orders.
</Warning>

<Info>
  **Recommended setup:** Store your HMAC credentials (`token_id` / `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

```python theme={null}
from limitless_sdk import Client, HMACCredentials

client = Client(
    base_url="https://api.limitless.exchange",
    hmac_credentials=HMACCredentials(token_id=token_id, secret=secret),
)

# Use client.delegated_orders.*
```

## Create a GTC delegated order

Builds an unsigned GTC (Good-til-cancelled) limit order and submits it to `POST /orders` with the `on_behalf_of` 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.

```python theme={null}
from limitless_sdk import OrderType, Side

response = await client.delegated_orders.create_order(
    token_id=market.tokens.yes,
    side=Side.BUY,
    order_type=OrderType.GTC,
    market_slug="btc-100k",
    on_behalf_of=partner_account.profile_id,
    price=0.55,
    size=10,
)

print(response.order.id)
```

Use `post_only=True` to ensure the order only rests on the book and is never filled immediately as a taker:

```python theme={null}
response = await client.delegated_orders.create_order(
    token_id=market.tokens.yes,
    side=Side.BUY,
    order_type=OrderType.GTC,
    market_slug="btc-100k",
    on_behalf_of=partner_account.profile_id,
    price=0.55,
    size=10,
    post_only=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.

`post_only` is not supported for FAK orders.

```python theme={null}
from limitless_sdk import OrderType, Side

response = await client.delegated_orders.create_order(
    token_id=market.tokens.yes,
    side=Side.BUY,
    order_type=OrderType.FAK,
    market_slug="btc-100k",
    on_behalf_of=partner_account.profile_id,
    price=0.45,
    size=10,
)

if response.maker_matches:
    print(f"FAK order matched immediately with {len(response.maker_matches)} fill(s)")
else:
    print("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 `maker_amount`:

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

```python theme={null}
from limitless_sdk import OrderType, Side

# BUY FOK — spend 1 USDC at market price
response = await client.delegated_orders.create_order(
    token_id=market.tokens.yes,
    side=Side.BUY,
    order_type=OrderType.FOK,
    market_slug="btc-100k",
    on_behalf_of=partner_account.profile_id,
    maker_amount=1.0,
)

if response.maker_matches:
    print(f"FOK order matched with {len(response.maker_matches)} fill(s)")
else:
    print("FOK order was not matched — cancelled automatically")

# SELL FOK — sell 10 shares at market price
response = await client.delegated_orders.create_order(
    token_id=market.tokens.yes,
    side=Side.SELL,
    order_type=OrderType.FOK,
    market_slug="btc-100k",
    on_behalf_of=partner_account.profile_id,
    maker_amount=10.0,
)
```

## Parameters

### GTC order parameters

| Parameter      | Type        | Description                                                                        |
| -------------- | ----------- | ---------------------------------------------------------------------------------- |
| `token_id`     | `str`       | Position token ID (YES or NO) from market data                                     |
| `side`         | `Side`      | `Side.BUY` or `Side.SELL`                                                          |
| `order_type`   | `OrderType` | `OrderType.GTC`                                                                    |
| `market_slug`  | `str`       | Market identifier                                                                  |
| `on_behalf_of` | `int`       | Profile ID of the sub-account                                                      |
| `price`        | `float`     | Price between 0 and 1                                                              |
| `size`         | `float`     | Number of contracts                                                                |
| `post_only`    | `bool`      | Optional. `True` rejects the order if it would immediately match. Default `False`. |
| `fee_rate_bps` | `int`       | Fee rate in basis points (defaults to 300 if omitted)                              |

### FAK order parameters

| Parameter      | Type        | Description                                           |
| -------------- | ----------- | ----------------------------------------------------- |
| `token_id`     | `str`       | Position token ID (YES or NO) from market data        |
| `side`         | `Side`      | `Side.BUY` or `Side.SELL`                             |
| `order_type`   | `OrderType` | `OrderType.FAK`                                       |
| `market_slug`  | `str`       | Market identifier                                     |
| `on_behalf_of` | `int`       | Profile ID of the sub-account                         |
| `price`        | `float`     | Price between 0 and 1                                 |
| `size`         | `float`     | Number of contracts                                   |
| `fee_rate_bps` | `int`       | Fee rate in basis points (defaults to 300 if omitted) |

### FOK order parameters

| Parameter      | Type        | Description                                               |
| -------------- | ----------- | --------------------------------------------------------- |
| `token_id`     | `str`       | Position token ID (YES or NO) from market data            |
| `side`         | `Side`      | `Side.BUY` or `Side.SELL`                                 |
| `order_type`   | `OrderType` | `OrderType.FOK`                                           |
| `market_slug`  | `str`       | Market identifier                                         |
| `on_behalf_of` | `int`       | Profile ID of the sub-account                             |
| `maker_amount` | `float`     | BUY: USDC to spend. SELL: shares to sell. Max 6 decimals. |
| `fee_rate_bps` | `int`       | Fee rate in basis points (defaults to 300 if omitted)     |

## Cancel an order

```python theme={null}
message = await client.delegated_orders.cancel(order_id)
```

### Cancel on behalf of a sub-account

```python theme={null}
message = await client.delegated_orders.cancel_on_behalf_of(order_id, partner_account.profile_id)
```

## Cancel all orders in a market

```python theme={null}
message = await client.delegated_orders.cancel_all(market_slug)
```

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

```python theme={null}
message = await client.delegated_orders.cancel_all_on_behalf_of(market_slug, partner_account.profile_id)
```

## How it works

1. The SDK builds an unsigned order locally with a zero verifying address
2. GTC and FAK orders use `price` and `size`; FOK orders use `maker_amount` (with `taker_amount` always set to 1)
3. The SDK posts the order to `POST /orders` with `on_behalf_of` and `owner_id` 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 server submits the signed order to the CLOB engine. GTC orders can rest on the book, FAK orders cancel unmatched remainder, and FOK orders either fully fill or cancel
