Spaces:
Running
Running
QAway-to
commited on
Commit
·
ed8fc2e
1
Parent(s):
b58afd7
model change
Browse files- alpha_chart.py +35 -0
- app.py +16 -1
- requirements.txt +2 -1
alpha_chart.py
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import matplotlib.pyplot as plt
|
| 2 |
+
import requests
|
| 3 |
+
import os
|
| 4 |
+
|
| 5 |
+
def plot_alpha_btc_chart_to_file(portfolio_id: str, output_path="alpha_chart.png"):
|
| 6 |
+
url = f"https://api.tradelink.pro/portfolio/get?portfolioId={portfolio_id}&extended=1&declaration=1&step=day&lang=en&incViews=1"
|
| 7 |
+
headers = {"User-Agent": "Mozilla/5.0", "Accept": "application/json"}
|
| 8 |
+
|
| 9 |
+
try:
|
| 10 |
+
response = requests.get(url, headers=headers)
|
| 11 |
+
response.raise_for_status()
|
| 12 |
+
alpha_data = response.json()["data"]["extended"]["alphaBTC"]
|
| 13 |
+
except Exception as e:
|
| 14 |
+
print(f"[Ошибка]: {e}")
|
| 15 |
+
return None
|
| 16 |
+
|
| 17 |
+
values = [item["value"] for item in alpha_data]
|
| 18 |
+
indices = list(range(len(values)))
|
| 19 |
+
|
| 20 |
+
fig, ax = plt.subplots(figsize=(12, 6))
|
| 21 |
+
ax.plot(indices, values, color='blue', linewidth=1.5, label='alphaBTC')
|
| 22 |
+
ax.axhline(0, color='black', linewidth=1)
|
| 23 |
+
ax.spines['right'].set_color('none')
|
| 24 |
+
ax.spines['top'].set_color('none')
|
| 25 |
+
ax.spines['bottom'].set_position('zero')
|
| 26 |
+
ax.spines['left'].set_position('zero')
|
| 27 |
+
ax.set_title("Alpha к BTC", fontsize=14)
|
| 28 |
+
ax.set_xlabel("Индекс")
|
| 29 |
+
ax.set_ylabel("Alpha")
|
| 30 |
+
ax.grid(True, linestyle='--', alpha=0.5)
|
| 31 |
+
ax.legend()
|
| 32 |
+
plt.tight_layout()
|
| 33 |
+
plt.savefig(output_path)
|
| 34 |
+
plt.close()
|
| 35 |
+
return output_path
|
app.py
CHANGED
|
@@ -1,11 +1,13 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import os
|
|
|
|
| 3 |
from prompts import TRADELINK_CONTEXT
|
| 4 |
from openai import OpenAI
|
| 5 |
from analyzer import analyze_portfolio_streaming
|
| 6 |
from comparer import compare_portfolio
|
| 7 |
from table_view import get_metrics_dataframe
|
| 8 |
-
import
|
|
|
|
| 9 |
|
| 10 |
|
| 11 |
api_key = os.getenv("featherless") #
|
|
@@ -82,5 +84,18 @@ with gr.Blocks() as demo:
|
|
| 82 |
|
| 83 |
metrics_button.click(fn=show_metrics_table, inputs=metrics_input, outputs=metrics_output)
|
| 84 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 85 |
if __name__ == "__main__":
|
| 86 |
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import os
|
| 3 |
+
import asyncio
|
| 4 |
from prompts import TRADELINK_CONTEXT
|
| 5 |
from openai import OpenAI
|
| 6 |
from analyzer import analyze_portfolio_streaming
|
| 7 |
from comparer import compare_portfolio
|
| 8 |
from table_view import get_metrics_dataframe
|
| 9 |
+
from alpha_chart import plot_alpha_btc_chart_to_file
|
| 10 |
+
|
| 11 |
|
| 12 |
|
| 13 |
api_key = os.getenv("featherless") #
|
|
|
|
| 84 |
|
| 85 |
metrics_button.click(fn=show_metrics_table, inputs=metrics_input, outputs=metrics_output)
|
| 86 |
|
| 87 |
+
|
| 88 |
+
|
| 89 |
+
with gr.Tab("📈 AlphaBTC график"):
|
| 90 |
+
chart_input = gr.Textbox(label="Введите portfolioId")
|
| 91 |
+
chart_button = gr.Button("Построить график")
|
| 92 |
+
chart_image = gr.Image(label="Alpha график")
|
| 93 |
+
|
| 94 |
+
def get_chart_image(portfolio_id):
|
| 95 |
+
path = plot_alpha_btc_chart_to_file(portfolio_id)
|
| 96 |
+
return path if path else None
|
| 97 |
+
|
| 98 |
+
chart_button.click(fn=get_chart_image, inputs=chart_input, outputs=chart_image)
|
| 99 |
+
|
| 100 |
if __name__ == "__main__":
|
| 101 |
demo.launch()
|
requirements.txt
CHANGED
|
@@ -2,4 +2,5 @@ gradio>=4.29.0
|
|
| 2 |
openai>=1.30.1
|
| 3 |
requests
|
| 4 |
httpx
|
| 5 |
-
pandas
|
|
|
|
|
|
| 2 |
openai>=1.30.1
|
| 3 |
requests
|
| 4 |
httpx
|
| 5 |
+
pandas
|
| 6 |
+
matplotlib
|