Spaces:
Sleeping
Sleeping
QAway-to
commited on
Commit
·
3ab96b9
1
Parent(s):
49e5fc1
fast api APP
Browse files- app.py +3 -0
- requirements.txt +4 -1
- rest_api_app.py +20 -0
app.py
CHANGED
|
@@ -3,6 +3,7 @@ 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
|
|
@@ -100,5 +101,7 @@ with gr.Blocks() as demo:
|
|
| 100 |
|
| 101 |
chart_button.click(fn=build_chart, inputs=chart_input, outputs=chart_output)
|
| 102 |
|
|
|
|
|
|
|
| 103 |
if __name__ == "__main__":
|
| 104 |
demo.launch()
|
|
|
|
| 3 |
import asyncio
|
| 4 |
from prompts import TRADELINK_CONTEXT
|
| 5 |
from openai import OpenAI
|
| 6 |
+
from fastapi import FastAPI
|
| 7 |
from analyzer import analyze_portfolio_streaming
|
| 8 |
from comparer import compare_portfolio
|
| 9 |
from table_view import get_metrics_dataframe
|
|
|
|
| 101 |
|
| 102 |
chart_button.click(fn=build_chart, inputs=chart_input, outputs=chart_output)
|
| 103 |
|
| 104 |
+
demo.mount_api(rest_api_app)
|
| 105 |
+
|
| 106 |
if __name__ == "__main__":
|
| 107 |
demo.launch()
|
requirements.txt
CHANGED
|
@@ -3,4 +3,7 @@ openai>=1.30.1
|
|
| 3 |
requests
|
| 4 |
httpx
|
| 5 |
pandas
|
| 6 |
-
matplotlib
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
requests
|
| 4 |
httpx
|
| 5 |
pandas
|
| 6 |
+
matplotlib
|
| 7 |
+
fastapi
|
| 8 |
+
uvicorn
|
| 9 |
+
httpx
|
rest_api_app.py
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastapi import FastAPI
|
| 2 |
+
from fetch import fetch_metrics_async, fetch_absolute_pnl_async
|
| 3 |
+
import asyncio
|
| 4 |
+
|
| 5 |
+
app = FastAPI()
|
| 6 |
+
|
| 7 |
+
@app.get("/api/metrics/{portfolio_id}")
|
| 8 |
+
async def get_metrics(portfolio_id: str):
|
| 9 |
+
data = await fetch_metrics_async(portfolio_id)
|
| 10 |
+
if data:
|
| 11 |
+
return {"status": "ok", "metrics": data}
|
| 12 |
+
return {"status": "error", "message": "Не удалось получить метрики"}
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
@app.get("/api/pnl/{portfolio_id}")
|
| 16 |
+
async def get_pnl(portfolio_id: str):
|
| 17 |
+
pnl_data = await fetch_absolute_pnl_async(portfolio_id)
|
| 18 |
+
if pnl_data:
|
| 19 |
+
return {"status": "ok", "pnl": pnl_data}
|
| 20 |
+
return {"status": "error", "message": "Не удалось получить PnL"}
|