alpha-strike 0.3.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (74) hide show
  1. alpha_strike-0.3.0/.claude/commands/pre-release.md +67 -0
  2. alpha_strike-0.3.0/.dockerignore +28 -0
  3. alpha_strike-0.3.0/.env.example +32 -0
  4. alpha_strike-0.3.0/.env.op +7 -0
  5. alpha_strike-0.3.0/.envrc +1 -0
  6. alpha_strike-0.3.0/.github/ISSUE_TEMPLATE/bug_report.yml +99 -0
  7. alpha_strike-0.3.0/.github/ISSUE_TEMPLATE/bug_report_ja.yml +99 -0
  8. alpha_strike-0.3.0/.github/ISSUE_TEMPLATE/config.yml +11 -0
  9. alpha_strike-0.3.0/.github/ISSUE_TEMPLATE/feature_request.yml +39 -0
  10. alpha_strike-0.3.0/.github/ISSUE_TEMPLATE/feature_request_ja.yml +39 -0
  11. alpha_strike-0.3.0/.github/PULL_REQUEST_TEMPLATE.md +58 -0
  12. alpha_strike-0.3.0/.github/codeql/codeql-config.yml +17 -0
  13. alpha_strike-0.3.0/.github/copilot-instructions.md +93 -0
  14. alpha_strike-0.3.0/.github/dependabot.yml +47 -0
  15. alpha_strike-0.3.0/.github/workflows/ci.yml +33 -0
  16. alpha_strike-0.3.0/.github/workflows/codeql.yml +44 -0
  17. alpha_strike-0.3.0/.github/workflows/release.yml +41 -0
  18. alpha_strike-0.3.0/.gitignore +35 -0
  19. alpha_strike-0.3.0/.python-version +1 -0
  20. alpha_strike-0.3.0/AGENTS.md +1 -0
  21. alpha_strike-0.3.0/CHANGELOG.md +170 -0
  22. alpha_strike-0.3.0/CLAUDE.md +78 -0
  23. alpha_strike-0.3.0/CODE_OF_CONDUCT.en.md +83 -0
  24. alpha_strike-0.3.0/CODE_OF_CONDUCT.md +83 -0
  25. alpha_strike-0.3.0/CONTRIBUTING.en.md +197 -0
  26. alpha_strike-0.3.0/CONTRIBUTING.md +229 -0
  27. alpha_strike-0.3.0/Dockerfile +33 -0
  28. alpha_strike-0.3.0/LICENSE +200 -0
  29. alpha_strike-0.3.0/Makefile +15 -0
  30. alpha_strike-0.3.0/NOTICE +9 -0
  31. alpha_strike-0.3.0/PKG-INFO +221 -0
  32. alpha_strike-0.3.0/README.en.md +185 -0
  33. alpha_strike-0.3.0/README.md +187 -0
  34. alpha_strike-0.3.0/SECURITY.en.md +86 -0
  35. alpha_strike-0.3.0/SECURITY.md +86 -0
  36. alpha_strike-0.3.0/cliff.toml +43 -0
  37. alpha_strike-0.3.0/docker-compose.yml +40 -0
  38. alpha_strike-0.3.0/docs/moomoo-API-Doc-jp-Python.md +15082 -0
  39. alpha_strike-0.3.0/docs/moomoo_futud.md +101 -0
  40. alpha_strike-0.3.0/docs/ops/paper-trading-go-live.md +221 -0
  41. alpha_strike-0.3.0/docs/ops/vm-provisioning.md +697 -0
  42. alpha_strike-0.3.0/docs/setup.md +121 -0
  43. alpha_strike-0.3.0/docs/superpowers/plans/2026-04-16-solid-phase1-alpha-strike.md +1391 -0
  44. alpha_strike-0.3.0/docs/tradingview.md +304 -0
  45. alpha_strike-0.3.0/docs/webhook-payload-v2.md +149 -0
  46. alpha_strike-0.3.0/ecosystem.config.js +36 -0
  47. alpha_strike-0.3.0/nginx.conf +41 -0
  48. alpha_strike-0.3.0/pyproject.toml +76 -0
  49. alpha_strike-0.3.0/release.sh +42 -0
  50. alpha_strike-0.3.0/scripts/check_memory.sh +140 -0
  51. alpha_strike-0.3.0/scripts/cleanup_simulate_orders.py +229 -0
  52. alpha_strike-0.3.0/scripts/go_live_smoke.sh +118 -0
  53. alpha_strike-0.3.0/scripts/run_apt_maintenance.sh +138 -0
  54. alpha_strike-0.3.0/scripts/show_simulate_status.py +378 -0
  55. alpha_strike-0.3.0/src/alpha_strike/__init__.py +10 -0
  56. alpha_strike-0.3.0/src/alpha_strike/cli.py +68 -0
  57. alpha_strike-0.3.0/src/alpha_strike/event_logger.py +74 -0
  58. alpha_strike-0.3.0/src/alpha_strike/handlers/__init__.py +5 -0
  59. alpha_strike-0.3.0/src/alpha_strike/handlers/base.py +22 -0
  60. alpha_strike-0.3.0/src/alpha_strike/handlers/moomoo_handler.py +195 -0
  61. alpha_strike-0.3.0/src/alpha_strike/handlers/oanda_handler.py +122 -0
  62. alpha_strike-0.3.0/src/alpha_strike/models.py +186 -0
  63. alpha_strike-0.3.0/src/alpha_strike/services/__init__.py +0 -0
  64. alpha_strike-0.3.0/src/alpha_strike/services/fill_service.py +274 -0
  65. alpha_strike-0.3.0/src/alpha_strike/services/order_service.py +37 -0
  66. alpha_strike-0.3.0/src/alpha_strike/webhook_server.py +371 -0
  67. alpha_strike-0.3.0/tests/__init__.py +0 -0
  68. alpha_strike-0.3.0/tests/test_fill_service.py +114 -0
  69. alpha_strike-0.3.0/tests/test_main.py +63 -0
  70. alpha_strike-0.3.0/tests/test_moomoo_handler.py +208 -0
  71. alpha_strike-0.3.0/tests/test_oanda_handler.py +184 -0
  72. alpha_strike-0.3.0/tests/test_order_service.py +57 -0
  73. alpha_strike-0.3.0/tests/test_webhook_server.py +614 -0
  74. alpha_strike-0.3.0/uv.lock +1352 -0
