> For the complete documentation index, see [llms.txt](https://docs.zofinance.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.zofinance.io/building-on-zo/zo-sdk/trading-examples.md).

# Trading Examples

### Limit order vs. market order

When you open or decrease a position, you choose how the order is executed:

| Type                | `isLimitOrder` | `isIocOrder` | Behavior                                                                                                                             |
| ------------------- | -------------- | ------------ | ------------------------------------------------------------------------------------------------------------------------------------ |
| **Market order**    | `false`        | —            | Execute immediately at market. Use **slippage** (`pricesSlippage`, `collateralSlippage`) to bound worst price.                       |
| **Limit order**     | `true`         | `false`      | Stored as a pending order; executes when the price condition is met. Typically use **zero or small slippage** (`pricesSlippage: 0`). |
| **IOC limit order** | `true`         | `true`       | Fill only if the limit can be met immediately; otherwise cancel (no partial fill).                                                   |

* **Market**: best for “get in/out now”; you accept some slippage.
* **Limit**: best when you want a specific price; order stays pending until the price condition is met.
* **IOC limit**: “fill at my price or not at all” in one block.

***

### ZLP / SLP: Open position (market order)

Execute immediately with slippage protection:

```typescript
const tx = await zlpAPI.openPositionV2(
  'usdc',             // collateral token
  'btc',              // index token
  BigInt(1000000),    // size
  BigInt(100000),     // collateral amount
  ['coinObjectId'],   // coin objects
  true,               // long position
  BigInt(50000),      // reserve amount
  30000,              // index price (reference)
  1.5,                // collateral price (reference)
  false,              // isLimitOrder: false = market order
  false,              // isIocOrder (ignored for market)
  0.003,              // pricesSlippage: 0.3% for market
  0.5,                // collateralSlippage: 50% for market
  BigInt(500),        // relayer fee
  'referralAddress',
  'senderAddress'
)
```

***

### ZLP / SLP: Open position (limit order)

Pending order at your limit price; use zero or small slippage:

```typescript
const tx = await zlpAPI.openPositionV2(
  'usdc',
  'btc',
  BigInt(1000000),
  BigInt(100000),
  ['coinObjectId'],
  true,                // long
  BigInt(50000),
  30000,               // your limit price (index)
  1.5,                 // collateral price
  true,                // isLimitOrder: true = limit order
  false,               // isIocOrder: false = pending until price is met
  0,                   // pricesSlippage: 0 for limit (exact price)
  0.5,                 // collateralSlippage
  BigInt(500),
  'referralAddress',
  'senderAddress'
)
```

***

### ZLP / SLP: Open position (IOC limit order)

Fill only if the limit can be met immediately; otherwise the order does not execute:

```typescript
const tx = await zlpAPI.openPositionV2(
  'usdc',
  'btc',
  BigInt(1000000),
  BigInt(100000),
  ['coinObjectId'],
  true,
  BigInt(50000),
  30000,
  1.5,
  true,                // isLimitOrder: true
  true,                // isIocOrder: true = fill now or cancel
  0,
  0.5,
  BigInt(500),
  'referralAddress',
  'senderAddress'
)
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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://docs.zofinance.io/building-on-zo/zo-sdk/trading-examples.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.
