feat: holdings_reconciliation + process_trade + import_holding_xls → DB writes
This commit is contained in:
@@ -120,8 +120,19 @@ def main():
|
|||||||
print(f"decisions stock_value: {dec_total:.2f}")
|
print(f"decisions stock_value: {dec_total:.2f}")
|
||||||
print(f"decisions count(shares>0): {len([d for d in dec['decisions'] if d.get('shares',0)>0])}")
|
print(f"decisions count(shares>0): {len([d for d in dec['decisions'] if d.get('shares',0)>0])}")
|
||||||
|
|
||||||
# Write
|
# Write — DB 优先(强制币种约束),JSON 冷备
|
||||||
dec["total"] = len(dec["decisions"])
|
dec["total"] = len(dec["decisions"])
|
||||||
|
try:
|
||||||
|
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||||
|
from mofin_db import get_conn, write_holdings_batch, write_portfolio_summary, write_holding_strategy
|
||||||
|
conn = get_conn()
|
||||||
|
write_holdings_batch(conn, pf.get('holdings', []))
|
||||||
|
write_portfolio_summary(conn, pf)
|
||||||
|
for d in dec.get('decisions', []):
|
||||||
|
write_holding_strategy(conn, d.get('code', ''), d.get('name', ''), d)
|
||||||
|
conn.close()
|
||||||
|
except Exception as e:
|
||||||
|
print(f" [DB写入失败] {e}")
|
||||||
json.dump(dec, open(DECISIONS, "w"), ensure_ascii=False, indent=2)
|
json.dump(dec, open(DECISIONS, "w"), ensure_ascii=False, indent=2)
|
||||||
json.dump(pf, open(PORTFOLIO, "w"), ensure_ascii=False, indent=2)
|
json.dump(pf, open(PORTFOLIO, "w"), ensure_ascii=False, indent=2)
|
||||||
print(f"done")
|
print(f"done")
|
||||||
|
|||||||
@@ -142,6 +142,15 @@ def main():
|
|||||||
}
|
}
|
||||||
with open(PORTFOLIO_PATH, 'w') as f:
|
with open(PORTFOLIO_PATH, 'w') as f:
|
||||||
json.dump(portfolio, f, indent=2, ensure_ascii=False)
|
json.dump(portfolio, f, indent=2, ensure_ascii=False)
|
||||||
|
# DB 写入
|
||||||
|
try:
|
||||||
|
from mofin_db import get_conn, write_holdings_batch, write_portfolio_summary
|
||||||
|
conn = get_conn()
|
||||||
|
write_holdings_batch(conn, portfolio.get('holdings', []))
|
||||||
|
write_portfolio_summary(conn, portfolio)
|
||||||
|
conn.close()
|
||||||
|
except Exception as e:
|
||||||
|
print(f" [DB写入失败] {e}")
|
||||||
|
|
||||||
# Step 4: Rebuild decision trees
|
# Step 4: Rebuild decision trees
|
||||||
print("\n→ 重建决策树...")
|
print("\n→ 重建决策树...")
|
||||||
|
|||||||
@@ -120,8 +120,19 @@ def main():
|
|||||||
})
|
})
|
||||||
break
|
break
|
||||||
|
|
||||||
# 写入
|
# 写入 — DB 优先
|
||||||
pf["updated_at"] = now
|
pf["updated_at"] = now
|
||||||
|
try:
|
||||||
|
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||||
|
from mofin_db import get_conn, write_holdings_batch, write_portfolio_summary, write_holding_strategy
|
||||||
|
conn = get_conn()
|
||||||
|
write_holdings_batch(conn, pf.get('holdings', []))
|
||||||
|
write_portfolio_summary(conn, pf)
|
||||||
|
for d in dec.get('decisions', []):
|
||||||
|
write_holding_strategy(conn, d.get('code', ''), d.get('name', ''), d)
|
||||||
|
conn.close()
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
json.dump(pf, open(PORTFOLIO_PATH, "w"), indent=2, ensure_ascii=False)
|
json.dump(pf, open(PORTFOLIO_PATH, "w"), indent=2, ensure_ascii=False)
|
||||||
json.dump(dec, open(DECISIONS_PATH, "w"), indent=2, ensure_ascii=False)
|
json.dump(dec, open(DECISIONS_PATH, "w"), indent=2, ensure_ascii=False)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user