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格式,分析要精准专业。"""
|
||||
|
||||
def analyze_all_symbols(self) -> Dict[str, Dict[str, Any]]:
|
||||
def analyze_symbol(self, symbol: str) -> Dict[str, Any]:
|
||||
"""
|
||||
分析所有支持的交易对
|
||||
|
||||
Returns:
|
||||
所有交易对的分析结果
|
||||
分析单个交易对
|
||||
"""
|
||||
results = {}
|
||||
|
||||
for symbol in self.symbols:
|
||||
print(f"\n开始分析{symbol}...")
|
||||
|
||||
# 获取并处理数据
|
||||
@ -302,8 +298,25 @@ class CryptoAgent:
|
||||
|
||||
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()}")
|
||||
|
||||
if symbol:
|
||||
results = self.analyze_symbol(symbol)
|
||||
else:
|
||||
results = self.analyze_all_symbols()
|
||||
|
||||
# 保存分析结果
|
||||
@ -343,7 +359,7 @@ class CryptoAgent:
|
||||
把分析的JSON结果调用大模型转化成交易建议
|
||||
"""
|
||||
prompt = f"""
|
||||
请对以下加密货币市场分析的JSON结果进行深入分析, 转化成包含:分析时间,技术分析,支撑位,压力位, 建议买点,卖点,止损位,止盈位,仓位建议, 增加适当的emoji便于阅读, 简单明了。
|
||||
请对以下加密货币市场分析的JSON结果进行深入分析, 转化成包含:分析时间,分析时间级别,技术分析,支撑位,压力位, 建议买点,卖点,止损位,止盈位,仓位建议, 增加适当的emoji便于阅读, 简单明了。
|
||||
|
||||
分析 JSON 结果:
|
||||
{results}
|
||||
@ -392,7 +408,7 @@ class CryptoAgent:
|
||||
except Exception as 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("启动加密货币分析智能体...")
|
||||
|
||||
try:
|
||||
if symbol:
|
||||
self.run_analysis_cycle(symbol)
|
||||
else:
|
||||
self.run_analysis_cycle()
|
||||
# 导出最终的token使用情况
|
||||
self._export_token_usage()
|
||||
|
||||
|
||||
except KeyboardInterrupt:
|
||||
print("\n智能体已停止")
|
||||
# 导出最终的token使用情况
|
||||
|
||||
@ -276,7 +276,7 @@ class GoldAgent:
|
||||
"seasonal_factor": float(processed_data['seasonal_factor'].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 使用情况
|
||||
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:
|
||||
"""
|
||||
|
||||
@ -25,13 +25,13 @@ alltick:
|
||||
# 加密货币设置
|
||||
crypto:
|
||||
base_currencies:
|
||||
- "BTC"
|
||||
- "ETH"
|
||||
# - "BTC"
|
||||
# - "ETH"
|
||||
# - "SOL"
|
||||
# - "SUI"
|
||||
# - "XRP"
|
||||
- "CETUS"
|
||||
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
|
||||
|
||||
# 黄金市场分析配置
|
||||
@ -39,9 +39,9 @@ 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():
|
||||
try:
|
||||
print("程序启动")
|
||||
print("定时程序启动")
|
||||
# 设置每个4小时运行一次
|
||||
schedule.every(4).hours.do(CryptoAgent().start_agent)
|
||||
|
||||
@ -26,7 +26,10 @@ def main():
|
||||
while True:
|
||||
schedule.run_pending()
|
||||
time.sleep(1)
|
||||
# CryptoAgent().start_agent()
|
||||
|
||||
|
||||
# GoldAgent().start_agent()
|
||||
# CryptoAgent().start_agent('BTCUSDT')
|
||||
|
||||
except KeyboardInterrupt:
|
||||
print("\n程序已退出")
|
||||
|
||||
Loading…
Reference in New Issue
Block a user