from services.indicator import Indicator from models.ichimoku import IchimokuPayload from models.rsi import RSIPayload from models.price import PricePayload from models.macd import MACDPayload from models.index import IndexPayload from fastapi import status, APIRouter from typing import Sequence import json import asyncio router = APIRouter() @router.get( "/update_daily_price", name="Update daily price data", status_code=status.HTTP_200_OK ) async def update_daily_price(): asyncio.create_task(Indicator.update_daily_price()) return {"message": "Updating"} @router.get( "/update_entire_price", name="Update entire price data", status_code=status.HTTP_200_OK ) async def update_entire_price(): return Indicator.update_entire_price() @router.get( "/update_daily_rsi", name="Update daily rsi data", status_code=status.HTTP_200_OK ) async def update_daily_rsi(): asyncio.create_task(Indicator.update_daily_rsi()) return {"message": "Updating"} @router.get( "/update_entire_rsi", name="Update entire rsi data", status_code=status.HTTP_200_OK ) async def update_entire_rsi(): return Indicator.update_entire_rsi() @router.get( "/update_entire_macd", name="Update entire macd data", status_code=status.HTTP_200_OK ) async def update_entire_macd(): asyncio.create_task(Indicator.update_entire_macd()) return {"message": "Updating"} @router.post( "/vn100", name="Get VN100 symbols", status_code=status.HTTP_200_OK ) async def get_vn100(payload: IndexPayload) -> dict: return Indicator.get_vn100(payload.source) @router.post( "/get_price", name="Get price", status_code=status.HTTP_200_OK ) async def get_price_data(payload: PricePayload) -> Sequence[dict]: price_df = Indicator.get_price(payload.symbol, payload.count_back, payload.source) return json.loads(price_df.to_json(orient="records")) @router.post( "/get_rsi", name="Get data of RSI", status_code=status.HTTP_200_OK ) async def get_rsi_data(payload: RSIPayload) -> Sequence[dict]: rsi_df = Indicator.get_rsi( payload.symbol, payload.periods, payload.smooth_k, payload.smooth_d ) return json.loads(rsi_df.to_json(orient="records")) @router.post( "/get_macd", name="Get data of MACD", status_code=status.HTTP_200_OK ) async def get_macd_data(payload: MACDPayload) -> Sequence[dict]: macd_df = Indicator.get_macd( payload.symbol ) return json.loads(macd_df.to_json(orient="records")) @router.post( "/get_ichimoku", name="Get data of Ichimoku cloud", status_code=status.HTTP_200_OK ) async def get_ichimoku_data(payload: IchimokuPayload) -> Sequence[dict]: price_df = Indicator.get_price(payload.symbol) ichimoku_df = Indicator.get_ichimoku_cloud(price_df, payload.conversion_period, payload.base_period, payload.span_b_period, payload.displacement) return json.loads(ichimoku_df.to_json(orient="records")) @router.get( "/admin/routers", name="Get router gates by admin", status_code=status.HTTP_200_OK ) async def get_router_event(): return { route.path: route.methods for route in router.routes }