Bot auto-update: src/report_generator.py,src/web_dashboard.py

This commit is contained in:
Marc Blatter 2026-07-04 16:35:01 +02:00
parent 1885ef468e
commit f018a121d9
2 changed files with 51 additions and 1 deletions

50
src/report_generator.py Normal file
View File

@ -0,0 +1,50 @@
#!/usr/bin/env python3
import os, json, logging, requests
from datetime import datetime
from binance.client import Client
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
env = {}
with open("/home/marc/bot-deploy/.env") as f:
for line in f:
k, _, v = line.partition("=")
if k and v:
env[k.strip()] = v.strip()
def get_bot_state():
try:
r = requests.get("http://localhost:7000/api/state", timeout=5)
return r.json()
except:
return {}
def generate_report():
state = get_bot_state()
if not state:
return None
completed = state.get("completed_trades", [])
if not completed:
return "📊 No trades yet today"
total = len(completed)
wins = len([t for t in completed if t.get("profit_usd", 0) > 0])
losses = total - wins
profit = sum(t.get("profit_usd", 0) for t in completed)
wr = (wins/total*100) if total > 0 else 0
report = f"""📊 **Performance Report** - {datetime.now().strftime("%H:%M")}
🎯 Trades: {total} | {wins} ({wr:.0f}%) | {losses}
💰 P&L: ${profit:.2f} | Avg: ${profit/total:.2f}
💵 USDT: ${state.get("balance", {}).get("USDT", {}).get("free", 0):.2f}"""
return report
if __name__ == "__main__":
report = generate_report()
if report:
print(report)
logger.info("✅ Report generated")

View File

@ -56,7 +56,7 @@ async def dashboard():
<script>
async function refresh(){
try{
const r = await fetch("/api/state");
const r = await fetch("http://localhost:7000/api/state");
const d = await r.json();
const usdt_data = d.balance && d.balance.USDT ? d.balance.USDT : {free: 0};