File: //opt/trading-bot/check_remote_pnl.py
import os
import pymysql
from dotenv import load_dotenv
load_dotenv("/opt/trading-bot/.env")
def audit_pnl():
try:
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))
)
with conn.cursor() as cur:
print("=== LATEST 15 PORTFOLIO SNAPSHOTS (GLOBAL) ===")
cur.execute("SELECT strategy_name, equity, cash, exposure, ts FROM portfolio_state ORDER BY ts DESC LIMIT 15")
for row in cur.fetchall():
print(row)
print("\n=== LATEST SNAPSHOT PER STRATEGY ===")
strategies = [
"LegacyBasis", "MultiAssetAlpha", "TrendFollower", "VolatilityHunter",
"GridBot", "MeanRevScalper", "MomentumBreakout",
"EquityMomentum", "EquityMeanReversion", "EquityBollingerBreakout",
"EquityTrendPullback", "EquityATRBreakout", "EquityPairsTrading", "EquityTripleThreat"
]
for s in strategies:
cur.execute("SELECT strategy_name, equity, cash, ts FROM portfolio_state WHERE strategy_name=%s ORDER BY ts DESC LIMIT 1", (s,))
r = cur.fetchone()
if r:
print(f"{s}: ${r[1]:.2f} (at {r[3]})")
else:
print(f"{s}: [NO DATA]")
except Exception as e:
print(f"Error: {e}")
finally:
conn.close()
if __name__ == "__main__":
audit_pnl()