longbridge
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseWhat this is
功能介绍
☁️ Cloud broker — runs directly in the container via the official SDK (formerly ). Covers US, HK, and A-share markets.
longportlongbridgeAuth 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 here is trust-declared (echoed back as ); it does not verify anything on the server. Live placement still requires . Treat the token you configure as authoritative for which environment you're in.
--profilepaper_guard: config_declared--confirm-live☁️ 云端券商工具 — 通过官方 SDK(原)直接在容器中运行。覆盖美股、港股及A股市场。
longportlongbridge认证方式为静态密钥:App Key + App Secret + Access Token。这些密钥使用SDK自带的环境变量名称,可自动被识别。
⚠️ API中无模拟/实盘区分标识。模拟盘与实盘仅由你加载的Access Token决定——没有字段、账户前缀或主机地址可用于区分两者。因此此处的仅为信任声明(返回时显示为);它不会在服务器端进行任何验证。实盘下单仍需添加参数。请以你配置的Token作为当前环境的权威依据。
--profilepaper_guard: config_declared--confirm-liveGet your credentials
获取凭证
- Open a Longbridge account, then go to the LongPort OpenAPI console (开放平台).
- Apply for / enable OpenAPI access. The console issues three values:
- App Key
- App Secret
- Access Token (has an expiry — regenerate when it lapses)
- 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.)
- 开通长桥证券账户,然后访问LongPort开放平台控制台(开放平台)。
- 申请/启用OpenAPI权限。控制台会生成三个凭证:
- App Key
- App Secret
- Access Token(存在有效期,过期后需重新生成)
- 若使用模拟交易,请在账户/环境处于平台提供的模拟模式时生成Token;若使用实盘,则使用实盘Token。(两种模式下的三个字段名称一致。)
Configure (.env)
配置(.env)
Request via secure input — never paste keys in chat. These are the SDK's standard names:
| Variable | Required | Notes |
|---|---|---|
| yes | App Key |
| yes | App Secret |
| yes | Access Token (expires — refresh when needed) |
请通过安全输入方式配置——切勿在聊天中粘贴密钥。以下是SDK的标准环境变量名称:
| 变量名 | 是否必填 | 说明 |
|---|---|---|
| 是 | App Key |
| 是 | App Secret |
| 是 | Access Token(存在有效期,过期后需刷新) |
Usage
使用方法
pip install longportpaperbash
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首次运行前执行。输出格式为JSON。默认配置文件为(仅为标签)。
pip install longportpaperbash
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 90place: 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 (shares).
--qty - 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无法帮你识别错误标记的环境。