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

# Trading

> Trading and account actions on Lighter

The Lighter provider exposes trading and balance operations in the `actions` array from `GET /providers`. Each action lists which signers can execute it.

For account setup actions (the provider's `setup` array) and post-setup options (`options`), see [Setup](/providers/lighter/setup). For full parameter schemas, see the [Actions API reference](/api-reference/actions).

## `actions`

Trading actions are signed by the **registered API key** (`PerpsSigner.SDK`). Deposits are the exception — a plain L1 EVM transaction signed by the user's wallet (documented separately, see the note below).

### `placeOrder`

Places a new market or limit order. Attached take-profit and stop-loss wires remain part of this `placeOrder` step. Standalone trigger orders use the separate `placeTriggerOrder` action below.

|                 |                                                                                                                                                     |
| --------------- | --------------------------------------------------------------------------------------------------------------------------------------------------- |
| **Signers**     | `SDK` (WASM blob)                                                                                                                                   |
| **Params**      | `PlaceOrderParams` — `{ market, side, type?, size, price?, leverage?, marginMode?, reduceOnly?, timeInForce?, expiresAt?, takeProfit?, stopLoss? }` |
| **SDK methods** | `placeOrder()`                                                                                                                                      |

On Lighter **spot** markets `placeOrder` rejects features that only exist for perpetuals: a validation error is thrown for `reduceOnly`, for bundled take-profit / stop-loss legs, and for any order type other than `MARKET` or `LIMIT`.

### `placeTriggerOrder`

Places standalone take-profit or stop-loss orders for an existing position. Each trigger can omit `size` to track the full position or set a fixed base-asset size for a partial close.

|                 |                                                                        |
| --------------- | ---------------------------------------------------------------------- |
| **Signers**     | `SDK` (WASM blob)                                                      |
| **Params**      | `PlaceTriggerOrderParams` — `{ market, side, takeProfit?, stopLoss? }` |
| **SDK methods** | `placeTriggerOrder()`                                                  |

### `placeTwapOrder`

Places a TWAP parent as an ordinary signed order with `order_type = 6`, rather than through a dedicated TWAP transaction type. The engine fires a market sub-order every 30 seconds until the parent's `order_expiry`.

|                 |                                                                                                                                                                                              |
| --------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **Signers**     | `SDK` (WASM blob)                                                                                                                                                                            |
| **Params**      | `PlaceTwapOrderParams` — `{ market, side, size, durationSeconds, reduceOnly? }` — Lighter advertises no extras; `randomize`, `frequencySeconds`, `minPrice`, and `maxPrice` are all rejected |
| **SDK methods** | `placeTwapOrder()`                                                                                                                                                                           |

`durationSeconds` sets the parent's `order_expiry` as an absolute timestamp (`now + durationSeconds * 1000`) rather than the `-1` default-expiry sentinel a limit order uses, and must fall within `[300, 2592000]` seconds (5 minutes–30 days). TWAP orders are perps-only — a spot `marketId` is rejected. Because the wire still requires a bounding price even though sub-orders fill at market, the parent signs the extremum in its own trade direction (max for a buy, min for a sell) so its own limit can never bind.

`placeTwapOrder`'s result carries a submit-time transaction hash on both `orderId` and `twapId` — Lighter assigns the parent's real order index asynchronously. That hash is not a valid `cancelTwapOrder` input; read the real index back via [`getRunningTwaps`](/sdk/account/get-running-twaps) once assigned.

### `cancelOrder`

Cancels one or more open orders by ID. Lighter order IDs (`order_index`) are scoped per market, so supply the market context: pass the composite `"<market_id>:<order_id>"` form in `ids`, or set `assetId` to the order's `market.id`.

|                 |                                           |
| --------------- | ----------------------------------------- |
| **Signers**     | `SDK` (WASM blob)                         |
| **Params**      | `CancelOrderParams` — `{ ids, assetId? }` |
| **SDK methods** | `cancelOrders()`                          |

### `cancelTwapOrder`

Cancels a running TWAP parent by emitting the same signed cancel-order blob as `cancelOrder`, keyed by the parent's order index, rather than through a TWAP-specific cancel transaction.

|                 |                                                |
| --------------- | ---------------------------------------------- |
| **Signers**     | `SDK` (WASM blob)                              |
| **Params**      | `CancelTwapOrderParams` — `{ market, twapId }` |
| **SDK methods** | `cancelTwapOrder()`                            |

`twapId` is the parent's order index as a decimal string. Order indexes are scoped per market, so `market` supplies the disambiguating `market_index`.

### `cancelAllOrders`

Cancels every open order on the account. Lighter exposes this as a first-class WASM action (`SignCancelAllOrders`) rather than requiring per-order cancellation.

|                 |                                                                                   |
| --------------- | --------------------------------------------------------------------------------- |
| **Signers**     | `SDK` (WASM blob)                                                                 |
| **Params**      | (none beyond the implicit account/key context)                                    |
| **SDK methods** | Dispatched via [`execute()`](/sdk/trading/methods#execute) — no dedicated wrapper |

### `modifyOrder`

Modifies one or more existing orders in-place — change price, size, or trigger parameters without cancelling and re-placing.

|                 |                                                                                   |
| --------------- | --------------------------------------------------------------------------------- |
| **Signers**     | `SDK` (WASM blob)                                                                 |
| **Params**      | `ModifyOrderParams` — `{ modifications: [{ id, price?, size?, triggerPrice? }] }` |
| **SDK methods** | `modifyOrders()`                                                                  |

### `updateLeverage`

Changes the leverage and/or margin mode (cross / isolated) for a market.

|             |                                                              |
| ----------- | ------------------------------------------------------------ |
| **Signers** | `SDK` (WASM blob)                                            |
| **Params**  | `UpdateLeverageParams` — `{ market, leverage, marginMode? }` |

### `updatePositionMargin`

Adds or removes margin on an isolated position. Use this to adjust liquidation price without changing the position size.

|                 |                                                                                |
| --------------- | ------------------------------------------------------------------------------ |
| **Signers**     | `SDK` (WASM blob)                                                              |
| **Params**      | `UpdatePositionMarginParams` — `{ market, action: 'add' \| 'remove', amount }` |
| **SDK methods** | `updatePositionMargin()`                                                       |

### `updateAssetCollateral`

Opts a single spot asset in or out of the account's cross-margin collateral pool. Valid only within a **Unified Trading Account** (`accountMode = unifiedTradingAccount`); on a Simple account the per-asset collateral flag does not exist and the action is rejected. Describes an `L2UpdateAccountAssetConfig` (tx type 42) WASM blob signed by the API key and relayed through `/sendTx`. Idempotent — a no-op when the asset is already in the requested state.

|             |                                                                                                            |
| ----------- | ---------------------------------------------------------------------------------------------------------- |
| **Signers** | `SDK` (WASM blob)                                                                                          |
| **Params**  | `UpdateAssetCollateralParams` — `{ assetId, enabled }` (`assetId` is the spot `Asset.id`, keyed per asset) |

### `sendAsset`

Moves the deployment collateral between the account's **perpetual** and **spot** balances — USDC on `lighter`, USDG on `lighter-rh`. This is a same-account route transfer, not a withdrawal. `sourceDex` and `destinationDex` are `perps` and `spot`.

|             |                                                                                                                                                                       |
| ----------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **Signers** | `SDK` (WASM blob)                                                                                                                                                     |
| **Params**  | `SendAssetParams` — `{ collateral, sourceDex, destinationDex, amount }` — e.g. `{ collateral: 'USDC', sourceDex: 'perps', destinationDex: 'spot', amount: '100.00' }` |

> **Deposits** are documented on [Deposits](/providers/lighter/deposits). The user wallet authorizes the deployment-specific EVM deposit flow; resolve its chain and collateral through `getDepositFlow()` rather than assuming Ethereum/USDC for `lighter-rh`.

> **Withdrawals** are documented on [Withdrawals](/providers/lighter/withdrawals), including per-asset/per-route discovery and the standard versus fast settlement paths. Provider metadata exposes the signer as `SDK`; the L1 wallet is not prompted.

## Integrator fees

`placeOrder`, `placeTriggerOrder`, and `modifyOrder` on Lighter carry the integrator-fee fields (`integrator_account_index`, `integrator_taker_fee`, `integrator_maker_fee`) in the unsigned WASM `CreateOrder` payload returned from `/createAction`. The integrator identifier is read from the `x-lifi-integrator` request header (see [Authentication](/api-reference/introduction)) or the SDK's `integrator` client option — there is **no** dedicated request-body parameter for it on `PlaceOrderParams`, `PlaceTriggerOrderParams`, or `ModifyOrderParams`.

Per-order fees resolve end-to-end. The backend derives the rate for the request's integrator (clamped to a maximum bps cap) and injects it into the three fields, and the SDK's `LighterSigner` threads them through to the Go WASM `SignCreateOrder` binding. The fields fall back to zero (no integrator fee) when LI.FI's integrator account is not provisioned or the resolved rate is zero. A non-zero fee applies only once the account has satisfied the [`approveIntegrator`](/providers/lighter/setup#approveintegrator) setup gate.

Submitted (signed) payloads are validated on `/executeAction` against the values issued at `/createAction` via a generic payload-hash check; the integrator-fee fields are part of the hashed payload like any other field.

## Internal-only actions

The following action types exist in the Lighter provider's internal registry but are deliberately **not** surfaced via `GET /providers`. They are reachable only through internal dispatch (e.g. the fastwithdraw rewrite) and cannot be invoked directly through the public action API:

| Internal action | Used by                             | Why hidden                                                                   |
| --------------- | ----------------------------------- | ---------------------------------------------------------------------------- |
| `TRANSFER`      | `WITHDRAWAL` (fastwithdraw rewrite) | Exposing it would allow arbitrary balance transfers between Lighter accounts |

## Margin modes

Lighter supports two margin modes per market, sourced from `market_margin_mode` in each market's `market_config` (on `orderBookDetails`):

| Mode       | Value | Description                    |
| ---------- | ----- | ------------------------------ |
| `CROSS`    | `0`   | Shared margin across positions |
| `ISOLATED` | `1`   | Per-position isolated margin   |

Mode is configurable per asset via `updateLeverage`.
