longbridge

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

What this is

功能介绍

☁️ Cloud broker — runs directly in the container via the official
longport
SDK (formerly
longbridge
). Covers US, HK, and A-share markets.
Auth is static key: App Key + App Secret + Access Token. These use the SDK's own env var names so they're picked up automatically.
⚠️ No paper/live discriminator exists in the API. Paper vs live is determined only by which Access Token you loaded — there is no field, account prefix, or host that distinguishes them. So
--profile
here is trust-declared (echoed back as
paper_guard: config_declared
); it does not verify anything on the server. Live placement still requires
--confirm-live
. Treat the token you configure as authoritative for which environment you're in.
☁️ 云端券商工具 — 通过官方
longport
SDK(原
longbridge
)直接在容器中运行。覆盖美股、港股及A股市场。
认证方式为静态密钥:App Key + App Secret + Access Token。这些密钥使用SDK自带的环境变量名称,可自动被识别。
⚠️ API中无模拟/实盘区分标识。模拟盘与实盘仅由你加载的Access Token决定——没有字段、账户前缀或主机地址可用于区分两者。因此此处的
--profile
仅为信任声明(返回时显示为
paper_guard: config_declared
);它不会在服务器端进行任何验证。实盘下单仍需添加
--confirm-live
参数。请以你配置的Token作为当前环境的权威依据。

Get your credentials

获取凭证

  1. Open a Longbridge account, then go to the LongPort OpenAPI console (开放平台).
  2. Apply for / enable OpenAPI access. The console issues three values:
    • App Key
    • App Secret
    • Access Token (has an expiry — regenerate when it lapses)
  3. For paper trading, generate the token while your account/environment is in the paper/模拟 mode the platform offers; for live, use the live token. (Same three field names either way.)
  1. 开通长桥证券账户,然后访问LongPort开放平台控制台(开放平台)。
  2. 申请/启用OpenAPI权限。控制台会生成三个凭证:
    • App Key
    • App Secret
    • Access Token(存在有效期,过期后需重新生成)
  3. 若使用模拟交易,请在账户/环境处于平台提供的模拟模式时生成Token;若使用实盘,则使用实盘Token。(两种模式下的三个字段名称一致。)

Configure (.env)

配置(.env)

Request via secure input — never paste keys in chat. These are the SDK's standard names:
VariableRequiredNotes
LONGPORT_APP_KEY
yesApp Key
LONGPORT_APP_SECRET
yesApp Secret
LONGPORT_ACCESS_TOKEN
yesAccess Token (expires — refresh when needed)
请通过安全输入方式配置——切勿在聊天中粘贴密钥。以下是SDK的标准环境变量名称:
变量名是否必填说明
LONGPORT_APP_KEY
App Key
LONGPORT_APP_SECRET
App Secret
LONGPORT_ACCESS_TOKEN
Access Token(存在有效期,过期后需刷新)

Usage

使用方法

pip install longport
(first run). JSON output. Default profile
paper
(label only).
bash
python skills/longbridge/scripts/longbridge_cli.py status
python skills/longbridge/scripts/longbridge_cli.py account
python skills/longbridge/scripts/longbridge_cli.py positions
python skills/longbridge/scripts/longbridge_cli.py orders [--executions]
python skills/longbridge/scripts/longbridge_cli.py quote --symbol 700.HK
python skills/longbridge/scripts/longbridge_cli.py history --symbol AAPL.US --period 1d --limit 90
首次运行前执行
pip install longport
。输出格式为JSON。默认配置文件为
paper
(仅为标签)。
bash
python skills/longbridge/scripts/longbridge_cli.py status
python skills/longbridge/scripts/longbridge_cli.py account
python skills/longbridge/scripts/longbridge_cli.py positions
python skills/longbridge/scripts/longbridge_cli.py orders [--executions]
python skills/longbridge/scripts/longbridge_cli.py quote --symbol 700.HK
python skills/longbridge/scripts/longbridge_cli.py history --symbol AAPL.US --period 1d --limit 90

place: qty in shares only; market or limit

下单:仅支持股数(qty);市价单或限价单

python skills/longbridge/scripts/longbridge_cli.py place --symbol 700.HK --side buy --qty 100 --type limit --limit-price 350 python skills/longbridge/scripts/longbridge_cli.py cancel --order-id <id>
python skills/longbridge/scripts/longbridge_cli.py place --symbol 700.HK --side buy --qty 100 --type limit --limit-price 350 python skills/longbridge/scripts/longbridge_cli.py cancel --order-id <id>

live (real money): add --confirm-live (profile is label-only)

实盘(真实资金):添加--confirm-live参数(配置文件仅为标签)

python skills/longbridge/scripts/longbridge_cli.py --confirm-live place --symbol AAPL.US --side buy --qty 1

**Symbol format is mandatory:** `<ticker>.<market>` — `700.HK`, `AAPL.US`, `000001.SZ`, `600519.SH`. Periods: `1m 5m 15m 30m 1h 1d 1w 1M`.
python skills/longbridge/scripts/longbridge_cli.py --confirm-live place --symbol AAPL.US --side buy --qty 1

**股票代码格式为必填项**:`<股票代码>.<市场代码>`——例如`700.HK`、`AAPL.US`、`000001.SZ`、`600519.SH`。周期选项:`1m 5m 15m 30m 1h 1d 1w 1M`。

Gotchas

注意事项

  • Longbridge has no notional path — always
    --qty
    (shares).
  • The Access Token expires; if calls start failing auth, regenerate it in the console and update
    .env
    .
  • Because there's no server-side paper/live check, double-check which token you loaded before any live order — the CLI can't catch a mislabeled environment for you.
  • 长桥证券不支持按金额下单——仅能使用
    --qty
    参数(股数)。
  • Access Token会过期;若调用时出现认证失败,请在控制台重新生成Token并更新
    .env
    文件。
  • 由于服务器端无模拟/实盘校验,在进行任何实盘下单前,请务必确认你加载的是实盘Token——CLI无法帮你识别错误标记的环境。