fix: currency+PnL+is_hk_stock+gate+zone+total_pnl
This commit is contained in:
+723
-718
File diff suppressed because it is too large
Load Diff
@@ -67,20 +67,29 @@ def main():
|
|||||||
currency = 'HKD' if '港币' in price_raw or '港' in r[10] else 'CNY'
|
currency = 'HKD' if '港币' in price_raw or '港' in r[10] else 'CNY'
|
||||||
price_str = price_raw.replace('港币', '').replace('港元', '').replace('港', '').strip()
|
price_str = price_raw.replace('港币', '').replace('港元', '').replace('港', '').strip()
|
||||||
price = float(price_str)
|
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
|
pl = float(clean_cell(r[6])) if r[6].strip() else 0
|
||||||
mkt_val = float(clean_cell(r[11]))
|
mkt_val_raw = float(clean_cell(r[11]))
|
||||||
cost_amount = float(clean_cell(r[15])) if r[15].strip() and r[15].strip() != '--' else 0
|
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_str = clean_cell(r[16])
|
||||||
rate = float(rate_str) if rate_str and rate_str != '--' else 0.8664
|
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
|
total_mv_cny += mv_cny
|
||||||
|
|
||||||
holdings.append({
|
holdings.append({
|
||||||
'code': code, 'name': name, 'shares': shares,
|
'code': code, 'name': name, 'shares': shares,
|
||||||
'price': price, 'cost_price': round(cost_price, 2),
|
'price': price_cny, 'cost_price': cost_price,
|
||||||
'currency': currency, 'market_val': mkt_val,
|
'currency': 'CNY', 'market_val': mv_cny,
|
||||||
'cost_amount': cost_amount, 'exchange_rate': rate,
|
'cost_amount_raw': cost_amount_raw, 'exchange_rate': rate,
|
||||||
})
|
})
|
||||||
|
|
||||||
if cash <= 0:
|
if cash <= 0:
|
||||||
@@ -105,9 +114,9 @@ def main():
|
|||||||
c.execute('DELETE FROM portfolio_summary')
|
c.execute('DELETE FROM portfolio_summary')
|
||||||
for h in holdings:
|
for h in holdings:
|
||||||
c.execute('''
|
c.execute('''
|
||||||
INSERT INTO holdings (code, name, shares, cost, position_pct, added_at, is_active)
|
INSERT INTO holdings (code, name, shares, cost, currency, position_pct, added_at, is_active)
|
||||||
VALUES (?, ?, ?, ?, ?, ?, 1)
|
VALUES (?, ?, ?, ?, ?, ?, ?, 1)
|
||||||
''', (h['code'], h['name'], h['shares'], h['cost_price'],
|
''', (h['code'], h['name'], h['shares'], h['cost_price'], 'CNY',
|
||||||
round(h['market_val'] / total_assets * 100, 2),
|
round(h['market_val'] / total_assets * 100, 2),
|
||||||
datetime.now().strftime('%Y-%m-%d')))
|
datetime.now().strftime('%Y-%m-%d')))
|
||||||
c.execute('''
|
c.execute('''
|
||||||
|
|||||||
+2072
-2074
File diff suppressed because it is too large
Load Diff
+2583
-2574
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user