update
This commit is contained in:
parent
a5b25d6482
commit
e799afccc3
Binary file not shown.
@ -84,7 +84,7 @@ class BinanceAPI:
|
|||||||
print(f"获取交易对大户持仓多空比时出错: {e}")
|
print(f"获取交易对大户持仓多空比时出错: {e}")
|
||||||
return 0
|
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线数据
|
获取历史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'))
|
if ts_transform:
|
||||||
df['close_time'] = pd.to_datetime(df['close_time'], unit='ms', utc=True).map(lambda x: x.tz_convert('Asia/Shanghai'))
|
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',
|
for col in ['open', 'high', 'low', 'close', 'volume', 'quote_asset_volume',
|
||||||
'taker_buy_base_asset_volume', 'taker_buy_quote_asset_volume']:
|
'taker_buy_base_asset_volume', 'taker_buy_quote_asset_volume']:
|
||||||
|
|||||||
@ -36,7 +36,7 @@ async def get_crypto_kline(symbol: str, timeframe: Optional[str] = None, limit:
|
|||||||
|
|
||||||
binance_api = get_binance_api()
|
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()
|
data_processor = DataProcessor()
|
||||||
|
|
||||||
@ -47,6 +47,51 @@ async def get_crypto_kline(symbol: str, timeframe: Optional[str] = None, limit:
|
|||||||
return result
|
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")
|
@router.post("/analysis")
|
||||||
async def analysis_crypto(request: CryptoAnalysisRequest,
|
async def analysis_crypto(request: CryptoAnalysisRequest,
|
||||||
current_user: dict = Depends(get_current_user)):
|
current_user: dict = Depends(get_current_user)):
|
||||||
|
|||||||
@ -29,7 +29,7 @@ services:
|
|||||||
cryptoai-api:
|
cryptoai-api:
|
||||||
build: .
|
build: .
|
||||||
container_name: cryptoai-api
|
container_name: cryptoai-api
|
||||||
image: cryptoai-api:0.0.26
|
image: cryptoai-api:0.0.27
|
||||||
restart: always
|
restart: always
|
||||||
ports:
|
ports:
|
||||||
- "8000:8000"
|
- "8000:8000"
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user