# Prices API

## Supported Pairs

The **`/v0.1/prices/pairs`** API returns a list of price pairs supported by the Spice.xyz platform.

{% hint style="info" %}
The **/prices/pairs** endpoint only returns pairs natively where Spice is the data provider. The price quote APIs below aggregate data from other providers (e.g. CoinMarketCap) and support significantly more pairs not listed by this endpoint.
{% endhint %}

## Get supported price pairs

<mark style="color:blue;">`GET`</mark> `https://data.spiceai.io/v0.1/prices/pairs`

Returns a list of token/currency Spice provided price pairs.

{% tabs %}
{% tab title="200: OK Pairs successfully returned" %}

```json
["BTC-USD", "ETH-USD", "LTC-USD"]
```

{% endtab %}
{% endtabs %}

## Spot/Latest Prices

The **`/v0.1/prices`** API returns the spot (latest) prices of popular token/currency pairs for several exchanges, such as Binance, Coinbase, and Gemini, and the min, max, and average price across them.

## Get exchange prices for a symbol/currency

<mark style="color:blue;">`GET`</mark> `https://data.spiceai.io/v0.1/prices`

Returns token/currency pairs for several exchanges, such as Coinbase, and Gemini and the min, max, and average price across them.

{% tabs %}
{% tab title="200: OK Prices successfully returned." %}

```javascript
[
	{
		"pair": "BTCUSD",
		"prices": {
			"coinbase": "41818.02",
			"gemini": "41918.76"
		},
		"minPrice": "41818.02",
		"maxPrice": "41918.76",
		"meanPrice": "41868.39"
	},
	{
		"pair": "LTCUSD",
		"prices": {
			"coinbase": "128.07",
			"gemini": "129.12"
		},
		"minPrice": "128.07",
		"maxPrice": "129.12",
		"meanPrice": "128.595"
	},
	{
		"pair": "ETHUSD",
		"prices": {
			"coinbase": "3108.88",
			"gemini": "3132.97"
		},
		"minPrice": "3108.88",
		"maxPrice": "3132.97",
		"meanPrice": "3120.925"
	},
	{
		"pair": "LRCUSD",
		"prices": {
			"coinbase": "1.4611",
			"gemini": "1.47834"
		},
		"minPrice": "1.4611",
		"maxPrice": "1.47834",
		"meanPrice": "1.46972"
	}
]
```

{% endtab %}
{% endtabs %}

To fetch the price of multiple currency/tokens in a single request, `POST` to the `/v0.1/prices` endpoint.

## Get exchange prices for multiple symbols/currencies

<mark style="color:green;">`POST`</mark> `https://data.spiceai.io/v0.1/prices`

#### Request Body

| Name                                      | Type      | Description                                                                                               |
| ----------------------------------------- | --------- | --------------------------------------------------------------------------------------------------------- |
| symbols<mark style="color:red;">\*</mark> | String\[] | An array of one or more currency/token symbols. E.g. `"symbols": ["cbETH", "stETH", "rETH"]`              |
| convert                                   | String    | An optional conversion currency/token symbol. E.g. `"convert": "AUD"`  If not provided defaults to "USD". |

{% tabs %}
{% tab title="200: OK An array of price pairs for each of the symbols provided to the conversion symbol" %}

```json
[
	{
		"pair": "CBETH-USD",
		"prices": {
			"coinmarketcap": "1958.4909298141743"
		},
		"minPrice": "1958.49093",
		"maxPrice": "1958.49093",
		"avePrice": "1958.49093"
	},
	{
		"pair": "STETH-USD",
		"prices": {
			"coinmarketcap": "1865.1506855247744"
		},
		"minPrice": "1865.150686",
		"maxPrice": "1865.150686",
		"avePrice": "1865.150686"
	},
	{
		"pair": "RETH-USD",
		"prices": {
			"coinmarketcap": "2024.2628747010635"
		},
		"minPrice": "2024.262875",
		"maxPrice": "2024.262875",
		"avePrice": "2024.262875"
	}
]
```

{% endtab %}
{% endtabs %}

The **`/v0.1/prices/[pair]`** API returns spot prices of the specified token/currency pair.

E.g. `/v0.1/prices/btc-aud` will return the price of BTC in AUD.

The API will default to **USD** as the base currency if one is not provided.

E.g. `/v0.1/prices/btc` will return the price of BTC in USD.

## Get exchange prices for a specific currency/token pair

<mark style="color:blue;">`GET`</mark> `https://data.spiceai.io/v0.1/prices/[pair]`

#### Path Parameters

| Name                                   | Type   | Description             |
| -------------------------------------- | ------ | ----------------------- |
| pair<mark style="color:red;">\*</mark> | String | The currency/token pair |

