You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
|`IB_GATEWAY_HOST`| Conditional | Legacy explicit host or IP. If not set, the app falls back to `IB_GATEWAY_INSTANCE_NAME`. |
103
-
|`IB_GATEWAY_INSTANCE_NAME`| Conditional | Recommended shared config name for the GCE instance. Useful when Gateway and Quant share the same GitHub-managed config. |
102
+
|`IB_GATEWAY_INSTANCE_NAME`| Yes | GCE instance name for the IB gateway. |
104
103
|`IB_GATEWAY_ZONE`| Yes | GCE zone (e.g. `us-central1-a`) |
105
104
|`IB_GATEWAY_IP_MODE`| No |`internal` (default) or `external`; for Cloud Run, `internal` with Direct VPC egress is recommended |
106
-
|`IB_GATEWAY_MODE`| No | Recommended shared mode flag. `live` maps to port `4001`, `paper` maps to port `4002`. |
107
-
|`IB_GATEWAY_PORT`| No | Legacy explicit port override. If set together with `IB_GATEWAY_MODE`, it must match (`live`=`4001`, `paper`=`4002`). |
105
+
|`IB_GATEWAY_MODE`| Yes | Required mode flag. `live` maps to port `4001`, `paper` maps to port `4002`. |
108
106
|`IB_CLIENT_ID`| No | IB client ID (default: 1) |
109
107
|`TELEGRAM_TOKEN`| Yes | Telegram bot token |
110
-
|`TELEGRAM_CHAT_ID`| Conditional | Per-service Telegram chat ID. If not set, the app falls back to `GLOBAL_TELEGRAM_CHAT_ID`. |
111
-
|`GLOBAL_TELEGRAM_CHAT_ID`| No | Optional shared Telegram chat ID for teams that keep one common destination across multiple quant services. |
108
+
|`GLOBAL_TELEGRAM_CHAT_ID`| Yes | Telegram chat ID used by this service. |
112
109
|`NOTIFY_LANG`| No |`en` (default) or `zh`|
113
110
114
-
`IB_GATEWAY_HOST` and `IB_GATEWAY_INSTANCE_NAME` are backward-compatible alternatives; one of them must be set. If you use instance-name resolution with `IB_GATEWAY_ZONE`, the service account needs `roles/compute.viewer`. The recommended deployment is Cloud Run with Direct VPC egress to the GCE private IP. Set `IB_GATEWAY_IP_MODE=external` only if you intentionally expose the gateway over a public IP and have locked down API access and firewall rules.
111
+
If you use instance-name resolution with `IB_GATEWAY_ZONE`, the service account needs `roles/compute.viewer`. The recommended deployment is Cloud Run with Direct VPC egress to the GCE private IP. Set `IB_GATEWAY_IP_MODE=external` only if you intentionally expose the gateway over a public IP and have locked down API access and firewall rules.
115
112
116
113
**Recommended shared-config mode**
117
114
@@ -126,8 +123,6 @@ IB_CLIENT_ID=1
126
123
NOTIFY_LANG=zh
127
124
```
128
125
129
-
In this mode, you do not need to set `IB_GATEWAY_PORT` manually; the app derives it from `IB_GATEWAY_MODE`.
130
-
131
126
This shared-config mode is only for the **IBKR pair** (`IBKRQuant` + `IBKRGatewayManager`). It is not meant to become a global secret bundle for unrelated quant repos. Across multiple quant projects, the only broadly reusable runtime settings are usually `GLOBAL_TELEGRAM_CHAT_ID` and `NOTIFY_LANG`.
132
127
133
128
### GitHub-managed Cloud Run env sync
@@ -152,18 +147,18 @@ Recommended setup:
152
147
-`GLOBAL_TELEGRAM_CHAT_ID`
153
148
-`NOTIFY_LANG`
154
149
155
-
On every push to `main`, the workflow updates the existing Cloud Run service with the values above. It does **not** remove legacy `IB_GATEWAY_HOST`, `IB_GATEWAY_PORT`, or`TELEGRAM_CHAT_ID`, so existing deployments keep working. Once you have confirmed the service is reading the new shared values as intended, you can remove the legacy Cloud Run env vars manually.
150
+
On every push to `main`, the workflow updates the existing Cloud Run service with the values above and removes `IB_GATEWAY_HOST`, `IB_GATEWAY_PORT`, and`TELEGRAM_CHAT_ID`.
156
151
157
152
Important:
158
153
159
-
- The workflow only becomes strict when `ENABLE_GITHUB_ENV_SYNC=true`. If this variable is unset, the sync job is skipped and the old Google Cloud Trigger + manual Cloud Run env setup keeps working.
154
+
- The workflow only becomes strict when `ENABLE_GITHUB_ENV_SYNC=true`. If this variable is unset, the sync job is skipped.
160
155
- Here "shared config" still only means the **IBKR pair** (`IBKRQuant` + `IBKRGatewayManager`). `GCP_SA_KEY` and `TELEGRAM_TOKEN` remain repository-specific.
161
156
162
157
### Deployment
163
158
164
159
1.**GCE**: Set up IB Gateway (paper or live) on a GCE instance. Ensure API access is enabled, remote clients are allowed when needed, and use `4001` for `live` or `4002` for `paper`.
165
160
2.**VPC / Subnet**: Put Cloud Run and GCE in the same VPC. For cleaner firewall rules, reserve a dedicated subnet for Cloud Run Direct VPC egress.
166
-
3.**Cloud Run**: Deploy or update this Flask app with Direct VPC egress. You can either keep the legacy pair `IB_GATEWAY_HOST + IB_GATEWAY_PORT`, or use the shared-config pair `IB_GATEWAY_INSTANCE_NAME + IB_GATEWAY_MODE`. In both cases keep `IB_GATEWAY_ZONE` and `IB_GATEWAY_IP_MODE=internal`.
161
+
3.**Cloud Run**: Deploy or update this Flask app with Direct VPC egress. Use `IB_GATEWAY_INSTANCE_NAME + IB_GATEWAY_MODE`, and keep `IB_GATEWAY_ZONE` and `IB_GATEWAY_IP_MODE=internal`.
167
162
4.**Firewall**: Allow TCP `4001` (`live`) or `4002` (`paper`) from the Cloud Run egress subnet CIDR to the GCE instance.
168
163
5.**Cloud Scheduler**: Create a job: `45 15 * * 1-5` (America/New_York), POST to the Cloud Run URL. The code handles market calendar checks internally.
169
164
6.**Optional public-IP mode**: Only if you cannot use VPC, set `IB_GATEWAY_IP_MODE=external`, expose the GCE public IP deliberately, and restrict source ranges tightly. This is not the default path.
0 commit comments