File size: 576 Bytes
71fec75
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
from fastapi import FastAPI
from vnstock import Vnstock

app = FastAPI()
vnstock = Vnstock()

@app.get("/")
def root():
    return {"message": "🇻🇳 Vietnam Stock API từ Hugging Face đã sẵn sàng!"}

@app.get("/hello")
def say_hello():
    return {"message": "Chào bạn từ FastAPI chạy trên Hugging Face!"}

@app.get("/price/{symbol}")
def get_realtime_price(symbol: str):
    try:
        stock = vnstock.stock(symbol=symbol, source="VCI")
        data = stock.quote.realtime()
        return data
    except Exception as e:
        return {"error": str(e)}