# How to Configure the Xueqiu (雪球) Channel for Stock Market Data in Agent-Reach

> Learn to configure the Xueqiu channel in Agent-Reach for stock market data. Easily set your Xueqiu cookie manually or extract it automatically from your browser for seamless integration.

- Repository: [Pnant/Agent-Reach](https://github.com/Panniantong/Agent-Reach)
- Tags: how-to-guide
- Published: 2026-06-27

---

**The Xueqiu channel requires a valid Xueqiu cookie stored in `~/.agent-reach/config.yaml` under the `xueqiu_cookie` key, which you can extract automatically from Chrome or Firefox via the CLI or set manually as a semicolon-delimited string.**

The Xueqiu (雪球) channel in Agent-Reach provides real-time stock quotes, search functionality, hot posts, and hot-stock rankings from the Xueqiu social trading platform. Because the Xueqiu API requires an authenticated session to access market data, you must configure a valid browser cookie before using the channel. This guide walks through the configuration process using both automated browser extraction and manual cookie entry, referencing the actual implementation in the `Panniantong/Agent-Reach` repository.

## Why Xueqiu Requires Cookie-Based Authentication

Unlike open data feeds, the Xueqiu API endpoints require a logged-in session to retrieve real-time quotes and social content. According to the source code in [`agent_reach/channels/xueqiu.py`](https://github.com/Panniantong/Agent-Reach/blob/main/agent_reach/channels/xueqiu.py), the channel manages authentication by loading cookies from Agent-Reach's central configuration file located at `~/.agent-reach/config.yaml`. Specifically, the `_load_cookies_from_config()` method (lines 60-70) retrieves the `xueqiu_cookie` value and injects it into an internal `CookieJar` before making any API requests.

## Configuration Methods

You can configure the Xueqiu channel using either automatic browser extraction or manual cookie string entry.

### Automatic Extraction from Chrome or Firefox

The fastest method uses the CLI to extract cookies directly from your browser profile. As implemented in [`agent_reach/cli.py`](https://github.com/Panniantong/Agent-Reach/blob/main/agent_reach/cli.py) (lines 104-112), the `configure_from_browser()` function reads `.xueqiu.com` cookies from Chrome or Firefox and saves them automatically.

Run the following command:

```bash
agent-reach configure --from-browser chrome

```

Or for Firefox:

```bash
agent-reach configure --from-browser firefox

```

This command extracts all relevant cookies (including `auth_token` and `xq_a_token`) and writes them to the configuration file under the `xueqiu_cookie` key.

### Manual Cookie Configuration

If automatic extraction fails or you prefer to manually supply cookies from another source, use the CLI's dedicated configuration command:

```bash
agent-reach configure xueqiu-cookies "auth_token=abc123; xq_a_token=def456; xq_r_token=xyz789"

```

The `Config` class in [`agent_reach/config.py`](https://github.com/Panniantong/Agent-Reach/blob/main/agent_reach/config.py) (lines 70-78) stores this string verbatim in `~/.agent-reach/config.yaml`. The channel's `_inject_cookie_string()` method (lines 31-56 in [`xueqiu.py`](https://github.com/Panniantong/Agent-Reach/blob/main/xueqiu.py)) later parses this string into `http.cookiejar.Cookie` objects, splitting on semicolons to separate name-value pairs.

## Verifying the Configuration

After storing the cookie, verify that the channel can reach Xueqiu's public API using the doctor command:

```bash
agent-reach doctor

```

The `XueqiuChannel.check()` method (lines 164-174) validates connectivity and returns a health status. A successful configuration displays:

```

xueqiu: ok — 公开 API 可用（行情、搜索、热帖、热股）

```

This indicates the channel can access market data, search, hot posts, and hot stock rankings.

## Fetching Stock Data with the Xueqiu Channel

Once configured, instantiate the `XueqiuChannel` class to fetch real-time data. The channel automatically loads cookies from the config file during initialization via `_load_cookies_from_config()`.

### Real-Time Stock Quotes

Retrieve the latest quote for a specific ticker:

```python
from agent_reach.channels.xueqiu import XueqiuChannel

# Initialize channel (cookies loaded automatically from config)

xq = XueqiuChannel()

# Get quote for Shanghai 600519 (Kweichow Moutai)

quote = xq.get_stock_quote("SH600519")
print(quote)

```

The response includes `current` price, `percent` change, `volume`, `market_capital`, and other fields.

### Searching for Stocks

Use the `search_stock()` method to find securities by name:

```python
stocks = XueqiuChannel().search_stock("茅台", limit=5)
for stock in stocks:
    print(f"{stock['symbol']}: {stock['name']}")

```

### Accessing Social Content

Retrieve trending posts from the Xueqiu community:

```python
posts = XueqiuChannel().get_hot_posts(limit=3)
for post in posts:
    print(f"{post['title']} - {post['url']}")

```

## Summary

- The Xueqiu channel requires authentication via cookies stored in `~/.agent-reach/config.yaml` under the `xueqiu_cookie` key.
- Use `agent-reach configure --from-browser chrome` (or `firefox`) to automatically extract cookies from your browser profile.
- Alternatively, manually set cookies with `agent-reach configure xueqiu-cookies "name=value; ..."`.
- Verify connectivity with `agent-reach doctor`, which should report the public API as available.
- Once configured, the `XueqiuChannel` class provides methods for quotes (`get_stock_quote`), search (`search_stock`), and social content (`get_hot_posts`).

## Frequently Asked Questions

### What specific cookies does the Xueqiu channel require?

The channel typically requires `auth_token`, `xq_a_token`, and related session cookies from `.xueqiu.com`. The `_inject_cookie_string()` method in [`agent_reach/channels/xueqiu.py`](https://github.com/Panniantong/Agent-Reach/blob/main/agent_reach/channels/xueqiu.py) (lines 31-56) parses any semicolon-delimited cookie string, so you should include all active cookies from an authenticated Xueqiu browser session to ensure API access.

### Can I use the Xueqiu channel without configuring cookies?

No. As implemented in the source code, the channel relies on `_load_cookies_from_config()` (lines 60-70) to populate the `CookieJar` before making requests. Without valid cookies, the Xueqiu API returns authentication errors, and the `doctor` command will fail to report the API as available.

### How do I update the cookies when they expire?

Run the automatic extraction command again: `agent-reach configure --from-browser chrome`. This overwrites the existing `xueqiu_cookie` value in `~/.agent-reach/config.yaml` with fresh cookies from your browser. Alternatively, manually update the cookie string using the `configure xueqiu-cookies` command.

### Where does the configuration file store the Xueqiu cookie?

The configuration is stored in `~/.agent-reach/config.yaml` under the key `xueqiu_cookie`. The `Config` class in [`agent_reach/config.py`](https://github.com/Panniantong/Agent-Reach/blob/main/agent_reach/config.py) (lines 70-78) handles reading and writing these values, while the channel implementation specifically looks for this key during initialization.