File size: 1,179 Bytes
d53dc44
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""Quick script to close all positions and cancel all orders."""
from execution import broker
import config

print("Cancelling all open orders...")
try:
    broker.cancel_all_orders()
    print("Orders cancelled.")
except Exception as e:
    print(f"Cancel orders: {e}")

print("Closing all positions...")
try:
    broker.close_all_positions()
    print("All positions closed.")
except Exception as e:
    print(f"Close positions: {e}")

try:
    acct = broker.get_account()
    eq = float(acct.get("equity", 0))
    bp = float(acct.get("buying_power", 0))
    print(f"Account equity: ${eq:,.2f}")
    print(f"Buying power: ${bp:,.2f}")
except Exception as e:
    print(f"Account check: {e}")

try:
    positions = broker.get_positions()
    if positions:
        print(f"WARNING: {len(positions)} positions still open:")
        for p in positions:
            sym = p.get("symbol")
            qty = p.get("qty")
            pl = float(p.get("unrealized_pl", 0))
            print(f"  {sym}: {qty} shares, P&L: ${pl:,.2f}")
    else:
        print("Confirmed: 0 open positions.")
except Exception as e:
    print(f"Position check: {e}")