Skip to content

Commit

Permalink
Added module import resolution in backtest.py
Browse files Browse the repository at this point in the history
  • Loading branch information
SelamT94 committed Jun 21, 2024
1 parent e11411e commit 41547dc
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions app/routes/backtest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
from flask import Flask, request, jsonify
import sys
import os
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..')))

from scripts.backtest_runner import run_backtest, RsiBollingerBandsStrategy
app = Flask(__name__)

@app.route('/backtest', methods=['GET','POST'])
def backtest():
data = request.get_json()
symbol = data['symbol']
start_date = data['start_date']
end_date = data['end_date']
strategy_name = data['strategy']

strategies = {
'rsi_bollinger': RsiBollingerBandsStrategy
}

strategy = strategies.get(strategy_name.lower())
if not strategy:
return jsonify({'error': 'Invalid strategy name'}), 400

try:
stats = run_backtest(strategy, symbol, start_date, end_date)
return jsonify(stats)
except Exception as e:
return jsonify({'error': str(e)}), 400

# def backtest():
# return 'Backtest endpoint accessed successfully'

if __name__ == '__main__':
app.run(debug=True)

0 comments on commit 41547dc

Please sign in to comment.