revert(币种统一): 回退CNY转换

港股价格存原币(HKD),不存CNY。
Dad需要在股软里看港币价下单操作。
This commit is contained in:
知微
2026-06-29 17:46:14 +08:00
parent 6aa338ee4d
commit d82de939ff
8 changed files with 784 additions and 1559 deletions
-63
View File
@@ -174,69 +174,6 @@ def refresh_data_prices():
except:
pass
# --- 同步统一CNY价格到decisions.json (2026-06-29 currency bugfix) ---
# decisions.json存的HK股价格是HKD(腾讯API原始值)
# portfolio.json/watchlist已统一CNYHK×0.87),但decisions.json没同步
# LLM报告读portfolio.jsonCNYvs decisions.json止损/价(HKD)→ 币种错配
# 修复:decisions.json的 所有价格字段 统一CNYprice/stop_loss/take_profit/entry_low/entry_high
try:
dec = json.load(open(DECISIONS_PATH))
dec_updated = False
for d in dec.get('decisions', []):
code = d.get('code', '')
if not (str(code).startswith(('0','1')) and len(str(code))==5):
continue # 只修港股
if code not in prices:
continue
raw_hkd, _, _ = prices[code]
if raw_hkd <= 0:
continue
cny = round(raw_hkd * HK_RATE, 2)
# 逐字段转换
for field in ['price', 'stop_loss', 'take_profit', 'entry_low', 'entry_high',
'last_reassessed_price', 'avg_price']:
old = d.get(field, 0) or 0
if old > 0:
new_val = round(old * HK_RATE, 2)
if abs(old - new_val) > 0.01:
d[field] = new_val
dec_updated = True
# 处理嵌套的analysis字段
analysis = d.get('analysis', {})
for field in ['stop_loss', 'take_profit', 'entry_low', 'entry_high']:
old = analysis.get(field, 0) or 0
if old > 0:
analysis[field] = round(old * HK_RATE, 2)
# 处理trigger字段
trigger = d.get('trigger', {})
for field in ['stop_loss', 'take_profit_zone']:
old = trigger.get(field, 0) or 0
if old > 0:
trigger[field] = round(old * HK_RATE, 2)
elif isinstance(trigger.get(field), str) and '~' in str(trigger.get(field,'')):
# take_profit_zone格式: "0~X"
parts = str(trigger[field]).split('~')
if len(parts) == 2 and parts[1]:
parts[1] = str(round(float(parts[1]) * HK_RATE, 2))
trigger[field] = '~'.join(parts)
# entry_zone: "X~Y"
ez = trigger.get('entry_zone', '')
if '~' in str(ez):
parts = str(ez).split('~')
for i, p in enumerate(parts):
try:
parts[i] = str(round(float(p) * HK_RATE, 2))
except: pass
trigger['entry_zone'] = '~'.join(parts)
if dec_updated:
dec['total'] = len(dec['decisions'])
json.dump(dec, open(DECISIONS_PATH, 'w'), ensure_ascii=False, indent=2)
except Exception as e:
print(f" [decisions.json CNY同步失败] {e}", flush=True)
# --- 结束 CNY同步 ---
# 更新watchlist(只在价格变化时写入)
changed = False
for s in wl.get('stocks', []):