sdk.orica client provides methods for reading market data from the blockchain.
Fetch All Markets
- TypeScript
- Python
// 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);
}
}
# 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
- TypeScript
- Python
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);
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)
const creatorPubkey = new PublicKey("Creator123...");
const markets = await sdk.orica.fetchMarketsByCreator(creatorPubkey, {
includeMetadata: true,
});
Market Account Structure
- TypeScript
- Python
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
}
@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:- TypeScript
- Python
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`);
});
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")
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)
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
- TypeScript
- Python
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");
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
Trading
Execute buy, sell, and redeem operations.
Positions
Track user positions and balances.