fix: currency+PnL+is_hk_stock+gate+zone+total_pnl

This commit is contained in:
知微
2026-07-03 10:27:17 +08:00
parent cc55ff76ad
commit 6eecc4d4eb
4 changed files with 5397 additions and 5376 deletions
+19 -10
View File
@@ -67,20 +67,29 @@ def main():
currency = 'HKD' if '港币' in price_raw or '' in r[10] else 'CNY'
price_str = price_raw.replace('港币', '').replace('港元', '').replace('', '').strip()
price = float(price_str)
cost_price = float(clean_cell(r[5]))
cost_price_raw = float(clean_cell(r[5]))
pl = float(clean_cell(r[6])) if r[6].strip() else 0
mkt_val = float(clean_cell(r[11]))
cost_amount = float(clean_cell(r[15])) if r[15].strip() and r[15].strip() != '--' else 0
mkt_val_raw = float(clean_cell(r[11]))
cost_amount_raw = float(clean_cell(r[15])) if r[15].strip() and r[15].strip() != '--' else 0
rate_str = clean_cell(r[16])
rate = float(rate_str) if rate_str and rate_str != '--' else 0.8664
mv_cny = mkt_val
# 港股:所有金额必须转为 CNY 再存储(mo_models 设计规范:portfolio 应全部存 CNY
if currency == 'HKD':
cost_price = round(cost_price_raw * rate, 2)
mv_cny = round(mkt_val_raw * rate, 2)
price_cny = round(price * rate, 2)
else:
cost_price = round(cost_price_raw, 2)
mv_cny = mkt_val_raw
price_cny = price
total_mv_cny += mv_cny
holdings.append({
'code': code, 'name': name, 'shares': shares,
'price': price, 'cost_price': round(cost_price, 2),
'currency': currency, 'market_val': mkt_val,
'cost_amount': cost_amount, 'exchange_rate': rate,
'price': price_cny, 'cost_price': cost_price,
'currency': 'CNY', 'market_val': mv_cny,
'cost_amount_raw': cost_amount_raw, 'exchange_rate': rate,
})
if cash <= 0:
@@ -105,9 +114,9 @@ def main():
c.execute('DELETE FROM portfolio_summary')
for h in holdings:
c.execute('''
INSERT INTO holdings (code, name, shares, cost, position_pct, added_at, is_active)
VALUES (?, ?, ?, ?, ?, ?, 1)
''', (h['code'], h['name'], h['shares'], h['cost_price'],
INSERT INTO holdings (code, name, shares, cost, currency, position_pct, added_at, is_active)
VALUES (?, ?, ?, ?, ?, ?, ?, 1)
''', (h['code'], h['name'], h['shares'], h['cost_price'], 'CNY',
round(h['market_val'] / total_assets * 100, 2),
datetime.now().strftime('%Y-%m-%d')))
c.execute('''
+2072 -2074
View File
File diff suppressed because it is too large Load Diff