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
12 changes: 6 additions & 6 deletions python/scripts/daily_digest_notify.py
Original file line number Diff line number Diff line change
Expand Up @@ -824,9 +824,9 @@ def _block_title(entry: DigestRunEntry, locale: DigestLocale) -> str:

_SCOPE_TAG_ALLOWED = frozenset({"live", "paper", "shadow", "research"})
_HEX_HINT_RE = re.compile(r"^[0-9a-fA-F]{12,}$")
# Broker account ids like IBKR ``U15998061`` / ``u15998061``.
# Broker account ids like IBKR ``U00000008`` / ``u00000008``.
_BROKER_ACCOUNT_ID_RE = re.compile(r"^[Uu]\d{5,}$")
# Scope forms that embed the broker id: ``live-u15998061``, ``paper_U16608560``.
# Scope forms that embed the broker id: ``live-u00000008``, ``paper_U00000009``.
_SCOPE_EMBEDDED_ACCOUNT_RE = re.compile(
r"^(?:live|paper|shadow|research)[_-]([Uu]\d{5,})$",
re.IGNORECASE,
Expand Down Expand Up @@ -870,7 +870,7 @@ def _human_account_hint(raw: str) -> str:
"""Return account_hint when it is already a good human label.

Reject empty values and opaque hex hashes (those are not display tags).
IBKR-style ids such as ``U16608560`` are kept (normalized to ``U######``).
IBKR-style ids such as ``U00000009`` are kept (normalized to ``U######``).
"""

hint = str(raw or "").strip()
Expand All @@ -888,8 +888,8 @@ def _account_label(entry: DigestRunEntry) -> str:
"""Resolve the account half of ``[{platform_id} {account_label}]``.

Preference (universal):
1. human ``account_hint`` / broker id (e.g. IBKR ``U15998061``)
2. broker id embedded in ``account_scope`` (``live-u15998061``)
1. human ``account_hint`` / broker id (e.g. IBKR ``U00000008``)
2. broker id embedded in ``account_scope`` (``live-u00000008``)
3. broker id on ``opaque_account_uid`` when it is already ``U######``
4. normalized scope ``live|paper|shadow|research``
5. short ``opaque_account_uid`` / ``target_id`` last resorts
Expand Down Expand Up @@ -920,7 +920,7 @@ def _account_label(entry: DigestRunEntry) -> str:
def account_block_tag(entry: DigestRunEntry) -> str:
"""Account tag body for ``[tag]`` block titles.

Universal form: ``{platform_id} {account_label}`` — e.g. ``ibkr U15998061``,
Universal form: ``{platform_id} {account_label}`` — e.g. ``ibkr U00000008``,
``schwab live``, ``firstrade paper``. Never hard-code a single venue.
Returns empty string when nothing usable is present.
"""
Expand Down
2 changes: 1 addition & 1 deletion python/tests/test_daily_digest_delivery_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ def test_explicit_producer_execution_status_passthrough(self):
"business_day": "2026-10-09",
"strategy_profile": "tqqq_growth_income",
"actually_ran": True,
"account_hint": "U16608560",
"account_hint": "U00000009",
"fill_count": 0,
"execution_status": "ok_no_order",
"evidence_persistence_status": "persisted",
Expand Down
22 changes: 11 additions & 11 deletions python/tests/test_daily_digest_notify.py
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ def test_omits_missing_observation_fields(self):
rebalance_kind="no_rebalance",
target_id="schwab-primary",
opaque_account_uid=(
"bf2e669106f029a41e6f36dc18f704906ad6078d1f16a171ec0001e992d39b7d"
"000000a100000000000000000000000000000000000000000000000000000000"
),
),
)
Expand All @@ -392,7 +392,7 @@ def test_omits_missing_observation_fields(self):
business_day="2026-10-08", locale="zh", runs=runs
)
)
self.assertIn("[schwab bf2e6691] 💓 【心跳检测】", text) # no scope → platform + short uid
self.assertIn("[schwab 000000a1] 💓 【心跳检测】", text) # no scope → platform + short uid
self.assertNotIn("[schwab-primary]", text)
self.assertIn("半导体趋势收益", text)
self.assertIn("✅ 无需调仓", text)
Expand All @@ -411,7 +411,7 @@ def test_single_schwab_omits_window_and_channel(self):
equity=989.34,
rebalance_kind="no_rebalance",
opaque_account_uid=(
"bf2e669106f029a41e6f36dc18f704906ad6078d1f16a171ec0001e992d39b7d"
"000000a100000000000000000000000000000000000000000000000000000000"
),
target_id="schwab-primary",
account_scope="live",
Expand Down Expand Up @@ -449,7 +449,7 @@ def test_multi_platform_observation_blocks_separated(self):
equity=989.34,
rebalance_kind="no_rebalance",
opaque_account_uid=(
"bf2e669106f029a41e6f36dc18f704906ad6078d1f16a171ec0001e992d39b7d"
"000000a100000000000000000000000000000000000000000000000000000000"
),
target_id="schwab-primary",
account_scope="live",
Expand Down Expand Up @@ -553,7 +553,7 @@ def test_account_block_tag_preference_order(self):
hex_hint = daily_digest_notify.DigestRunEntry(
platform_id="schwab",
strategy_profile="soxl_soxx_trend_income",
account_hint="bf2e669106f029a4",
account_hint="000000a100000000",
account_scope="live",
)
self.assertEqual(
Expand All @@ -571,7 +571,7 @@ def test_account_block_tag_preference_order(self):
strategy_profile="any_strategy",
account_scope=scope,
opaque_account_uid=(
"bf2e669106f029a41e6f36dc18f704906ad6078d1f16a171ec0001e992d39b7d"
"000000a100000000000000000000000000000000000000000000000000000000"
),
target_id=f"{platform}-primary",
)
Expand All @@ -591,12 +591,12 @@ def test_account_block_tag_preference_order(self):
platform_id="schwab",
strategy_profile="soxl_soxx_trend_income",
opaque_account_uid=(
"bf2e669106f029a41e6f36dc18f704906ad6078d1f16a171ec0001e992d39b7d"
"000000a100000000000000000000000000000000000000000000000000000000"
),
target_id="schwab-primary",
)
self.assertEqual(
daily_digest_notify.account_block_tag(uid_beats_target), "schwab bf2e6691"
daily_digest_notify.account_block_tag(uid_beats_target), "schwab 000000a1"
)
target_last = daily_digest_notify.DigestRunEntry(
platform_id="schwab",
Expand Down Expand Up @@ -668,7 +668,7 @@ def test_trade_success_default_fills_conclusion(self):
strategy_label="半导体趋势收益",
target_id="schwab-primary",
opaque_account_uid=(
"bf2e669106f029a41e6f36dc18f704906ad6078d1f16a171ec0001e992d39b7d"
"000000a100000000000000000000000000000000000000000000000000000000"
),
account_scope="live",
fill_count=2,
Expand Down Expand Up @@ -701,7 +701,7 @@ def test_multi_heartbeat_plus_fills_uses_digest_title(self):
strategy_label="半导体趋势收益",
target_id="schwab-primary",
opaque_account_uid=(
"bf2e669106f029a41e6f36dc18f704906ad6078d1f16a171ec0001e992d39b7d"
"000000a100000000000000000000000000000000000000000000000000000000"
),
account_scope="live",
fill_count=None,
Expand Down Expand Up @@ -793,7 +793,7 @@ def test_multi_platform_scope_tags_universal(self):
self.assertIn("[schwab live] 💓 【心跳检测】", text)
self.assertIn("[ibkr live] 💓 【心跳检测】", text)
self.assertIn("[firstrade paper] 💓 【心跳检测】", text)
self.assertNotIn("[bf2e6691]", text)
self.assertNotIn("[000000a1]", text)
self.assertNotIn("[schwab-primary]", text)
self.assertNotIn("[live]", text) # bare scope alone is not the tag

Expand Down
4 changes: 2 additions & 2 deletions schemas/qsl-digest-candidates.v1.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -162,12 +162,12 @@
"account_hint": {
"type": "string",
"maxLength": 64,
"description": "Human display account label when already safe (e.g. IBKR U15998061)."
"description": "Human display account label when already safe (e.g. IBKR U00000008)."
},
"account_scope": {
"type": "string",
"maxLength": 64,
"description": "Runtime account_scope / mode token (e.g. live, paper, live-u15998061)."
"description": "Runtime account_scope / mode token (e.g. live, paper, live-u00000008)."
},
"execution_mode": {
"type": "string",
Expand Down
20 changes: 10 additions & 10 deletions tests/account_facts_validation.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ assert.equal(accountFactsScopesMatch("hk", "HK"), false);
assert.equal(accountFactsScopesMatch("HK", "PAPER"), false);
assert.equal(accountFactsScopesMatch("sg", "HK"), false);
assert.deepEqual([...ACCOUNT_FACTS_PLATFORMS], ["longbridge", "ibkr"]);
assert.equal(accountFactsScopesMatchForPlatform("ibkr", "live-u16608560", "live-u16608560"), true);
assert.equal(accountFactsScopesMatchForPlatform("ibkr", "live-u16608560", "U16608560"), false);
assert.equal(accountFactsScopesMatchForPlatform("ibkr", "live-u00000009", "live-u00000009"), true);
assert.equal(accountFactsScopesMatchForPlatform("ibkr", "live-u00000009", "U00000009"), false);

const account = {
key: "lb-paper",
Expand Down Expand Up @@ -981,10 +981,10 @@ const ibkrAccount = {
key: "tqqq",
label: "tqqq",
target_name: "tqqq",
service_name: "interactive-brokers-quant-live-u16608560-service",
deployment_selector: "live-u16608560",
account_scope: "live-u16608560",
account_selector: "U16608560",
service_name: "interactive-brokers-quant-live-u00000009-service",
deployment_selector: "live-u00000009",
account_scope: "live-u00000009",
account_selector: "U00000009",
supported_domains: ["us_equity"],
};
const ibkrBinding = {
Expand All @@ -995,7 +995,7 @@ const ibkrBinding = {
service_name: ibkrAccount.service_name,
deployment_selector: ibkrAccount.deployment_selector,
account_selector: ibkrAccount.account_selector,
target_id: "ibkr-u16608560",
target_id: "ibkr-u00000009",
source_binding: { kind: IBKR_ACCOUNT_FACTS_SOURCE_KIND, id: "e".repeat(64) },
};
function ibkrHistory(patch = {}) {
Expand Down Expand Up @@ -1184,7 +1184,7 @@ assert.throws(() => normalizeAccountFactsHistoryPayload({
...ibkrHistory(),
snapshot_schema_version: ACCOUNT_FACTS_SNAPSHOT_SCHEMA,
}), /invalid_account_facts_history/);
assert.throws(() => normalizeAccountFactsHistoryPayload(ibkrHistory({ account_ids: ["DU123", "U16608560"] })), /account_facts_identity_mismatch/);
assert.throws(() => normalizeAccountFactsHistoryPayload(ibkrHistory({ account_ids: ["DU123", "U00000009"] })), /account_facts_identity_mismatch/);
assert.throws(() => normalizeAccountFactsHistoryPayload(ibkrHistory({ account_ids: ["DU123"] }), {
expectedPlatform: IBKR_ACCOUNT_FACTS_PLATFORM,
expectedAccountSelector: ibkrBinding.account_selector,
Expand Down Expand Up @@ -1213,7 +1213,7 @@ const normalizedIbkrHistory = normalizeAccountFactsHistoryPayload(acceptedIbkrHi
expectedAccountSelector: ibkrBinding.account_selector,
});
assert.equal(normalizedIbkrHistory.broker_reported_balances[0].net_assets, null);
assert.deepEqual(normalizedIbkrHistory.account_ids, ["U16608560"]);
assert.deepEqual(normalizedIbkrHistory.account_ids, ["U00000009"]);

// Optional broker-reported positions (read-only holdings panel).
assert.equal(Object.hasOwn(normalizedIbkrHistory, "broker_reported_positions"), false, "history without positions stays readable");
Expand Down Expand Up @@ -1353,7 +1353,7 @@ const mixedIbkrSchema = ibkrHistory({ snapshot_schema_version: ACCOUNT_FACTS_SNA
assert.equal((await post(mixedIbkrSchema, ibkrAuth, env)).status, 400);
const wrongIbkrIdentity = await post(ibkrHistory({ account_ids: ["DU123"] }), ibkrAuth, env);
assert.equal(wrongIbkrIdentity.status, 409);
const wrongIbkrScope = await post(ibkrHistory({ account_scope: "U16608560" }), ibkrAuth, env);
const wrongIbkrScope = await post(ibkrHistory({ account_scope: "U00000009" }), ibkrAuth, env);
assert.equal(wrongIbkrScope.status, 409, "native ID is not an account-scope substitute");
const ibkrFortyMinuteStarted = new Date(Date.now() - 41 * 60 * 1000).toISOString();
const ibkrFortyMinuteFinished = new Date(Date.now() - 40 * 60 * 1000).toISOString();
Expand Down
Loading