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

# Markets

> Fetching and querying market data with the SDK.

The `sdk.orica` client provides methods for reading market data from the blockchain.

***

## Fetch All Markets

> [tab] TypeScript
>
> ```typescript theme={"dark"}
> // Basic fetch (on-chain data only)
> const markets = await sdk.orica.fetchAllMarkets();
>
> // With IPFS metadata
> const marketsWithMeta = await sdk.orica.fetchAllMarkets({
>   includeMetadata: true,
>   metadataTimeout: 10000,
> });
>
> for (const { publicKey, account, metadata } of marketsWithMeta) {
>   console.log("Address:", publicKey.toBase58());
>   console.log("Question:", account.question);
>   console.log("Status:", account.status);
>
>   if (metadata) {
>     console.log("Resolution Method:", metadata.resolution_method);
>     console.log("Image:", metadata.image_url);
>   }
> }
> ```

> [tab] Python
>
> ```python theme={"dark"}
> # Fetch all markets
> markets = await sdk.orica.fetch_all_markets()
>
> for address, market in markets:
>     print(f"Address: {address}")
>     print(f"Question: {market.question}")
>     print(f"Status: {market.status.value}")
> ```

***

## Fetch Single Market

> [tab] TypeScript
>
> ```typescript theme={"dark"}
> const marketAddress = new PublicKey("ABC123...");
> const account = await sdk.orica.fetchMarket(marketAddress);
>
> console.log("Question:", account.question);
> console.log("Close Time:", new Date(account.closeTime.toNumber() * 1000));
>
> // With metadata
> const market = await sdk.orica.fetchMarketWithMetadata(marketAddress, {
>   includeMetadata: true,
> });
>
> console.log("Description:", market.metadata?.reasoning);
> ```

> [tab] Python
>
> ```python theme={"dark"}
> market_address = Pubkey.from_string("ABC123...")
> market = await sdk.orica.fetch_market(market_address)
>
> print(f"Question: {market.question}")
> print(f"Close Time: {market.close_time}")
> ```

***

## Filter by Creator (TypeScript)

```typescript theme={"dark"}
const creatorPubkey = new PublicKey("Creator123...");
const markets = await sdk.orica.fetchMarketsByCreator(creatorPubkey, {
  includeMetadata: true,
});
```

***

## Market Account Structure

> [tab] TypeScript
>
> ```typescript theme={"dark"}
> interface Market {
>   id: BN;                      // Numeric market ID
>   creator: PublicKey;          // Creator's wallet
>   question: string;            // The question
>   metadataUri: string;         // IPFS metadata URI
>   closeTime: BN;               // Unix timestamp
>   createdAt: BN;               // Creation timestamp
>   status: MarketStatus;        // open, resolved, disputed
>   outcomeCount: number;        // Number of outcomes
>   pools: BN[];                 // USDC in each pool
>   supplies: BN[];              // Shares per outcome
>   optionNames: string[];       // Outcome names
>   resolution: Resolution | null;
>   resolutionMetadataUri: string | null;
>   disputeThresholdMet: boolean;
>   creatorFeeVault: PublicKey;  // Creator's fee account
> }
> ```

> [tab] Python
>
> ```python theme={"dark"}
> @dataclass
> class Market:
>     id: int                          # Numeric market ID
>     creator: Pubkey                  # Creator's wallet
>     question: str                    # The question
>     metadata_uri: str                # IPFS metadata URI
>     close_time: int                  # Unix timestamp
>     created_at: int                  # Creation timestamp
>     status: MarketStatus             # OPEN, RESOLVED, DISPUTED
>     outcome_count: int               # Number of outcomes
>     pools: list[int]                 # USDC in each pool
>     supplies: list[int]              # Shares per outcome
>     option_names: list[str]          # Outcome names
>     resolution: Resolution | None
>     resolution_metadata_uri: str | None
>     dispute_threshold_met: bool
>     creator_fee_vault: Pubkey        # Creator's fee account
> ```

***

## Calculate Prices

Get current share prices for all outcomes:

> [tab] TypeScript
>
> ```typescript theme={"dark"}
> const market = await sdk.orica.fetchMarket(marketAddress);
> const prices = sdk.orica.calculatePrices(market);
>
> market.optionNames.forEach((name, i) => {
>   console.log(`${name}: $${prices[i].toFixed(4)} per share`);
> });
> ```

> [tab] Python
>
> ```python theme={"dark"}
> market = await sdk.orica.fetch_market(market_address)
> prices = sdk.orica.calculate_prices(market)
>
> for i, name in enumerate(market.option_names):
>     print(f"{name}: ${prices[i]:.4f} per share")
> ```

The calculation uses the bonding curve formula:

```
Price = (BASE_PRICE + SLOPE * supply) / SCALE

CURVE_BASE_PRICE = 1,000    // 0.001 USDC
CURVE_SLOPE = 10            // 0.00001 USDC per share
USDC_SCALE = 1,000,000
```

***

## Fetch IPFS Metadata (TypeScript)

```typescript theme={"dark"}
const metadata = await sdk.orica.fetchIpfsMetadata(
  market.metadataUri,
  5000 // timeout in ms
);

if (metadata) {
  console.log("Resolution Method:", metadata.resolution_method);
  console.log("Image URL:", metadata.image_url);
}
```

***

## Global State

> [tab] TypeScript
>
> ```typescript theme={"dark"}
> const globalState = await sdk.orica.fetchGlobalState();
>
> console.log("Authority:", globalState.authority.toBase58());
> console.log("Market Count:", globalState.marketCount.toString());
> console.log("USDC Mint:", globalState.usdcMint.toBase58());
> console.log("Trading Fee (Protocol):", globalState.authorityTradingFeeBps, "bps");
> console.log("Trading Fee (Creator):", globalState.creatorTradingFeeBps, "bps");
> console.log("Redemption Fee:", globalState.redemptionFeeBps, "bps");
> ```

> [tab] Python
>
> ```python theme={"dark"}
> global_state = await sdk.orica.fetch_global_state()
>
> print(f"Authority: {global_state.authority}")
> print(f"Market Count: {global_state.market_count}")
> print(f"USDC Mint: {global_state.usdc_mint}")
> print(f"Trading Fee (Protocol): {global_state.authority_trading_fee_bps} bps")
> print(f"Trading Fee (Creator): {global_state.creator_trading_fee_bps} bps")
> print(f"Redemption Fee: {global_state.redemption_fee_bps} bps")
> ```

***

## Next Steps

> [card] [Trading](https://docs.orica.markets/sdk/trading.md)
>
> Execute buy, sell, and redeem operations.

> [card] [Positions](https://docs.orica.markets/sdk/positions.md)
>
> Track user positions and balances.


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