diff --git a/cryptoai/api/__pycache__/binance_api.cpython-313.pyc b/cryptoai/api/__pycache__/binance_api.cpython-313.pyc index 6e4225a..fe33dda 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 40984fa..372e4de 100644 --- a/cryptoai/api/binance_api.py +++ b/cryptoai/api/binance_api.py @@ -84,7 +84,7 @@ class BinanceAPI: print(f"获取交易对大户持仓多空比时出错: {e}") return 0 - def get_historical_klines(self, symbol: str, interval: str, start_str: Optional[str] = None, end_str: Optional[str] = None, limit: Optional[int] = None) -> pd.DataFrame: + def get_historical_klines(self, symbol: str, interval: str, start_str: Optional[str] = None, end_str: Optional[str] = None, limit: Optional[int] = None, ts_transform: bool = True) -> pd.DataFrame: """ 获取历史K线数据 @@ -114,8 +114,9 @@ class BinanceAPI: ]) # 转换数据类型 - df['timestamp'] = pd.to_datetime(df['timestamp'], unit='ms', utc=True).map(lambda x: x.tz_convert('Asia/Shanghai')) - df['close_time'] = pd.to_datetime(df['close_time'], unit='ms', utc=True).map(lambda x: x.tz_convert('Asia/Shanghai')) + if ts_transform: + df['timestamp'] = pd.to_datetime(df['timestamp'], unit='ms', utc=True).map(lambda x: x.tz_convert('Asia/Shanghai')) + df['close_time'] = pd.to_datetime(df['close_time'], unit='ms', utc=True).map(lambda x: x.tz_convert('Asia/Shanghai')) for col in ['open', 'high', 'low', 'close', 'volume', 'quote_asset_volume', 'taker_buy_base_asset_volume', 'taker_buy_quote_asset_volume']: diff --git a/cryptoai/routes/crypto.py b/cryptoai/routes/crypto.py index f48ca23..39d9846 100644 --- a/cryptoai/routes/crypto.py +++ b/cryptoai/routes/crypto.py @@ -36,7 +36,7 @@ async def get_crypto_kline(symbol: str, timeframe: Optional[str] = None, limit: binance_api = get_binance_api() - kline = binance_api.get_historical_klines(symbol=symbol, interval=timeframe, limit=limit) + kline = binance_api.get_historical_klines(symbol=symbol, interval=timeframe, limit=limit, ts_transform=False) data_processor = DataProcessor() @@ -47,6 +47,51 @@ async def get_crypto_kline(symbol: str, timeframe: Optional[str] = None, limit: return result +@router.post("/analysis_v2") +async def analysis_crypto_v2(request: CryptoAnalysisRequest, + current_user: dict = Depends(get_current_user)): + + if request.symbol.endswith("USDT"): + symbol = request.symbol + else: + symbol = request.symbol + "USDT" + + url = 'https://mate.aimateplus.com/v1/workflows/run' + token = 'app-BbaqIAMPi0ktgaV9IizMlc2N' + headers = { + 'Authorization': f'Bearer {token}', + 'Content-Type': 'application/json' + } + + data = { + "inputs" : { + "symbol" : symbol, + "timeframe" : request.timeframe + }, + "response_mode": "streaming", + "user": current_user["mail"] + } + + # 保存用户提问 + get_db_manager().save_user_question(current_user["id"], symbol, "请分析以下加密货币:" + symbol + ",并给出分析报告。") + + response = requests.post(url, headers=headers, json=data, stream=True) + + # 如果响应不成功,返回错误 + if response.status_code != 200: + raise HTTPException( + status_code=response.status_code, + detail=f"Failed to get response from Dify API: {response.text}" + ) + + # 获取response的stream + def stream_response(): + for chunk in response.iter_content(chunk_size=1024): + if chunk: + yield chunk + + return StreamingResponse(stream_response(), media_type="text/plain") + @router.post("/analysis") async def analysis_crypto(request: CryptoAnalysisRequest, current_user: dict = Depends(get_current_user)): diff --git a/docker-compose.yml b/docker-compose.yml index 47236b4..641728f 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.26 + image: cryptoai-api:0.0.27 restart: always ports: - "8000:8000"