06/03 Optimize codes, Schwab account
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user