Overview
The Alpha SDK provides multiple methods to discover and fetch prediction markets:getLiveMarkets()- Smart default that uses API if key is configured, otherwise on-chaingetMarket(marketId)- Fetch a single market by ID (API or on-chain)getMarketsOnChain()- Direct on-chain discovery (no API key needed)getMarketOnChain(marketAppId)- Fetch single market from blockchain
getLiveMarkets
Fetches all live, tradeable markets using the best available data source. Behavior:- If
apiKeyis configured → uses Alpha REST API (richer data) - If no
apiKey→ falls back to on-chain discovery
Returns
Array of live prediction markets
getMarket
Fetches a single market by its ID. Behavior:- If
apiKeyis configured → fetches from Alpha REST API using UUID - If no
apiKey→ reads from blockchain using app ID
Parameters
Market identifier:
- With API key: Use the market UUID (e.g.
'abc123-def456-...') - Without API key: Use the market app ID as a string (e.g.
'1234567890')
Returns
The market data, or
null if not found. See Market type above for field details.getMarketsOnChain
Fetches all live markets directly from the Algorand blockchain. No API key required. Discovers markets by querying all applications created by the market creator address, then reads their global state. Includes:- Market title
- App ID and token ASAs
- Resolution time
- Fee structure
- Resolved status
- Images
- Categories
- Volume
- Probabilities
Returns
Array of markets with on-chain data only. See Market type above for field details.Note: Fields like
yesProb, noProb, volume, image, and categories will be undefined.getMarketOnChain
Fetches a single market by its app ID directly from the blockchain. No API key required.Parameters
The Algorand application ID of the market contract
Returns
The market data from blockchain, or
null if not found. See Market type above for field details.Note: Only on-chain fields are populated. API-only fields like image, volume, etc. will be undefined.Multi-Choice Markets
Multi-choice markets are automatically grouped by the SDK. Options use the title format"Parent Title : Option Name".
marketAppId- Separate market contractyesAssetId/noAssetId- Separate outcome tokensyesProb/noProb- Independent probabilities
When to Use Each Method
- getLiveMarkets
- getMarketsOnChain
- getLiveMarketsFromApi
Best for: General use
- Automatically uses best available data source
- Falls back gracefully if no API key
- Recommended for most applications
Related
- Reward Markets - Markets with liquidity rewards
- On-Chain vs API - Detailed comparison guide
- AlphaClient - Client configuration
