Spaces:
Sleeping
Sleeping
QAway-to
commited on
Commit
·
c82df6a
1
Parent(s):
7882463
model change
Browse files- alpha_chart.py +40 -22
alpha_chart.py
CHANGED
|
@@ -3,31 +3,49 @@ import requests
|
|
| 3 |
|
| 4 |
def plot_alpha_btc_chart(portfolio_id: str):
|
| 5 |
url = f"https://api.tradelink.pro/portfolio/get?portfolioId={portfolio_id}&extended=1&declaration=1&step=day&lang=en&incViews=1"
|
| 6 |
-
headers = {
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
try:
|
| 9 |
response = requests.get(url, headers=headers)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
response.raise_for_status()
|
| 11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
except Exception as e:
|
| 13 |
-
print(f"[
|
| 14 |
return None
|
| 15 |
-
|
| 16 |
-
values = [item["value"] for item in alpha_data]
|
| 17 |
-
indices = list(range(len(values)))
|
| 18 |
-
|
| 19 |
-
fig, ax = plt.subplots(figsize=(12, 6))
|
| 20 |
-
ax.plot(indices, values, color='blue', linewidth=1.5, label='alphaBTC')
|
| 21 |
-
ax.axhline(0, color='black', linewidth=1)
|
| 22 |
-
ax.spines['right'].set_color('none')
|
| 23 |
-
ax.spines['top'].set_color('none')
|
| 24 |
-
ax.spines['bottom'].set_position('zero')
|
| 25 |
-
ax.spines['left'].set_position('zero')
|
| 26 |
-
ax.set_title("Alpha к BTC", fontsize=14)
|
| 27 |
-
ax.set_xlabel("Индекс")
|
| 28 |
-
ax.set_ylabel("Alpha")
|
| 29 |
-
ax.grid(True, linestyle='--', alpha=0.5)
|
| 30 |
-
ax.legend()
|
| 31 |
-
plt.tight_layout()
|
| 32 |
-
|
| 33 |
-
return fig # Возвращаем фигуру напрямую
|
|
|
|
| 3 |
|
| 4 |
def plot_alpha_btc_chart(portfolio_id: str):
|
| 5 |
url = f"https://api.tradelink.pro/portfolio/get?portfolioId={portfolio_id}&extended=1&declaration=1&step=day&lang=en&incViews=1"
|
| 6 |
+
headers = {
|
| 7 |
+
"User-Agent": "Mozilla/5.0",
|
| 8 |
+
"Accept": "application/json"
|
| 9 |
+
}
|
| 10 |
|
| 11 |
try:
|
| 12 |
response = requests.get(url, headers=headers)
|
| 13 |
+
print(f"[DEBUG] Status: {response.status_code}")
|
| 14 |
+
print(f"[DEBUG] Headers: {response.headers.get('Content-Type')}")
|
| 15 |
+
print(f"[DEBUG] Response preview: {response.text[:300]}...")
|
| 16 |
+
|
| 17 |
response.raise_for_status()
|
| 18 |
+
data = response.json()
|
| 19 |
+
|
| 20 |
+
extended = data.get("data", {}).get("extended", {})
|
| 21 |
+
alpha_data = extended.get("alphaBTC", [])
|
| 22 |
+
|
| 23 |
+
print(f"[DEBUG] Длина alphaBTC: {len(alpha_data)}")
|
| 24 |
+
|
| 25 |
+
if not alpha_data:
|
| 26 |
+
print("[ERROR] alphaBTC пустой")
|
| 27 |
+
return None
|
| 28 |
+
|
| 29 |
+
values = [item["value"] for item in alpha_data]
|
| 30 |
+
indices = list(range(len(values)))
|
| 31 |
+
|
| 32 |
+
fig, ax = plt.subplots(figsize=(12, 6))
|
| 33 |
+
ax.plot(indices, values, color='blue', label='alphaBTC')
|
| 34 |
+
ax.axhline(0, color='black', linewidth=1)
|
| 35 |
+
ax.spines['right'].set_color('none')
|
| 36 |
+
ax.spines['top'].set_color('none')
|
| 37 |
+
ax.spines['bottom'].set_position('zero')
|
| 38 |
+
ax.spines['left'].set_position('zero')
|
| 39 |
+
ax.set_title("Alpha к BTC", fontsize=14)
|
| 40 |
+
ax.set_xlabel("Индекс")
|
| 41 |
+
ax.set_ylabel("Alpha")
|
| 42 |
+
ax.grid(True, linestyle='--', alpha=0.5)
|
| 43 |
+
ax.legend()
|
| 44 |
+
plt.tight_layout()
|
| 45 |
+
|
| 46 |
+
print("[DEBUG] График построен успешно ✅")
|
| 47 |
+
return fig
|
| 48 |
+
|
| 49 |
except Exception as e:
|
| 50 |
+
print(f"[ERROR] Исключение при построении графика: {e}")
|
| 51 |
return None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|