Spaces:
Sleeping
Sleeping
File size: 1,671 Bytes
fe31096 06e5903 375614c e63adc7 06e5903 e63adc7 06e5903 e63adc7 06e5903 e63adc7 06e5903 e63adc7 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
import re
import requests
import httpx
#Извлечение UUID из строки
def extract_portfolio_id(text: str) -> str | None:
match = re.search(
r"[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}",
text
)
return match.group(0) if match else None
async def fetch_metrics_async(portfolio_id: str) -> dict | None:
url = f"https://api.tradelink.pro/portfolio/get?portfolioId={portfolio_id}&extended=1"
try:
async with httpx.AsyncClient(timeout=10) as client:
resp = await client.get(url)
extended = resp.json().get("data", {}).get("extended", {})
return {k: v for k, v in extended.items() if isinstance(v, (int, float))}
except Exception as e:
print(f"[API ошибка]: {e}")
return None
# print(f"[API ошибка]: {e}")
# return None
#
# keys = [
# # 🔹 Доходность и риск
# "alphaRatio", "betaRatio", "cagr", "sharpe", "sortino", "volatility",
# "kSortino", "kCalmar", "kSharpe",
#
# # 🔹 Просадки
# "maxDD", "mddDuration", "maxBalance",
#
# # 🔹 Поведение стратегии
# "losingDays", "winningDays", "selfProfitRate",
#
# # 🔹 Актуальные показатели доходности
# "lastWeekNetProfit", "lastMonthNetProfit", "lastQuarterGrowth", "lastYearNetGrowth"
# ]
# return {k: extended[k] for k in keys if isinstance(extended.get(k), (int, float))}
# except:
# return None
|