> For the complete documentation index, see [llms.txt](https://docs.vela.exchange/vela-knowledge-base/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.vela.exchange/vela-knowledge-base/developers/contract-functions/price-manager.md).

# Price Manager

**Initialize**

This function initializes the `PriceManager` contract with the addresses of the `operators` and `pyth` contracts.

```solidity
initialize(address _operators, address _pyth) public
```

**Set Asset**

This function sets the details of an asset, such as its symbol, Pyth ID, price, allowed staleness, allowed deviation, and maximum leverage.

```solidity
setAsset(
uint256 _assetId, 
string calldata _symbol, 
bytes32 _pythId, 
uint256 _price, 
uint256 _allowedStaleness, 
uint256 _allowedDeviation, 
uint256 _maxLeverage
)
```

**Set Usd Asset**

This function sets the details of a USD stablecoin asset, including its token address, symbol, Pyth ID, price, allowed staleness, allowed deviation, and token decimals.

```solidity
setUsdAsset(
address _tokenAddress, 
uint256 _assetId, 
string calldata _symbol, 
bytes32 _pythId, 
uint256 _price, 
uint256 _allowedStaleness, 
uint256 _allowedDeviation, 
uint256 _tokenDecimals
)
```

**Get Pyth Last Price**

This function retrieves the last price of an asset from the Pyth network. It takes the asset ID and a flag indicating whether freshness is required. It returns the last price as a uint256 value.

```solidity
getPythLastPrice(
uint256 _assetId, 
bool _requireFreshness
) public view returns (uint256)
```

**Get Last Price**

This function returns the last price of an asset. If the price is still fresh (within the allowed staleness), it returns the stored price. Otherwise, it queries the Pyth network for the last price.

```solidity
getLastPrice(uint256 _assetId) public view override returns (uint256)
```

**Set Price**

This function sets the price of an asset. If the asset has a Pyth ID, it checks the deviation between the proposed price and the price from the Pyth network.

```solidity
setPrice(uint256 _assetId, uint256 _price, uint256 _ts) public
```

**Token To Usd**

This function converts the specified amount of tokens to an equivalent USD value. It takes the token address and the token amount and returns the USD value as a uint256 value.

```solidity
tokenToUsd(
address _token, 
uint256 _tokenAmount
) external view override returns (uint256)
```

**Usd To Token**

This function converts the specified USD amount to an equivalent amount of tokens. It takes the token address and the USD amount and returns the token amount as a uint256 value.

```solidity
usdToToken(
address _token, 
uint256 _usdAmount
) external view override returns (uint256)
```

**Get Current Time**

This function returns the current timestamp as a uint256 value.

```solidity
getCurrentTime() external view returns (uint256)
```

**Max Leverage**

This function returns the maximum leverage allowed for the specified asset ID.

```solidity
maxLeverage(uint256 _assetId) external view override returns (uint256)
```

**Get Valid Asset Ids**

This function returns an array of valid asset IDs.

```solidity
getValidAssetIds() external view returns (uint256[] memory)
```


---

# 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.vela.exchange/vela-knowledge-base/developers/contract-functions/price-manager.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.
