diff --git a/cryptoai/api/__pycache__/binance_api.cpython-313.pyc b/cryptoai/api/__pycache__/binance_api.cpython-313.pyc index 01b0d34..68d6366 100644 Binary files a/cryptoai/api/__pycache__/binance_api.cpython-313.pyc and b/cryptoai/api/__pycache__/binance_api.cpython-313.pyc differ diff --git a/cryptoai/api/binance_api.py b/cryptoai/api/binance_api.py index 77d26ea..ba40749 100644 --- a/cryptoai/api/binance_api.py +++ b/cryptoai/api/binance_api.py @@ -47,6 +47,41 @@ class BinanceAPI: return result + def get_top_longshort_position_ratio(self, symbol: str, period: str = '1h') -> float: + """ + 获取交易对大户持仓多空比 + + Args: + symbol: 交易对符号,例如 'BTCUSDT' + period: 时间间隔,例如 '1h', '1d' + + Returns: + 大户持仓多空比 + """ + try: + response = self.client.futures_top_longshort_position_ratio(symbol=symbol, period=period) + return response + except BinanceAPIException as e: + print(f"获取交易对大户持仓多空比时出错: {e}") + return 0 + + def get_top_longshort_account_ratio(self, symbol: str, period: str = '1h') -> float: + """ + 获取交易对大户持仓多空比 + + Args: + symbol: 交易对符号,例如 'BTCUSDT' + period: 时间间隔,例如 '1h', '1d' + + Returns: + 大户持仓多空比 + """ + try: + response = self.client.futures_top_longshort_account_ratio(symbol=symbol, period=period) + return response + except BinanceAPIException as e: + print(f"获取交易对大户持仓多空比时出错: {e}") + return 0 def get_historical_klines(self, symbol: str, interval: str, start_str: str, end_str: Optional[str] = None) -> pd.DataFrame: """ diff --git a/cryptoai/routes/agent.py b/cryptoai/routes/agent.py index 3caeead..3ca6586 100644 --- a/cryptoai/routes/agent.py +++ b/cryptoai/routes/agent.py @@ -15,6 +15,8 @@ import logging from cryptoai.api.deepseek_api import DeepSeekAPI from cryptoai.utils.config_loader import ConfigLoader from fastapi.responses import StreamingResponse +from cryptoai.routes.user import get_current_user +import requests # 创建路由 router = APIRouter() @@ -22,13 +24,45 @@ class ChatRequest(BaseModel): user_prompt: str +@router.get("/list") +async def get_agents(current_user: Dict[str, Any] = Depends(get_current_user)): + """ + 获取所有代理 + """ + return [ + { + "id": "1", + "name": "二级市场助手", + "hello_prompt": "您好,我是二级市场助手,为您提供专业的二级市场分析和建议", + "description": "为您提供专业的二级市场分析和建议", + } + ] + + @router.post("/chat") -async def chat(request: ChatRequest): +async def chat(request: ChatRequest,current_user: Dict[str, Any] = Depends(get_current_user)): """ 聊天接口 """ + + token = "app-vhJecqbcLukf72g0uxAb9tcz" + url = "https://mate.aimateplus.com/v1/chat-messages" + headers = { + "Authorization": f"Bearer {token}", + "Content-Type": "application/json" + } + data = { + "inputs" : {}, + "query" : request.user_prompt, + "response_mode" : "streaming", + "user" : current_user["mail"] + } + response = requests.post(url, headers=headers, json=data, stream=True) - deepseek_api = DeepSeekAPI() - response = deepseek_api.streaming_call(request.user_prompt) + #获取response 的 stream + def stream_response(): + for chunk in response.iter_content(chunk_size=1024): + if chunk: + yield chunk - return StreamingResponse(response, media_type="text/plain") + return StreamingResponse(stream_response(), media_type="text/plain") diff --git a/cryptoai/task_endpoint.py b/cryptoai/task_endpoint.py index 445e37b..85ff471 100644 --- a/cryptoai/task_endpoint.py +++ b/cryptoai/task_endpoint.py @@ -25,7 +25,7 @@ def task_start(): try: # GoldAgent().start_agent() - # CryptoAgent().start_agent() + # CryptoAgent().start_agent("WLDUSDT") # return logger.info("🚀 加密货币Agent程序已启动") diff --git a/docker-compose.yml b/docker-compose.yml index b313220..d1eae38 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -29,7 +29,7 @@ services: cryptoai-api: build: . container_name: cryptoai-api - image: cryptoai-api:0.0.4 + image: cryptoai-api:0.0.5 restart: always ports: - "8000:8000" diff --git a/test.py b/test.py new file mode 100644 index 0000000..80c57dc --- /dev/null +++ b/test.py @@ -0,0 +1,8 @@ +from cryptoai.api.binance_api import BinanceAPI +from cryptoai.utils.config_loader import ConfigLoader + +config = ConfigLoader().get_binance_config() + +binance_api = BinanceAPI(config['api_key'], config['api_secret']) + +print(binance_api.get_top_longshort_position_ratio("BTCUSDT", "1h")) \ No newline at end of file