> ## 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 Go 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

```go theme={null}
import "github.com/limitless-labs-group/limitless-exchange-go-sdk/limitless"

client := limitless.NewClient(
    limitless.WithHMACCredentials(limitless.HMACCredentials{
        TokenID: tokenID,
        Secret:  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.

```go theme={null}
response, err := client.DelegatedOrders.CreateOrder(ctx, limitless.CreateDelegatedOrderParams{
    MarketSlug: "btc-100k",
    OrderType:  limitless.OrderTypeGTC,
    OnBehalfOf: partnerAccount.ProfileID,
    Args: limitless.GTCOrderArgs{
        TokenID: market.Tokens.Yes,
        Side:    limitless.SideBuy,
        Price:   0.55,
        Size:    10,
    },
})
if err != nil {
    log.Fatal(err)
}

fmt.Println(response.Order.ID)
```

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

```go theme={null}
response, err := client.DelegatedOrders.CreateOrder(ctx, limitless.CreateDelegatedOrderParams{
    MarketSlug: "btc-100k",
    OrderType:  limitless.OrderTypeGTC,
    OnBehalfOf: partnerAccount.ProfileID,
    Args: limitless.GTCOrderArgs{
        TokenID:  market.Tokens.Yes,
        Side:     limitless.SideBuy,
        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.

```go theme={null}
response, err := client.DelegatedOrders.CreateOrder(ctx, limitless.CreateDelegatedOrderParams{
    MarketSlug: "btc-100k",
    OrderType:  limitless.OrderTypeFAK,
    OnBehalfOf: partnerAccount.ProfileID,
    Args: limitless.FAKOrderArgs{
        TokenID: market.Tokens.Yes,
        Side:    limitless.SideBuy,
        Price:   0.45,
        Size:    10.0,
    },
})
if err != nil {
    log.Fatal(err)
}

if len(response.MakerMatches) > 0 {
    fmt.Printf("FAK order matched immediately with %d fill(s)\n", len(response.MakerMatches))
} else {
    fmt.Println("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.0` = spend \$50 USDC)
* **SELL**: `MakerAmount` is the number of shares to sell (e.g., `18.64` = sell 18.64 shares)

```go theme={null}
// BUY FOK — spend 1 USDC at market price
response, err := client.DelegatedOrders.CreateOrder(ctx, limitless.CreateDelegatedOrderParams{
    MarketSlug: "btc-100k",
    OrderType:  limitless.OrderTypeFOK,
    OnBehalfOf: partnerAccount.ProfileID,
    FeeRateBps: 300,
    Args: limitless.FOKOrderArgs{
        TokenID:     market.Tokens.Yes,
        Side:        limitless.SideBuy,
        MakerAmount: 1.0,
    },
})
if err != nil {
    log.Fatal(err)
}

if len(response.MakerMatches) > 0 {
    fmt.Printf("FOK order matched with %d fill(s)\n", len(response.MakerMatches))
} else {
    fmt.Println("FOK order was not matched — cancelled automatically")
}

// SELL FOK — sell 10 shares at market price
response, err = client.DelegatedOrders.CreateOrder(ctx, limitless.CreateDelegatedOrderParams{
    MarketSlug: "btc-100k",
    OrderType:  limitless.OrderTypeFOK,
    OnBehalfOf: partnerAccount.ProfileID,
    Args: limitless.FOKOrderArgs{
        TokenID:     market.Tokens.Yes,
        Side:        limitless.SideSell,
        MakerAmount: 10.0,
    },
})
```

## Parameters

### GTC order args (`GTCOrderArgs`)

| Field           | Type        | Description                                                                        |
| --------------- | ----------- | ---------------------------------------------------------------------------------- |
| `MarketSlug`    | `string`    | Market identifier                                                                  |
| `OrderType`     | `OrderType` | `limitless.OrderTypeGTC`                                                           |
| `OnBehalfOf`    | `int`       | Profile ID of the sub-account                                                      |
| `Args.TokenID`  | `string`    | Position token ID (YES or NO) from market data                                     |
| `Args.Side`     | `Side`      | `limitless.SideBuy` or `limitless.SideSell`                                        |
| `Args.Price`    | `float64`   | Price between 0 and 1                                                              |
| `Args.Size`     | `float64`   | Number of contracts                                                                |
| `Args.PostOnly` | `bool`      | Optional. `true` rejects the order if it would immediately match. Default `false`. |
| `FeeRateBps`    | `int`       | Fee rate in basis points (defaults to 300 if omitted)                              |

### FAK order args (`FAKOrderArgs`)

| Field          | Type        | Description                                           |
| -------------- | ----------- | ----------------------------------------------------- |
| `MarketSlug`   | `string`    | Market identifier                                     |
| `OrderType`    | `OrderType` | `limitless.OrderTypeFAK`                              |
| `OnBehalfOf`   | `int`       | Profile ID of the sub-account                         |
| `Args.TokenID` | `string`    | Position token ID (YES or NO) from market data        |
| `Args.Side`    | `Side`      | `limitless.SideBuy` or `limitless.SideSell`           |
| `Args.Price`   | `float64`   | Price between 0 and 1                                 |
| `Args.Size`    | `float64`   | Number of contracts                                   |
| `FeeRateBps`   | `int`       | Fee rate in basis points (defaults to 300 if omitted) |

### FOK order args (`FOKOrderArgs`)

| Field              | Type        | Description                                               |
| ------------------ | ----------- | --------------------------------------------------------- |
| `MarketSlug`       | `string`    | Market identifier                                         |
| `OrderType`        | `OrderType` | `limitless.OrderTypeFOK`                                  |
| `OnBehalfOf`       | `int`       | Profile ID of the sub-account                             |
| `Args.TokenID`     | `string`    | Position token ID (YES or NO) from market data            |
| `Args.Side`        | `Side`      | `limitless.SideBuy` or `limitless.SideSell`               |
| `Args.MakerAmount` | `float64`   | BUY: USDC to spend. SELL: shares to sell. Max 6 decimals. |
| `FeeRateBps`       | `int`       | Fee rate in basis points (defaults to 300 if omitted)     |

## Cancel an order

```go theme={null}
message, err := client.DelegatedOrders.Cancel(ctx, orderID)
```

### Cancel on behalf of a sub-account

```go theme={null}
message, err := client.DelegatedOrders.CancelOnBehalfOf(ctx, orderID, partnerAccount.ProfileID)
```

## Cancel all orders in a market

```go theme={null}
message, err := client.DelegatedOrders.CancelAll(ctx, marketSlug)
```

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

```go theme={null}
message, err := client.DelegatedOrders.CancelAllOnBehalfOf(ctx, marketSlug, partnerAccount.ProfileID)
```

## How it works

1. The SDK builds an unsigned order locally with a zero verifying address and default fee rate (300 bps)
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
