-
Notifications
You must be signed in to change notification settings - Fork 5
/
main.py
49 lines (39 loc) · 1.19 KB
/
main.py
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
47
48
49
import json
from pathlib import Path
import requests
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from fastapi.responses import JSONResponse
app = FastAPI()
origins = [
"https://pro.openbb.co",
"https://excel.openbb.co",
"http://localhost:1420"
]
app.add_middleware(
CORSMiddleware,
allow_origins=origins,
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
ROOT_PATH = Path(__file__).parent.resolve()
@app.get("/")
def read_root():
return {"Info": "Full example for OpenBB Custom Backend"}
@app.get("/widgets.json")
def get_widgets():
"""Widgets configuration file for the OpenBB Custom Backend"""
return JSONResponse(
content=json.load((Path(__file__).parent.resolve() / "widgets.json").open())
)
@app.get("/chains_table")
def chains_table():
"""Get current TVL of all chains using Defi LLama"""
response = requests.get("https://api.llama.fi/v2/chains")
if response.status_code == 200:
return response.json()
print(f"Request error {response.status_code}: {response.text}")
return JSONResponse(
content={"error": response.text}, status_code=response.status_code
)