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

# Orders

> Build Phoenix order, cancellation, stop-loss, and conditional-order instructions with the Rise SDK.

Use this page when a trader account already exists and you want to build Solana instructions for trading. Your app still signs and sends the transaction with the correct authority, position authority, delegated wallet, or fee payer.

For account indexes, cross vs isolated accounts, and trader-state subscriptions across all subaccounts, see [Accounts](/sdk/accounts). For mark-price joins, account health, and liquidation estimates, see [Margin](/sdk/margin).

## Instruction Builders

All order builders produce Phoenix instructions. They do not submit transactions by themselves.

| Action                   | TypeScript builder                                   | Rust builder                                                               | Phoenix instruction             |
| ------------------------ | ---------------------------------------------------- | -------------------------------------------------------------------------- | ------------------------------- |
| Place limit order        | `client.ixs.buildPlaceLimitOrder(...)`               | `PhoenixTxBuilder::place_limit_order(...)`                                 | `PlaceLimitOrder`               |
| Cancel by order id       | `client.ixs.buildCancelOrdersById(...)`              | `PhoenixTxBuilder::build_cancel_orders(...)`                               | `CancelOrdersById`              |
| Cancel all in a market   | `client.ixs.buildCancelAll(...)`                     | `PhoenixTxBuilder::build_cancel_all_orders(...)`                           | `CancelAll`                     |
| Place market order       | `client.ixs.buildPlaceMarketOrder(...)`              | `PhoenixTxBuilder::place_market_order(...)`                                | `PlaceMarketOrder`              |
| Place position stop loss | `client.ixs.buildPlaceStopLoss(...)`                 | `PhoenixTxBuilder::build_stop_loss_orders(...)`                            | `PlaceStopLoss`                 |
| Place conditional order  | `client.ixs.buildPlacePositionConditionalOrder(...)` | `PhoenixTxBuilder::place_position_bracket_order(...)` or raw `ix` builders | `PlacePositionConditionalOrder` |

## Limit Order

<CodeGroup>
  ```ts TypeScript theme={null}
  import { Side } from "@ellipsis-labs/rise";

  await client.exchange.ready();

  const orderPacket = await client.orderPackets.buildLimitOrderPacket({
    symbol: "SOL",
    side: Side.Bid,
    priceUsd: "150.50",
    baseUnits: "0.25",
  });

  const ix = await client.ixs.buildPlaceLimitOrder({
    authority: "AUTHORITY_PUBKEY",
    symbol: "SOL",
    orderPacket,
    traderPdaIndex: 0,
    traderSubaccountIndex: 0,
  });
  ```

  ```rust Rust theme={null}
  use phoenix_rise::{LimitOrderTicket, PhoenixTxBuilder, Side, TraderKey};

  let trader = TraderKey::new(authority);
  let builder = PhoenixTxBuilder::new(&metadata);

  let ticket = LimitOrderTicket::builder()
      .authority(trader.authority())
      .trader_account(trader.pda())
      .symbol("SOL")
      .side(Side::Bid)
      .price(150.50)
      .num_base_lots(50_000)
      .build()?;

  let ixs = builder.place_limit_order(ticket).await?;
  ```
</CodeGroup>

References:

