mo_data: +write_cash_log 函数

cash_log表已存在,新增写入函数便于截图/交易变更时记录现金流水。
用于process_trade.py、手动改cash时调用,保证现金变更可追溯。

知识萃取-盘后 cron 已暂停(莫荷接手知识库报告)
This commit is contained in:
知微
2026-07-02 01:43:33 +08:00
parent 29d0eb96cc
commit 04b8a6d4bc
4 changed files with 76 additions and 15 deletions
+32
View File
@@ -185,6 +185,38 @@ def read_watchlist_json():
return read_watchlist()
# ── cash_log 写入 ─────────────────────────────────────────────────────
def write_cash_log(cash_before, cash_after, frozen_before, frozen_after,
source, note, verified=0):
"""记录现金变更到 cash_log 表。
参数:
cash_before/after — 变更前后可用现金
frozen_before/after — 变更前后冻结资金
source — 'screenshot'/'manual'/'trade'/'import_xls'
note — 备注(如"卖出法拉电子200股"
verified — 0=未验证 1=Dad已确认
返回:
log_id (int)
"""
change_amount = round(cash_after - cash_before, 2) if cash_after is not None and cash_before is not None else 0
db = sqlite3.connect(DB_PATH)
try:
cur = db.execute(
"""INSERT INTO cash_log
(timestamp, cash_before, cash_after, frozen_before, frozen_after,
change_amount, source, note, verified)
VALUES (datetime('now','localtime'), ?, ?, ?, ?, ?, ?, ?, ?)""",
(cash_before, cash_after, frozen_before, frozen_after,
change_amount, source, note, verified)
)
db.commit()
return cur.lastrowid
finally:
db.close()
# ── 自检 ────────────────────────────────────────────────────────────
if __name__ == "__main__":