@@ -0,0 +1,67 @@
1
+ ---
2
+ name: pre-release
3
+ description: PyPI リリース前のローカル検証 → リリース実行
4
+ command: true
5
+ ---
6
+
7
+ # pre-release コマンド
8
+
9
+ alpha-strike を PyPI に公開する前にローカルで lint / test / build を検証し、問題なければリリースする。
10
+
11
+ ## 使い方
12
+
13
+ ```
14
+ /pre-release [patch|minor|major]
15
+ ```
16
+
17
+ 引数を省略した場合は `patch` として扱う。
18
+
19
+ ## 実行手順
20
+
21
+ 1. **作業ディレクトリの確認**
22
+
23
+ alpha-strike リポジトリのルートにいること、かつ `main` ブランチにいることを確認する。
24
+
25
+ ```bash
26
+ git branch --show-current
27
+ git status
28
+ ```
29
+
30
+ 未コミットの変更があれば中断してユーザーに確認を求める。
31
+
32
+ 2. **ローカル検証**
33
+
34
+ ```bash
35
+ uv sync --all-groups
36
+ uv run ruff check .
37
+ uv run pytest -q
38
+ uv build
39
+ ```
40
+
41
+ wheel / sdist が `dist/alpha_strike-*.whl` / `dist/alpha_strike-*.tar.gz` として生成されることを確認。
42
+ 失敗した場合は中断してエラー内容をユーザーに報告する。
43
+
44
+ 3. **バージョン確認**
45
+
46
+ 現在のバージョンと、バンプ後のバージョンをユーザーに提示して確認を求める。
47
+
48
+ ```bash
49
+ grep '^version' pyproject.toml
50
+ ```
51
+
52
+ 4. **リリース実行**
53
+
54
+ ユーザーの承認を得てから実行する。
55
+
56
+ ```bash
57
+ bash release.sh ${PART}
58
+ ```
59
+
60
+ `release.sh` がタグを push すると `.github/workflows/release.yml` が走り、
61
+ PyPI Trusted Publisher 経由で wheel / sdist が PyPI に公開される。
62
+
63
+ ## 注意
64
+
65
+ - `release.sh` は `git push --tags` まで実行するため、実行前に必ずユーザーの承認を取ること。
66
+ - `git-cliff` と `bump-my-version` が必要(`uv sync --all-groups` で導入済み)。
67
+ - PyPI 公開には事前に PyPI の Trusted Publisher 設定で `alforge-labs/alpha-strike` を登録する必要がある。
@@ -0,0 +1,28 @@
1
+ # 機密情報・環境変数(絶対にイメージに含めないこと)
2
+ .env
3
+
4
+ # Python キャッシュ
5
+ __pycache__/
6
+ *.py[oc]
7
+ .venv/
8
+ .pytest_cache/
9
+ .coverage
10
+ htmlcov/
11
+
12
+ # Git
13
+ .git/
14
+ .gitignore
15
+
16
+ # IDE
17
+ .vscode/
18
+ .idea/
19
+
20
+ # macOS
21
+ .DS_Store
22
+
23
+ # PM2 ログ
24
+ logs/
25
+
26
+ # ドキュメント(本番イメージ不要)
27
+ docs/
28
+ *.md
@@ -0,0 +1,32 @@
1
+ # Alpha-Strike 環境変数サンプル
2
+ # このファイルをコピーして .env を作成し、実際の値を設定してください。
3
+ # .env はバージョン管理対象外(.gitignore に記載済み)です。
4
+ #
5
+ # [セキュリティ]
6
+ # VPS などのサーバーに配置する場合: chmod 600 .env でアクセス権を制限してください。
7
+ # 開発者向け: 1Password CLI (op) を使用する場合は .env.op を参照してください。
8
+ # → brew install 1password-cli && make run
9
+
10
+ # TradingView Webhook認証パスフレーズ(必須)
11
+ # TradingViewのアラート設定で同じ値を使用してください
12
+ WEBHOOK_PASSPHRASE=your-secret-passphrase
13
+
14
+ # OANDA証券 設定
15
+ # Personal Access Token(OANDAのマイページから取得)
16
+ OANDA_API_KEY=your-oanda-personal-access-token
17
+ # 口座ID(OANDAのマイページで確認)
18
+ OANDA_ACCOUNT_ID=your-account-id
19
+ # テスト時は必ずPRACTICEを使用してください(LIVE=本番)
20
+ OANDA_ENV=PRACTICE
21
+
22
+ # moomoo証券 (Futu OpenAPI) 設定
23
+ # VPS上で systemd 起動した Futu OpenD へ Docker コンテナから接続するための設定
24
+ # ローカル開発時は 127.0.0.1 に変更してください
25
+ MOOMOO_HOST=host.docker.internal
26
+ MOOMOO_PORT=11111
27
+ # テスト時は必ずSIMULATEを使用してください(REAL=本番)
28
+ MOOMOO_TRD_ENV=SIMULATE
29
+
30
+ # イベントログ保存先(docker-compose.yml の volumes マウント先と一致させること)
31
+ # ローカル開発時: LIVE_EVENTS_PATH=./data/events
32
+ LIVE_EVENTS_PATH=/app/data/events
@@ -0,0 +1,7 @@
1
+ WEBHOOK_PASSPHRASE=op://AlphaTrade/alpha-strike/WEBHOOK_PASSPHRASE
2
+ OANDA_API_KEY=op://AlphaTrade/alpha-strike/OANDA_API_KEY
3
+ OANDA_ACCOUNT_ID=op://AlphaTrade/alpha-strike/OANDA_ACCOUNT_ID
4
+ OANDA_ENV=op://AlphaTrade/alpha-strike/OANDA_ENV
5
+ MOOMOO_HOST=op://AlphaTrade/alpha-strike/MOOMOO_HOST
6
+ MOOMOO_PORT=op://AlphaTrade/alpha-strike/MOOMOO_PORT
7
+ MOOMOO_TRD_ENV=op://AlphaTrade/alpha-strike/MOOMOO_TRD_ENV
@@ -0,0 +1 @@
1
+ dotenv
@@ -0,0 +1,99 @@
1
+ name: 🐛 Bug Report (English)
2
+ description: Report a reproducible bug to help us improve alpha-strike.
3
+ title: "[Bug]: "
4
+ labels: ["bug", "needs-triage"]
5
+ body:
6
+ - type: markdown
7
+ attributes:
8
+ value: |
9
+ Thanks for taking the time to file a bug report! Please fill out the sections below.
10
+ Before submitting, please [search existing issues](https://github.com/alforge-labs/alpha-strike/issues) to avoid duplicates.
11
+
12
+ - type: textarea
13
+ id: description
14
+ attributes:
15
+ label: What happened?
16
+ description: A clear and concise description of the bug.
17
+ placeholder: When I run `vis serve`, ...
18
+ validations:
19
+ required: true
20
+
21
+ - type: textarea
22
+ id: reproduction
23
+ attributes:
24
+ label: Steps to reproduce
25
+ description: Minimal steps to reproduce the issue.
26
+ placeholder: |
27
+ 1. Run `vis serve --forge-dir /path/to/data`
28
+ 2. Open browser at http://127.0.0.1:8000/browse
29
+ 3. Click on strategy "X"
30
+ 4. See error
31
+ validations:
32
+ required: true
33
+
34
+ - type: textarea
35
+ id: expected
36
+ attributes:
37
+ label: Expected behavior
38
+ description: What did you expect to happen?
39
+ validations:
40
+ required: true
41
+
42
+ - type: input
43
+ id: version
44
+ attributes:
45
+ label: alpha-strike version
46
+ description: Output of `vis --version` or the value in pyproject.toml.
47
+ placeholder: "0.1.1"
48
+ validations:
49
+ required: true
50
+
51
+ - type: dropdown
52
+ id: os
53
+ attributes:
54
+ label: Operating System
55
+ options:
56
+ - macOS
57
+ - Linux
58
+ - Windows
59
+ - Other
60
+ validations:
61
+ required: true
62
+
63
+ - type: input
64
+ id: python-version
65
+ attributes:
66
+ label: Python version
67
+ description: Output of `python --version`.
68
+ placeholder: "3.12.x"
69
+ validations:
70
+ required: true
71
+
72
+ - type: input
73
+ id: browser
74
+ attributes:
75
+ label: Browser (if frontend issue)
76
+ placeholder: "Chrome 132 / Firefox 134 / Safari 18"
77
+
78
+ - type: textarea
79
+ id: logs
80
+ attributes:
81
+ label: Logs / error output
82
+ description: Paste any relevant logs, stack traces, or browser console errors.
83
+ render: shell
84
+
85
+ - type: textarea
86
+ id: additional
87
+ attributes:
88
+ label: Additional context
89
+ description: Anything else that might help us understand the problem.
90
+
91
+ - type: checkboxes
92
+ id: confirm
93
+ attributes:
94
+ label: Pre-submit checklist
95
+ options:
96
+ - label: I have searched existing issues for duplicates
97
+ required: true
98
+ - label: I am running a supported version of alpha-strike
99
+ required: true
@@ -0,0 +1,99 @@
1
+ name: 🐛 バグ報告(日本語)
2
+ description: 再現可能なバグを報告して alpha-strike の改善にご協力ください。
3
+ title: "[Bug]: "
4
+ labels: ["bug", "needs-triage"]
5
+ body:
6
+ - type: markdown
7
+ attributes:
8
+ value: |
9
+ バグ報告をいただきありがとうございます。以下の項目にご記入ください。
10
+ 提出前に [既存の Issue](https://github.com/alforge-labs/alpha-strike/issues) を検索し、重複を避けてください。
11
+
12
+ - type: textarea
13
+ id: description
14
+ attributes:
15
+ label: 何が起きましたか?
16
+ description: バグの内容を簡潔に説明してください。
17
+ placeholder: vis serve を実行すると...
18
+ validations:
19
+ required: true
20
+
21
+ - type: textarea
22
+ id: reproduction
23
+ attributes:
24
+ label: 再現手順
25
+ description: 最小限の再現手順をご記入ください。
26
+ placeholder: |
27
+ 1. `vis serve --forge-dir /path/to/data` を実行
28
+ 2. ブラウザで http://127.0.0.1:8000/browse を開く
29
+ 3. 戦略 "X" をクリック
30
+ 4. エラーが表示される
31
+ validations:
32
+ required: true
33
+
34
+ - type: textarea
35
+ id: expected
36
+ attributes:
37
+ label: 期待する動作
38
+ description: 本来どうなるべきだと考えていますか?
39
+ validations:
40
+ required: true
41
+
42
+ - type: input
43
+ id: version
44
+ attributes:
45
+ label: alpha-strike のバージョン
46
+ description: "`vis --version` の出力、または pyproject.toml の値。"
47
+ placeholder: "0.1.1"
48
+ validations:
49
+ required: true
50
+
51
+ - type: dropdown
52
+ id: os
53
+ attributes:
54
+ label: OS
55
+ options:
56
+ - macOS
57
+ - Linux
58
+ - Windows
59
+ - その他
60
+ validations:
61
+ required: true
62
+
63
+ - type: input
64
+ id: python-version
65
+ attributes:
66
+ label: Python バージョン
67
+ description: "`python --version` の出力。"
68
+ placeholder: "3.12.x"
69
+ validations:
70
+ required: true
71
+
72
+ - type: input
73
+ id: browser
74
+ attributes:
75
+ label: ブラウザ(フロントエンドの問題の場合)
76
+ placeholder: "Chrome 132 / Firefox 134 / Safari 18"
77
+
78
+ - type: textarea
79
+ id: logs
80
+ attributes:
81
+ label: ログ・エラー出力
82
+ description: 関連するログ、スタックトレース、ブラウザコンソールエラーを貼り付けてください。
83
+ render: shell
84
+
85
+ - type: textarea
86
+ id: additional
87
+ attributes:
88
+ label: 追加情報
89
+ description: 問題の理解に役立つ情報があればご記入ください。
90
+
91
+ - type: checkboxes
92
+ id: confirm
93
+ attributes:
94
+ label: 提出前チェックリスト
95
+ options:
96
+ - label: 既存 Issue を検索し重複がないことを確認した
97
+ required: true
98
+ - label: サポート対象バージョンの alpha-strike を使用している
99
+ required: true
@@ -0,0 +1,11 @@
1
+ blank_issues_enabled: false
2
+ contact_links:
3
+ - name: 📖 Documentation / 公式ドキュメント
4
+ url: https://alforgelabs.com/ja/docs/guides/alpha-strike-setup/
5
+ about: Read the docs before opening an issue. / Issue を立てる前に公式ドキュメントを確認してください。
6
+ - name: 💬 Discussions
7
+ url: https://github.com/alforge-labs/alpha-strike/discussions
8
+ about: Ask questions or start a discussion. / 質問・議論はこちらから。
9
+ - name: 🛡️ Security vulnerability / セキュリティ脆弱性
10
+ url: https://github.com/alforge-labs/alpha-strike/security/advisories/new
11
+ about: Do NOT open a public issue. Use GitHub Security Advisories. / セキュリティ問題は public Issue ではなく Security Advisories で報告してください。
@@ -0,0 +1,39 @@
1
+ name: 💡 Feature Request (English)
2
+ description: Suggest an idea or enhancement for alpha-strike.
3
+ title: "[Feature]: "
4
+ labels: ["enhancement", "needs-triage"]
5
+ body:
6
+ - type: markdown
7
+ attributes:
8
+ value: |
9
+ Thanks for suggesting an enhancement! Please describe your idea below.
10
+ Search [existing issues](https://github.com/alforge-labs/alpha-strike/issues?q=is%3Aissue+label%3Aenhancement) first to avoid duplicates.
11
+
12
+ - type: textarea
13
+ id: problem
14
+ attributes:
15
+ label: Problem / motivation
16
+ description: What problem does this feature solve? What is the use case?
17
+ placeholder: When I'm comparing 5+ strategies, I can't easily ...
18
+ validations:
19
+ required: true
20
+
21
+ - type: textarea
22
+ id: proposal
23
+ attributes:
24
+ label: Proposed solution
25
+ description: How would you like this to work? UI sketches, API mockups, sample code all welcome.
26
+ validations:
27
+ required: true
28
+
29
+ - type: textarea
30
+ id: alternatives
31
+ attributes:
32
+ label: Alternatives considered
33
+ description: Other approaches you've considered, if any.
34
+
35
+ - type: textarea
36
+ id: additional
37
+ attributes:
38
+ label: Additional context
39
+ description: Screenshots, links to similar features in other tools, etc.
@@ -0,0 +1,39 @@
1
+ name: 💡 機能要望(日本語)
2
+ description: alpha-strike の改善案・新機能を提案してください。
3
+ title: "[Feature]: "
4
+ labels: ["enhancement", "needs-triage"]
5
+ body:
6
+ - type: markdown
7
+ attributes:
8
+ value: |
9
+ ご提案ありがとうございます。アイデアの詳細をご記入ください。
10
+ 提出前に [既存の Issue](https://github.com/alforge-labs/alpha-strike/issues?q=is%3Aissue+label%3Aenhancement) を検索し、重複を避けてください。
11
+
12
+ - type: textarea
13
+ id: problem
14
+ attributes:
15
+ label: 解決したい課題・動機
16
+ description: この機能が解決する問題は何ですか?ユースケースを教えてください。
17
+ placeholder: 5戦略以上を比較する際に...
18
+ validations:
19
+ required: true
20
+
21
+ - type: textarea
22
+ id: proposal
23
+ attributes:
24
+ label: 提案する解決策
25
+ description: どのように動作してほしいか、UI スケッチ・API モック・サンプルコードなどあれば歓迎です。
26
+ validations:
27
+ required: true
28
+
29
+ - type: textarea
30
+ id: alternatives
31
+ attributes:
32
+ label: 検討した代替案
33
+ description: 他に検討したアプローチがあればご記入ください。
34
+
35
+ - type: textarea
36
+ id: additional
37
+ attributes:
38
+ label: 追加情報
39
+ description: スクリーンショット、他ツールでの類似機能へのリンクなど。
@@ -0,0 +1,58 @@
1
+ <!--
2
+ 日本語ガイド: https://github.com/alforge-labs/alpha-strike/blob/main/CONTRIBUTING.md
3
+ English guide: https://github.com/alforge-labs/alpha-strike/blob/main/CONTRIBUTING.en.md
4
+ -->
5
+
6
+ ## 概要 / Summary
7
+
8
+ <!--
9
+ この PR で何を変更したかを 1〜3 行で説明してください。
10
+ Briefly describe what this PR changes (1-3 lines).
11
+ -->
12
+
13
+ ## 関連 Issue / Related Issue
14
+
15
+ <!--
16
+ Closes #123 のように記載してください(マージ時に自動で Issue がクローズされます)。
17
+ Use `Closes #123` to auto-close the related issue on merge.
18
+ -->
19
+
20
+ Closes #
21
+
22
+ ## 変更内容 / Changes
23
+
24
+ <!--
25
+ - 主な変更点を箇条書きで
26
+ - Key changes as bullet points
27
+ -->
28
+
29
+ -
30
+
31
+ ## テスト / Testing
32
+
33
+ <!--
34
+ - [x] 単体テストを追加・更新した / Added or updated unit tests
35
+ - [x] CI が緑 / CI is green
36
+ -->
37
+
38
+ - [ ] バックエンドテスト: `uv run pytest tests/ -v`
39
+ - [ ] バックエンド Lint: `uv run ruff check src/ tests/`
40
+ - [ ] フロントエンドテスト: `cd frontend && pnpm run test:ci`
41
+ - [ ] フロントエンド Lint: `cd frontend && pnpm run lint`
42
+ - [ ] フロントエンドビルド: `cd frontend && pnpm run build`
43
+ - [ ] E2E(UI 変更時): `cd frontend && pnpm run e2e`
44
+ - [ ] スクリーンショット再撮影(UI 変更時): `cd frontend && pnpm run screenshots`
45
+
46
+ ## スクリーンショット / Screenshots
47
+
48
+ <!--
49
+ UI 変更がある場合、Before / After のスクリーンショットを貼ってください。
50
+ For UI changes, paste before/after screenshots.
51
+ -->
52
+
53
+ ## チェックリスト / Checklist
54
+
55
+ - [ ] [CONTRIBUTING.md](../blob/main/CONTRIBUTING.md) を読んだ / Read CONTRIBUTING
56
+ - [ ] Conventional Commits 形式でコミットしている / Commits follow Conventional Commits
57
+ - [ ] 公開 API / CLI / 設定変更時は alforge-labs ドキュメントも更新 / Public API/CLI/config changes update alforge-labs docs
58
+ - [ ] 破壊的変更がある場合 PR 説明欄に明記 / Breaking changes are clearly noted
@@ -0,0 +1,17 @@
1
+ name: alpha-strike CodeQL config
2
+
3
+ # 既定の `security-and-quality` に加えて `security-extended` も有効化する。
4
+ # `security-extended` は精度の高い高重要度クエリのみだが、デフォルトより
5
+ # 範囲が広い(SQL injection / SSRF / path traversal 等の疑わしい
6
+ # データフローもアラート対象になる)。
7
+ queries:
8
+ - uses: security-and-quality
9
+ - uses: security-extended
10
+
11
+ # 解析対象から除外するパス。
12
+ # - テストフィクスチャ / __pycache__ / dist
13
+ paths-ignore:
14
+ - "tests/fixtures/**"
15
+ - "**/__pycache__/**"
16
+ - "dist/**"
17
+ - "build/**"
@@ -0,0 +1,93 @@
1
+ # Alpha-Strike — Copilot Instructions
2
+
3
+ FastAPI webhook server that receives TradingView alerts and routes orders to OANDA or moomoo brokers.
4
+
5
+ ## Commands
6
+
7
+ ```bash
8
+ uv sync # install / update dependencies
9
+ uv run uvicorn webhook_server:app --host 0.0.0.0 --port 8080 --reload # dev server
10
+ uv run pytest # full test suite
11
+ uv run pytest tests/test_oanda_handler.py -v # single test file
12
+ uv run pytest tests/test_webhook_server.py::test_name -v # single test
13
+ uv run ruff check . # lint
14
+ ```
15
+
16
+ Requires Python 3.14. Add packages with `uv add <package>`, not `pip install`.
17
+
18
+ ## Architecture
19
+
20
+ ```
21
+ POST /webhook → webhook_server.py → handlers/oanda_handler.py → OANDA REST API v20
22
+ → handlers/moomoo_handler.py → moomoo OpenD (local)
23
+ POST /events/trade-closed → event_logger.py → JSONL files
24
+ ```
25
+
26
+ **Entry point**: `webhook_server.py` (FastAPI + slowapi rate limiting)
27
+
28
+ **Handlers** (`handlers/`):
29
+ - `oanda_handler.py` — OANDA REST API v20 (`api-fxpractice.oanda.com` / `api-fxtrade.oanda.com`)
30
+ - `moomoo_handler.py` — moomoo/Futu OpenAPI via OpenD local gateway
31
+
32
+ **Event logger**: `event_logger.py` — writes `SignalEvent`, `OrderEvent`, `FillEvent`, `TradeClosedEvent` as JSONL to `$LIVE_EVENTS_PATH` (format: `YYYY-MM-DD.<broker>.jsonl`)
33
+
34
+ **Models**: `models.py` — all Pydantic models (`WebhookPayload`, `OrderResult`, event types)
35
+
36
+ ## Key Implementation Details
37
+
38
+ ### OANDA instrument conversion (`oanda_handler.py`)
39
+ - `FX` / `COMMODITY`: `USDJPY` → `USD_JPY` (split 6-char ticker at position 3)
40
+ - `US` / `INDEX`: `AAPL` → `AAPL_USD` (append `_USD`)
41
+ - Other: pass through as-is
42
+
43
+ ### OANDA SELL orders
44
+ `units` must be negative for SELL (e.g., `-1000`).
45
+
46
+ ### moomoo asset classes
47
+ - `HK` → `OpenHKTradeContext`; all others → `OpenUSTradeContext`
48
+ - Ticker format: `US.AAPL`, `HK.00700`
49
+
50
+ ### OpenD pre-flight check
51
+ `moomoo_handler.py` does a TCP connection check to `MOOMOO_HOST:MOOMOO_PORT` (3s timeout) before placing any order. Raises `RuntimeError` if unreachable. Start OpenD before the server.
52
+
53
+ ### Opposite-fill detection
54
+ Both handlers detect when an incoming fill closes an existing open position (opposite-side fill for same strategy/ticker). Generates `TradeClosedEvent` automatically. For reversal fills (quantity exceeds open position), the excess becomes a new `FillEvent` with a fresh `trade_id`.
55
+
56
+ ### Passphrase authentication
57
+ All endpoints (`/webhook`, `/events/trade-closed`) validate `passphrase` against `WEBHOOK_PASSPHRASE` env var. Use `hmac.compare_digest` to prevent timing attacks.
58
+
59
+ ## Environment Variables
60
+
61
+ | Variable | Required | Default | Description |
62
+ |----------|----------|---------|-------------|
63
+ | `WEBHOOK_PASSPHRASE` | Yes | — | TradingView auth passphrase |
64
+ | `LIVE_EVENTS_PATH` | No | — | JSONL event output directory |
65
+ | `OANDA_API_KEY` | OANDA | — | Personal Access Token |
66
+ | `OANDA_ACCOUNT_ID` | OANDA | — | Account ID |
67
+ | `OANDA_ENV` | OANDA | `PRACTICE` | `PRACTICE` or `LIVE` |
68
+ | `MOOMOO_HOST` | moomoo | `127.0.0.1` | OpenD host |
69
+ | `MOOMOO_PORT` | moomoo | `11111` | OpenD port |
70
+ | `MOOMOO_TRD_ENV` | moomoo | `SIMULATE` | `SIMULATE` or `REAL` |
71
+
72
+ ## Webhook Payload
73
+
74
+ ```json
75
+ {
76
+ "passphrase": "secret",
77
+ "broker": "oanda",
78
+ "asset_class": "FX",
79
+ "action": "buy",
80
+ "ticker": "USDJPY",
81
+ "quantity": 1000
82
+ }
83
+ ```
84
+
85
+ `broker` is `"oanda"` or `"moomoo"`. `action` is `"buy"` or `"sell"`.
86
+
87
+ ## Docker
88
+
89
+ ```bash
90
+ docker compose up -d # production (port 8080, nginx reverse proxy)
91
+ ```
92
+
93
+ `ecosystem.config.js` is a PM2 config for non-Docker deployments.
@@ -0,0 +1,47 @@
1
+ version: 2
2
+ updates:
3
+ # Python パッケージ(uv が pyproject.toml + uv.lock を使うが、Dependabot は pip エコシステムとして扱う)
4
+ - package-ecosystem: "pip"
5
+ directory: "/"
6
+ schedule:
7
+ interval: "weekly"
8
+ day: "monday"
9
+ open-pull-requests-limit: 5
10
+ labels:
11
+ - "dependencies"
12
+ - "python"
13
+ commit-message:
14
+ prefix: "chore"
15
+ include: "scope"
16
+ groups:
17
+ fastapi:
18
+ patterns:
19
+ - "fastapi"
20
+ - "starlette"
21
+ - "uvicorn*"
22
+ pydantic:
23
+ patterns:
24
+ - "pydantic*"
25
+ moomoo-sdk:
26
+ patterns:
27
+ - "futu-api"
28
+ - "moomoo-api"
29
+ test:
30
+ patterns:
31
+ - "pytest*"
32
+ lint:
33
+ patterns:
34
+ - "ruff"
35
+
36
+ # GitHub Actions ワークフロー
37
+ - package-ecosystem: "github-actions"
38
+ directory: "/"
39
+ schedule:
40
+ interval: "weekly"
41
+ day: "monday"
42
+ labels:
43
+ - "dependencies"
44
+ - "ci"
45
+ commit-message:
46
+ prefix: "ci"
47
+ include: "scope"
@@ -0,0 +1,33 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches: [main]
6
+ pull_request:
7
+ branches: [main]
8
+
9
+ permissions:
10
+ contents: read
11
+
12
+ jobs:
13
+ lint-and-test:
14
+ runs-on: ubuntu-latest
15
+ steps:
16
+ - uses: actions/checkout@v6
17
+
18
+ - name: Install uv
19
+ uses: astral-sh/setup-uv@v7
20
+ with:
21
+ version: "latest"
22
+
23
+ - name: Set up Python
24
+ run: uv python install 3.12
25
+
26
+ - name: Install dependencies
27
+ run: uv sync --all-groups
28
+
29
+ - name: Lint (ruff)
30
+ run: uv run ruff check .
31
+
32
+ - name: Test (pytest)
33
+ run: uv run pytest tests/ -q