---
name: hermes-trading-knowledge
slug: hermes-trading-knowledge
title: Hermes Trading Knowledge Base
description: Guidelines for configuring and using the Hermes trading project, including dispatcher setup, automatic markdown loading, and file structure.
---

# Overview

## Sub‑agent Orchestration
The trading system now consists of five dedicated sub‑agents that implement the workflow described in **AGENTS.md**:

- **Market Analyst** – fetches current price and 24 h volume for each symbol via Bybit public ticker endpoint.
- **News Analyst** – evaluates macro‑economic and crypto‑news impact (currently returns a low‑risk placeholder).
- **Strategy Checker** – validates volume thresholds (≥ 30 M USDT) and decides whether a **TRADE SETUP** with quality *A* is viable.
- **Risk Manager** – reads the wallet balance, applies `RISK_PERCENT` and `RR_THRESHOLD` from `strategy_core.md`, and computes `qty`, `stopLoss` and `takeProfit`.
- **Execution Controller** – sends a market order to Bybit Demo API including SL/TP fields, using the unified signature method.

The **orchestrator** (`auto_trader.py`) calls each sub‑agent in sequence, builds a comprehensive JSON report and appends it to `hermes‑trading/journal.log`. All sub‑agents reside in `/root/hermes_projects/trading/subagents/` and are referenced in the skill's `references/` directory for quick lookup.

The orchestration respects the risk rules and setup‑quality system defined in `risk_rules.md` and `setup_quality_score.md`.

## Sub‑agent Reference
See `references/subagents_overview.md` for a concise description of each sub‑agent, their inputs/outputs and the associated JSON schemas.
This skill captures the class‑level workflow for a multi‑project Hermes deployment focused on the **trading** domain. It explains:
- Directory layout (`~/hermes‑trading/` and `~/hermes_projects/trading/`).
- How the dispatcher (`dispatch_hermes.py`) selects the trading project and sets `HERMES_HOME`.
- Automatic loading of all `*.md` files from the project directory into the model context.
- Required environment variables (e.g., `OPENROUTER_API_KEY`).
- Common pitfalls and verification steps.

# Trigger Conditions
The skill is applicable when:
- A user asks to run a trading‑related command via Telegram (keywords: `трейдинг`, `btc`, `eth`, `crypto`).
- The dispatcher resolves the request to the trading project.
- The user wants to ensure the knowledge base (system prompts, strategy docs, glossaries, risk rules) is loaded automatically.

# Steps
1. **Detect project** – `dispatch_hermes.py` reads `project_map.yaml` and matches trading keywords.
2. **Set environment** – `HERMES_HOME` is set to the directory that holds the markdown knowledge base (`~/hermes-trading`).
3. **Run Hermes** – `hermes chat -q "<text>" --yolo` is executed with the environment.
4. **Hermes internal load** – the Hermes CLI scans `HERMES_HOME` for `*.md` files and injects them into the prompt before generation.
5. **Sub‑agent execution** – agents (Market Analyst, News Analyst, …) read the loaded knowledge as needed.
6. **Return formatted report** – using `response_format.md`.

# Pitfalls & Mitigations
- **Missing API key** – Hermes will abort with a configuration error. Ensure `OPENROUTER_API_KEY` (or another provider key) is exported before dispatch.
- **Incorrect `HERMES_HOME` path** – if the dispatcher points to a non‑existent directory, Hermes returns `Project directory … not found`. Verify `project_map.yaml` entries point to absolute paths or sub‑folders under `~/hermes_projects`.
- **Stale markdown files** – after editing any of the knowledge files, restart the Telegram gateway (`/restart`) so the dispatcher reloads the environment.
- **File naming collisions** – keep knowledge files with `.md` extension; other files (JSON schemas, scripts) are ignored by the automatic loader.

## Verification
After configuring, run a test command:
```
{"chat_id":"test","text":"трейдинг BTCUSDT, дай текущий контекст"}
```
You should receive a response that follows `response_format.md` and references data from `strategy_core.md`, `glossary.md`, etc.

## Тестовый запуск
Для быстрого локального теста в терминале используйте:
```bash
export OPENROUTER_API_KEY=YOUR_KEY   # убедитесь, что ключ установлен
HERMES_HOME=~/hermes-trading \
hermes chat -q "Проанализируй рынок: BTCUSDT, ETHUSDT, SOLUSDT, BNBUSDT, XRPUSDT" --yolo
```
Эта команда гарантирует, что Hermes загрузит все markdown‑файлы из `~/hermes-trading` и выполнит запрос в режиме демо‑торговли.

**Проверьте**:
- `OPENROUTER_API_KEY` присутствует в текущей сессии.
- Переменная `BYBIT_TESTNET=1` и `BROKER_LIVE_MODE=0` заданы в `~/hermes_projects/trading/.env`.
- В `~/.hermes/config.yaml` корректно указаны `model.provider = openrouter` и `model.openrouter = openai/gpt-oss-120b:free`.

Если один из пунктов не выполнен, Hermes вернёт ошибку конфигурации.

## Pitfalls & Mitigations
- **Missing API key** – Hermes will abort with a configuration error. Ensure `OPENROUTER_API_KEY` (or another provider key) is exported before dispatch.
- **Incorrect `HERMES_HOME` path** – if the dispatcher points to a non‑existent directory, Hermes returns `Project directory … not found`. Verify `project_map.yaml` entries point to absolute paths or sub‑folders under `~/hermes_projects`.
- **Stale markdown files** – after editing any of the knowledge files, restart the Telegram gateway (`/restart`) so the dispatcher reloads the environment.
- **File naming collisions** – keep knowledge files with `.md` extension; other files (JSON schemas, scripts) are ignored by the automatic loader.

# References
- `references/directory_structure.md` – detailed list of files in the trading knowledge base.
- `references/dispatch_flow.md` – description of the dispatcher script.
- `references/test_command.md` – примеры тестовых запусков и проверка окружения.

# See Also
- `hermes-agent` – generic Hermes configuration.
- `hermes-multi-project-architecture` – broader multi‑project layout.
After configuring, run a test command:
```
{"chat_id":"test","text":"трейдинг BTCUSDT, дай текущий контекст"}
```
You should receive a response that follows `response_format.md` and references data from `strategy_core.md`, `glossary.md`, etc.

# References
- `references/directory_structure.md` – detailed list of files in the trading knowledge base.
- `references/dispatch_flow.md` – description of the dispatcher script.

# See Also
- `hermes-agent` – generic Hermes configuration.
- `hermes-multi-project-architecture` – broader multi‑project layout.
