Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
/.env.example @Pigbibi
/.github/CODEOWNERS @Pigbibi
/.github/workflows/ @Pigbibi
/application/execution_receipt_adapter.py @Pigbibi
/application/execution_service.py @Pigbibi
/application/paper_execution_admission.py @Pigbibi
/application/paper_execution_command_consumer.py @Pigbibi
/runtime_execution_policy.py @Pigbibi
/src/firstrade_platform/application/execution_receipt_adapter.py @Pigbibi
/src/firstrade_platform/application/execution_service.py @Pigbibi
/src/firstrade_platform/application/paper_execution_admission.py @Pigbibi
/src/firstrade_platform/application/paper_execution_command_consumer.py @Pigbibi
/src/firstrade_platform/runtime_execution_policy.py @Pigbibi
/scripts/execution_report_heartbeat.py @Pigbibi
4 changes: 3 additions & 1 deletion .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ updates:
directory: /
schedule:
interval: weekly
commit-message:
prefix: "chore"
groups:
actions-minor-and-patch:
actions:
patterns:
- "*"
open-pull-requests-limit: 3
Expand Down
5 changes: 5 additions & 0 deletions .github/scripts/dependabot-policy.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"action_files": [
".github/workflows/ci.yml"
]
}
3 changes: 2 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ jobs:
shell: bash
run: |
set -euo pipefail
command -v rg
rg_bin="$(command -v rg)"
test -x "$rg_bin"
if rg -l '\$\{\{[[:space:]]*vars\.(GLOBAL_TELEGRAM_CHAT_ID|CLOUD_RUN_SERVICES|CLOUD_RUN_SERVICE|RUNTIME_HEARTBEAT_REQUIRED_SERVICES|RUNTIME_GUARD_SCHEDULER_JOB_PATTERN)([[:space:]]|\}\}|\|\|)' .github/workflows; then
echo "Sensitive operational runtime configuration must use GitHub Secrets, not GitHub Variables." >&2
exit 1
Expand Down
8 changes: 7 additions & 1 deletion .github/workflows/engineering-governance.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ jobs:
tool="$RUNNER_TEMP/governance-commitlint"
npm install --prefix "$tool" --ignore-scripts --no-audit --no-fund \
@commitlint/cli@21.2.4 @commitlint/config-conventional@21.2.4
printf '%s\n' "module.exports = {extends: [require.resolve('@commitlint/config-conventional')], defaultIgnores: true, ignores: [(message) => /^Merge /.test(message)], rules: {'subject-case': [0], 'header-max-length': [2, 'always', 72], 'type-enum': [2, 'always', ['feat', 'fix', 'docs', 'refactor', 'test', 'chore', 'perf', 'ci']]}};" > "$tool/commitlint.config.cjs"
printf '%s\n' "module.exports = {extends: [require.resolve('@commitlint/config-conventional')], defaultIgnores: true, rules: {'subject-case': [0], 'header-max-length': [2, 'always', 72], 'type-enum': [2, 'always', ['feat', 'fix', 'docs', 'refactor', 'test', 'chore', 'perf', 'ci', 'build']]}};" > "$tool/commitlint.config.cjs"
for message in 'Merge bypass' 'Merge fix: bypass'; do
if printf '%s\n' "$message" | node "$tool/node_modules/@commitlint/cli/cli.js" --config "$tool/commitlint.config.cjs" >/dev/null 2>&1; then
echo "commitlint incorrectly ignored: $message" >&2
exit 1
fi
done
node "$tool/node_modules/@commitlint/cli/cli.js" \
--config "$tool/commitlint.config.cjs" --from "$PR_BASE" --to "$PR_HEAD" --verbose
4 changes: 2 additions & 2 deletions .github/workflows/fee-schedule-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Fee schedule check
# Monthly review of the Firstrade fee schedule (tracking issue #497).
#
# check: compares the SEC Section 31 rate and the FINRA TAF rates on the official sites with
# application/firstrade_fee_schedule.py. Any fetch/parse failure is an error, never a pass.
# src/firstrade_platform/application/firstrade_fee_schedule.py. Any fetch/parse failure is an error, never a pass.
# bump: only when every value is unchanged. Pushes a branch that moves `verified_through` to the
# end of next month (plus the test pin and docs) and opens a PR. It never merges.
# notify: when rates changed, the check failed, or the PR could not be opened. Opens or updates one
Expand Down Expand Up @@ -205,7 +205,7 @@ jobs:
echo
echo "## What changed"
echo
echo "Moves \`verified_through\` in \`application/firstrade_fee_schedule.py\` to \`$new_date\`"
echo "Moves \`verified_through\` in \`src/firstrade_platform/application/firstrade_fee_schedule.py\` to \`$new_date\`"
echo "so sells dated up to then keep reconciling instead of returning \`unsupported\`. No"
echo "rate row was changed. The test review pin and the doc mentions move with it."
echo
Expand Down
82 changes: 0 additions & 82 deletions .github/workflows/ft-account-facts-sync-once.yml

