owned this note
owned this note
Published
Linked with GitHub
# yPriceAPI Documentation
yPriceAPI allows you to fetch various data related to tokens, such as price, symbol, and name. It also provides the ability to get block information for a specific timestamp. To use this API, you need to provide your wallet address and signature in the headers.
- **Live API URL: https://ypriceapi-beta.yearn.finance**
## Table of Contents
- [yPriceAPI Documentation](#ypriceapi-documentation)
- [Generating Signature](#generating-signature)
- [Request Headers](#request-headers)
- [Routes](#routes)
- [1. Get Price](#1-get-price)
- [2. Get Price at Block](#2-get-price-at-block)
- [3. Get Block at Timestamp](#3-get-block-at-timestamp)
- [4. Get Symbol](#4-get-symbol)
- [5. Get Name](#5-get-name)
## Generating Signature
To generate a signature, follow these steps:
1. Visit [https://ypriceapi-beta.yearn.finance/](https://ypriceapi-beta.yearn.finance/)
2. Connect your wallet
3. Sign the message "I am proving ownership of this wallet so I can access ypriceAPI."
4. Copy the generated signature
## Request Headers
For each request, you need to include the following headers:
- `X-Signer`: Your wallet address (e.g., `0x_your_wallet_address_here`)
- `X-Signature`: Your generated signature (e.g., `0x_your_signature_here`)
## Routes
### 1. Get Price
Fetches the price of a token.
#### Request
`GET /get_price/{chainid}/{token}`
#### Parameters
- `chainid`: Integer, required. The chain ID.
- `token`: String, required. The token address.
#### Response
- `200`: Successful response. Returns the price as a number.
#### Examples
##### curl
```bash
curl -X 'GET' \
'https://ypriceapi-beta.yearn.finance/get_price/CHAIN_ID/TOKEN_ADDRESS' \
-H "X-Signer: WALLET_ADDRESS" \
-H "X-Signature: SIGNATURE"
```
##### Python
```python
import requests
url = "https://ypriceapi-beta.yearn.finance/get_price/CHAIN_ID/TOKEN_ADDRESS"
headers = {
"X-Signer": "WALLET_ADDRESS",
"X-Signature": "SIGNATURE"
}
response = requests.get(url, headers=headers)
print(response.json())
```
##### Node.js
```javascript
const axios = require('axios');
const url = 'https://ypriceapi-beta.yearn.finance/get_price/CHAIN_ID/TOKEN_ADDRESS';
const headers = {
'X-Signer': 'WALLET_ADDRESS',
'X-Signature': 'SIGNATURE'
};
axios.get(url, { headers })
.then(response => console.log(response.data))
.catch(error => console.error(error));
```
##### Rust
```rust
use reqwest::header::{HeaderMap, HeaderValue};
#[tokio::main]
async fn main() -> Result<(), reqwest::Error> {
let url = "https://ypriceapi-beta.yearn.finance/get_price/CHAIN_ID/TOKEN_ADDRESS";
let mut headers = HeaderMap::new();
headers.insert("X-Signer", HeaderValue::from_str("WALLET_ADDRESS").unwrap());
headers.insert("X-Signature", HeaderValue::from_str("SIGNATURE").unwrap());
let response = reqwest::Client::new()
.get(url)
.headers(headers)
.send()
.await?
.text()
.await?;
println!("{}", response);
Ok(())
}
```
##### Go
```go
package main
import (
"fmt"
"io/ioutil"
"net/http"
)
func main() {
url := "https://ypriceapi-beta.yearn.finance/get_price/CHAIN_ID/TOKEN_ADDRESS"
req, _ := http.NewRequest("GET", url, nil)
req.Header.Add("X-Signer", "WALLET_ADDRESS")
req.Header.Add("X-Signature", "SIGNATURE")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := ioutil.ReadAll(res.Body)
fmt.Println(string(body))
}
```
### 2. Get Price at Block
Fetches the price of a token at a specific block.
#### Request
`GET /get_price/{chainid}/{token}/{block}`
#### Parameters
- `chainid`: Integer, required. The chain ID.
- `token`: String, required. The token address.
- `block`: Integer or "latest", required. The block number or "latest" for the latest block.
#### Response
- `200`: Successful response. Returns the price as a number.
#### Examples
##### curl
```bash
curl -X 'GET' \
'https://ypriceapi-beta.yearn.finance/get_price/CHAIN_ID/TOKEN_ADDRESS/BLOCK_NUMBER' \
-H "X-Signer: WALLET_ADDRESS" \
-H "X-Signature: SIGNATURE"
```
##### Python
```python
import requests
url = "https://ypriceapi-beta.yearn.finance/get_price/CHAIN_ID/TOKEN_ADDRESS/BLOCK_NUMBER"
headers = {
"X-Signer": "WALLET_ADDRESS",
"X-Signature": "SIGNATURE"
}
response = requests.get(url, headers=headers)
print(response.json())
```
##### Node.js
```javascript
const axios = require('axios');
const url = 'https://ypriceapi-beta.yearn.finance/get_price/CHAIN_ID/TOKEN_ADDRESS/BLOCK_NUMBER';
const headers = {
'X-Signer': 'WALLET_ADDRESS',
'X-Signature': 'SIGNATURE'
};
axios.get(url, { headers })
.then(response => console.log(response.data))
.catch(error => console.error(error));
```
##### Rust
```rust
use reqwest::header::{HeaderMap, HeaderValue};
#[tokio::main]
async fn main() -> Result<(), reqwest::Error> {
let url = "https://ypriceapi-beta.yearn.finance/get_price/CHAIN_ID/TOKEN_ADDRESS/BLOCK_NUMBER";
let mut headers = HeaderMap::new();
headers.insert("X-Signer", HeaderValue::from_str("WALLET_ADDRESS").unwrap());
headers.insert("X-Signature", HeaderValue::from_str("SIGNATURE").unwrap());
let response = reqwest::Client::new()
.get(url)
.headers(headers)
.send()
.await?
.text()
.await?;
println!("{}", response);
Ok(())
}
```
##### Go
```go
package main
import (
"fmt"
"io/ioutil"
"net/http"
)
func main() {
url := "https://ypriceapi-beta.yearn.finance/get_price/CHAIN_ID/TOKEN_ADDRESS/BLOCK_NUMBER"
req, _ := http.NewRequest("GET", url, nil)
req.Header.Add("X-Signer", "WALLET_ADDRESS")
req.Header.Add("X-Signature", "SIGNATURE")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := ioutil.ReadAll(res.Body)
fmt.Println(string(body))
}
```
### 3. Get Block at Timestamp
Fetches the block number for a specific timestamp.
#### Request
`GET /get_block_at_timestamp/{chainid}/{timestamp}`
#### Parameters
- `chainid`: Integer, required. The chain ID.
- `
#### Response
- `200`: Successful response. Returns the block number as an integer.
timestamp`: Integer, required. The UNIX timestamp.
#### Examples
##### curl
```bash
curl -X 'GET' \
'https://ypriceapi-beta.yearn.finance/get_block_at_timestamp/CHAIN_ID/TIMESTAMP' \
-H "X-Signer: WALLET_ADDRESS" \
-H "X-Signature: SIGNATURE"
```
##### Python
```python
import requests
url = "https://ypriceapi-beta.yearn.finance/get_block_at_timestamp/CHAIN_ID/TIMESTAMP"
headers = {
"X-Signer": "WALLET_ADDRESS",
"X-Signature": "SIGNATURE"
}
response = requests.get(url, headers=headers)
print(response.json())
```
##### Node.js
```javascript
const axios = require('axios');
const url = 'https://ypriceapi-beta.yearn.finance/get_block_at_timestamp/CHAIN_ID/TIMESTAMP';
const headers = {
'X-Signer': 'WALLET_ADDRESS',
'X-Signature': 'SIGNATURE'
};
axios.get(url, { headers })
.then(response => console.log(response.data))
.catch(error => console.error(error));
```
##### Rust
```rust
use reqwest::header::{HeaderMap, HeaderValue};
#[tokio::main]
async fn main() -> Result<(), reqwest::Error> {
let url = "https://ypriceapi-beta.yearn.finance/get_block_at_timestamp/CHAIN_ID/TIMESTAMP";
let mut headers = HeaderMap::new();
headers.insert("X-Signer", HeaderValue::from_str("WALLET_ADDRESS").unwrap());
headers.insert("X-Signature", HeaderValue::from_str("SIGNATURE").unwrap());
let response = reqwest::Client::new()
.get(url)
.headers(headers)
.send()
.await?
.text()
.await?;
println!("{}", response);
Ok(())
}
```
##### Go
```go
package main
import (
"fmt"
"io/ioutil"
"net/http"
)
func main() {
url := "https://ypriceapi-beta.yearn.finance/get_block_at_timestamp/CHAIN_ID/TIMESTAMP"
req, _ := http.NewRequest("GET", url, nil)
req.Header.Add("X-Signer", "WALLET_ADDRESS")
req.Header.Add("X-Signature", "SIGNATURE")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := ioutil.ReadAll(res.Body)
fmt.Println(string(body))
}
```
### 4. Get Symbol
Fetches the symbol of a token.
#### Request
`GET /get_symbol/{chainid}/{token}`
#### Parameters
- `chainid`: Integer, required. The chain ID.
- `token`: String, required. The token address.
#### Response
- `200`: Successful response. Returns the token symbol as a string.
#### Examples
##### curl
```bash
curl -X 'GET' \
'https://ypriceapi-beta.yearn.finance/get_symbol/CHAIN_ID/TOKEN_ADDRESS' \
-H "X-Signer: WALLET_ADDRESS" \
-H "X-Signature: SIGNATURE"
```
##### Python
```python
import requests
url = "https://ypriceapi-beta.yearn.finance/get_symbol/CHAIN_ID/TOKEN_ADDRESS"
headers = {
"X-Signer": "WALLET_ADDRESS",
"X-Signature": "SIGNATURE"
}
response = requests.get(url, headers=headers)
print(response.json())
```
##### Node.js
```javascript
const axios = require('axios');
const url = 'https://ypriceapi-beta.yearn.finance/get_symbol/CHAIN_ID/TOKEN_ADDRESS';
const headers = {
'X-Signer': 'WALLET_ADDRESS',
'X-Signature': 'SIGNATURE'
};
axios.get(url, { headers })
.then(response => console.log(response.data))
.catch(error => console.error(error));
```
##### Rust
```rust
use reqwest::header::{HeaderMap, HeaderValue};
#[tokio::main]
async fn main() -> Result<(), reqwest::Error> {
let url = "https://ypriceapi-beta.yearn.finance/get_symbol/CHAIN_ID/TOKEN_ADDRESS";
let mut headers = HeaderMap::new();
headers.insert("X-Signer", HeaderValue::from_str("WALLET_ADDRESS").unwrap());
headers.insert("X-Signature", HeaderValue::from_str("SIGNATURE").unwrap());
let response = reqwest::Client::new()
.get(url)
.headers(headers)
.send()
.await?
.text()
.await?;
println!("{}", response);
Ok(())
}
```
##### Go
```go
package main
import (
"fmt"
"io/ioutil"
"net/http"
)
func main() {
url := "https://ypriceapi-beta.yearn.finance/get_symbol/CHAIN_ID/TOKEN_ADDRESS"
req, _ := http.NewRequest("GET", url, nil)
req.Header.Add("X-Signer", "WALLET_ADDRESS")
req.Header.Add("X-Signature", "SIGNATURE")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := ioutil.ReadAll(res.Body)
fmt.Println(string(body))
}
```
### 5. Get Name
Fetches the name of a token.
#### Request
`GET /get_name/{chainid}/{token}`
#### Parameters
- `chainid`: Integer, required. The chain ID.
- `token`: String, required. The token address.
#### Response
- `200`: Successful response. Returns the token name as a string.
#### Examples
##### curl
```bash
curl -X 'GET' \
'https://ypriceapi-beta.yearn.finance/get_name/CHAIN_ID/TOKEN_ADDRESS' \
-H "X-Signer: WALLET_ADDRESS" \
-H "X-Signature: SIGNATURE"
```
##### Python
```python
import requests
url = "https://ypriceapi-beta.yearn.finance/get_name/CHAIN_ID/TOKEN_ADDRESS"
headers = {
"X-Signer": "WALLET_ADDRESS",
"X-Signature": "SIGNATURE"
}
response = requests.get(url, headers=headers)
print(response.json())
```
##### Node.js
```javascript
const axios = require('axios');
const url = 'https://ypriceapi-beta.yearn.finance/get_name/CHAIN_ID/TOKEN_ADDRESS';
const headers = {
'X-Signer': 'WALLET_ADDRESS',
'X-Signature': 'SIGNATURE'
};
axios.get(url, { headers })
.then(response => console.log(response.data))
.catch(error => console.error(error));
```
##### Rust
```rust
use reqwest::header::{HeaderMap, HeaderValue};
#[tokio::main]
async fn main() -> Result<(), reqwest::Error> {
let url = "https://ypriceapi-beta.yearn.finance/get_name/CHAIN_ID/TOKEN_ADDRESS";
let mut headers = HeaderMap::new();
headers.insert("X-Signer", HeaderValue::from_str("WALLET_ADDRESS").unwrap());
headers.insert("X-Signature", HeaderValue::from_str("SIGNATURE").unwrap());
let response = reqwest::Client::new()
.get(url)
.headers(headers)
.send()
.await?
.text()
.await?;
println!("{}", response);
Ok(())
}
```
##### Go
```go
package main
import (
"fmt"
"io/ioutil"
"net/http"
)
func main() {
url := "https://ypriceapi-beta.yearn.finance/get_name/CHAIN_ID/TOKEN_ADDRESS"
req, _ := http.NewRequest("GET", url, nil)
req.Header.Add("X-Signer", "WALLET_ADDRESS")
req.Header.Add("X-Signature", "SIGNATURE")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := ioutil.ReadAll(res.Body)
fmt.Println(string(body))
}
```