> 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/tr/gelistir/gelismis/on-chain-fiyat-beslemeleri/fiyat-okuma.md).

# Fiyat Okuma

## Adım 1: Oracle Adresini Bulma

Belirli bir çift için `PriceFeed` sözleşme adresini bulmanın üç yolu:

* **Price Oracle Tracker** (geliştirme sırasında en kolay): [price-oracle-tracker.vercel.app](https://price-oracle-tracker.vercel.app/?network=mainnet) — dağıtılmış tüm çiftleri, canlı fiyatları, ondalık basamakları, heartbeat değerlerini ve adresleri gösterir.
* **Zincir üstünde OracleFactory aracılığıyla**: `pairToOracle(string pair)` işlevini çağırın. Çift sembolleri büyük harfle girilmelidir (örn. `"PSG/USDT"`) — fabrika, okuma sırasında girdiyi normalleştirmez.
* **Toplu olarak zincir üstünde OracleFactoryReader aracılığıyla**: tek bir çağrıda tüm aktif çiftleri ve adreslerini almak için `getActiveOracles()` işlevini çağırın.

```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);
}
```

## Adım 2: Arayüzü Kullanarak Bağlanma

`PriceFeed` sözleşmesi, standart Chainlink `IAggregatorV3Interface` arayüzünü ve sağlık ile duraklatma durumu için Chiliz'e özgü uzantıları uygular.

```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
        );
}
```

## Adım 3: Fiyatı Okuma

{% hint style="warning" %}
**Besleme, bayat veya duraklatılmış durumda hata döndürmez — bu tasarım gereğidir.** `latestRoundData()`, henüz round mevcut değilse `NoDataAvailable()` hatasıyla döner; ancak beslemenin duraklatılıp duraklatılmadığını veya bayat olup olmadığını kontrol etmez. Bu, Chainlink AggregatorV3Interface tasarımıyla örtüşür: fiyatı kullanmadan önce `paused()` ve `getHealthStatus()` kontrollerini yapmak tüketicinin sorumluluğundadır. Not: skaler yardımcılar (`latestAnswer()`, `latestTimestamp()`, `getAnswer()`, `getTimestamp()`), veri yokken hata döndürmek yerine `0` döndürür. Tam doğrulama örüntüsü için [En İyi Uygulamalar](/tr/gelistir/gelismis/on-chain-fiyat-beslemeleri/en-iyi-uygulamalar.md) sayfasına bakın.
{% endhint %}

Temel işlev, mevcut fiyatı round ve zaman damgası meta verileriyle birlikte döndüren `latestRoundData()` işlevidir.

```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
    }
}
```

Protokolünüz 18'e normalleştirmek yerine beslemenin yerel ondalık basamaklarını kullanıyorsa:

```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;
}
```

## Geçmiş Veriler

Oracle, tüm geçmiş round verilerini zincir üstünde saklar. Her fiyat güncellemesi artan bir `roundId` ile yeni bir round oluşturur.

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

Chiliz beslemesinin sunduğu ek yardımcı görünümler:

| İşlev                              | Döndürür                                            |
| ---------------------------------- | --------------------------------------------------- |
| `latestAnswer()`                   | Son fiyat veya yoksa `0`                            |
| `latestTimestamp()`                | Son `updatedAt` değeri veya yoksa `0`               |
| `latestRound()`                    | Mevcut round ID                                     |
| `getAnswer(uint80 roundId)`        | Belirli bir round için fiyat veya yoksa `0`         |
| `getTimestamp(uint80 roundId)`     | Belirli bir round için zaman damgası veya yoksa `0` |
| `getRoundsData(uint80[] roundIds)` | Toplu `RoundData` dizisi                            |
| `roundExists(uint80 roundId)`      | `updatedAt > 0` ise `true`                          |

## Olaylar (Events)

Her `PriceFeed` sözleşmesi şu olayları yayar:

* **`AnswerUpdated(int256 indexed current, uint80 indexed roundId, uint256 updatedAt)`**: her fiyat güncellemesinde yayılır. Fiyata veya round'a göre filtreleyin.
* **`NewRound(uint80 indexed roundId, address indexed startedBy, uint256 startedAt)`**: yeni bir round başladığında yayılır. Round'a veya başlatan adrese göre filtreleyin.

## Keşif İşlevleri (OracleFactoryReader)

| İşlev                                   | Açıklama                                                     |
| --------------------------------------- | ------------------------------------------------------------ |
| `getActiveOracles()`                    | Oracle adresleriyle birlikte tüm aktif çiftleri döndürür     |
| `getAllOracles()`                       | Pasif olanlar dahil tüm oracle'ları döndürür                 |
| `getOraclesByPairs(string[] pairs)`     | Birden fazla çift adını tek çağrıda oracle adreslerine çözer |
| `getOracleHealthStatus(address oracle)` | Tek bir oracle için sağlık durumu                            |
| `getAllOracleHealthStatus()`            | Sistemdeki her oracle için sağlık durumu                     |


---

# 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/tr/gelistir/gelismis/on-chain-fiyat-beslemeleri/fiyat-okuma.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.
