> For the complete documentation index, see [llms.txt](https://docs.chiliz.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.chiliz.com/develop/advanced/get-asset-and-fan-token-prices/reading-prices.md).

# Reading prices

## Step 1: Find the Oracle Address

Three ways to find a `PriceFeed` contract address for a given pair:

* **Price Oracle Tracker** (easiest during development): [price-oracle-tracker.vercel.app](https://price-oracle-tracker.vercel.app/?network=mainnet), which shows all deployed pairs, live prices, decimals, heartbeat, and addresses.
* **On-chain via OracleFactory**: call `pairToOracle(string pair)`. Pair symbols must be passed in uppercase (e.g. `"PSG/USDT"`); the factory does not normalise input on reads.
* **Bulk on-chain via OracleFactoryReader**: call `getActiveOracles()` to retrieve all active pairs and their addresses in one call.

```solidity
interface IOracleFactory {
    function pairToOracle(string memory pair) external view returns (address);
    function getOracleCount() external view returns (uint256);
}

function resolveFeed(address factory, string memory pair)
    external view returns (address)
{
    // Pair symbol must be passed in uppercase (e.g. "PSG/USDT").
    return IOracleFactory(factory).pairToOracle(pair);
}
```

## Step 2: Connect Using the Interface

The `PriceFeed` contract implements the standard Chainlink `IAggregatorV3Interface`, plus Chiliz-specific extensions for health and pause status.

```solidity
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.30;

interface IAggregatorV3Interface {
    function decimals() external view returns (uint8);
    function description() external view returns (string memory);
    function version() external view returns (uint256);

    function getRoundData(uint80 _roundId)
        external view
        returns (
            uint80 roundId,
            int256 answer,
            uint256 startedAt,
            uint256 updatedAt,
            uint80 answeredInRound
        );

    function latestRoundData()
        external view
        returns (
            uint80 roundId,
            int256 answer,
            uint256 startedAt,
            uint256 updatedAt,
            uint80 answeredInRound
        );
}

interface IChilizPriceFeed is IAggregatorV3Interface {
    function paused() external view returns (bool);
    function updateInterval() external view returns (uint256);
    function healthFactor() external view returns (uint80);
    function getHealthStatus()
        external view
        returns (
            uint256 lastUpdateTimestamp,
            uint256 totalRounds,
            uint256 timeSinceLastUpdate,
            bool isHealthy
        );
}
```

## Step 3: Read the Price

{% hint style="warning" %}
**The feed does not revert on stale or paused state; this is intentional.** `latestRoundData()` reverts with `NoDataAvailable()` if no rounds exist yet, but it does not check whether the feed is paused or stale. This matches the Chainlink AggregatorV3Interface design: consumers are responsible for gating on `paused()` and `getHealthStatus()` before consuming a price. Note: the scalar helpers (`latestAnswer()`, `latestTimestamp()`, `getAnswer()`, `getTimestamp()`) return `0` rather than reverting when no data is present. See [Best Practices](/develop/advanced/get-asset-and-fan-token-prices/best-practices.md) for the full validation pattern.
{% endhint %}

The primary function is `latestRoundData()`, which returns the current price alongside round and timestamp metadata.

```solidity
contract LendingOracleConsumer {
    IChilizPriceFeed public priceFeed;

    constructor(address _feed) {
        priceFeed = IChilizPriceFeed(_feed);
    }

    function getSafePrice() public view returns (uint256 price18) {
        // 1. Check feed is not paused
        require(!priceFeed.paused(), "Feed paused");

        // 2. Read latest data (reverts with NoDataAvailable() if no rounds exist)
        (
            uint80 roundId,
            int256 answer,
            uint256 startedAt,
            uint256 updatedAt,
            uint80 answeredInRound
        ) = priceFeed.latestRoundData();

        // 3. Basic sanity checks
        require(answer > 0, "Invalid price");

        // 4. Optional: use explicit health check for staleness
        (, , , bool isHealthy) = priceFeed.getHealthStatus();
        require(isHealthy, "Stale price");

        // 5. Normalize to 18 decimals for internal math
        uint8 decimals_ = priceFeed.decimals();
        uint256 scale = 10 ** uint256(decimals_);
        price18 = uint256(answer) * 1e18 / scale; // This is the actual price of an asset
    }
}
```

If your protocol uses the feed's native decimals rather than normalising to 18:

```solidity
function getRawPriceWithMeta()
    external view
    returns (int256 price, uint8 decimals_, uint256 updatedAt)
{
    require(!priceFeed.paused(), "Feed paused");

    (, int256 answer, , uint256 _updatedAt, ) =
        priceFeed.latestRoundData();
    require(answer > 0, "Invalid price");

    (, , , bool isHealthy) = priceFeed.getHealthStatus();
    require(isHealthy, "Stale price");

    decimals_ = priceFeed.decimals();
    price = answer;
    updatedAt = _updatedAt;
}
```

## Historical Data

The oracle stores all historical round data on-chain. Each price update creates a new round with an incrementing `roundId`.

```solidity
(uint80 roundId, int256 answer, , uint256 updatedAt, ) =
    priceFeed.getRoundData(targetRoundId);
```

Additional helper views exposed by the Chiliz feed:

| Function                           | Returns                                |
| ---------------------------------- | -------------------------------------- |
| `latestAnswer()`                   | Latest price, or `0` if none           |
| `latestTimestamp()`                | Latest `updatedAt`, or `0` if none     |
| `latestRound()`                    | Current round ID                       |
| `getAnswer(uint80 roundId)`        | Price for a specific round, or `0`     |
| `getTimestamp(uint80 roundId)`     | Timestamp for a specific round, or `0` |
| `getRoundsData(uint80[] roundIds)` | Bulk `RoundData` array                 |
| `roundExists(uint80 roundId)`      | `true` if `updatedAt > 0`              |

## Events

Each `PriceFeed` contract emits:

* **`AnswerUpdated(int256 indexed current, uint80 indexed roundId, uint256 updatedAt)`**: emitted on every price update. Filter by price or round.
* **`NewRound(uint80 indexed roundId, address indexed startedBy, uint256 startedAt)`**: emitted when a new round begins. Filter by round or by the address that started it.

## Discovery Functions (OracleFactoryReader)

| Function                                | Description                                                 |
| --------------------------------------- | ----------------------------------------------------------- |
| `getActiveOracles()`                    | Returns all active pairs with their oracle addresses        |
| `getAllOracles()`                       | Returns all oracles, including inactive ones                |
| `getOraclesByPairs(string[] pairs)`     | Resolve multiple pair names to oracle addresses in one call |
| `getOracleHealthStatus(address oracle)` | Health status for a single oracle                           |
| `getAllOracleHealthStatus()`            | Health status for every oracle in the system                |


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.chiliz.com/develop/advanced/get-asset-and-fan-token-prices/reading-prices.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
