<div align="center">

<a href="https://ashareapi.com/en/"><img src="https://ashareapi.com/icon-512.png" width="88" height="88" alt="ashareapi"></a>

# ashareapi — Official Pi Package for the A-Share Data API

Let **Pi** ([pi.dev](https://pi.dev)) query China A-share data directly: quotes / candles / **5-level order book** / financials / money flow / dragon-tiger list / sectors / convertible bonds / factor screening / macro / **quant backtests** — **40 endpoints, and 5 of them need no key**.

One command to install — afterwards Pi knows **which endpoint to call, how to fill the parameters, what units the fields use, and what to do on errors**.

![Pi](https://img.shields.io/badge/Pi-pi.dev-6E56CF)
![Agent Skills](https://img.shields.io/badge/Agent%20Skills-spec-4D6BFE)
[![npm](https://img.shields.io/npm/v/ashareapi-pi?label=npm)](https://www.npmjs.com/package/ashareapi-pi)
![License](https://img.shields.io/badge/license-MIT-green)

**Runs on Pi (pi.dev)**:

![Pi package](https://img.shields.io/badge/pi.dev-package-6E56CF)

[中文](README.md) · **English**

[Website](https://ashareapi.com/en/) · [Docs](https://ashareapi.com/en/docs/) · [Endpoint list](https://ashareapi.com/en/endpoints/) · [MCP](https://ashareapi.com/en/mcp/) · [Agent Skill](https://ashareapi.com/en/skill/)

[Source](https://github.com/ashareapi/ashareapi-skill) · [Issues](https://github.com/ashareapi/ashareapi-skill/issues) · [Changelog](https://ashareapi.com/en/changelog/)

</div>

---

## What is this

An **A-share data Pi package**: once installed, asking Pi "what is 600667 trading at?" makes it call the API and answer with **real market data** instead of guessing.

Inside is an **Agent Skill** (an open standard) — Pi and Claude Code / Codex use **the same skill specification**, so this manual is portable across them. It covers the parameters and field semantics of 40 endpoints, unit conventions (`volume` is in lots / `amount` in yuan / ratios are percentages), date semantics, and common errors plus rate-limit handling.

Under the hood it talks to the REST API at [ashareapi.com](https://ashareapi.com/en/) (`https://api.ashareapi.com/v1/...`) — Pi can just `curl` it; the official SDKs or MCP are equally fine.

---

## Why use it

- **One command to install**: `pi install npm:ashareapi-pi`, then `/reload` — no JSON to hand-edit, no script to run
- **Free endpoints are genuinely key-free**: `/v1/quote` `/v1/kline` `/v1/hot` `/v1/changedist` `/v1/market-overview` work right after installation
- **Automatic source failover**: 70 data sources back each other up on the backend; if one has a problem it switches to the next, and **your quota is not charged**
- **Fixed conventions, no post-processing**: K-lines are always **forward-adjusted (qfq)** (there is no `adjust` parameter), so there is no double-adjustment
- **No data ≠ failure**: "the market genuinely has no data" (e.g. a suspended stock) is returned separately from "the fetch failed" — the agent will not mistake a suspension for an outage
- **Written for AI**: it states *when to use which endpoint / how to fill the parameters / what units the fields use / what to do on errors*, so the agent does not call it wrong
- **Nothing for you to maintain**: the content is generated by a script from the Agent Skill (single source of truth), and a Pi upgrade needs no change here

---

## Install

```bash
pi install npm:ashareapi-pi
```

Then `/reload` (or restart Pi). To try it once without touching your config:

```bash
pi -e npm:ashareapi-pi
```

Then just ask:

| You ask | Endpoint used |
|---|---|
| What is 600667 trading at? | `/v1/quote` |
| Pull the last 60 daily candles for 600667 | `/v1/kline` |
| How is the market doing today? | `/v1/market-overview` |
| What are people watching right now? | `/v1/hot` |
| What is today's advance/decline distribution? | `/v1/changedist` |

Uninstall:

```bash
pi remove npm:ashareapi-pi
```

---

## API key setup

The 5 endpoints above work with **no configuration at all**.

To use the rest (order book / financials / money flow / dragon-tiger list / sectors / screening / macro …) you need a key: [get one here](https://ashareapi.com/en/pricing/) (from ¥9.9).

Put the key in the `ASHAREAPI_KEY` environment variable, or just tell Pi — the manual spells out how to send it:

```bash
curl -H "Authorization: Bearer ct-your-key" "https://api.ashareapi.com/v1/quote?code=sh600667"
```

---

## What you can query

**Free (no key)**

Live quotes · candles · attention list · market breadth · market overview

**Requires a key**

Order book · full-field profile · financial statements · money flow · technical indicators · shareholders · events · dragon-tiger list · factor screening · sectors · sector valuation · macro · convertible bonds · ETFs · IPOs · dividends · research digest · symbol search · usage

Field meanings, parameters, and response samples are in the [docs](https://ashareapi.com/en/docs/).

---

## Related

**Official SDKs**: Python `pip install ashareapi` · Node.js / TypeScript `npm install ashareapi`

**MCP server**: `https://api.ashareapi.com/mcp` ([configuration guide](https://ashareapi.com/en/mcp/)) — Pi has **MCP built in**, so a single URL is enough; Claude Code / Codex / Cursor and 15+ other clients work the same way

**Agent Skill** (an endpoint manual for AI agents): <https://ashareapi.com/en/skill/>

**This package's content** is generated by a script from the Agent Skill (single source of truth: <https://github.com/ashareapi/ashareapi-skill>), never maintained by hand.

---

## Version

See [npm](https://www.npmjs.com/package/ashareapi-pi) for the latest version. The content comes from the Agent Skill and **the version tracks the skill**; see the [changelog](https://ashareapi.com/en/changelog/).

---

## License

MIT
