# Use Pyth Network

The `Use Pyth Network` tool, part of AgentiPy, enables users to interact with the Pyth Network on Solana. Its primary function is to fetch real-time token price data from Pyth's on-chain oracles.

## Functionality

This tool is implemented in the `PythManager` class. It uses the `pythclient` library to connect to Pyth Network endpoints and retrieve price information.

### Key Methods:

* `get_price(mint_address: str)`:
  * (Static async method) Fetches the current aggregate price data for a given token `mint_address` (string representing the Pyth price account, which might be different from the SPL token mint for a given asset).
  * It initializes a `SolanaClient` from `pythclient` using PythNet's public HTTP/WS endpoints.
  * Creates a `PythPriceAccount` object and calls `update()` to get the latest price.
  * Returns a dictionary containing:
    * `price`: The aggregate price.
    * `confidence_interval`: The confidence interval for the price.
    * `status`: The trading status of the price feed (e.g., "TRADING", "NOT\_TRADING").
    * `message`: An optional message if the status is not "TRADING".
  * Closes the `solana_client` connection after fetching the price.

##

**Important Considerations:**

* **Direct On-Chain/Oracle Interaction:** This tool interacts directly with the Pyth Network's oracle program accounts on Solana via Pyth's defined client endpoints.
* **Pyth Price Accounts:** You must use the correct Pyth price account address for the asset you are interested in. These are specific to Pyth and are not the same as SPL token mint addresses, though they correspond to an underlying asset. Refer to Pyth Network documentation for a list of available price feeds.
* **Price Status:** Always check the `status` field in the response. A status other than "TRADING" (e.g., "UNKNOWN", "HALTED") means the price may not be current or reliable.

## Source Code

You can find the source code for this tool on GitHub: <https://github.com/niceberginc/agentipy/blob/main/agentipy/tools/use_pyth.py>


---

# Agent Instructions: 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:

```
GET https://docs.agentipy.fun/tools/use-pyth-network.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
