-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathreset_paper.py
More file actions
56 lines (44 loc) · 1.66 KB
/
Copy pathreset_paper.py
File metadata and controls
56 lines (44 loc) · 1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/usr/bin/env python3
"""
One-off reset: void all stale open paper trades, restore bankroll to $1000.
"Stale" = open trades whose target_date is strictly before today's UTC date.
Sets status=void, pnl=0, exit_price=0, resolved_at=now.
Does NOT touch bankroll for each void (the bankroll snapshot at trade entry
is already deducted; we just wipe the liability and restart fresh from $1000).
"""
import sqlite3
from datetime import date, datetime
import db
def reset():
db.init_db()
today = date.today().isoformat()
conn = sqlite3.connect(db.DB_PATH)
conn.row_factory = sqlite3.Row
conn.execute("PRAGMA journal_mode=WAL")
try:
stale = conn.execute(
"SELECT trade_id, city, target_date, size_usdc FROM trades WHERE status='open'"
).fetchall()
print(f"Found {len(stale)} open trades to void:")
for t in stale:
print(f" {t['trade_id'][:12]} {t['city']:<18} {t['target_date']} ${t['size_usdc']:.2f}")
if stale:
now = datetime.utcnow().isoformat()
conn.execute(
"UPDATE trades SET status='void', pnl=0, exit_price=0, resolved_at=? "
"WHERE status='open'",
(now,)
)
print(f"\nVoided {len(stale)} trades.")
else:
print(" (none)")
conn.execute("UPDATE bankroll SET balance=1000.00 WHERE id=1")
conn.commit()
print(f"\nBankroll reset to $1000.00")
finally:
conn.close()
print(f"\nVerification:")
print(f" Bankroll: ${db.get_bankroll():.2f}")
print(f" Open trades: {len(db.get_open_trades())}")
if __name__ == "__main__":
reset()