Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
5ad08fc
Improve Windows and Qlib Docker integration for local fin_* runs.
qwertyregion May 19, 2026
aa42a7b
checkpoint: save return point before terminal PR #1
qwertyregion May 23, 2026
10f82d8
docs(terminal): add architecture analysis and PR #1 implementation plan
qwertyregion May 23, 2026
3a64cdd
chore(terminal): scaffold directory structure for PR #1
qwertyregion May 23, 2026
46cd446
feat(gateway): config, pydantic models, and broker adapter interface
qwertyregion May 23, 2026
88f73cf
feat(gateway): implement BybitAdapter for read-only market data
qwertyregion May 23, 2026
a4b23a6
feat(gateway): add health and market REST endpoints
qwertyregion May 23, 2026
79a8cf4
feat(terminal): vite react scaffold with tailwind and shadcn
qwertyregion May 23, 2026
24ab271
feat(terminal): typed API client and market data hooks
qwertyregion May 23, 2026
0832df6
feat(terminal): candlestick chart with lightweight-charts
qwertyregion May 23, 2026
a462f7e
chore(terminal): docker compose and development guide
qwertyregion May 23, 2026
8166c6c
docs(terminal): phase 2 architecture and prompt sequence
qwertyregion May 23, 2026
c1ef668
feat(gateway): phase 2 agent runner, websocket trace, and research API
qwertyregion May 23, 2026
4fd6253
docs(terminal): update development guide for phase 2
qwertyregion May 23, 2026
4b632e0
feat(terminal): agent console and research lab UI with phase 2 tabs
qwertyregion May 23, 2026
4a14987
feat(terminal): Phase 2 closure and Phase 3 execution desk
qwertyregion May 24, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,28 @@ EMBEDDING_MODEL="litellm_proxy/BAAI/bge-large-en-v1.5"
# FT_DOCKER_ENABLE_CACHE=True
# DS_DOCKER_ENABLE_CACHE=True
# Senario Configs:
# ==========================================

# ==========================================
# Qlib + Docker (finance quant scenarios)
# ==========================================
# Run Qlib backtests inside the RD-Agent Qlib image instead of conda:
# MODEL_CoSTEER_env_type=docker
#
# Optional: use your local Qlib clone on the host (directory that contains setup.py), e.g. Desktop\QLIB\qlib.
# It is mounted at /workspace/qlib in the container (editable install in the image then sees your sources).
# QLIB_DOCKER_local_qlib_repo_path=C:\Users\QWERTY\Desktop\QLIB\qlib
#
# Qlib data cache is still shared via ~/.qlib -> /root/.qlib in the container (download once on the host).
# ==========================================

# ==========================================
# RD-Agent Terminal Gateway (Bybit market data)
# ==========================================
# GATEWAY_PORT=6900
# BYBIT_TESTNET=true
# BYBIT_API_KEY=
# BYBIT_API_SECRET=
# Empty keys are OK for public klines/tickers on testnet.
# UI_TRACE_FOLDER=git_ignore_folder/traces
# ==========================================
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -188,3 +188,10 @@ AGENTS.md
!rdagent/**/AGENTS.md

scripts/

# RD-Agent Terminal (PR #1)
terminal/node_modules/
terminal/dist/
gateway/.venv/
gateway/**/__pycache__/
!terminal/src/lib/
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,23 @@ rdagent server_ui --port 19899

After that, open `http://127.0.0.1:19899` in your browser.

#### RD-Agent Terminal (PR #1)

A new React terminal-style UI lives in `terminal/` with a FastAPI gateway in `gateway/` for Bybit market data and charts.

See [docs/terminal/DEVELOPMENT.md](docs/terminal/DEVELOPMENT.md) for setup. Quick start:

```sh
# Terminal 1 — gateway
cd gateway && pip install -r requirements.txt
uvicorn app.main:app --host 0.0.0.0 --port 6900 --reload

# Terminal 2 — frontend
cd terminal && npm install && npm run dev
```

