Skip to content

Commit aa72f46

Browse files
committed
Add LongBridge API probe workflow
1 parent a4d91e1 commit aa72f46

4 files changed

Lines changed: 179 additions & 0 deletions

File tree

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
name: LongBridge API Probe
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
qpk_ref:
7+
description: "QuantPlatformKit ref containing the probe test"
8+
required: false
9+
default: "main"
10+
type: string
11+
symbol:
12+
description: "US symbol to use for the probe"
13+
required: false
14+
default: "SOXX.US"
15+
type: string
16+
limit_price:
17+
description: "Low buy limit price used by the cancellable probe order"
18+
required: false
19+
default: "0.01"
20+
type: string
21+
22+
env:
23+
GCP_PROJECT_ID: longbridgequant
24+
GCP_WORKLOAD_IDENTITY_PROVIDER: projects/252919773759/locations/global/workloadIdentityPools/github-actions/providers/github-main
25+
GCP_WORKLOAD_IDENTITY_SERVICE_ACCOUNT: longbridge-platform-deploy@longbridgequant.iam.gserviceaccount.com
26+
27+
jobs:
28+
hk-fractional-order:
29+
name: Probe HK Simulated Fractional Orders
30+
runs-on: ubuntu-latest
31+
permissions:
32+
contents: read
33+
id-token: write
34+
environment: longbridge-hk
35+
env:
36+
LONGPORT_APP_KEY_SECRET_NAME: ${{ vars.LONGPORT_APP_KEY_SECRET_NAME }}
37+
LONGPORT_APP_SECRET_SECRET_NAME: ${{ vars.LONGPORT_APP_SECRET_SECRET_NAME }}
38+
LONGPORT_SECRET_NAME: ${{ vars.LONGPORT_SECRET_NAME }}
39+
steps:
40+
- name: Validate inputs
41+
run: |
42+
set -euo pipefail
43+
44+
missing_vars=()
45+
for var_name in LONGPORT_APP_KEY_SECRET_NAME LONGPORT_APP_SECRET_SECRET_NAME LONGPORT_SECRET_NAME; do
46+
if [ -z "${!var_name:-}" ]; then
47+
missing_vars+=("${var_name}")
48+
fi
49+
done
50+
51+
if [ "${#missing_vars[@]}" -gt 0 ]; then
52+
printf 'Missing longbridge-hk variables:\n' >&2
53+
printf ' - %s\n' "${missing_vars[@]}" >&2
54+
exit 1
55+
fi
56+
57+
- name: Checkout QuantPlatformKit
58+
uses: actions/checkout@v6
59+
with:
60+
repository: QuantStrategyLab/QuantPlatformKit
61+
ref: ${{ inputs.qpk_ref }}
62+
path: quant-platform-kit
63+
64+
- name: Set up Python
65+
uses: actions/setup-python@v6
66+
with:
67+
python-version: "3.12"
68+
69+
- name: Authenticate to Google Cloud
70+
uses: google-github-actions/auth@v3
71+
with:
72+
workload_identity_provider: ${{ env.GCP_WORKLOAD_IDENTITY_PROVIDER }}
73+
service_account: ${{ env.GCP_WORKLOAD_IDENTITY_SERVICE_ACCOUNT }}
74+
75+
- name: Set up gcloud
76+
uses: google-github-actions/setup-gcloud@v3
77+
with:
78+
project_id: ${{ env.GCP_PROJECT_ID }}
79+
version: ">= 416.0.0"
80+
81+
- name: Export LongPort credentials
82+
run: |
83+
set -euo pipefail
84+
85+
longport_app_key="$(gcloud secrets versions access latest --secret="${LONGPORT_APP_KEY_SECRET_NAME}")"
86+
longport_app_secret="$(gcloud secrets versions access latest --secret="${LONGPORT_APP_SECRET_SECRET_NAME}")"
87+
longport_access_token="$(gcloud secrets versions access latest --secret="${LONGPORT_SECRET_NAME}")"
88+
89+
echo "::add-mask::${longport_app_key}"
90+
echo "::add-mask::${longport_app_secret}"
91+
echo "::add-mask::${longport_access_token}"
92+
93+
{
94+
echo "LONGPORT_APP_KEY=${longport_app_key}"
95+
echo "LONGPORT_APP_SECRET=${longport_app_secret}"
96+
echo "LONGPORT_ACCESS_TOKEN=${longport_access_token}"
97+
} >> "$GITHUB_ENV"
98+
99+
- name: Install probe dependencies
100+
run: |
101+
set -euo pipefail
102+
103+
python -m pip install --upgrade pip
104+
python -m pip install -e quant-platform-kit pytest longport
105+
106+
- name: Run HK simulated fractional order probe
107+
env:
108+
LONGBRIDGE_API_PROBE: "1"
109+
LONGBRIDGE_API_PROBE_SYMBOL: ${{ inputs.symbol }}
110+
LONGBRIDGE_API_PROBE_LIMIT_PRICE: ${{ inputs.limit_price }}
111+
run: |
112+
set -euo pipefail
113+
114+
python -m pytest quant-platform-kit/tests/test_longbridge_fractional_order_api_probe.py -q -s

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,11 @@ Important:
146146
- If you later rename or move this repository, rebuild the GitHub source binding in Google Cloud for both triggers instead of assuming the existing source binding will follow the rename.
147147
- For the shared deployment model and trigger migration checklist, see [`QuantPlatformKit/docs/deployment_model.md`](../QuantPlatformKit/docs/deployment_model.md).
148148

149+
### Manual API probes
150+
151+
- `.github/workflows/longbridge-api-probe.yml` can be triggered manually against the `longbridge-hk` GitHub Environment. It checks out a selected `QuantPlatformKit` ref and runs the skipped LongBridge fractional-order API probe with HK simulated-account credentials from Secret Manager.
152+
- The probe is for broker API validation only. It does not run on normal CI or `main` pushes.
153+
149154
### Quick deploy
150155

