Overview
The Futarchy DEX API calculates prices from on-chain spot pool reserves, ensuring accurate and real-time pricing data for all trading pairs.All prices are calculated from spot pools only, not conditional or futarchy markets.
Price Formula
The price calculation accounts for token decimal differences to provide accurate exchange rates:Components
The amount of quote token (typically USDC) in the pool
The amount of base token in the pool
Number of decimal places for the base token (often 9 for Solana tokens)
Number of decimal places for the quote token (6 for USDC)
Example Calculation
Let’s calculate the price for a ZKFG/USDC pool:1
Pool Reserves
- Base reserves (ZKFG): 1,000,000 tokens
- Quote reserves (USDC): 81,340 tokens
2
Token Decimals
- Base decimals (ZKFG): 9
- Quote decimals (USDC): 6
3
Apply Formula
4
Result
The price of 1 ZKFG = 0.08134 USDC
Why Decimal Adjustment Matters
Without accounting for decimals, prices would be incorrect:Without Adjustment
With Adjustment
Real-World Token Decimals
Common token decimal configurations on Solana:| Token | Decimals | Example |
|---|---|---|
| USDC | 6 | 1,000,000 = 1 USDC |
| USDT | 6 | 1,000,000 = 1 USDT |
| SOL | 9 | 1,000,000,000 = 1 SOL |
| Most SPL Tokens | 9 | 1,000,000,000 = 1 token |
Bid and Ask Prices
In addition to the last price, the API provides bid and ask prices:Bid Price
Bid Price
The bid price is the highest price a buyer is willing to pay. In the API, this accounts for:
- Current pool reserves
- Expected price impact from a small sell order
- Slippage considerations
Ask Price
Ask Price
The ask price is the lowest price a seller is willing to accept. This accounts for:
- Current pool reserves
- Expected price impact from a small buy order
- Slippage considerations
Price Updates
Prices are updated in real-time as trades occur and pool reserves change.
- Cache Hit: Returns cached price instantly
- Cache Miss: Fetches fresh data from blockchain
- Pool Changes: Triggers cache invalidation
Data Sources
All price data comes from:- On-chain pool accounts - Reserve balances
- Token metadata programs - Decimal information
- Spot pools only - Excludes conditional markets
Best Practices
Use Last Price
For current market price, use
last_price fieldConsider Bid/Ask
For execution estimates, use bid/ask spread
Monitor Liquidity
Check liquidity_in_usd for price stability
Handle Decimals
Always respect token decimal places in calculations
