File: //proc/self/root/opt/trading-bot/nuke_and_reset.py
import os
import pymysql
from dotenv import load_dotenv
load_dotenv()
def nuke_and_reset():
conn = pymysql.connect(
host=os.getenv('MYSQL_HOST'),
user=os.getenv('MYSQL_USER'),
password=os.getenv('MYSQL_PASSWORD'),
database=os.getenv('MYSQL_DATABASE'),
port=int(os.getenv('MYSQL_PORT', 3306))
)
strategies = [
"LegacyBasis", "MultiAssetAlpha", "TrendFollower", "VolatilityHunter",
"GridBot", "MeanRevScalper", "MomentumBreakout",
"EquityMomentum", "EquityMeanReversion", "EquityBollingerBreakout",
"EquityTrendPullback", "EquityATRBreakout", "EquityPairsTrading", "EquityTripleThreat"
]
tables_to_truncate = [
"positions", "pnl_history", "portfolio_state", "orders", "fills", "signals"
]
try:
with conn.cursor() as cur:
# Disable foreign key checks for truncate
cur.execute("SET FOREIGN_KEY_CHECKS = 0")
for table in tables_to_truncate:
print(f"Truncating {table}...")
cur.execute(f"TRUNCATE TABLE {table}")
cur.execute("SET FOREIGN_KEY_CHECKS = 1")
print(f"Inserting fresh $10,000 states for {len(strategies)} strategies...")
for strat in strategies:
cur.execute("""
INSERT INTO portfolio_state (strategy_name, equity, cash, exposure, drawdown, ts)
VALUES (%s, 10000.0, 10000.0, 0.0, 0.0, NOW())
""", (strat,))
conn.commit()
print("System successfully NUKE-AND-RESET.")
except Exception as e:
print(f"Error during nuke-and-reset: {e}")
conn.rollback()
finally:
conn.close()
if __name__ == "__main__":
nuke_and_reset()