151156
1. Enable **Cloud Run** and **Secret Manager API** in GCP.
@@ -299,6 +304,11 @@ Secret Manager 中需存在 `LONGPORT_SECRET_NAME` 指定的密钥(默认: `lo
299304
- 如果后面改 GitHub 仓库名或再次迁组织,Google Cloud 里的两个 trigger 都要重新选择 GitHub 来源,不要假设旧绑定会自动跟过去。
300305
- 统一部署模型和触发器迁移清单见 [`QuantPlatformKit/docs/deployment_model.md`](../QuantPlatformKit/docs/deployment_model.md)
301306

307+
### 手动 API probe
308+
309+
- `.github/workflows/longbridge-api-probe.yml` 可手动触发,固定使用 `longbridge-hk` GitHub Environment。它会 checkout 指定的 `QuantPlatformKit` ref,并用 Secret Manager 中的 HK 模拟盘 LongPort 凭证运行默认跳过的碎股下单 API probe。
310+
- 这个 probe 只用于券商 API 验证,不会进入普通 CI 或 `main` push 流程。
311+
302312
### 快速部署
303313

304314
1. 在 GCP 中启用 **Cloud Run****Secret Manager API**
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import unittest
2+
from pathlib import Path
3+
4+
5+
class LongBridgeApiProbeWorkflowTests(unittest.TestCase):
6+
def test_workflow_uses_hk_environment_and_gcp_secrets(self) -> None:
7+
workflow = Path(".github/workflows/longbridge-api-probe.yml").read_text(encoding="utf-8")
8+
9+
self.assertIn("name: LongBridge API Probe", workflow)
10+
self.assertIn("workflow_dispatch:", workflow)
11+
self.assertIn("environment: longbridge-hk", workflow)
12+
self.assertIn("id-token: write", workflow)
13+
self.assertIn("repository: QuantStrategyLab/QuantPlatformKit", workflow)
14+
self.assertIn("ref: ${{ inputs.qpk_ref }}", workflow)
15+
self.assertIn("google-github-actions/auth@v3", workflow)
16+
self.assertIn("google-github-actions/setup-gcloud@v3", workflow)
17+
self.assertIn("LONGPORT_APP_KEY_SECRET_NAME: ${{ vars.LONGPORT_APP_KEY_SECRET_NAME }}", workflow)
18+
self.assertIn("LONGPORT_APP_SECRET_SECRET_NAME: ${{ vars.LONGPORT_APP_SECRET_SECRET_NAME }}", workflow)
19+
self.assertIn("LONGPORT_SECRET_NAME: ${{ vars.LONGPORT_SECRET_NAME }}", workflow)
20+
self.assertIn('gcloud secrets versions access latest --secret="${LONGPORT_APP_KEY_SECRET_NAME}"', workflow)
21+
self.assertIn(
22+
'gcloud secrets versions access latest --secret="${LONGPORT_APP_SECRET_SECRET_NAME}"',
23+
workflow,
24+
)
25+
self.assertIn('gcloud secrets versions access latest --secret="${LONGPORT_SECRET_NAME}"', workflow)
26+
self.assertIn("python -m pip install -e quant-platform-kit pytest longport", workflow)
27+
self.assertIn('LONGBRIDGE_API_PROBE: "1"', workflow)
28+
self.assertIn("test_longbridge_fractional_order_api_probe.py", workflow)
29+
30+
31+
if __name__ == "__main__":
32+
unittest.main()
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
repo_dir="$(cd "$(dirname "$0")/.." && pwd)"
5+
workflow_file="$repo_dir/.github/workflows/longbridge-api-probe.yml"
6+
7+
grep -Fq "name: LongBridge API Probe" "$workflow_file"
8+
grep -Fq "workflow_dispatch:" "$workflow_file"
9+
grep -Fq "environment: longbridge-hk" "$workflow_file"
10+
grep -Fq "id-token: write" "$workflow_file"
11+
grep -Fq "repository: QuantStrategyLab/QuantPlatformKit" "$workflow_file"
12+
grep -Fq "ref: \${{ inputs.qpk_ref }}" "$workflow_file"
13+
grep -Fq "google-github-actions/auth@v3" "$workflow_file"
14+
grep -Fq "google-github-actions/setup-gcloud@v3" "$workflow_file"
15+
grep -Fq "LONGPORT_APP_KEY_SECRET_NAME: \${{ vars.LONGPORT_APP_KEY_SECRET_NAME }}" "$workflow_file"
16+
grep -Fq "LONGPORT_APP_SECRET_SECRET_NAME: \${{ vars.LONGPORT_APP_SECRET_SECRET_NAME }}" "$workflow_file"
17+
grep -Fq "LONGPORT_SECRET_NAME: \${{ vars.LONGPORT_SECRET_NAME }}" "$workflow_file"
18+
grep -Fq 'gcloud secrets versions access latest --secret="${LONGPORT_APP_KEY_SECRET_NAME}"' "$workflow_file"
19+
grep -Fq 'gcloud secrets versions access latest --secret="${LONGPORT_APP_SECRET_SECRET_NAME}"' "$workflow_file"
20+
grep -Fq 'gcloud secrets versions access latest --secret="${LONGPORT_SECRET_NAME}"' "$workflow_file"
21+
grep -Fq "python -m pip install -e quant-platform-kit pytest longport" "$workflow_file"
22+
grep -Fq 'LONGBRIDGE_API_PROBE: "1"' "$workflow_file"
23+
grep -Fq "test_longbridge_fractional_order_api_probe.py" "$workflow_file"

0 commit comments

Comments
 (0)