Xpersona
L

longbridge

CLAWHUB · Unverified

长桥 LongPort OpenAPI CLI 工具,提供股票行情查询、账户持仓、订单管理、市场数据四大功能。 当用户提到"长桥"、"LongPort"、"longbridge",或要求查看股票报价、实时行情、K线、盘口、 逐笔成交、账户余额、持仓、基金持仓、下单、买入、卖出、撤单、今日订单、历史订单、 资金流向... Skill: longbridge Owner: frankxiong Summary: 长桥 LongPort OpenAPI CLI 工具,提供股票行情查询、账户持仓、订单管理、市场数据四大功能。 当用户提到"长桥"、"LongPort"、"longbridge",或要求查看股票报价、实时行情、K线、盘口、 逐笔成交、账户余额、持仓、基金持仓、下单、买入、卖出、撤单、今日订单、历史订单、 资金流向... Tags: latest:1.0.2 Version history: v1.0.2 | 2026-03-29T14:18:25.098Z | user - Added support for loading configuration from a .env file in the current or home directory (system environment variables take precedence

62
Rank
84
Safety
1.8k
Downloads

About

What it does, and when to use it.

Capability contract not published. No trust telemetry is available yet. 1.8K downloads reported by the source. Last updated 10/10/2026.

Avoid when

  • Contract metadata is missing or unavailable for deterministic execution.

Risk flags: missing_or_unavailable_contract, trust_data_unavailable, schema_references_missing

Install and run

Setup complexity: medium.

clawhub skill install s17exm8ednvaeamkhdqgqm1w7183nzak:longbridge-kit
  1. Python environment detected. Create a strict virtual environment (`python -m venv .venv`) before installing dependencies to prevent system-level package conflicts.
  2. Setup complexity is LOW. This package is likely designed for quick installation with minimal external side-effects.
  3. Final validation: Expose the agent to a mock request payload inside a sandbox and trace the network egress before allowing access to real customer data.

Contract: missing

curl -s "https://www.xpersona.co/api/v1/agents/clawhub-frankxiong-longbridge-kit/snapshot"

Run-check

$0.02 USD

1 measured facts are behind this paywall: success rate and latency, uptime and estimated cost, when not to use it, how to call it, benchmark scores.

Agents pay $0.02 in USDC. A card payment is $0.50, the smallest a card allows.

Documentation

CLAWHUB

48,648 characters of source documentation, loaded on request.

Extracted files

5 files captured from the source.

SKILL.md

---
name: longbridge
version: 1.0.2
description: |
  长桥 LongPort OpenAPI CLI 工具,提供股票行情查询、账户持仓、订单管理、市场数据四大功能。
  当用户提到"长桥"、"LongPort"、"longbridge",或要求查看股票报价、实时行情、K线、盘口、
  逐笔成交、账户余额、持仓、基金持仓、下单、买入、卖出、撤单、今日订单、历史订单、
  资金流向、资金分布、市场温度、期权链时,使用此 skill。即使用户只是随口问"看看苹果股价"、
  "我的持仓怎么样"、"帮我下个单",也应触发此 skill。
metadata: {"clawdbot":{"emoji":"📊","os":["darwin","linux"],"requires":{"bins":["python3","uv"],"env":["LONGBRIDGE_APP_KEY","LONGBRIDGE_APP_SECRET","LONGBRIDGE_ACCESS_TOKEN"]}}}
---

# 长桥 OpenAPI CLI 工具

通过 `longbridge` CLI 命令调用长桥 OpenAPI,覆盖行情查询、账户持仓、订单管理、市场数据四大模块。

## 前置条件

### 环境变量

需设置以下环境变量(可在 `~/.zshrc` 或 `~/.bashrc` 中配置):

```bash
export LONGBRIDGE_APP_KEY="your_app_key"
export LONGBRIDGE_APP_SECRET="your_app_secret"
export LONGBRIDGE_ACCESS_TOKEN="your_access_token"

# 可选:开启交易权限(默认只读,禁止 buy/sell/cancel)
# export LONGBRIDGE_TRADE_ENABLED=false
```

也可以在当前目录或主目录创建 `.env` 文件(系统环境变量优先级更高,不会被 `.env` 覆盖)。

多账户切换:使用 `--profile <名称>` 加载 `.<名称>.env` 文件,例如:

```bash
longbridge --profile paper balance   # 加载 .paper.env
longbridge --profile live positions  # 加载 .live.env
```

### 安装

先检测是否已安装:

```bash
which longbridge
```

- 若输出路径(如 `/Users/xxx/.local/bin/longbridge`),说明已安装,跳过安装步骤。
- 若未找到,从本 skill 目录安装(`SKILL_DIR` 为本文件所在目录):

```bash
uv tool install "$SKILL_DIR"
```

验证安装:

```bash
longbridge --help
```

## 使用方式

所有命令均支持 `--json` 选项输出 JSON 格式。

### 行情模块

```bash
# 实时报价(支持多个标的)
longbridge quote AAPL.US 700.HK
longbridge quote AAPL.US --json

# 盘口(买5卖5)
longbridge depth 700.HK

# 逐笔成交
longbridge trades 700.HK --count 20

# K 线(period 可选:1m 5m 15m 30m 60m day week month quarter year)
longbridge candlesticks AAPL.US day --count 30
longbridge candlesticks 700.HK 60m --count 100

# 标的静态信息
longbridge info 700.HK AAPL.US
```

### 账户模块

```bash
# 账户余额与净资产
longbridge balance

# 股票持仓
longbridge positions
longbridge positions --json

# 基金持仓
longbridge funds
```

### 订单模块

```bash
# 今日订单(只读,无需交易权限)
longbridge orders

# 历史订单(只读,无需交易权限)
longbridge history-orders --start 2026-01-01 --end 2026-03-14

# 以下命令需设置 LONGBRIDGE_TRADE_ENABLED=true

# 限价买入(会有确认提示,防止误操作)
longbridge buy AAPL.US --qty 100 --price 180.0

# 限价卖出(会有确认提示)
longbridge sell 700.HK --qty 500 --price 320.0

# 撤销订单(会有确认提示)
longbridge cancel 701234567890

# 跳过确认提示(AI Agent 程序化调用时推荐加 --yes)
longbridge buy AAPL.US --qty 100 --price 180.0 --yes
longbridge sell 700.HK --qty 500 --price 320.0 -y
```

### 市场数据模块

```bash
# 市场温度(US/HK/CN/SG)
longbridge temperature US
longbridge temperature HK

# 资金流向
longbridge capital-flow 700.HK

# 资金分布(大单/中单/小单)
longbridge capital-dist 700.HK

# 期权链到期日列表
longbridge option-chain AAPL.US
```

## 注意事项

- **下单/撤单命令**:`buy`、`sell`、`cancel` 均有确认提示,确认后才会执行,防止误操作。AI Agent 程序化调用时请加 `--yes` 或 `-y` 跳过确认
- **港股代码格式**:使用 4 位 + `.HK` 后缀,如 `0700.HK`、`9988.HK`
- **美股代码格式**:使用股票代码 + `.US` 后缀,如 `AAPL.US`、`NVDA.US`
- **JSON 输出**:所有命令加 `--json` 可输出机器可读的 JSON 格式,便于 AI 解析
- **错误处理**:SDK 异常会输出友好提示,不暴露原始堆栈

README.md

# longbridge

English | [中文](#中文)

---

## English

A command-line tool built on the [LongPort OpenAPI](https://open.longportapp.com/) Python SDK. Supports real-time quotes, account positions, order management, and market data. Ships with a `SKILL.md` for direct integration as a Claude Code Skill.

---

### Features

- **Quotes**: Real-time prices, order book, trade ticks, candlesticks, static info
- **Account**: Balance & net assets, stock positions, fund positions
- **Orders**: Today's / historical orders (read-only); limit buy/sell, cancel (requires trade permission)
- **Market**: Market temperature, capital flow, capital distribution, option chain

---

### Authentication

Apply for an API Key at [open.longportapp.com](https://open.longportapp.com/), then configure credentials using either method below.

#### Method 1: .env file (recommended)

Create a `.env` file in the current directory or home directory (`~/.env`):

```bash
LONGBRIDGE_APP_KEY=your_app_key
LONGBRIDGE_APP_SECRET=your_app_secret
LONGBRIDGE_ACCESS_TOKEN=your_access_token

# Optional: enable trading (default is read-only)
LONGBRIDGE_TRADE_ENABLED=true
```

Search order: **current directory** → **home directory**. Values in `.env` do **not** override existing system environment variables (system env takes precedence).

#### Method 3: Multiple accounts with `--profile`

Use named profile files to switch between accounts (e.g., paper trading vs live):

```bash
# Create .paper.env and .live.env in the current or home directory
# Each file contains the credentials for that account

longbridge --profile paper balance
longbridge --profile live positions
```

The `--profile paper` flag loads `.paper.env` instead of `.env`. If the file is not found, an error is raised.

#### Method 2: Shell environment variables

```bash
export LONGBRIDGE_APP_KEY="your_app_key"
export LONGBRIDGE_APP_SECRET="your_app_secret"
export LONGBRIDGE_ACCESS_TOKEN="your_access_token"
```

Add to `~/.zshrc` or `~/.bashrc` for persistence.

| Variable | Required | Description |
|----------|----------|-------------|
| `LONGBRIDGE_APP_KEY` | ✅ | App Key |
| `LONGBRIDGE_APP_SECRET` | ✅ | App Secret |
| `LONGBRIDGE_ACCESS_TOKEN` | ✅ | Access Token |
| `LONGBRIDGE_TRADE_ENABLED` | Optional | Set to `true` to enable trading (default: read-only) |

---

### Read-only Mode & Trade Permission

**Default is read-only**: `buy`, `sell`, `cancel` are disabled unless `LONGBRIDGE_TRADE_ENABLED=true` is set:

```
Error: 当前为只读模式,下单/撤单操作已禁用。
如需开启交易权限,请设置环境变量:
  export LONGBRIDGE_TRADE_ENABLED=true
⚠️  开启后请确保操作正确,下单指令将直接提交至长桥交易系统。
```

Read commands (`orders`, `history-orders`, `positions`, etc.) are always available without extra configuration.

---

### Usage

All commands support `--json` for machine-readable output.

#### Quotes

```bash
# Real-time quotes (multiple symbols)
longbridge quote AAPL.US 700.HK
longbridge quote AAPL.US --json

# Order book (top 5 bid/ask)
longbridge depth 700.HK

# Trade ticks
longbridge trades 700.HK

_meta.json

{
  "ownerId": "kn710bpt2w6p9mw4nm8g03f82582w94c",
  "slug": "longbridge-kit",
  "version": "1.0.2",
  "publishedAt": 1774793905098
}

skill-card.md

## Description:

Provides agent-facing LongPort OpenAPI CLI workflows for stock quotes, account balances and positions, order management, and market data.

This skill is ready for commercial/non-commercial use.

## Publisher:

[frankxiong](https://clawhub.ai/user/frankxiong)

### License/Terms of Use:

MIT-0

## Use Case:

Developers and external users can use this skill to let an agent query Longbridge account and market data, produce CLI calls, and format results as text or JSON. Users may also route order-management requests through the CLI when trading is deliberately enabled.

### Deployment Geography for Use:

Global

## Known Risks and Mitigations:

Risk: An AI-accessible CLI can read Longbridge brokerage account data when credentials are available.

Mitigation: Install only for intended account access, keep credentials least-privileged, and prefer paper or read-only profiles for agent workflows.

Risk: Live buy, sell, or cancel commands can execute when trading is enabled, and --yes/-y bypasses confirmation prompts.

Mitigation: Keep the default read-only mode unless deliberately trading, avoid --yes/-y for live orders, and require human review before order submission.

Risk: Profile and .env files may hold brokerage secrets used by the CLI.

Mitigation: Protect profile files, separate paper and live credentials, and review environment-file handling before using real brokerage accounts.

## Reference(s):

- [ClawHub skill page](https://clawhub.ai/frankxiong/skills/longbridge-kit)
- [LongPort OpenAPI](https://open.longportapp.com/)

## Skill Output:

**Output Type(s):** [Text, Markdown, Shell commands, Configuration, JSON, Guidance]

**Output Format:** [Markdown guidance with bash examples; CLI commands can return table text or JSON.]

**Output Parameters:** [1D]

**Other Properties Related to Output:** [Requires python3, uv, and Longbridge credential environment variables; trade actions remain read-only unless explicitly enabled.]

## Skill Version(s):

1.0.2 (source: SKILL.md frontmatter, ClawHub release metadata)

## Ethical Considerations:

Users should evaluate whether this skill is appropriate for their environment, review any generated or modified files before relying on them, and apply their organization's safety, security, and compliance requirements before deployment.

pyproject.toml

[build-system]
requires = ["setuptools>=42", "wheel"]
build-backend = "setuptools.build_meta"

[project]
name = "longbridge-cli"
version = "1.0.0"
description = "长桥 LongPort OpenAPI CLI 工具"
requires-python = ">=3.9"
dependencies = [
    "longbridge",
    "click>=8.0",
    "rich>=13.0",
]

[project.scripts]
longbridge = "longbridge_cli.cli:cli"

[tool.setuptools.packages.find]
where = ["."]
include = ["longbridge_cli*"]

Sponsored

Ads related to longbridge and adjacent AI workflows.