migrate: live_prices+mtf+capital_flow DB read/write, cleanup remaining JSON refs

This commit is contained in:
知微
2026-07-03 13:46:12 +08:00
parent bb9b3922c9
commit 5bd8af20ac
6 changed files with 44 additions and 46 deletions
Binary file not shown.
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
+38 -38
View File
@@ -5,9 +5,9 @@
"name": "中际旭创", "name": "中际旭创",
"shares": 100, "shares": 100,
"cost": 1316.53, "cost": 1316.53,
"price": 1145.0, "price": 1143.84,
"market_value": 114101.0, "market_value": 114101.0,
"change_pct": 0.17, "change_pct": 0.07,
"currency": "CNY", "currency": "CNY",
"position_pct": 15.27, "position_pct": 15.27,
"_currency": "CNY" "_currency": "CNY"
@@ -17,9 +17,9 @@
"name": "长飞光纤光缆", "name": "长飞光纤光缆",
"shares": 500, "shares": 500,
"cost": 228.65, "cost": 228.65,
"price": 178.26, "price": 177.39,
"market_value": 89910.0, "market_value": 89910.0,
"change_pct": 3.859, "change_pct": 3.35,
"currency": "CNY", "currency": "CNY",
"position_pct": 13.47, "position_pct": 13.47,
"_currency": "CNY" "_currency": "CNY"
@@ -29,9 +29,9 @@
"name": "丘钛科技", "name": "丘钛科技",
"shares": 11000, "shares": 11000,
"cost": 11.68, "cost": 11.68,
"price": 6.1, "price": 6.09,
"market_value": 67210.0, "market_value": 67210.0,
"change_pct": 4.762, "change_pct": 4.464,
"currency": "CNY", "currency": "CNY",
"position_pct": 7.97, "position_pct": 7.97,
"_currency": "CNY" "_currency": "CNY"
@@ -41,9 +41,9 @@
"name": "紫金矿业", "name": "紫金矿业",
"shares": 2400, "shares": 2400,
"cost": 39.89, "cost": 39.89,
"price": 27.8, "price": 27.86,
"market_value": 66864.0, "market_value": 66864.0,
"change_pct": 5.7, "change_pct": 5.93,
"currency": "CNY", "currency": "CNY",
"position_pct": 7.34, "position_pct": 7.34,
"_currency": "CNY" "_currency": "CNY"
@@ -53,9 +53,9 @@
"name": "海博思创", "name": "海博思创",
"shares": 200, "shares": 200,
"cost": 266.95, "cost": 266.95,
"price": 254.75, "price": 254.42,
"market_value": 50842.0, "market_value": 50842.0,
"change_pct": -0.38, "change_pct": -0.5,
"currency": "CNY", "currency": "CNY",
"position_pct": 6.31, "position_pct": 6.31,
"_currency": "CNY" "_currency": "CNY"
@@ -65,9 +65,9 @@
"name": "中芯国际", "name": "中芯国际",
"shares": 300, "shares": 300,
"cost": 126.07, "cost": 126.07,
"price": 142.97, "price": 143.01,
"market_value": 42600.0, "market_value": 42600.0,
"change_pct": -0.78, "change_pct": -0.76,
"currency": "CNY", "currency": "CNY",
"position_pct": 5.44, "position_pct": 5.44,
"_currency": "CNY" "_currency": "CNY"
@@ -77,9 +77,9 @@
"name": "建滔积层板", "name": "建滔积层板",
"shares": 500, "shares": 500,
"cost": 76.5, "cost": 76.5,
"price": 74.17, "price": 73.96,
"market_value": 37325.0, "market_value": 37325.0,
"change_pct": 2.088, "change_pct": 1.79,
"currency": "CNY", "currency": "CNY",
"position_pct": 5.28, "position_pct": 5.28,
"_currency": "CNY" "_currency": "CNY"
@@ -89,9 +89,9 @@
"name": "华恒生物", "name": "华恒生物",
"shares": 2800, "shares": 2800,
"cost": 21.51, "cost": 21.51,
"price": 16.72, "price": 16.71,
"market_value": 46900.0, "market_value": 46900.0,
"change_pct": -1.36, "change_pct": -1.42,
"currency": "CNY", "currency": "CNY",
"position_pct": 5.25, "position_pct": 5.25,
"_currency": "CNY" "_currency": "CNY"
@@ -101,9 +101,9 @@
"name": "宁德时代", "name": "宁德时代",
"shares": 100, "shares": 100,
"cost": 401.78, "cost": 401.78,
"price": 380.24, "price": 380.88,
"market_value": 38032.0, "market_value": 38032.0,
"change_pct": -0.55, "change_pct": -0.38,
"currency": "CNY", "currency": "CNY",
"position_pct": 4.64, "position_pct": 4.64,
"_currency": "CNY" "_currency": "CNY"
@@ -113,9 +113,9 @@
"name": "比亚迪股份", "name": "比亚迪股份",
"shares": 600, "shares": 600,
"cost": 90.92, "cost": 90.92,
"price": 71.83, "price": 71.4,
"market_value": 43044.0, "market_value": 43044.0,
"change_pct": 5.811, "change_pct": 5.172,
"currency": "CNY", "currency": "CNY",
"position_pct": 4.62, "position_pct": 4.62,
"_currency": "CNY" "_currency": "CNY"
@@ -137,9 +137,9 @@
"name": "腾讯", "name": "腾讯",
"shares": 100, "shares": 100,
"cost": null, "cost": null,
"price": 376.8, "price": 374.72,
"market_value": 37541.0, "market_value": 37541.0,
"change_pct": 1.023, "change_pct": 0.465,
"currency": "CNY", "currency": "CNY",
"position_pct": null, "position_pct": null,
"_currency": "CNY" "_currency": "CNY"
@@ -149,9 +149,9 @@
"name": "中芯国际", "name": "中芯国际",
"shares": 500, "shares": 500,
"cost": 65.84, "cost": 65.84,
"price": 68.41, "price": 67.63,
"market_value": 34440.0, "market_value": 34440.0,
"change_pct": -1.866, "change_pct": -2.985,
"currency": "CNY", "currency": "CNY",
"position_pct": 4.2, "position_pct": 4.2,
"_currency": "CNY" "_currency": "CNY"
@@ -161,9 +161,9 @@
"name": "长芯博创", "name": "长芯博创",
"shares": 100, "shares": 100,
"cost": 231.46, "cost": 231.46,
"price": 226.5, "price": 226.24,
"market_value": 22599.0, "market_value": 22599.0,
"change_pct": 2.03, "change_pct": 1.91,
"currency": "CNY", "currency": "CNY",
"position_pct": 3.2, "position_pct": 3.2,
"_currency": "CNY" "_currency": "CNY"
@@ -185,9 +185,9 @@
"name": "中科电气", "name": "中科电气",
"shares": 1400, "shares": 1400,
"cost": 22.29, "cost": 22.29,
"price": 14.38, "price": 14.37,
"market_value": 20062.0, "market_value": 20062.0,
"change_pct": 1.48, "change_pct": 1.41,
"currency": "CNY", "currency": "CNY",
"position_pct": 2.42, "position_pct": 2.42,
"_currency": "CNY" "_currency": "CNY"
@@ -197,9 +197,9 @@
"name": "模塑科技", "name": "模塑科技",
"shares": 1400, "shares": 1400,
"cost": 14.83, "cost": 14.83,
"price": 17.62, "price": 17.66,
"market_value": 25088.0, "market_value": 25088.0,
"change_pct": 4.45, "change_pct": 4.68,
"currency": "CNY", "currency": "CNY",
"position_pct": 2.41, "position_pct": 2.41,
"_currency": "CNY" "_currency": "CNY"
@@ -209,9 +209,9 @@
"name": "法拉电子", "name": "法拉电子",
"shares": 100, "shares": 100,
"cost": 147.18, "cost": 147.18,
"price": 160.0, "price": 160.15,
"market_value": 15900.0, "market_value": 15900.0,
"change_pct": -2.62, "change_pct": -2.53,
"currency": "CNY", "currency": "CNY",
"position_pct": 2.3, "position_pct": 2.3,
"_currency": "CNY" "_currency": "CNY"
@@ -221,20 +221,20 @@
"name": "中国神华", "name": "中国神华",
"shares": 500, "shares": 500,
"cost": 39.79, "cost": 39.79,
"price": 34.59, "price": 34.56,
"market_value": 17305.0, "market_value": 17305.0,
"change_pct": 0.758, "change_pct": 0.657,
"currency": "CNY", "currency": "CNY",
"position_pct": 2.14, "position_pct": 2.14,
"_currency": "CNY" "_currency": "CNY"
} }
], ],
"total_assets": 860913.13, "total_assets": 859635.43,
"total_mv": 780437.13, "total_mv": 779159.43,
"stock_value": null, "stock_value": null,
"cash": 80476.0, "cash": 80476.0,
"frozen_cash": 0.0, "frozen_cash": 0.0,
"position_pct": 90.65, "position_pct": 90.64,
"currency": "CNY", "currency": "CNY",
"updated_at": "2026-07-03 13:42" "updated_at": "2026-07-03 13:44"
} }
+3 -2
View File
@@ -314,7 +314,7 @@ def refresh_data_prices():
if code in prices: if code in prices:
p, c, chg = prices[code] p, c, chg = prices[code]
live["prices"][code] = {"price": p, "change_pct": chg} live["prices"][code] = {"price": p, "change_pct": chg}
json.dump(live, open("/home/hmo/web-dashboard/data/live_prices.json", "w"), indent=2) # json.dump(live, ...) — 已迁移到 DB,见根 price_monitor.py
except Exception: except Exception:
pass pass
@@ -739,7 +739,8 @@ def run_once(round_label=""):
# === 3.5 资金流异常检测(2026-06-27 新增)=== # === 3.5 资金流异常检测(2026-06-27 新增)===
try: try:
cf = json.load(open("/home/hmo/web-dashboard/data/capital_flow_cache.json")) from mofin_db import get_conn, read_capital_flow_cache
cf = read_capital_flow_cache(get_conn())
# 检查所有 active decision 中的资金流异常 # 检查所有 active decision 中的资金流异常
for d in active: for d in active:
code = d["code"] code = d["code"]
+3 -6
View File
@@ -989,7 +989,7 @@ def reassess_strategy(code, name, price, cost, shares, current_action,
time_horizon = "2周~3月" time_horizon = "2周~3月"
position_advice = "中等仓位" position_advice = "中等仓位"
try: try:
mtf_cache = json.load(open("/home/hmo/web-dashboard/data/multi_tf_cache.json")) mtf_cache = mtf._load_mtf_cache()
stock_data = mtf_cache.get(code, {}) stock_data = mtf_cache.get(code, {})
daily_klines = stock_data.get("daily", []) daily_klines = stock_data.get("daily", [])
fund = stock_data.get("fundamentals", {}) fund = stock_data.get("fundamentals", {})
@@ -1537,11 +1537,8 @@ def load_stock_news_sentiment(code):
def load_fundamentals(code): def load_fundamentals(code):
"""加载个股基本面""" """加载个股基本面"""
try: try:
path = "/home/hmo/web-dashboard/data/multi_tf_cache.json" cache = mtf._load_mtf_cache()
if not os.path.exists(path): return cache.get(code, {}).get("fundamentals", {}) or {}
return {}
m = json.load(open(path))
return m.get(code, {}).get("fundamentals", {}) or {}
except Exception: except Exception:
return {} return {}