This file was deleted.

7 changes: 2 additions & 5 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@ QuantPlatformKit and UsEquityStrategies at pinned revisions.

## Layout

- `application/` — Firstrade client, execution and reconciliation logic.
- `entrypoints/`, `main.py` — service entry points.
- `strategy/` — strategy loading and registry.
- `notifications/` — notification composition.
- `src/firstrade_platform/` — installable runtime package (`application/`, `entrypoints/`, `notifications/`, `main.py`, strategy loading/registry, and runtime policy modules).
- `scripts/`, `cloudbuild.yaml` — deployment and operator tooling.
- `docs/` — runtime and notification contracts.
- `tests/` — offline tests with a mocked broker boundary.
Expand Down Expand Up @@ -54,7 +51,7 @@ Organization documentation rules run in CI via `QuantStrategyLab/.github/.github
## Do not

- Do not remove the default dry-run behaviour or weaken the live order gates in
`application/firstrade_client.py`.
`src/firstrade_platform/application/firstrade_client.py`.
- Do not add credentials, cookies, account identifiers, balances or raw order
payloads to examples or tests.
- Do not treat a successful call to the unofficial API as proof of account
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ make failure modes obvious.
Rules for contributions:

- Do not remove the default dry-run behavior.
- Do not weaken the live order gates in `application/firstrade_client.py`.
- Do not weaken the live order gates in `src/firstrade_platform/application/firstrade_client.py`.
- Do not add credentials, cookies, account IDs, balances, or raw order payloads
to examples or tests.
- Keep upstream attribution in `NOTICE.md`.
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ USER appuser

RUN /app/.venv/bin/python -m scripts.publish_digest_before_read --help

CMD ["/app/.venv/bin/python", "-m", "gunicorn", "--bind", ":8080", "main:app"]
CMD ["/app/.venv/bin/python", "-m", "gunicorn", "--bind", ":8080", "firstrade_platform.main:app"]
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ The existing daily Execution Report Heartbeat also invokes this snapshot path on

The Cloud Run service must remain IAM-protected. The caller needs `roles/run.invoker` and must send its Google-signed ID token in `X-Serverless-Authorization`; the separate application token goes in `Authorization: Bearer …`. See [Cloud Run service-to-service authentication](https://cloud.google.com/run/docs/authenticating/service-to-service). Neither token is a Firstrade credential.

Configure the following only through protected Cloud Run environment variables and Secret Manager references: `FIRSTRADE_ACCOUNT_FACTS_SYNC_ENABLED`, `FIRSTRADE_ACCOUNT_FACTS_SYNC_URL` (must equal the approved sync URL defined as `_APPROVED_SYNC_URL` in `application/account_facts_publisher.py`), `FIRSTRADE_ACCOUNT_FACTS_SYNC_TOKEN` (a dedicated secret), `FIRSTRADE_ACCOUNT_FACTS_TARGET_ID`, `FIRSTRADE_ACCOUNT_FACTS_SOURCE_BINDING_ID`, `FIRSTRADE_ACCOUNT_FACTS_ACCOUNT_KEY`, and `FIRSTRADE_ACCOUNT_FACTS_ACCOUNT_SCOPE`. The account identity is taken from the single exact selector in the protected runtime target; if `FIRSTRADE_ACCOUNT` is also set, it must match. All values must match the trusted QRS binding and current runtime target. Do not derive or invent a binding ID.
Configure the following only through protected Cloud Run environment variables and Secret Manager references: `FIRSTRADE_ACCOUNT_FACTS_SYNC_ENABLED`, `FIRSTRADE_ACCOUNT_FACTS_SYNC_URL` (must equal the approved sync URL defined as `_APPROVED_SYNC_URL` in `src/firstrade_platform/application/account_facts_publisher.py`), `FIRSTRADE_ACCOUNT_FACTS_SYNC_TOKEN` (a dedicated secret), `FIRSTRADE_ACCOUNT_FACTS_TARGET_ID`, `FIRSTRADE_ACCOUNT_FACTS_SOURCE_BINDING_ID`, `FIRSTRADE_ACCOUNT_FACTS_ACCOUNT_KEY`, and `FIRSTRADE_ACCOUNT_FACTS_ACCOUNT_SCOPE`. The account identity is taken from the single exact selector in the protected runtime target; if `FIRSTRADE_ACCOUNT` is also set, it must match. All values must match the trusted QRS binding and current runtime target. Do not derive or invent a binding ID.

The existing manual Cloud Run environment sync carries the six non-token settings through the selected Firstrade target's `env` configuration in `CLOUD_RUN_SERVICE_TARGETS_JSON`; the legacy single-service path can use matching `FIRSTRADE_ACCOUNT_FACTS_*` inputs. Keep target, binding, account key, and scope in protected GitHub configuration. Set the protected GitHub variable `FIRSTRADE_ACCOUNT_FACTS_SYNC_TOKEN_SECRET_NAME` to the name of the already-approved Secret Manager secret. The workflow maps that Secret Manager reference to `FIRSTRADE_ACCOUNT_FACTS_SYNC_TOKEN`; it never accepts a raw token value from GitHub Actions. Keep the enable switch unset or `false` until deployment adoption is separately reviewed. This source change does not apply Cloud Run configuration or establish deployment adoption.

Expand All @@ -128,9 +128,11 @@ Keep the sync disabled until the receiver-side account binding and separate sync

## Repository layout

- `src/firstrade_platform/`: installable runtime package (`application/`, `entrypoints/`, `notifications/`, `main.py`, and strategy and runtime policy modules).
- `tests/`: unit, contract, and regression tests.
- `.github/workflows/`: CI, scheduled jobs, release, or deployment workflows.
- `scripts/`: operator scripts and local helpers.
- `docs/`: runtime, reconciliation, and notification contracts.

## Quick start

Expand All @@ -142,7 +144,9 @@ uv run --no-sync python scripts/check_qpk_pin_consistency.py

## Useful docs

- [Documentation index](docs/README.md)
- [Isolated paper command consumer](docs/paper-execution-command-consumer.md)
- [Configurable display names](docs/display-names.md)

## Community and security

Expand All @@ -157,5 +161,3 @@ See [CONTRIBUTING.md](CONTRIBUTING.md). AI assistants and maintainers follow [AG
## License

See [LICENSE](LICENSE).

Display/notification naming configuration: [display names](docs/display-names.md).
10 changes: 7 additions & 3 deletions README.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ FirstradePlatform 是 QuantStrategyLab 的实验性 Firstrade 执行平台。实

现有 Runtime Target Lifecycle 手动入口的 `metadata_only=true` 会核实际接收流量的修订,并只输出同步开关、固定目的地、绑定配置、token 引用与缓存配置是否存在。它不读取 Secret 内容或缓存,不调用券商;绑定准确性及缓存有效性明确标为尚未核验。配置存在不能代表余额已同步。

`POST /account-facts-sync` 是手动触发、仅读取缓存会话的账户快照入口。只有 `FIRSTRADE_ACCOUNT_FACTS_SYNC_ENABLED=true` 时才开放;它不会登录、刷新凭据、自行定时、下单或发送通知。它只发布券商直接返回的净资产,以及存在时的 `cash_balance`;不会读取持仓,因此持仓读取失败或持仓资料不完整不会阻塞余额快照;也不会用 buying power 或持仓计算资产或现金。
`POST /account-facts-sync` 是手动触发、仅读取缓存会话的账户快照入口。只有 `FIRSTRADE_ACCOUNT_FACTS_SYNC_ENABLED=true` 时才开放;它不会登录、刷新凭据、自行定时、下单或发送通知。它发布券商直接返回的净资产,以及存在时的 `cash_balance`;显式设置 `FIRSTRADE_ACCOUNT_FACTS_POSITION_CURRENCY` 时也会采集持仓,否则不会因持仓读取失败或持仓资料不完整阻塞余额快照;也不会用 buying power 或持仓计算资产或现金。

Cloud Run 服务必须继续受 IAM 保护。调用方需要 `roles/run.invoker`,并把 Google 签名的 ID token 放在 `X-Serverless-Authorization`;独立的应用 token 放在 `Authorization: Bearer …`。参见 [Cloud Run 服务间认证文档](https://cloud.google.com/run/docs/authenticating/service-to-service)。这两种 token 都不是 Firstrade 凭据。

以下配置只能通过受保护的 Cloud Run 环境变量和 Secret Manager 引用配置:`FIRSTRADE_ACCOUNT_FACTS_SYNC_ENABLED`、`FIRSTRADE_ACCOUNT_FACTS_SYNC_URL`(必须与 `application/account_facts_publisher.py` 中 `_APPROVED_SYNC_URL` 定义的已批准同步地址完全一致)、`FIRSTRADE_ACCOUNT_FACTS_SYNC_TOKEN`(专用 secret)、`FIRSTRADE_ACCOUNT_FACTS_TARGET_ID`、`FIRSTRADE_ACCOUNT_FACTS_SOURCE_BINDING_ID`、`FIRSTRADE_ACCOUNT_FACTS_ACCOUNT_KEY` 和 `FIRSTRADE_ACCOUNT_FACTS_ACCOUNT_SCOPE`。账户身份复用受保护 runtime target 中唯一且精确的 selector;若同时设置 `FIRSTRADE_ACCOUNT`,它必须完全匹配。所有值都必须与 QRS 可信绑定及当前 runtime target 一致;不要推导或编造 binding ID。
以下配置只能通过受保护的 Cloud Run 环境变量和 Secret Manager 引用配置:`FIRSTRADE_ACCOUNT_FACTS_SYNC_ENABLED`、`FIRSTRADE_ACCOUNT_FACTS_SYNC_URL`(必须与 `src/firstrade_platform/application/account_facts_publisher.py` 中 `_APPROVED_SYNC_URL` 定义的已批准同步地址完全一致)、`FIRSTRADE_ACCOUNT_FACTS_SYNC_TOKEN`(专用 secret)、`FIRSTRADE_ACCOUNT_FACTS_TARGET_ID`、`FIRSTRADE_ACCOUNT_FACTS_SOURCE_BINDING_ID`、`FIRSTRADE_ACCOUNT_FACTS_ACCOUNT_KEY` 和 `FIRSTRADE_ACCOUNT_FACTS_ACCOUNT_SCOPE`。账户身份复用受保护 runtime target 中唯一且精确的 selector;若同时设置 `FIRSTRADE_ACCOUNT`,它必须完全匹配。所有值都必须与 QRS 可信绑定及当前 runtime target 一致;不要推导或编造 binding ID。

现有手动 Cloud Run 环境同步会从 `CLOUD_RUN_SERVICE_TARGETS_JSON` 中所选 Firstrade target 的 `env` 配置传递六个非 token 项;单服务旧配置路径也可使用匹配的 `FIRSTRADE_ACCOUNT_FACTS_*` 输入。target、binding、account key 和 scope 放在受保护的 GitHub 配置中。受保护的 GitHub variable `FIRSTRADE_ACCOUNT_FACTS_SYNC_TOKEN_SECRET_NAME` 只填写已批准 Secret Manager secret 的名称;workflow 只把这个 Secret Manager 引用映射到 `FIRSTRADE_ACCOUNT_FACTS_SYNC_TOKEN`,不会接受 GitHub Actions 传入的明文 token。部署另行审查和采用前,启用开关应保持未设置或 `false`。本次源码修改没有应用 Cloud Run 配置,也不代表部署已采用。

Expand All @@ -80,9 +80,11 @@ FIRSTRADE_ACCOUNT=synthetic-native-account-id # 可选;设置后必须匹配

## 仓库结构

- `src/firstrade_platform/`:可安装的运行时包(`application/`、`entrypoints/`、`notifications/`、`main.py` 及策略与运行时策略模块)。
- `tests/`:单元测试、契约测试和回归测试。
- `.github/workflows/`:CI、定时任务、发布或部署 workflow。
- `scripts/`:运维脚本和本地辅助工具。
- `docs/`:运行时、对账与通知契约文档。

## 快速开始

Expand All @@ -94,7 +96,9 @@ uv run --no-sync python scripts/check_qpk_pin_consistency.py

## 延伸文档

- 暂无独立 `docs/` 目录;请先阅读本 README 和 workflow 文件。
- [文档索引](docs/README.md)
- [隔离的 paper 命令消费者](docs/paper-execution-command-consumer.md)
- [显示名称配置](docs/display-names.md)

## 社区和安全

Expand Down
5 changes: 3 additions & 2 deletions docs/shared-test-imports.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Dependency installation is preparation; run tests without network or credential
The installed-lock lane checks VCS URL, exact locked revision and version together
with every loaded shared module's actual file/spec origin, package search path,
distribution ownership and RECORD SHA-256. Editable installs and sibling shadows fail.
The existing sibling entries in pytest's `pythonpath` remain unchanged.
Pytest's `pythonpath` resolves `src` and `.` without sibling repository checkouts.

```bash
uv run --no-sync python -m pytest -q -p test_support.pytest_provenance \
Expand Down Expand Up @@ -55,4 +55,5 @@ transient modules loaded and removed between boundaries by arbitrary third-party
Existing test-specific path edits and mocks remain in place, so legacy whole-suite
source ambiguity remains characterized rather than eliminated. The test support is
excluded from the setuptools production package selection; pins, production source,
existing scanner/completion checks and coverage configuration are unchanged.
existing scanner/completion checks and `src/firstrade_platform` coverage configuration
remain intact.
Loading
Loading