Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastapi import FastAPI
|
| 2 |
+
from vnstock import Vnstock
|
| 3 |
+
|
| 4 |
+
app = FastAPI()
|
| 5 |
+
vnstock = Vnstock()
|
| 6 |
+
|
| 7 |
+
@app.get("/")
|
| 8 |
+
def root():
|
| 9 |
+
return {"message": "🇻🇳 Vietnam Stock API từ Hugging Face đã sẵn sàng!"}
|
| 10 |
+
|
| 11 |
+
@app.get("/hello")
|
| 12 |
+
def say_hello():
|
| 13 |
+
return {"message": "Chào bạn từ FastAPI chạy trên Hugging Face!"}
|
| 14 |
+
|
| 15 |
+
@app.get("/price/{symbol}")
|
| 16 |
+
def get_realtime_price(symbol: str):
|
| 17 |
+
try:
|
| 18 |
+
stock = vnstock.stock(symbol=symbol, source="VCI")
|
| 19 |
+
data = stock.quote.realtime()
|
| 20 |
+
return data
|
| 21 |
+
except Exception as e:
|
| 22 |
+
return {"error": str(e)}
|