-
Notifications
You must be signed in to change notification settings - Fork 0
Add LongBridge API probe workflow #52
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,114 @@ | ||
| name: LongBridge API Probe | ||
|
|
||
| on: | ||
| workflow_dispatch: | ||
| inputs: | ||
| qpk_ref: | ||
| description: "QuantPlatformKit ref containing the probe test" | ||
| required: false | ||
| default: "main" | ||
| type: string | ||
| symbol: | ||
| description: "US symbol to use for the probe" | ||
| required: false | ||
| default: "SOXX.US" | ||
| type: string | ||
| limit_price: | ||
| description: "Low buy limit price used by the cancellable probe order" | ||
| required: false | ||
| default: "0.01" | ||
| type: string | ||
|
|
||
| env: | ||
| GCP_PROJECT_ID: longbridgequant | ||
| GCP_WORKLOAD_IDENTITY_PROVIDER: projects/252919773759/locations/global/workloadIdentityPools/github-actions/providers/github-main | ||
| GCP_WORKLOAD_IDENTITY_SERVICE_ACCOUNT: longbridge-platform-deploy@longbridgequant.iam.gserviceaccount.com | ||
|
|
||
| jobs: | ||
| hk-fractional-order: | ||
| name: Probe HK Simulated Fractional Orders | ||
| runs-on: ubuntu-latest | ||
| permissions: | ||
| contents: read | ||
| id-token: write | ||
| environment: longbridge-hk | ||
| env: | ||
| LONGPORT_APP_KEY_SECRET_NAME: ${{ vars.LONGPORT_APP_KEY_SECRET_NAME }} | ||
| LONGPORT_APP_SECRET_SECRET_NAME: ${{ vars.LONGPORT_APP_SECRET_SECRET_NAME }} | ||
| LONGPORT_SECRET_NAME: ${{ vars.LONGPORT_SECRET_NAME }} | ||
| steps: | ||
| - name: Validate inputs | ||
| run: | | ||
| set -euo pipefail | ||
|
|
||
| missing_vars=() | ||
| for var_name in LONGPORT_APP_KEY_SECRET_NAME LONGPORT_APP_SECRET_SECRET_NAME LONGPORT_SECRET_NAME; do | ||
| if [ -z "${!var_name:-}" ]; then | ||
| missing_vars+=("${var_name}") | ||
| fi | ||
| done | ||
|
|
||
| if [ "${#missing_vars[@]}" -gt 0 ]; then | ||
| printf 'Missing longbridge-hk variables:\n' >&2 | ||
| printf ' - %s\n' "${missing_vars[@]}" >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| - name: Checkout QuantPlatformKit | ||
| uses: actions/checkout@v6 | ||
| with: | ||
| repository: QuantStrategyLab/QuantPlatformKit | ||
| ref: ${{ inputs.qpk_ref }} | ||
| path: quant-platform-kit | ||
|
|
||
| - name: Set up Python | ||
| uses: actions/setup-python@v6 | ||
| with: | ||
| python-version: "3.12" | ||
|
|
||
| - name: Authenticate to Google Cloud | ||
| uses: google-github-actions/auth@v3 | ||
| with: | ||
| workload_identity_provider: ${{ env.GCP_WORKLOAD_IDENTITY_PROVIDER }} | ||
| service_account: ${{ env.GCP_WORKLOAD_IDENTITY_SERVICE_ACCOUNT }} | ||
|
|
||
| - name: Set up gcloud | ||
| uses: google-github-actions/setup-gcloud@v3 | ||
| with: | ||
| project_id: ${{ env.GCP_PROJECT_ID }} | ||
| version: ">= 416.0.0" | ||
|
|
||
| - name: Export LongPort credentials | ||
| run: | | ||
| set -euo pipefail | ||
|
|
||
| longport_app_key="$(gcloud secrets versions access latest --secret="${LONGPORT_APP_KEY_SECRET_NAME}")" | ||
| longport_app_secret="$(gcloud secrets versions access latest --secret="${LONGPORT_APP_SECRET_SECRET_NAME}")" | ||
| longport_access_token="$(gcloud secrets versions access latest --secret="${LONGPORT_SECRET_NAME}")" | ||
|
|
||
| echo "::add-mask::${longport_app_key}" | ||
| echo "::add-mask::${longport_app_secret}" | ||
| echo "::add-mask::${longport_access_token}" | ||
|
|
||
| { | ||
| echo "LONGPORT_APP_KEY=${longport_app_key}" | ||
| echo "LONGPORT_APP_SECRET=${longport_app_secret}" | ||
| echo "LONGPORT_ACCESS_TOKEN=${longport_access_token}" | ||
| } >> "$GITHUB_ENV" | ||
|
|
||
| - name: Install probe dependencies | ||
| run: | | ||
| set -euo pipefail | ||
|
|
||
| python -m pip install --upgrade pip | ||
| python -m pip install -e quant-platform-kit pytest longport | ||
|
|
||
| - name: Run HK simulated fractional order probe | ||
| env: | ||
| LONGBRIDGE_API_PROBE: "1" | ||
| LONGBRIDGE_API_PROBE_SYMBOL: ${{ inputs.symbol }} | ||
| LONGBRIDGE_API_PROBE_LIMIT_PRICE: ${{ inputs.limit_price }} | ||
| run: | | ||
| set -euo pipefail | ||
|
|
||
| python -m pytest quant-platform-kit/tests/test_longbridge_fractional_order_api_probe.py -q -s | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| import unittest | ||
| from pathlib import Path | ||
|
|
||
|
|
||
| class LongBridgeApiProbeWorkflowTests(unittest.TestCase): | ||
| def test_workflow_uses_hk_environment_and_gcp_secrets(self) -> None: | ||
| workflow = Path(".github/workflows/longbridge-api-probe.yml").read_text(encoding="utf-8") | ||
|
|
||
| self.assertIn("name: LongBridge API Probe", workflow) | ||
| self.assertIn("workflow_dispatch:", workflow) | ||
| self.assertIn("environment: longbridge-hk", workflow) | ||
| self.assertIn("id-token: write", workflow) | ||
| self.assertIn("repository: QuantStrategyLab/QuantPlatformKit", workflow) | ||
| self.assertIn("ref: ${{ inputs.qpk_ref }}", workflow) | ||
| self.assertIn("google-github-actions/auth@v3", workflow) | ||
| self.assertIn("google-github-actions/setup-gcloud@v3", workflow) | ||
| self.assertIn("LONGPORT_APP_KEY_SECRET_NAME: ${{ vars.LONGPORT_APP_KEY_SECRET_NAME }}", workflow) | ||
| self.assertIn("LONGPORT_APP_SECRET_SECRET_NAME: ${{ vars.LONGPORT_APP_SECRET_SECRET_NAME }}", workflow) | ||
| self.assertIn("LONGPORT_SECRET_NAME: ${{ vars.LONGPORT_SECRET_NAME }}", workflow) | ||
| self.assertIn('gcloud secrets versions access latest --secret="${LONGPORT_APP_KEY_SECRET_NAME}"', workflow) | ||
| self.assertIn( | ||
| 'gcloud secrets versions access latest --secret="${LONGPORT_APP_SECRET_SECRET_NAME}"', | ||
| workflow, | ||
| ) | ||
| self.assertIn('gcloud secrets versions access latest --secret="${LONGPORT_SECRET_NAME}"', workflow) | ||
| self.assertIn("python -m pip install -e quant-platform-kit pytest longport", workflow) | ||
| self.assertIn('LONGBRIDGE_API_PROBE: "1"', workflow) | ||
| self.assertIn("test_longbridge_fractional_order_api_probe.py", workflow) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| unittest.main() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| #!/usr/bin/env bash | ||
| set -euo pipefail | ||
|
|
||
| repo_dir="$(cd "$(dirname "$0")/.." && pwd)" | ||
| workflow_file="$repo_dir/.github/workflows/longbridge-api-probe.yml" | ||
|
|
||
| grep -Fq "name: LongBridge API Probe" "$workflow_file" | ||
| grep -Fq "workflow_dispatch:" "$workflow_file" | ||
| grep -Fq "environment: longbridge-hk" "$workflow_file" | ||
| grep -Fq "id-token: write" "$workflow_file" | ||
| grep -Fq "repository: QuantStrategyLab/QuantPlatformKit" "$workflow_file" | ||
| grep -Fq "ref: \${{ inputs.qpk_ref }}" "$workflow_file" | ||
| grep -Fq "google-github-actions/auth@v3" "$workflow_file" | ||
| grep -Fq "google-github-actions/setup-gcloud@v3" "$workflow_file" | ||
| grep -Fq "LONGPORT_APP_KEY_SECRET_NAME: \${{ vars.LONGPORT_APP_KEY_SECRET_NAME }}" "$workflow_file" | ||
| grep -Fq "LONGPORT_APP_SECRET_SECRET_NAME: \${{ vars.LONGPORT_APP_SECRET_SECRET_NAME }}" "$workflow_file" | ||
| grep -Fq "LONGPORT_SECRET_NAME: \${{ vars.LONGPORT_SECRET_NAME }}" "$workflow_file" | ||
| grep -Fq 'gcloud secrets versions access latest --secret="${LONGPORT_APP_KEY_SECRET_NAME}"' "$workflow_file" | ||
| grep -Fq 'gcloud secrets versions access latest --secret="${LONGPORT_APP_SECRET_SECRET_NAME}"' "$workflow_file" | ||
| grep -Fq 'gcloud secrets versions access latest --secret="${LONGPORT_SECRET_NAME}"' "$workflow_file" | ||
| grep -Fq "python -m pip install -e quant-platform-kit pytest longport" "$workflow_file" | ||
| grep -Fq 'LONGBRIDGE_API_PROBE: "1"' "$workflow_file" | ||
| grep -Fq "test_longbridge_fractional_order_api_probe.py" "$workflow_file" |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The workflow allows a user-provided
qpk_refto control whichQuantPlatformKitcode is checked out, then exportsLONGPORT_*credentials toGITHUB_ENVbefore runningpython -m pip install -e quant-platform-kit pytest longport. Editable installs can execute package build/install hooks from that checked-out ref, so a malicious or unreviewed ref can read and exfiltrate the broker credentials during install. This is a real secret-exposure path whenever the dispatch input is set to an untrusted ref; move secret export after all untrusted code execution or restrictqpk_refto trusted immutable refs.Useful? React with 👍 / 👎.