Skip to content

Commit bbd60e1

Browse files
Pigbibicursoragent
andauthored
Show full account in notifications and sync cash-only execution tests. (#131)
Display full Firstrade account IDs in user-facing probe/rebalance messages and align test expectations with cash-only equity execution defaults from main. Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 9094dee commit bbd60e1

8 files changed

Lines changed: 18 additions & 17 deletions

application/rebalance_service.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,7 @@ def log_message(message: str) -> None:
492492
result = {
493493
"ok": True,
494494
"api_kind": "unofficial-reverse-engineered",
495-
"account": masked_account,
495+
"account": account,
496496
"strategy_profile": strategy_runtime.profile,
497497
"strategy_display_name": strategy_runtime.display_name,
498498
"dry_run_only": settings.dry_run_only,
@@ -594,7 +594,7 @@ def log_message(message: str) -> None:
594594
result = {
595595
"ok": not execution_blocked,
596596
"api_kind": "unofficial-reverse-engineered",
597-
"account": mask_account_id(account),
597+
"account": account,
598598
"strategy_profile": strategy_runtime.profile,
599599
"strategy_display_name": strategy_runtime.display_name,
600600
"dry_run_only": settings.dry_run_only,

application/session_check_service.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ def persist_session_check_maintenance(
291291
as_of = now or _utcnow()
292292
payload = {
293293
"checked_at": as_of.isoformat(),
294-
"account": mask_account_id(account),
294+
"account": account,
295295
"session_reused": session_reused,
296296
"strategy_profile": decision.strategy_profile,
297297
"strategy_cadence": decision.strategy_cadence,
@@ -332,7 +332,7 @@ def build_account_funds_snapshot(
332332
as_of = now or _utcnow()
333333
snapshot: dict[str, Any] = {
334334
"as_of": as_of.isoformat(),
335-
"account": mask_account_id(account),
335+
"account": account,
336336
"session_reused": session_reused,
337337
"account_summaries": account_summaries,
338338
"balance_metrics": selected_numeric_metrics(balances, BALANCE_KEYWORDS),
@@ -445,7 +445,7 @@ def run_session_check(
445445
result: dict[str, Any] = {
446446
"ok": True,
447447
"api_kind": "unofficial-reverse-engineered",
448-
"account": mask_account_id(account),
448+
"account": account,
449449
"session_reused": session_reused,
450450
"funds_snapshot": snapshot,
451451
"snapshot_persisted": snapshot_persisted,

tests/test_decision_mapper.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,8 @@ def test_value_decision_without_threshold_uses_platform_default():
160160
strategy_profile="russell_top50_leader_rotation",
161161
)
162162

163-
assert plan["execution"]["trade_threshold_value"] == 200.0
164-
assert plan["execution"]["current_min_trade"] == 200.0
163+
assert plan["execution"]["trade_threshold_value"] == 100.0
164+
assert plan["execution"]["current_min_trade"] == 100.0
165165
assert plan["allocation"]["targets"]["AAA"] == 500.0
166166

167167

tests/test_execution_service.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ def test_execute_value_target_plan_projects_unbuyable_value_target_to_zero():
265265
assert result.action_done is True
266266
assert [(order.side, order.symbol, order.quantity) for order in execution_port.orders] == [
267267
("sell", "SOXX", 1.0),
268-
("buy", "SOXL", 1.0),
268+
("buy", "SOXL", 2.0),
269269
]
270270

271271

tests/test_notifications_telegram.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def test_render_cycle_summary_dashboard_text_does_not_hide_account_overview():
4141
)
4242

4343
assert " - Total assets: $2,345.67" in message
44-
assert " - Buying power: $456.78" in message
44+
assert " - Available cash: $456.78" in message
4545
assert " - Reserved cash: $50.00" in message
4646
assert " - Investable cash: $406.78" in message
4747
assert " - SOXL: $1,000.00 / 5 shares" in message

tests/test_rebalance_service.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ def test_runtime_metadata_uses_platform_execution_policy_over_strategy_metadata(
5959
"firstrade_execution_policy": {
6060
"reserved_cash_floor_usd": 250.0,
6161
"reserved_cash_ratio": 0.03,
62+
"cash_only_execution": True,
6263
},
6364
}
6465

@@ -242,7 +243,7 @@ def fake_client_factory(*args, **kwargs):
242243
assert result["notification_sent"] is True
243244
assert "🔔 【Rebalance Instruction】" in messages[0]
244245
assert "🧭 Strategy: TQQQ Growth Income" in messages[0]
245-
assert "🆔 Account: ****5678" in messages[0]
246+
assert "🆔 Account: 12345678" in messages[0]
246247
assert "📌 Strategy Account" in messages[0]
247248
assert "Target changes: AAA +50.00 USD" in messages[0]
248249
assert "🧾 Execution details" in messages[0]

tests/test_runtime_broker_adapters.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@ def get_balances(self, _account):
6161

6262
portfolio = adapters.build_portfolio_port().get_portfolio_snapshot()
6363

64-
assert portfolio.total_equity == 1234.56
64+
assert portfolio.total_equity == 221.0
6565
assert portfolio.cash_balance == 200.0
66-
assert portfolio.metadata["total_equity_source"] == "balance_total"
66+
assert portfolio.metadata["total_equity_source"] == "cash_plus_positions"
6767

6868

6969
def test_managed_portfolio_snapshot_ignores_full_account_value_balance_key():

tests/test_session_check_service.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def _env(values):
6464
return lambda name, default=None: values.get(name, default)
6565

6666

67-
def test_build_account_funds_snapshot_masks_account_and_compacts_values():
67+
def test_build_account_funds_snapshot_uses_full_account_and_compacts_values():
6868
snapshot = build_account_funds_snapshot(
6969
account="12345678",
7070
account_summaries=[{"account": "****5678", "total_value": "100.00"}],
@@ -74,7 +74,7 @@ def test_build_account_funds_snapshot_masks_account_and_compacts_values():
7474
now=datetime(2026, 5, 23, 1, 2, 3, tzinfo=timezone.utc),
7575
)
7676

77-
assert snapshot["account"] == "****5678"
77+
assert snapshot["account"] == "12345678"
7878
assert snapshot["session_reused"] is True
7979
assert snapshot["balance_metrics"] == {
8080
"total_account_value": 100.0,
@@ -104,8 +104,8 @@ def test_run_session_check_persists_funds_snapshot_when_enabled():
104104
assert result["session_reused"] is True
105105
assert result["snapshot_persisted"] is True
106106
assert len(store.writes) == 2
107-
assert store.writes[0][0] == "accounts/____5678/funds/latest.json"
108-
assert store.writes[1][0] == "accounts/____5678/funds/history/2026/05/23/20260523T010203Z.json"
107+
assert store.writes[0][0] == "accounts/12345678/funds/latest.json"
108+
assert store.writes[1][0] == "accounts/12345678/funds/history/2026/05/23/20260523T010203Z.json"
109109
assert store.writes[0][1]["positions"][0]["symbol"] == "SPY"
110110

111111

@@ -162,7 +162,7 @@ def test_monthly_session_check_runs_and_persists_maintenance_state_when_due():
162162
state_key,
163163
{
164164
"checked_at": "2026-06-03T01:02:03+00:00",
165-
"account": "****5678",
165+
"account": "12345678",
166166
"session_reused": True,
167167
"strategy_profile": "russell_top50_leader_rotation",
168168
"strategy_cadence": "monthly",

0 commit comments

Comments
 (0)