06/03 Optimize codes, Schwab account
This commit is contained in:
@@ -247,14 +247,18 @@ def sync_account_snapshot(schwab_account):
|
|||||||
instrument = pos.get('instrument') or {}
|
instrument = pos.get('instrument') or {}
|
||||||
asset_key = instrument.get('assetType', '')
|
asset_key = instrument.get('assetType', '')
|
||||||
symbol = (instrument.get('symbol') or '').upper().strip()
|
symbol = (instrument.get('symbol') or '').upper().strip()
|
||||||
long_qty = float(pos.get('longQuantity') or 0)
|
# Use longQuantity; fall back to settledLongQuantity for positions that
|
||||||
|
# were just purchased and haven't fully settled yet (T+1 / T+2).
|
||||||
|
long_qty = float(pos.get('longQuantity') or
|
||||||
|
pos.get('settledLongQuantity') or 0)
|
||||||
|
|
||||||
pfm_type = ASSET_TYPE_MAP.get(asset_key)
|
pfm_type = ASSET_TYPE_MAP.get(asset_key)
|
||||||
log.debug('[schwab] position: symbol=%s assetType=%s longQty=%s pfm_type=%s',
|
log.debug('[schwab] position: symbol=%s assetType=%s longQty=%s pfm_type=%s',
|
||||||
symbol, asset_key, long_qty, pfm_type)
|
symbol, asset_key, long_qty, pfm_type)
|
||||||
|
|
||||||
# Skip unknowns, empty symbols, and zero-quantity positions
|
# Skip empty symbols and zero-quantity positions
|
||||||
if not symbol or long_qty <= 0:
|
if not symbol or long_qty <= 0:
|
||||||
|
log.debug('[schwab] skipping %s — qty=%s symbol=%r', asset_key, long_qty, symbol)
|
||||||
continue
|
continue
|
||||||
# Fall back to 'other' if the asset type isn't in our map
|
# Fall back to 'other' if the asset type isn't in our map
|
||||||
if not pfm_type:
|
if not pfm_type:
|
||||||
|
|||||||
Reference in New Issue
Block a user