This commit is contained in:
aaron 2025-05-08 00:44:07 +08:00
parent 854bf07286
commit d71d6cca5b
6 changed files with 83 additions and 6 deletions

View File

@ -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:
"""

View File

@ -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")

View File

@ -25,7 +25,7 @@ def task_start():
try:
# GoldAgent().start_agent()
# CryptoAgent().start_agent()
# CryptoAgent().start_agent("WLDUSDT")
# return
logger.info("🚀 加密货币Agent程序已启动")

View File

@ -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"

8
test.py Normal file
View File

@ -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"))