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

# Trading

> How to buy, sell, and redeem shares in Orica markets.

Trading in Orica involves exchanging USDC for outcome shares. When you buy shares, you are betting that outcome will occur. When you sell, you exit your position and receive USDC back from the pool.

***

## Trade Types

> [tab] Buy
>
> **Buying** mints new shares of a specific outcome.
>
> * You send USDC to the market vault
> * New shares are minted to your position account
> * The price increases based on the bonding curve
> * Fees are deducted from your input amount
>
> ```typescript theme={"dark"}
> const instructions = await sdk.orica.buildBuy(
>   userPubkey,
>   userUsdcAccount,
>   marketAddress,
>   new BN(10_000_000), // 10 USDC
>   0 // Outcome index
> );
> ```

> [tab] Sell
>
> **Selling** burns your shares and returns USDC from the pool.
>
> * Your shares are burned
> * USDC is transferred from the vault to your account
> * The price decreases based on the bonding curve
> * Fees are deducted from the output amount
>
> ```typescript theme={"dark"}
> const instructions = await sdk.orica.buildSell(
>   userPubkey,
>   userUsdcAccount,
>   marketAddress,
>   new BN(5000), // Number of shares to sell
>   0 // Outcome index
> );
> ```

> [tab] Redeem
>
> **Redemption** is only available after a market is resolved.
>
> * Only winning shares can be redeemed
> * Each winning share is exchanged 1:1 for USDC
> * A small redemption fee may apply
> * Losing shares become worthless
>
> ```typescript theme={"dark"}
> const instruction = await sdk.orica.buildRedeem(
>   userPubkey,
>   userUsdcAccount,
>   marketAddress
> );
> ```

***

## Trade Data Structure

When a trade is executed, the indexer records the following data:

| Field | Type | Description |
| - | - | - |
| `signature` | `string` | Solana transaction signature |
| `market_address` | `string` | Market being traded |
| `user_address` | `string` | Trader's wallet |
| `trade_type` | `string` | `buy`, `sell`, or `redeem` |
| `outcome_index` | `number` | Which outcome was traded |
| `amount_usdc` | `number` | USDC amount (input for buy, output for sell) |
| `shares` | `number` | Number of shares traded |
| `price` | `number` | Average price per share |
| `market_cap_at_trade` | `number` | Market cap at time of trade |
| `timestamp` | `number` | Unix timestamp |
| `fees_paid_usdc` | `number` | Fees deducted |

***

## Fees

Orica charges fees on trading activity. These fees are distributed between the protocol and market creators.

| Fee Type | Recipient | Rate |
| - | - | - |
| Trading Fee (Authority) | Protocol | 1.25% |
| Trading Fee (Creator) | Market Creator | 0.45% |
| Redemption Fee | Protocol | 0.30% |

> [!WARNING]
>
> Fee rates are configurable by protocol governance and may change. Always fetch the current `GlobalState` to verify rates.

***

## Positions

A **Position** tracks how many shares a user holds in each outcome of a market.

```typescript theme={"dark"}
const position = await sdk.orica.fetchPosition(marketAddress, userPubkey);

if (position) {
  position.outcomeAmounts.forEach((amount, i) => {
    console.log(`Outcome ${i}: ${amount.toNumber()} shares`);
  });
}
```

Positions are stored in Program Derived Addresses (PDAs) derived from the market and user public keys.

***

## Trade History

Fetch historical trades via the API:

```bash By Market theme={"dark"}
curl "https://api.orica.markets/trades/market/MARKET_ADDRESS?limit=50"
```

```bash By User (WebSocket) theme={"dark"}
// Connect to WebSocket and send filter
ws.send(JSON.stringify({ type: "user", address: "USER_ADDRESS" }));
```

***

## Compute Units

Complex bonding curve calculations may require additional compute units. The SDK automatically includes a `ComputeBudgetProgram.setComputeUnitLimit` instruction.

```typescript theme={"dark"}
// Default: 1,400,000 compute units
const instructions = await sdk.orica.buildBuy(...);

// Custom compute units
const instructions = await sdk.orica.buildBuy(
  ...,
  { computeUnits: 500_000 }
);
```

***

## Next Steps

> [card] [Bonding Curve](https://docs.orica.markets/guides/bonding-curve.md)
>
> Understand how prices are calculated.

> [card] [Disputes](https://docs.orica.markets/guides/disputes.md)
>
> Learn about dispute resolution.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.