#!/usr/bin/env python3 from fastapi import FastAPI from fastapi.responses import HTMLResponse from binance.client import Client from datetime import datetime import json, os, time, sqlite3 app = FastAPI() env = {} with open('/home/marc/bot-deploy/.env') as f: for line in f: k, _, v = line.partition('=') env[k.strip()] = v.strip() binance = Client(env.get('BINANCE_API_KEY_LIVE'), env.get('BINANCE_API_SECRET_LIVE')) DB = '/home/marc/bot-deploy/pnl_charts.db' def get_chart_data(days=1): conn = sqlite3.connect(DB) rows = conn.execute(f"""SELECT ts, pv, pp FROM history WHERE ts > {int(time.time()) - days*86400} ORDER BY ts""").fetchall() conn.close() return [(datetime.fromtimestamp(r[0]).strftime('%H:%M'), r[2]) for r in rows] @app.get('/') async def root(): chart_1d = get_chart_data(1) chart_7d = get_chart_data(7) chart_30d = get_chart_data(30) html = f'''
Contrarian Mean Reversion Strategy
1-Day Chart: {len(chart_1d)} points
7-Day Chart: {len(chart_7d)} points
30-Day Chart: {len(chart_30d)} points