Affichage graph des données / sélection des indicateurs
This commit is contained in:
55
src/app.py
55
src/app.py
@@ -1,4 +1,4 @@
|
||||
from flask import Flask, jsonify, abort, render_template, send_from_directory
|
||||
from flask import Flask, jsonify, abort, render_template, send_from_directory,request
|
||||
import pandas as pd
|
||||
import json
|
||||
import zipfile
|
||||
@@ -102,14 +102,59 @@ def read_json(filename):
|
||||
def read_feather(filename):
|
||||
path = os.path.join(FREQTRADE_USERDATA_DIR + "/data/binance/", filename)
|
||||
try:
|
||||
print(path)
|
||||
df = pd.read_feather(path)
|
||||
print(df)
|
||||
return df.to_json(orient="records")
|
||||
dataframe = pd.read_feather(path)
|
||||
# dataframe['min'] = talib.MIN(dataframe['close'], timeperiod=200)
|
||||
# dataframe['min12'] = talib.MIN(dataframe['close'], timeperiod=12)
|
||||
#
|
||||
# dataframe['min50'] = talib.MIN(dataframe['close'], timeperiod=50)
|
||||
# dataframe['min200'] = talib.MIN(dataframe['close'], timeperiod=200)
|
||||
# dataframe['max200'] = talib.MAX(dataframe['close'], timeperiod=200)
|
||||
|
||||
return dataframe.to_json(orient="records")
|
||||
except Exception as e:
|
||||
print(e)
|
||||
return jsonify({"error": str(e)}), 500
|
||||
|
||||
@app.route('/get_chart_data')
|
||||
def get_chart_data():
|
||||
filename = request.args.get('filename', '')
|
||||
path = os.path.join(FREQTRADE_USERDATA_DIR + "/data/binance/", filename)
|
||||
print(path)
|
||||
indicators = request.args.get('indicators', '').split(',')
|
||||
df = pd.read_feather(path)
|
||||
print(df)
|
||||
|
||||
# # Calculs conditionnels
|
||||
# if 'sma' in indicators:
|
||||
# df['sma'] = df['close'].rolling(window=20).mean()
|
||||
# if 'rsi' in indicators:
|
||||
# delta = df['close'].diff()
|
||||
# gain = delta.where(delta > 0, 0)
|
||||
# loss = -delta.where(delta < 0, 0)
|
||||
# avg_gain = gain.rolling(14).mean()
|
||||
# avg_loss = loss.rolling(14).mean()
|
||||
# rs = avg_gain / avg_loss
|
||||
# df['rsi'] = 100 - (100 / (1 + rs))
|
||||
# if 'bollinger' in indicators:
|
||||
# sma = df['close'].rolling(window=20).mean()
|
||||
# std = df['close'].rolling(window=20).std()
|
||||
# df['bb_upper'] = sma + 2 * std
|
||||
# df['bb_lower'] = sma - 2 * std
|
||||
#
|
||||
# df = df.dropna()
|
||||
|
||||
# Simplifier les données pour le JSON
|
||||
# chart_data = {
|
||||
# 'date': df['date'].astype(str).tolist(),
|
||||
# 'close': df['close'].tolist(),
|
||||
# 'sma': df.get('sma', pd.Series()).tolist(),
|
||||
# 'rsi': df.get('rsi', pd.Series()).tolist(),
|
||||
# 'bb_upper': df.get('bb_upper', pd.Series()).tolist(),
|
||||
# 'bb_lower': df.get('bb_lower', pd.Series()).tolist(),
|
||||
# }
|
||||
|
||||
return df.to_json(orient="records") #jsonify(chart_data)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
app.run(debug=True, host='0.0.0.0', port=5000)
|
||||
|
||||
Reference in New Issue
Block a user