BrainDock/src/report_generator.py

59 lines
1.8 KiB
Python

#!/usr/bin/env python3
import os, json, subprocess
from datetime import datetime
from binance.client import Client
with open('/home/marc/bot-deploy/.env') as f:
env = {}
for line in f:
k, _, v = line.partition('=')
env[k.strip()] = v.strip()
# Load bot state
with open('/home/marc/bot-deploy/trades.json') as f:
bot_state = json.load(f)
# Get balance from Binance
c = Client(env.get('BINANCE_API_KEY_LIVE'), env.get('BINANCE_API_SECRET_LIVE'))
acc = c.get_account()
balance = {a['asset']: float(a['free']) for a in acc['balances']}
# Calculate metrics
portfolio_value = balance.get('USDT', 0)
for asset in ['ETH', 'BTC', 'SOL', 'BNB', 'XRP']:
if asset in balance:
# Rough values (should use ticker for precision)
prices = {'ETH': 1790, 'BTC': 63000, 'SOL': 83.5, 'BNB': 578, 'XRP': 2.5}
portfolio_value += balance.get(asset, 0) * prices.get(asset, 0)
completed = bot_state.get('completed', [])
daily_pnl = sum(t.get('profit_usd', 0) for t in completed)
wins = len([t for t in completed if t.get('profit_usd', 0) > 0])
losses = len([t for t in completed if t.get('profit_usd', 0) < 0])
# Format report
timestamp = datetime.now().strftime('%Y-%m-%d %H:%M UTC')
report = f'''📊 **TRADING BOT REPORT** — {timestamp}
💰 **PORTFOLIO**
• Total: ${portfolio_value:.2f}
• USDT Free: ${balance.get('USDT', 0):.2f}
• Open Trades: {len(bot_state.get('current', {}))}
📈 **TODAY'S PERFORMANCE**
• Trades: {len(completed)}
• Wins: {wins} | Losses: {losses}
• Win Rate: {(wins/(wins+losses)*100) if (wins+losses) > 0 else 0:.1f}%
• Daily P&L: ${daily_pnl:.2f}
🟢 **BOT STATUS**: OPERATIONAL
🔗 Dashboard: https://bot.bizmark.cloud
---
*Next report in 3 hours*
'''
# Send via Telegram using Hermes send_message
print(report)