"""Trading Bot Dashboard v0.6 (Contrarian Mean Reversion) - Auto-load 1-Day chart on page load"""
import os, json, logging, sqlite3
from datetime import datetime, timedelta
from flask import Flask, render_template_string, jsonify
from binance.client import Client
from dotenv import load_dotenv
load_dotenv()
API_KEY = os.getenv('BINANCE_API_KEY_LIVE')
API_SECRET = os.getenv('BINANCE_API_SECRET_LIVE')
client = Client(API_KEY, API_SECRET)
app = Flask(__name__)
@app.route('/')
def dashboard():
html = """
Trading Bot v0.6
Active Trades
| Symbol | Qty | Entry Price | Entry Time |
"""
return render_template_string(html)
@app.route('/api/state')
def api_state():
try:
with open('/home/marc/bot-deploy/active_trades.json') as f:
trades_data = json.load(f)
return jsonify({
'active_trades': trades_data.get('active_trades', {}),
'active_positions': trades_data.get('count', 0),
'portfolio_value': trades_data.get('portfolio_value', 0),
'pnl_pct': 0, # Fetched from DB
'pnl_usdt': 0
})
except:
return jsonify({'error': 'No data'}), 404
@app.route('/api/pnl-history')
def api_pnl_history():
try:
conn = sqlite3.connect('/home/marc/bot-deploy/pnl_charts.db')
rows = conn.execute('SELECT pp FROM history ORDER BY ts DESC LIMIT 1').fetchall()
conn.close()
if rows:
return jsonify({'current_pct': rows[0][0], 'current_usdt': 0, 'entries': []})
return jsonify({'current_pct': 0, 'current_usdt': 0, 'entries': []})
except:
return jsonify({'error': 'No data'}), 404
if __name__ == '__main__':
app.run(host='0.0.0.0', port=7000, debug=False)