# cg-ohlc

CLI tool to fetch OHLCV (Open, High, Low, Close, Volume) candlestick data from CoinGecko API.

## Features

- Historical price data with configurable time ranges
- Multiple granularities (auto-selected based on range)
- Support for different quote currencies
- 50+ pre-mapped crypto symbols

## Installation

```bash
cargo install cg-ohlc
```

Or build from source:

```bash
cargo build --release -p cg-ohlc
```

## Usage

```bash
# Fetch 7 days of Bitcoin OHLC data
cg-ohlc BTC --days 7

# Fetch 1 year of Ethereum data
cg-ohlc ETH --days 365

# Save to file
cg-ohlc BTC --days 30 -O bitcoin-ohlc.json

# Use different quote currency
cg-ohlc BTC --days 7 --vs-currency eur

# Compact JSON output
cg-ohlc BTC --days 7 -f compact

# Verbose logging
cg-ohlc BTC --days 7 -v
```

## Output

Returns array of OHLC candles:

```json
[
  {
    "timestamp": 1708992000000,
    "open": 51234.56,
    "high": 52100.00,
    "low": 50800.00,
    "close": 51890.25
  },
  ...
]
```

## Candle Granularity

CoinGecko auto-selects granularity based on range:

| Days | Granularity |
|------|-------------|
| 1-2 | 30-minute candles |
| 3-30 | 4-hour candles |
| 31-90 | Daily candles |
| 90+ | Daily candles |

**Note:** Free tier may return fewer candles for longer ranges (e.g., ~90 daily candles for 365-day request).

## Options

| Option | Description |
|--------|-------------|
| `--days` | Number of days of history (default: 7) |
| `--vs-currency` | Quote currency (default: usd) |
| `-O, --output-file` | Save output to file |
| `-f, --format` | Output format: `json` (pretty) or `compact` |
| `-v, --verbose` | Enable debug logging |

## Rate Limiting

Uses CoinGecko free tier (10 req/min). The client automatically:
- Throttles requests to stay under limit
- Retries on 429 with exponential backoff (30s/60s/120s)

## License

MIT
