# Crypto trading bot

Use case. Read closed one-minute candles for the signal and the latest price between candles.

A bot that decides once a minute needs a candle that is finished and does not change afterwards. `/v2/coins/{id}/ohlc?interval=1m` returns only closed candles, up to 5,000 in a request, on every plan. The API gives you data. It does not place orders.

- Only closed candles are published, so the last row you read never changes.
- Minute candles are kept 30 days on Free and 90 days on Starter, Basic and Pro. Minute history begins 23 Nov 2026 and grows a day each day, up to those limits.
- 5-minute and 15-minute candles are rolled up from the same minutes, so every timeframe agrees.

## Routes it uses

| Job | Route |
|---|---|
| Signal from closed candles | `/v2/coins/{id}/ohlc?interval=1m&limit=...` |
| Latest price between candles | `/v2/simple/price` |
| History for a test | `/v2/coins/{id}/ohlc` with `from` and `to`, in windows of up to 5,000 candles |
| Push instead of poll | The [price stream](/crypto-websocket-api) |

## Read the last hour

This script reads 60 closed candles and compares a 10-minute average of the close with a 30-minute one. It shows how to read the data, not a strategy. It needs `requests` and the key in `COINPRICE_API_KEY`.

Python:

```python
import os
import requests

API = "https://api.coinprice.dev/v2"
HEADERS = {"Authorization": f"Bearer {os.environ['COINPRICE_API_KEY']}"}


def minute_candles(coin, limit):
    response = requests.get(
        f"{API}/coins/{coin}/ohlc",
        headers=HEADERS,
        params={"interval": "1m", "limit": limit},
        timeout=10,
    )
    response.raise_for_status()
    return response.json()  # [[time_ms, open, high, low, close], ...] oldest first


def average(closes):
    return sum(closes) / len(closes)


candles = minute_candles("bitcoin", 60)
closes = [c[4] for c in candles]
fast, slow = average(closes[-10:]), average(closes[-30:])
print(f"{len(candles)} candles, last closed minute starts at {candles[-1][0]}")
print(f"10-minute average {fast:,.2f}, 30-minute average {slow:,.2f}")
print("fast is above slow" if fast > slow else "fast is below slow")
```

Output, real run, 2026-11-24 04:32 UTC:

```text
60 candles, last closed minute starts at 1795494720000
10-minute average 60,439.49, 30-minute average 60,372.76
fast is above slow
```

Each row is `[time in ms, open, high, low, close]`. The time is the start of the minute in UTC, and rows come oldest first. The candle for the minute that is still running is not in the list.

## Why this data fits

- Each minute's price is the median of the latest prices from seven exchanges after outliers are dropped, so one venue's spike does not draw a false wick.
- The call budget is easy to plan. One candle request a minute is 43,200 calls a month, inside the Free plan. Starter has 300 calls a minute for a bot that watches many coins.
- Minute candles on every plan, with 5,000 candles to a request. [How the candles are built](/guides/1-minute-crypto-candles).

## Limits to plan for

- Minute candles are kept 30 days on Free and 90 days on paid plans, and minute history begins 23 Nov 2026, so a window older than the minutes held starts at the oldest minute held. Save the candles you need for longer. Hourly and daily candles start 1 Jan 2023, or when the coin began; `/v2/coverage` shows `hourly_from` and `daily_from`.
- A plan that reaches its monthly limit stops answering until the next month. On a 429 `quota_exceeded` the bot should stop and tell you: there is no `Retry-After`, and it resets on the 1st of the month UTC. Retry only a 429 `rate_limited`, after `Retry-After` seconds.
- There are no orders, balances or exchange accounts here. Send your orders to your own exchange account.

## Questions

**Is there a free tier for minute candles?** Yes. The Free plan includes 1-minute candles, kept for 30 days, with 50,000 calls a month. Minute history begins 23 Nov 2026.

**Can the bot trade through this API?** No. The API returns prices and candles only.

**Can I get candles without polling?** The price stream pushes prices. Free has one stream of 10 channels every 5 seconds, and paid plans update every second.