{% tabs %}
{% tab title="200: OK Prices for the pair successfully returned." %}

```javascript
{
	"pair": "ETH-AUD",
	"prices": {
		"coinbase": "2405.566348377514821804",
		"gemini": ""
	},
	"minPrice": "2405.566348",
	"maxPrice": "2405.566348",
	"avePrice": "2405.566348"
}
```

{% endtab %}
{% endtabs %}

## Historical Prices (Preview)

The **`/v0.1/prices/[pair]`** API returns historical prices of the specified token/currency pair.

**NOTE: This method is in Preview. It's definition may change in non-backwards compatible ways.**

## Get Historical Prices

<mark style="color:blue;">`GET`</mark> `https://data.spiceai.io/v0.1/prices/[pair]?preview=true`

Returns historical prices of the specified token/currency pair.

Providing both `start` and `end` will return all prices between the two timestamps at the provided `granularity`, however this must not be more than 10,000 prices.

If no `start` or `end` is provided then the 10 most recent prices based on the provided `granularity` will be returned.&#x20;

If only `start` is provided, then `end` will default to the current UNIX timestamp. If only `end` is provided then the 10 most recent prices before `end` will be returned.

#### Path Parameters

| Name | Type   | Description                                  |
| ---- | ------ | -------------------------------------------- |
| pair | String | The token/currency pair to return prices for |

#### Query Parameters

| Name                                      | Type   | Description                                                                                            |
| ----------------------------------------- | ------ | ------------------------------------------------------------------------------------------------------ |
| preview<mark style="color:red;">\*</mark> | Bool   | Must be present and set to `true` to retrieve historical prices                                        |
| start                                     | Int    | UNIX timestamp of the start of the range to retrieve historical prices, cannot be before 12 months ago |
| end                                       | Int    | UNIX timestamp of the end of the range to retrieve historical prices, cannot be before 12 months ago   |
| granularity                               | String | Duration between each price returned (e.g. `5m`, `1h`, `7d`), default is `5m`                          |

{% tabs %}
{% tab title="200: OK Prices successfully returned." %}

```javascript
{
  "pair": "BTC-USD",
  "prices": [
    {
      "timestamp": "2023-03-15T15:45:00Z",
      "price": 24629.61,
      "high": 24652.55,
      "low": 24500,
      "open": 24514.67,
      "close": 24629.61
    },
    {
      "timestamp": "2023-03-15T15:50:00Z",
      "price": 24632.81,
      "high": 24726.31,
      "low": 24581.55,
      "open": 24589.89,
      "close": 24632.81
    },
    {
      "timestamp": "2023-03-15T15:55:00Z",
      "price": 24586.4,
      "high": 24721.65,
      "low": 24520,
      "open": 24706.59,
      "close": 24586.4
    },
    {
      "timestamp": "2023-03-15T16:00:00Z",
      "price": 24529.87,
      "high": 24578.71,
      "low": 24443.34,
      "open": 24515.43,
      "close": 24529.87
    },
    {
      "timestamp": "2023-03-15T16:05:00Z",
      "price": 24460.3,
      "high": 24584,
      "low": 24396.8,
      "open": 24534.23,
      "close": 24460.3
    },
    {
      "timestamp": "2023-03-15T16:10:00Z",
      "price": 24427.57,
      "high": 24528.9,
      "low": 24388,
      "open": 24415.61,
      "close": 24427.57
    },
    {
      "timestamp": "2023-03-15T16:15:00Z",
      "price": 24311.13,
      "high": 24431.47,
      "low": 24183.75,
      "open": 24411.63,
      "close": 24311.13
    },
    {
      "timestamp": "2023-03-15T16:20:00Z",
      "price": 24376.97,
      "high": 24394.36,
      "low": 24250,
      "open": 24286.56,
      "close": 24376.97
    },
    {
      "timestamp": "2023-03-15T16:25:00Z",
      "price": 24345.7,
      "high": 24428.51,
      "low": 24287.47,
      "open": 24295.9,
      "close": 24345.7
    },
    {
      "timestamp": "2023-03-15T16:30:00Z",
      "price": 24369.92,
      "high": 24393.88,
      "low": 24283.84,
      "open": 24329.97,
      "close": 24369.92
    }
  ]
}
```

{% endtab %}

{% tab title="400: Bad Request Bad request" %}

```javascript
{
    // Response
}
```

{% endtab %}

{% tab title="500: Internal Server Error Internal server error" %}

```javascript
{
    // Response
}
```

{% endtab %}

{% tab title="429: Too Many Requests Rate limit exceeded, slow down" %}

```javascript
{
    // Response
}
```

{% endtab %}
{% endtabs %}