Open `http://localhost:5173`. Legacy Vue UI in `web/` remains unchanged.

#### Common Notes

Port `19899` is used in the examples above. Before starting either UI, check whether this port is already occupied. If it is, please change it to another available port.
Expand Down
21 changes: 21 additions & 0 deletions docker-compose.terminal.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
services:
gateway:
build:
context: ./gateway
ports:
- "6900:6900"
env_file:
- .env
environment:
BYBIT_TESTNET: "${BYBIT_TESTNET:-true}"
EXECUTION_MODE: "${EXECUTION_MODE:-paper}"
MAX_ORDER_NOTIONAL: "${MAX_ORDER_NOTIONAL:-1000}"
MAX_POSITION_USD: "${MAX_POSITION_USD:-5000}"
DAILY_LOSS_LIMIT: "${DAILY_LOSS_LIMIT:-500}"

redis:
image: redis:7-alpine
ports:
- "6379:6379"
profiles:
- cache
135 changes: 135 additions & 0 deletions docs/terminal/DEVELOPMENT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
# RD-Agent Terminal — Development Guide

## Prerequisites

| Tool | Version |
|------|---------|
| Node.js | 20+ |
| Python | 3.10+ |
| npm | 10+ |
| Docker Desktop | optional (gateway container) |

## Quick Start (local)

### 1. Gateway (FastAPI)

```powershell
cd gateway
python -m venv .venv
.\.venv\Scripts\Activate.ps1
pip install -r requirements.txt
uvicorn app.main:app --host 0.0.0.0 --port 6900 --reload
```

Verify:

```powershell
curl http://localhost:6900/api/v1/health
curl "http://localhost:6900/api/v1/market/klines?symbol=BTCUSDT&interval=60&limit=10"
```

OpenAPI docs: http://localhost:6900/docs

### 2. Terminal (React)

```powershell
cd terminal
npm install
npm run dev
```

Open: http://localhost:5173

Vite proxies `/api` to `http://localhost:6900`.

## Environment

Copy root `.env.example` to `.env` and set:

```env
GATEWAY_PORT=6900
BYBIT_TESTNET=true
BYBIT_API_KEY=
BYBIT_API_SECRET=

# Phase 3 — Execution (paper by default)
EXECUTION_MODE=paper
MAX_ORDER_NOTIONAL=1000
MAX_POSITION_USD=5000
DAILY_LOSS_LIMIT=500
```

Public klines/tickers work **without** API keys on Bybit testnet.

### Bybit testnet keys (live execution)

For `EXECUTION_MODE=live` on testnet:

