Add configurable SIM equity (default 10k) and strategy docs.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -48,6 +48,24 @@ class Ledger:
|
||||
self.db._conn.commit()
|
||||
return equity
|
||||
|
||||
def reset_equity(self, amount: float, *, note: str = "重置模拟资金") -> float:
|
||||
"""将权益与可用资金重置为 amount(reserved 清零)。须在无持仓时调用。"""
|
||||
now = int(time.time() * 1000)
|
||||
amt = float(amount)
|
||||
if amt < 0:
|
||||
raise ValueError("模拟资金不能为负")
|
||||
with self.db._lock:
|
||||
self.db._conn.execute(
|
||||
"UPDATE ledger_meta SET equity=?, available=?, reserved=0, updated_at_ms=? WHERE id=1",
|
||||
(amt, amt, now),
|
||||
)
|
||||
self.db._conn.execute(
|
||||
"INSERT INTO ledger_entries(group_id, kind, amount, balance_after, note, ts_ms) VALUES (?,?,?,?,?,?)",
|
||||
(None, "reset", amt, amt, note, now),
|
||||
)
|
||||
self.db._conn.commit()
|
||||
return amt
|
||||
|
||||
def get_setting_float(self, key: str, default: float) -> float:
|
||||
v = self.db.get_setting(key)
|
||||
if v is None or v == "":
|
||||
|
||||
Reference in New Issue
Block a user