# Kraken Trading Bot

A configurable Kraken spot trading bot where every symbol is assigned exactly one strategy.

## What is included

- Kraken public OHLC data client and signed private order client.
- Dry-run mode by default.
- Per-pair strategy mapping in `config.example.json`.
- Strategy suite: `sma_crossover`, `rsi_mean_reversion`, `macd_trend`, `bollinger_mean_reversion`, `donchian_breakout`, and `ema_trend`.
- Fixed quote risk sizing, per-pair minimum base volume, cooldowns, and repeated-side protection.
- State file to reduce duplicate repeated trades.

## Quick start

```powershell
python -m kraken_bot --config config.example.json
```

The example config runs in dry-run mode, so it will fetch market data and print decisions without sending orders.

## Web dashboard

Run the browser-based dashboard locally:

```powershell
python -m kraken_bot.web.app --config config.example.json --host 127.0.0.1 --port 3105 --base-path /phenocrypto
```

Open `http://127.0.0.1:3105/phenocrypto/`.

Optional protection for mutating web actions:

```powershell
$env:PHENOCRYPTO_ADMIN_TOKEN="choose-a-long-token"
$env:PHENOCRYPTO_USERNAME="admin"
$env:PHENOCRYPTO_PASSWORD="choose-a-strong-password"
$env:PHENOCRYPTO_SESSION_SECRET="choose-a-long-random-secret"
python -m kraken_bot.web.app --config config.example.json
```

When a username and password are set, the dashboard requires login before the app or API can be used.

The dashboard includes a Kraken API Keys panel. Saved keys are stored in `state/kraken_credentials.json` inside the deployed app directory and loaded by the bot at runtime.

## Live trading

Set Kraken API credentials in your shell:

```powershell
$env:KRAKEN_API_KEY="your_key"
$env:KRAKEN_API_SECRET="your_secret"
```

Copy `config.example.json` to your own config, review every pair and strategy, then set:

```json
"dry_run": false
```

Run the bot:

```powershell
python -m kraken_bot --config your-config.json --loop --sleep 60
```

## Pair-to-strategy mapping

Each entry in `pairs` must contain one `symbol` and one `strategy`.

```json
{
  "symbol": "XBTUSD",
  "strategy": "sma_crossover",
  "interval": 15,
  "candles": 200,
  "min_order_base": 0.0001,
  "strategy_params": {
    "short_period": 20,
    "long_period": 50
  }
}
```

The bot refuses duplicate symbols or symbols without a strategy.

## Safety notes

This is functional trading software, not financial advice. Start in dry-run mode, use Kraken API keys with the minimum required permissions, and confirm Kraken's current pair names and minimum order sizes for your account before enabling live trading.