* [TypeScript limit-order example](https://github.com/Ellipsis-Labs/rise-public/blob/master/ts/examples/03-build-limit-order-ix.ts)
* [Rust limit-order example](https://github.com/Ellipsis-Labs/rise-public/blob/master/rust/sdk/examples/send_limit_order.rs)

## Cancel Limit Order

<CodeGroup>
  ```ts TypeScript theme={null}
  const ix = await client.ixs.buildCancelOrdersById({
    authority: "AUTHORITY_PUBKEY",
    symbol: "SOL",
    orders: [
      {
        price: 50_000n,
        orderSequenceNumber: "12345",
      },
    ],
    traderPdaIndex: 0,
    traderSubaccountIndex: 0,
  });
  ```

  ```rust Rust theme={null}
  use phoenix_rise::ix::types::CancelId;

  let cancel_id = CancelId::new(50_000, 12_345);
  let ixs = builder.build_cancel_orders(
      trader.authority(),
      trader.pda(),
      "SOL",
      vec![cancel_id],
  )?;
  ```
</CodeGroup>

Reference: [Rust cancel-order example](https://github.com/Ellipsis-Labs/rise-public/blob/master/rust/sdk/examples/cancel_order.rs).

## Cancel All

<CodeGroup>
  ```ts TypeScript theme={null}
  const ix = await client.ixs.buildCancelAll({
    authority: "AUTHORITY_PUBKEY",
    symbol: "SOL",
    traderPdaIndex: 0,
    traderSubaccountIndex: 0,
  });
  ```

  ```rust Rust theme={null}
  let ixs = builder.build_cancel_all_orders(
      trader.authority(),
      trader.pda(),
      "SOL",
  )?;
  ```
</CodeGroup>

## Market Order

<CodeGroup>
  ```ts TypeScript theme={null}
  import { Side } from "@ellipsis-labs/rise";

  const orderPacket = await client.orderPackets.buildMarketOrderPacket({
    symbol: "SOL",
    side: Side.Bid,
    baseUnits: "0.25",
  });

  const ix = await client.ixs.buildPlaceMarketOrder({
    authority: "AUTHORITY_PUBKEY",
    symbol: "SOL",
    orderPacket,
    traderPdaIndex: 0,
    traderSubaccountIndex: 0,
  });
  ```

  ```rust Rust theme={null}
  use phoenix_rise::{MarketOrderTicket, Side};

  let ticket = MarketOrderTicket::builder()
      .authority(trader.authority())
      .trader_account(trader.pda())
      .symbol("SOL")
      .side(Side::Bid)
      .num_base_lots(67)
      .build()?;

  let ixs = builder.place_market_order(ticket).await?;
  ```
</CodeGroup>

Reference: [Rust market-order example](https://github.com/Ellipsis-Labs/rise-public/blob/master/rust/sdk/examples/send_market_order.rs).

## Stop Losses

Position stop losses use a per-trader, per-asset stop-loss account. If the account does not already exist, creating it can add an account-init instruction and incur rent.

<CodeGroup>
  ```ts TypeScript theme={null}
  import { Direction, Side, StopLossOrderKind } from "@ellipsis-labs/rise";

  const ix = await client.ixs.buildPlaceStopLoss({
    authority: "AUTHORITY_PUBKEY",
    symbol: "SOL",
    triggerPrice: 140_000n,
    slippageBps: 100,
    tradeSide: Side.Ask,
    executionDirection: Direction.LessThan,
    orderKind: StopLossOrderKind.IOC,
    traderPdaIndex: 0,
    traderSubaccountIndex: 0,
  });
  ```

  ```rust Rust theme={null}
  use phoenix_rise::{BracketLeg, BracketLegOrders, Side};

  let bracket = BracketLegOrders {
      stop_loss: Some(BracketLeg::new(140.0).with_slippage_bps(100)),
      take_profit: None,
  };

  let ixs = builder.build_stop_loss_orders(
      trader.authority(),
      trader.pda(),
      "SOL",
      Side::Bid,
      &bracket,
  )?;
  ```
</CodeGroup>

To cancel a position stop loss:

<CodeGroup>
  ```ts TypeScript theme={null}
  import { Direction } from "@ellipsis-labs/rise";

  const ix = await client.ixs.buildCancelStopLoss({
    authority: "AUTHORITY_PUBKEY",
    symbol: "SOL",
    executionDirection: Direction.LessThan,
    traderPdaIndex: 0,
    traderSubaccountIndex: 0,
  });
  ```

  ```rust Rust theme={null}
  use phoenix_rise::Direction;

  let ixs = builder.build_cancel_bracket_leg(
      trader.authority(),
      trader.pda(),
      "SOL",
      Direction::LessThan,
  )?;
  ```
</CodeGroup>

Reference: [Rust cancel stop-loss example](https://github.com/Ellipsis-Labs/rise-public/blob/master/rust/sdk/examples/cancel_stop_loss.rs).

## Conditional Orders

Conditional orders use a trader conditional-orders account. If the account does not already exist, your flow may need to create it first and pay rent. The newer bracket helpers can check and create the account when configured with an RPC client; raw builders require you to include `CreateConditionalOrdersAccount` yourself when needed.

<CodeGroup>
  ```ts TypeScript theme={null}
  import {
    Direction,
    Side,
    StopLossOrderKind,
    ticks,
  } from "@ellipsis-labs/rise";

  declare const conditionalOrdersAccountExists: boolean;

  const ixs = [];

  if (!conditionalOrdersAccountExists) {
    ixs.push(
      await client.ixs.buildCreateConditionalOrdersAccount({
        authority: "AUTHORITY_PUBKEY",
        traderPdaIndex: 0,
        traderSubaccountIndex: 0,
      })
    );
  }

  ixs.push(
    await client.ixs.buildPlacePositionConditionalOrder({
      authority: "AUTHORITY_PUBKEY",
      symbol: "SOL",
      lessTriggerOrder: {
        triggerDirection: Direction.LessThan,
        tradeSide: Side.Ask,
        orderKind: StopLossOrderKind.IOC,
        triggerPrice: ticks(140_000n),
        slippageBps: 100,
      },
      sizePercent: 100,
      traderPdaIndex: 0,
      traderSubaccountIndex: 0,
    })
  );
  ```

  ```rust Rust theme={null}
  use std::sync::Arc;
  use phoenix_rise::{
      BracketLeg, BracketLegOrders, BracketLegTicket, Side,
  };
  use solana_rpc_client::nonblocking::rpc_client::RpcClient;

  let rpc = Arc::new(RpcClient::new("https://api.mainnet-beta.solana.com".to_string()));
  let bracket = BracketLegOrders {
      stop_loss: Some(BracketLeg::new(140.0).with_slippage_bps(100)),
      take_profit: Some(BracketLeg::new(180.0).with_limit_order()),
  };

  let ixs = builder
      .place_position_bracket_order(
          trader.authority(),
          trader.pda(),
          "SOL",
          Side::Bid,
          BracketLegTicket::new(rpc, bracket),
      )
      .await?;
  ```
</CodeGroup>

For bulk cancellation, read the conditional-orders account, enumerate active trigger legs, and build one cancel instruction per active leg. The public examples show the full account-read and batching flow:

* [TypeScript cancel all conditional orders](https://github.com/Ellipsis-Labs/rise-public/blob/master/ts/examples/05-cancel-all-conditional-orders.ts)
* [Rust cancel all conditional orders](https://github.com/Ellipsis-Labs/rise-public/blob/master/rust/sdk/examples/cancel_all_conditional_orders.rs)
