> ## 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.

# Buying Shares

> Purchasing outcome shares in a market.

Buy shares of an outcome you believe will occur. If your prediction is correct, each share redeems for \$1.

***

## Basic Buy

> [tab] TypeScript
>
> ```typescript theme={"dark"}
> import { BN } from "@coral-xyz/anchor";
> import { Transaction } from "@solana/web3.js";
>
> const amount = new BN(100_000_000); // 100 USDC (6 decimals)
> const outcomeIndex = 0; // First outcome (often "Yes")
>
> const instructions = await sdk.orica.buildBuy(
>   wallet.publicKey,
>   userUsdcAccount,
>   marketAddress,
>   amount,
>   outcomeIndex
> );
>
> const tx = new Transaction().add(...instructions);
> const sig = await sendAndConfirmTransaction(connection, tx, [wallet]);
> console.log("Buy transaction:", sig);
> ```

> [tab] Python
>
> ```python theme={"dark"}
> from solana.transaction import Transaction
>
> amount = 100_000_000  # 100 USDC (6 decimals)
> outcome_index = 0  # First outcome (often "Yes")
>
> instructions = await sdk.orica.build_buy(
>     user=wallet.pubkey(),
>     user_usdc=user_usdc_account,
>     market_address=market_address,
>     amount=amount,
>     outcome_index=outcome_index,
> )
>
> tx = Transaction()
> tx.add(*instructions)
> sig = await connection.send_transaction(tx, wallet)
> print(f"Buy transaction: {sig}")
> ```

***

## Understanding the Flow

**1. Input USDC**

You specify how much USDC to spend.

**2. Fee Deduction**

Trading fees (1.70%) are deducted from your input.

**3. Price Calculation**

The bonding curve determines how many shares you receive.

**4. Share Minting**

New shares are minted to your position account.

**5. Price Update**

The price for this outcome increases.

***

## Pre-Trade Calculations

Estimate the trade before submitting:

> [tab] TypeScript
>
> ```typescript theme={"dark"}
> // Get current prices
> const market = await sdk.orica.fetchMarket(marketAddress);
> const prices = sdk.orica.calculatePrices(market);
> const currentPrice = prices[outcomeIndex];
>
> // Estimate shares received (approximate)
> const amountUsdc = 100_000_000;
> const amountAfterFees = amountUsdc * 0.983; // After 1.70% fee
> const estimatedShares = amountAfterFees / currentPrice;
>
> console.log(`Current price: $${currentPrice.toFixed(4)}`);
> console.log(`Estimated shares: ${estimatedShares.toFixed(2)}`);
> ```

> [tab] Python
>
> ```python theme={"dark"}
> # Get current prices
> market = await sdk.orica.fetch_market(market_address)
> prices = sdk.orica.calculate_prices(market)
> current_price = prices[outcome_index]
>
> # Estimate shares received (approximate)
> amount_usdc = 100_000_000
> amount_after_fees = amount_usdc * 0.983  # After 1.70% fee
> estimated_shares = amount_after_fees / current_price
>
> print(f"Current price: ${current_price:.4f}")
> print(f"Estimated shares: {estimated_shares:.2f}")
> ```

***

## Account Requirements

> [card] USDC Balance
>
> You need sufficient USDC in your wallet.

> [card] SOL for Fees
>
> \~0.005 SOL for transaction fees.

> [card] Position Account
>
> Created automatically if this is your first trade in this market (\~0.002 SOL rent).

> [card] ATA
>
> Associated Token Account for USDC (created automatically if needed).

***

## Error Handling

> [tab] TypeScript
>
> ```typescript theme={"dark"}
> try {
>   const instructions = await sdk.orica.buildBuy(
>     wallet.publicKey,
>     userUsdcAccount,
>     marketAddress,
>     amount,
>     outcomeIndex
>   );
>
>   const tx = new Transaction().add(...instructions);
>   await sendAndConfirmTransaction(connection, tx, [wallet]);
> } catch (error) {
>   if (error.message.includes("insufficient funds")) {
>     console.error("Not enough USDC in wallet");
>   } else if (error.message.includes("MarketClosed")) {
>     console.error("Market is no longer accepting trades");
>   } else {
>     console.error("Transaction failed:", error);
>   }
> }
> ```

> [tab] Python
>
> ```python theme={"dark"}
> try:
>     instructions = await sdk.orica.build_buy(
>         user=wallet.pubkey(),
>         user_usdc=user_usdc_account,
>         market_address=market_address,
>         amount=amount,
>         outcome_index=outcome_index,
>     )
>
>     tx = Transaction()
>     tx.add(*instructions)
>     await connection.send_transaction(tx, wallet)
> except Exception as error:
>     if "insufficient funds" in str(error):
>         print("Not enough USDC in wallet")
>     elif "MarketClosed" in str(error):
>         print("Market is no longer accepting trades")
>     else:
>         print(f"Transaction failed: {error}")
> ```

***

## After Buying

Your position is updated immediately:

> [tab] TypeScript
>
> ```typescript theme={"dark"}
> const position = await sdk.orica.fetchPosition(marketAddress, wallet.publicKey);
> console.log("New position:", position.outcomeAmounts[outcomeIndex].toString());
> ```

> [tab] Python
>
> ```python theme={"dark"}
> position = await sdk.orica.fetch_position(market_address, wallet.pubkey())
> print(f"New position: {position.outcome_amounts[outcome_index]}")
> ```


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