update
This commit is contained in:
parent
13c335a524
commit
51a3ea5e2f
Binary file not shown.
Binary file not shown.
@ -217,16 +217,12 @@ class CryptoAgent:
|
|||||||
|
|
||||||
请确保回复为有效的JSON格式,分析要精准专业。"""
|
请确保回复为有效的JSON格式,分析要精准专业。"""
|
||||||
|
|
||||||
def analyze_all_symbols(self) -> Dict[str, Dict[str, Any]]:
|
def analyze_symbol(self, symbol: str) -> Dict[str, Any]:
|
||||||
"""
|
"""
|
||||||
分析所有支持的交易对
|
分析单个交易对
|
||||||
|
|
||||||
Returns:
|
|
||||||
所有交易对的分析结果
|
|
||||||
"""
|
"""
|
||||||
results = {}
|
results = {}
|
||||||
|
|
||||||
for symbol in self.symbols:
|
|
||||||
print(f"\n开始分析{symbol}...")
|
print(f"\n开始分析{symbol}...")
|
||||||
|
|
||||||
# 获取并处理数据
|
# 获取并处理数据
|
||||||
@ -302,8 +298,25 @@ class CryptoAgent:
|
|||||||
|
|
||||||
return results
|
return results
|
||||||
|
|
||||||
|
def analyze_all_symbols(self) -> Dict[str, Dict[str, Any]]:
|
||||||
|
"""
|
||||||
|
分析所有支持的交易对
|
||||||
|
|
||||||
def run_analysis_cycle(self) -> Dict[str, Any]:
|
Returns:
|
||||||
|
所有交易对的分析结果
|
||||||
|
"""
|
||||||
|
results = {}
|
||||||
|
|
||||||
|
for symbol in self.symbols:
|
||||||
|
print(f"\n开始分析{symbol}...")
|
||||||
|
|
||||||
|
single_result = self.analyze_symbol(symbol)
|
||||||
|
results[symbol] = single_result[symbol]
|
||||||
|
|
||||||
|
return results
|
||||||
|
|
||||||
|
|
||||||
|
def run_analysis_cycle(self, symbol: Optional[str] = None) -> Dict[str, Any]:
|
||||||
"""
|
"""
|
||||||
运行一个完整的分析周期
|
运行一个完整的分析周期
|
||||||
|
|
||||||
@ -312,6 +325,9 @@ class CryptoAgent:
|
|||||||
"""
|
"""
|
||||||
print(f"开始新的分析周期,时间:{datetime.now().isoformat()}")
|
print(f"开始新的分析周期,时间:{datetime.now().isoformat()}")
|
||||||
|
|
||||||
|
if symbol:
|
||||||
|
results = self.analyze_symbol(symbol)
|
||||||
|
else:
|
||||||
results = self.analyze_all_symbols()
|
results = self.analyze_all_symbols()
|
||||||
|
|
||||||
# 保存分析结果
|
# 保存分析结果
|
||||||
@ -343,7 +359,7 @@ class CryptoAgent:
|
|||||||
把分析的JSON结果调用大模型转化成交易建议
|
把分析的JSON结果调用大模型转化成交易建议
|
||||||
"""
|
"""
|
||||||
prompt = f"""
|
prompt = f"""
|
||||||
请对以下加密货币市场分析的JSON结果进行深入分析, 转化成包含:分析时间,技术分析,支撑位,压力位, 建议买点,卖点,止损位,止盈位,仓位建议, 增加适当的emoji便于阅读, 简单明了。
|
请对以下加密货币市场分析的JSON结果进行深入分析, 转化成包含:分析时间,分析时间级别,技术分析,支撑位,压力位, 建议买点,卖点,止损位,止盈位,仓位建议, 增加适当的emoji便于阅读, 简单明了。
|
||||||
|
|
||||||
分析 JSON 结果:
|
分析 JSON 结果:
|
||||||
{results}
|
{results}
|
||||||
@ -392,7 +408,7 @@ class CryptoAgent:
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"导出 token 使用情况时出错: {e}")
|
print(f"导出 token 使用情况时出错: {e}")
|
||||||
|
|
||||||
def start_agent(self) -> None:
|
def start_agent(self, symbol: Optional[str] = None) -> None:
|
||||||
"""
|
"""
|
||||||
启动智能体
|
启动智能体
|
||||||
|
|
||||||
@ -402,11 +418,13 @@ class CryptoAgent:
|
|||||||
print("启动加密货币分析智能体...")
|
print("启动加密货币分析智能体...")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
if symbol:
|
||||||
|
self.run_analysis_cycle(symbol)
|
||||||
|
else:
|
||||||
self.run_analysis_cycle()
|
self.run_analysis_cycle()
|
||||||
# 导出最终的token使用情况
|
# 导出最终的token使用情况
|
||||||
self._export_token_usage()
|
self._export_token_usage()
|
||||||
|
|
||||||
|
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
print("\n智能体已停止")
|
print("\n智能体已停止")
|
||||||
# 导出最终的token使用情况
|
# 导出最终的token使用情况
|
||||||
|
|||||||
@ -276,7 +276,7 @@ class GoldAgent:
|
|||||||
"seasonal_factor": float(processed_data['seasonal_factor'].iloc[-1]),
|
"seasonal_factor": float(processed_data['seasonal_factor'].iloc[-1]),
|
||||||
"gold_bull_signal": float(processed_data['gold_bull_signal'].iloc[-1])
|
"gold_bull_signal": float(processed_data['gold_bull_signal'].iloc[-1])
|
||||||
},
|
},
|
||||||
"klines": processed_data[['open', 'high', 'low', 'close', 'volume']].tail(30).to_dict('records')
|
"klines": processed_data[['open', 'high', 'low', 'close', 'volume']].tail(100).to_dict('records')
|
||||||
}
|
}
|
||||||
|
|
||||||
# 将市场数据格式化为适合大模型的格式
|
# 将市场数据格式化为适合大模型的格式
|
||||||
@ -332,7 +332,34 @@ class GoldAgent:
|
|||||||
# 导出 DeepSeek API token 使用情况
|
# 导出 DeepSeek API token 使用情况
|
||||||
self._export_token_usage()
|
self._export_token_usage()
|
||||||
|
|
||||||
return results
|
# 把分析的JSON结果调用大模型转化成交易建议
|
||||||
|
trading_suggestions = self.convert_analysis_to_trading_suggestions(results)
|
||||||
|
print(f"交易建议:{trading_suggestions}")
|
||||||
|
|
||||||
|
if self.dingtalk_bot:
|
||||||
|
self.dingtalk_bot.send_markdown(title="黄金交易建议", text=trading_suggestions)
|
||||||
|
|
||||||
|
return results, trading_suggestions
|
||||||
|
|
||||||
|
def convert_analysis_to_trading_suggestions(self, results: Dict[str, Any]) -> str:
|
||||||
|
"""
|
||||||
|
把分析的JSON结果调用大模型转化成交易建议
|
||||||
|
"""
|
||||||
|
prompt = f"""
|
||||||
|
请对以下黄金市场分析的JSON结果进行深入分析, 转化成包含:分析时间,技术分析,支撑位,压力位, 建议买点,卖点,止损位,止盈位,仓位建议, 增加适当的emoji便于阅读, 简单明了。
|
||||||
|
|
||||||
|
分析 JSON 结果:
|
||||||
|
{results}
|
||||||
|
"""
|
||||||
|
|
||||||
|
system_prompt = """
|
||||||
|
你是一个专业的黄金分析助手,你擅长分析市场趋势、预测价格走向和提供交易建议,请始终使用中文回复,并确保输出格式规范的Markdown。
|
||||||
|
"""
|
||||||
|
response, usage = self.deepseek_api.call_model(prompt, system_prompt=system_prompt, task_type="交易建议")
|
||||||
|
|
||||||
|
message = self.deepseek_api.extract_text_from_response(response)
|
||||||
|
|
||||||
|
return message
|
||||||
|
|
||||||
def _export_token_usage(self) -> None:
|
def _export_token_usage(self) -> None:
|
||||||
"""
|
"""
|
||||||
|
|||||||
@ -25,13 +25,13 @@ alltick:
|
|||||||
# 加密货币设置
|
# 加密货币设置
|
||||||
crypto:
|
crypto:
|
||||||
base_currencies:
|
base_currencies:
|
||||||
- "BTC"
|
# - "BTC"
|
||||||
- "ETH"
|
# - "ETH"
|
||||||
# - "SOL"
|
# - "SOL"
|
||||||
# - "SUI"
|
# - "SUI"
|
||||||
# - "XRP"
|
- "CETUS"
|
||||||
quote_currency: "USDT"
|
quote_currency: "USDT"
|
||||||
time_interval: "1h" # 可选: 1m, 5m, 15m, 30m, 1h, 4h, 1d
|
time_interval: "4h" # 可选: 1m, 5m, 15m, 30m, 1h, 4h, 1d
|
||||||
historical_days: 30
|
historical_days: 30
|
||||||
|
|
||||||
# 黄金市场分析配置
|
# 黄金市场分析配置
|
||||||
@ -39,9 +39,9 @@ gold:
|
|||||||
# 黄金交易对
|
# 黄金交易对
|
||||||
symbols: ["GOLD"]
|
symbols: ["GOLD"]
|
||||||
# 历史数据天数
|
# 历史数据天数
|
||||||
historical_days: 180
|
historical_days: 30
|
||||||
# 时间间隔
|
# 时间间隔
|
||||||
time_interval: "1d"
|
time_interval: "4h"
|
||||||
|
|
||||||
|
|
||||||
# 数据设置
|
# 数据设置
|
||||||
|
|||||||
@ -18,7 +18,7 @@ from cryptoai.utils.config_loader import ConfigLoader
|
|||||||
|
|
||||||
def main():
|
def main():
|
||||||
try:
|
try:
|
||||||
print("程序启动")
|
print("定时程序启动")
|
||||||
# 设置每个4小时运行一次
|
# 设置每个4小时运行一次
|
||||||
schedule.every(4).hours.do(CryptoAgent().start_agent)
|
schedule.every(4).hours.do(CryptoAgent().start_agent)
|
||||||
|
|
||||||
@ -26,7 +26,10 @@ def main():
|
|||||||
while True:
|
while True:
|
||||||
schedule.run_pending()
|
schedule.run_pending()
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
# CryptoAgent().start_agent()
|
|
||||||
|
|
||||||
|
# GoldAgent().start_agent()
|
||||||
|
# CryptoAgent().start_agent('BTCUSDT')
|
||||||
|
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
print("\n程序已退出")
|
print("\n程序已退出")
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user