from flask import Flask, jsonify from flask_cors import CORS import yfinance as yf app = Flask(__name__) CORS(app) @app.route('/fetch_candles', methods=['GET']) def fetch_candles(): try: ticker = yf.Ticker('AAPL') data = ticker.history(period='1y') candles = [] for index, row in data.iterrows(): candle = { 'time': int(index.timestamp() * 1000), 'open': float(row['Open']), 'high': float(row['High']), 'low': float(row['Low']), 'close': float(row['Close']), 'volume': float(row['Volume']) } candles.append(candle) return jsonify(candles) except Exception as e: return jsonify({'error': str(e)}), 500 if __name__ == '__main__': app.run(debug=True, port=5000)