Untitled
unknown
plain_text
a year ago
1.1 kB
4
Indexable
from flask import Flask, jsonify, render_template
import pandas as pd
app = Flask(__name__)
# Route to serve the main dashboard page
@app.route('/')
def index():
return render_template('index.html')
# Route to fetch trade history data
@app.route('/trades')
def trades():
try:
# Read trades from the CSV file
trades_df = pd.read_csv('trades_history.csv', names=['timestamp', 'symbol', 'signal', 'lot_size', 'price', 'sl_price', 'tp_price'])
# Convert the timestamp to datetime
trades_df['timestamp'] = pd.to_datetime(trades_df['timestamp'], errors='coerce')
# Drop rows where timestamp or price is NaT or NaN
trades_df = trades_df.dropna(subset=['timestamp', 'price'])
# Convert to a list of dictionaries
trades_list = trades_df.to_dict(orient='records')
return jsonify(trades_list)
except Exception as e:
# Return error if something goes wrong
return jsonify({"error": str(e)})
if __name__ == '__main__':
app.run(debug=True)Editor is loading...
Leave a Comment