Download _close_all.py from raghava4u/Trading-Bot-M20: direct link, hf CLI and curl.
- Browser
- Download file 1.18 kB
-
https://huggingface.co/raghava4u/Trading-Bot-M20/resolve/main/_close_all.py
- Command line
-
hf download hf://raghava4u/Trading-Bot-M20/_close_all.py
-
curl -L -o _close_all.py https://huggingface.co/raghava4u/Trading-Bot-M20/resolve/main/_close_all.py
1.18 kB
| """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}") | |