06/03 Optimize codes, Schwab account

This commit is contained in:
2026-06-03 14:46:30 -04:00
parent f59f9aa44c
commit 302fbf5fe2
5 changed files with 204 additions and 97 deletions
+8 -1
View File
@@ -264,7 +264,13 @@ def sync_account_snapshot(schwab_account):
market_value = float(pos.get('marketValue') or 0)
cur_price = round(market_value / long_qty, 4) if long_qty > 0 else avg_price
inv = Investment.query.filter_by(ticker=symbol, is_active=True).first()
pfm_acct_id = schwab_account.pfm_account_id
# Match on (ticker, account_id) so the same ticker in different accounts
# (e.g. AAPL in Individual vs Roth IRA) remains separate.
inv = Investment.query.filter_by(
ticker=symbol, account_id=pfm_acct_id, is_active=True
).first()
if inv:
inv.shares = long_qty
if avg_price > 0:
@@ -274,6 +280,7 @@ def sync_account_snapshot(schwab_account):
else:
name = (instrument.get('description') or symbol).strip()
inv = Investment(
account_id = pfm_acct_id,
asset_name = name,
ticker = symbol,
asset_type = pfm_type,