# Instructions

Instructions to interact with the Phoenix Legacy program are available in the [phoenix-v1](https://crates.io/crates/phoenix-v1) crate. The Phoenix Legacy IDL is available on [GitHub](https://github.com/Ellipsis-Labs/phoenix-v1/blob/master/idl/phoenix_v1.json).

### Swap

The `Swap` instruction is used for crossing the book. Aggregators and other programs wishing to access Phoenix Legacy liquidity will primarily use this instruction. A `Swap` instruction can be created using `phoenix-types::instructions::create_new_order_instruction`, passing in an `OrderPacket::ImmediateOrCancel` order specification.

### SwapWithFreeFunds

The `SwapWithFreeFunds` is the same as the `Swap` instruction except that it requires the caller to have an Approved seat on the market. It will attempt to cross the book only using funds that the trader has deposited into the market vaults. **If insufficient funds are deposited, this instruction will fail**. This instruction requires fewer account inputs and consumes less compute than \`Swap\`, which potentially makes it easier to compose with.

### RequestSeat

The `RequestSeat` instruction is used to request a Seat on a given Phoenix Legacy Market. A Seat is required to place limit orders.

### PlaceLimitOrder

The `PlaceLimitOrder` instruction is used for placing liquidity on the book. Only traders with a [Seat](/phoenix-dex/tRIkEFlLUzWK9uKO3W2V/getting-started/technical-overview/seats.md) may call this instruction. A `PlaceLimitOrder` instruction can be created using `phoenix-types::instructions::create_new_order_instruction`, passing in an `OrderPacket::Limit` (standard limit order) or an `OrderPacket::PostOnly` (post-only order) order specification.

### PlaceLimitOrderWithFreeFunds

The `PlaceLimitOrderWithFreeFunds` is the same as the `PlaceLimitOrder` instruction except that it will attempt to place an order only using funds that the trader has deposited into the market vaults. **If insufficient funds are deposited, this instruction will fail**. This instruction requires fewer account inputs and consumes less compute than `PlaceLimitOrder`, which potentially makes it easier to compose with.

### ReduceOrder

The `ReduceOrder` instruction is used to reduce the size of an order resting on the book, while maintaining queue position.

### ReduceWithFreeFunds

The `ReduceOrderWithFreeFunds` is the same as the `ReduceOrder` instruction except that it will not withdraw the freed funds. This instruction requires fewer account inputs and consumes less compute than `ReduceOrder`, which potentially makes it easier to compose with.

### CancelAllOrders

The `CancelAllOrders` instruction can be called by a market maker to cancel all of their resting orders on a particular market.

### CancelAllOrdersWithFreeFunds

The `CancelAllOrdersWithFreeFunds` is the same as the `CancelAllOrders` instruction except that it will not withdraw the freed funds. This instruction requires fewer account inputs and consumes less compute than `CancelAllOrders`, which potentially makes it easier to compose with.

### CancelMultipleOrdersById

The `CancelMultipleOrdersById` instruction can be called by a market maker to cancel specific orders on a particular market, selected by order ID.

### CancelMultipleOrdersByIdWithFreeFunds

The `CancelMultipleOrdersByIdWithFreeFunds` is the same as the `CancelMultipleOrdersById` instruction except that it will not withdraw the freed funds. This instruction requires fewer account inputs and consumes less compute than `CancelMultipleOrdersById`, which potentially makes it easier to compose with.

### CancelUpTo

The `CancelUpTo` instruction can be called by a market maker to cancel all orders on one side of the book that are more aggressive than the specified price.

### CancelUpToWithFreeFunds

The `CancelUpToWithFreeFunds` is the same as the `CancelUpTo` instruction except that it will not withdraw the freed funds. This instruction requires fewer account inputs and consumes less compute than `CancelUpTo`, which potentially makes it easier to compose with.

### WithdrawFunds

The `WithdrawFunds` instruction can be called by a market maker to withdraw a specified number of quote lots and base lots from a market.

### DepositFunds

The `DepositFunds` instruction can be called by a market maker to deposit a specified number of quote lots and base lots to a market. This can be used in conjunction with market actions utilizing free funds (e.g. `PlaceLimitOrderWithFreeFunds`) so that token transfers are not required for every market action, reducing the compute required for those market actions.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://ellipsis-labs.gitbook.io/phoenix-dex/tRIkEFlLUzWK9uKO3W2V/getting-started/technical-overview/instructions.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