1. Create API key at [Bybit testnet](https://testnet.bybit.com/) with **Contract Trade** permissions
2. Set `BYBIT_API_KEY` and `BYBIT_API_SECRET` in `.env`
3. Keep `BYBIT_TESTNET=true` — mainnet is blocked in Phase 3 gateway

Paper mode (`EXECUTION_MODE=paper`, default) simulates fills at mid price with no keys required.

## Docker (gateway only)

```powershell
docker compose -f docker-compose.terminal.yml up --build gateway
```

## Port Map

| Service | Port |
|---------|------|
| Terminal (Vite) | 5173 |
| Gateway (FastAPI) | 6900 |
| Flask server_ui (legacy) | 19899 |

## Windows + qlib (Phase 2+)

RD-Agent quant scenarios (`fin_factor`, `fin_model`) use qlib via Docker/WSL2.
Terminal PR #1 does not modify qlib execution.

- Use WSL2 Ubuntu for `local_qlib` Docker image
- Set `MODEL_CoSTEER_env_type=docker` in `.env`
- Mount `~/.qlib` for CN market data

## Troubleshooting

### CORS errors
Ensure gateway `cors_origins` includes `http://localhost:5173`.

### Chart empty / API errors
1. Confirm gateway is running on port 6900
2. Check `/api/v1/health` returns `"status": "ok"`
3. Test klines endpoint directly in browser

### Bybit 502 errors
Upstream Bybit API may be rate-limited or unavailable. Retry after a few seconds.

## Phase 2 — Agent Console + Research Lab

Requires `pip install -e .` from repo root so gateway can import `rdagent`.

Agent runs are orchestrated by gateway (`/api/v1/agent/*`) with WebSocket trace streaming.
Research metrics are read from trace pickles via `/api/v1/research/*`.

Legacy Vue UI (`web/`, `rdagent server_ui`) remains available but terminal is the primary UI for Phase 2+.

## Phase 3 — Execution Desk

Paper trading by default (`EXECUTION_MODE=paper`). Orders flow:

1. Terminal **Execution Desk** → `POST /api/v1/execution/orders`
2. Gateway **RiskManager** validates notional, position, daily loss, kill switch
3. **PaperAdapter** (default) or **BybitAdapter** (live testnet) executes

Endpoints:

- `GET /api/v1/execution/status` — mode and risk limits
- `GET /api/v1/execution/positions` — open positions
- `GET /api/v1/execution/pnl` — P&L snapshot
- `WS /api/v1/execution/ws/pnl` — live P&L stream

Research Lab **Use as signal** prefills Execution Desk (manual confirm only).

76 changes: 76 additions & 0 deletions docs/terminal/E2E_AGENT_RUN.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# E2E Agent Run — Finance Data Building (1 loop)

Manual end-to-end validation for Phase 2 agent integration.

## Prerequisites

| Requirement | Check |
|-------------|-------|
| Python 3.10+ | `python --version` |
| RD-Agent installed | `pip install -e .` from repo root |
| LLM keys in `.env` | `OPENAI_API_KEY`, `CHAT_MODEL` |
| Qlib data (cn) | `~/.qlib/qlib_data/cn_data` or Docker |
| Qlib env | `MODEL_CoSTEER_env_type=docker` (WSL2/Linux) |
| Gateway deps | `pip install -r gateway/requirements.txt` |

## Start services

```powershell
# Terminal 1 — Gateway
cd gateway
uvicorn app.main:app --host 0.0.0.0 --port 6900 --reload

# Terminal 2 — React UI
cd terminal
npm run dev
```

Open http://localhost:5173 → **Agent Console** tab.

## Run test

1. Scenario: **Finance Data Building**
2. Loops: **1**
3. Click **Run Agent**
4. Observe trace ID in history panel
5. WebSocket / poll should show tags in order:
- `research.hypothesis`
- `research.experiment`
- `feedback.metric`
- `END` (or loop completion)

## Verify Research Lab

1. Switch to **Research Lab** tab
2. Select the new trace in Experiments list
3. **Qlib Metrics** table shows loop metrics (IC, annualized return, etc.)
4. **Equity Curve** shows bench/strategy/excess lines
5. **Amber dots** = rebalance markers from `ret.pkl`

## API smoke (optional)

```powershell
# List experiments
curl http://localhost:6900/api/v1/research/experiments

# Returns + markers (replace TRACE_ID)
curl http://localhost:6900/api/v1/research/experiments/TRACE_ID/returns
```

## Troubleshooting

| Symptom | Fix |
|---------|-----|
| `ModuleNotFoundError: rdagent` | `pip install -e .` from repo root |
| Agent subprocess exits immediately | Check `.env` LLM keys; gateway logs |
| No experiments in Research Lab | Wait for trace to finish; check `trace_folder` in gateway config |
| Empty equity curve | Trace may lack `Quantitative Backtesting Chart` pickle |
| Qlib docker errors | WSL2 + Docker; see main README qlib section |

## Success criteria

- [ ] Agent run completes 1 loop without crash
- [ ] Trace visible in Agent Console history
- [ ] Research Lab shows metrics for trace
- [ ] Equity curve renders with markers
- [ ] Gateway tests pass: `pytest gateway/tests -q`
Loading
Loading