修改排版,加入up,down,flat,unknown显示
This commit is contained in:
+46
-5
@@ -352,12 +352,13 @@ def analyze_chan(df, symbol=None, timeframe=None):
|
||||
|
||||
# 初始化多时间周期数据以获取EMA52
|
||||
ema52_dict = None
|
||||
if symbol and timeframe:
|
||||
# 先暂时不用这个功能,太慢了
|
||||
if symbol and timeframe and False:
|
||||
try:
|
||||
# 获取不同时间周期的数据用于初始化
|
||||
df_1h = get_kl_data(symbol, '1h', limit=800) if timeframe != '1h' else df
|
||||
df_1d = get_kl_data(symbol, '1d', limit=800) if timeframe != '1d' else df
|
||||
df_1M = get_kl_data(symbol, '1M', limit=800) if timeframe != '1M' else df
|
||||
df_1h = get_kl_data(symbol, '1h', limit=1500) if timeframe != '1h' else df
|
||||
df_1d = get_kl_data(symbol, '1d', limit=2000) if timeframe != '1d' else df
|
||||
df_1M = get_kl_data(symbol, '1M', limit=1500) if timeframe != '1M' else df
|
||||
|
||||
# 添加指标
|
||||
if df_1h is not None and len(df_1h) > 0:
|
||||
@@ -1659,6 +1660,24 @@ def analyze():
|
||||
else:
|
||||
replay_data = None
|
||||
|
||||
# 基于已有 KLC 列表生成趋势标记(不做额外计算)
|
||||
klc_trend = []
|
||||
try:
|
||||
for klc in analysis_result.get('klc_list', []):
|
||||
trend_val = getattr(klc, 'trend', None)
|
||||
t_obj = getattr(klc, 'end_time', None) or getattr(klc, 'start_time', None)
|
||||
if trend_val is None or t_obj is None:
|
||||
continue
|
||||
# 统一成字符串:UP/DOWN/FLAT/UNKNOWN
|
||||
trend_name = str(trend_val)
|
||||
if '.' in trend_name:
|
||||
trend_name = trend_name.split('.')[-1]
|
||||
time_str = format_time_safely(t_obj, client_tz)
|
||||
if time_str:
|
||||
klc_trend.append({'time': time_str, 'trend': trend_name})
|
||||
except Exception:
|
||||
klc_trend = []
|
||||
|
||||
# 添加主周期分析结果到返回数据
|
||||
result.update({
|
||||
'kline_data': clean_dataframe_for_json(df).to_dict('records'),
|
||||
@@ -1753,7 +1772,9 @@ def analyze():
|
||||
# 添加ChanMACD分析数据
|
||||
'chan_macd': serialize_chan_macd_data(analysis_result.get('chan_macd', {}), client_tz),
|
||||
# 添加多时间周期EMA52数据
|
||||
'ema52_dict': analysis_result.get('ema52_dict', {})
|
||||
'ema52_dict': analysis_result.get('ema52_dict', {}),
|
||||
# 直接输出KLC趋势标记(使用已有trend字段)
|
||||
'klc_trend': klc_trend
|
||||
})
|
||||
|
||||
# 如果生成了回放数据,添加到返回结果中
|
||||
@@ -1775,6 +1796,23 @@ def analyze():
|
||||
# 计算小周期MACD数据
|
||||
element_macd_data = calculate_macd(element_df)
|
||||
|
||||
# 组装小周期 KLC 趋势(仅提取已有 trend,不做重算)
|
||||
try:
|
||||
element_klc_trend = []
|
||||
for klc in element_analysis.get('klc_list', []):
|
||||
trend_val = getattr(klc, 'trend', None)
|
||||
t_obj = getattr(klc, 'end_time', None) or getattr(klc, 'start_time', None)
|
||||
if trend_val is None or t_obj is None:
|
||||
continue
|
||||
trend_name = str(trend_val)
|
||||
if '.' in trend_name:
|
||||
trend_name = trend_name.split('.')[-1]
|
||||
time_str = format_time_safely(t_obj, client_tz)
|
||||
if time_str:
|
||||
element_klc_trend.append({'time': time_str, 'trend': trend_name})
|
||||
except Exception:
|
||||
element_klc_trend = []
|
||||
|
||||
# 添加小周期分析结果到返回数据
|
||||
result['element_timeframe'] = element_timeframe
|
||||
result['element_macd'] = element_macd_data # 添加小周期MACD数据
|
||||
@@ -1880,6 +1918,9 @@ def analyze():
|
||||
# 添加次周期ChanMACD分析数据
|
||||
result['element_chan_macd'] = serialize_chan_macd_data(element_analysis.get('chan_macd', {}), client_tz)
|
||||
|
||||
# 添加小周期 KLC 趋势标记
|
||||
result['element_klc_trend'] = element_klc_trend
|
||||
|
||||
pass
|
||||
|
||||
return jsonify(result)
|
||||
|
||||
Reference in New Issue
Block a user