# Prices

`GET /api/prices`

The current BTC/USD price and one price per UTC day since 2010-07-19, for converting sats to dollars at the time of a sale. Cacheable 5 minutes (1 minute while nothing is available). Never an error: unavailable parts are `null`.

#### Example request

```bash title="cURL"
curl 'https://raresats.net/api/prices'
```
```js title="JavaScript"
const response = await fetch('https://raresats.net/api/prices');
const data = await response.json();
```
```python title="Python"
import requests

data = requests.get("https://raresats.net/api/prices").json()
```

#### Response `200`

| Field | Type | Description |
| --- | --- | --- |
| `current` | object \| null | The BTC price now: `usd` (dollars) and `time` (unix seconds of the quote). `null` while the source is down (after an hour of last good values). |
| `current.usd` | number | Dollars per bitcoin. |
| `current.time` | integer | Unix seconds. |
| `history` | object \| null | One price a UTC day: `usd[i]` is the day starting `start + i × step`. `null` while unavailable. |
| `history.start` | integer | Unix seconds of the first day (2010-07-19). |
| `history.step` | `86400` | Seconds per entry: one day. |
| `history.usd` | array of number | Daily dollars per bitcoin (the mean of the day's quotes; 4 significant digits under $100, whole dollars above). |

```json title="Response"
{
  "current": {"usd": 86772, "time": 1790945710},
  "history": {"start": 1279497600, "step": 86400, "usd": [0.0858, 0.0808, 0.0747]}
}
```

#### Errors

None of its own.

To value a sale in dollars at the time it happened: `usd[Math.floor((time - start) / 86400)] × price / 100000000`, with `time` the sale's unix seconds and `price` in sats.
