Spaces:
Running
Running
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 | |
router = APIRouter() | |
async def update_daily_price(): | |
Indicator.update_daily_price() | |
async def update_entire_price(): | |
Indicator.update_entire_price() | |
async def update_daily_rsi(): | |
Indicator.update_daily_rsi() | |
async def update_entire_rsi(): | |
Indicator.update_entire_rsi() | |
async def update_entire_macd(): | |
Indicator.update_entire_macd() | |
async def get_vn100(payload: IndexPayload) -> dict: | |
return Indicator.get_vn100(payload.source) | |
async def get_price_data(payload: PricePayload) -> Sequence[dict]: | |
price_df = Indicator.get_price(payload.symbol, | |
payload.count_back, | |
payload.source) | |
if price_df is None: | |
return [{"message": "Error"}] | |
return json.loads(price_df.to_json(orient="records")) | |
async def get_rsi_data(payload: RSIPayload) -> Sequence[dict]: | |
rsi_df = Indicator.get_rsi( | |
payload.symbol, | |
payload.periods, | |
payload.smooth_k, | |
payload.smooth_d | |
) | |
if rsi_df is None: | |
return [{"message": "Error"}] | |
return json.loads(rsi_df.to_json(orient="records")) | |
async def get_macd_data(payload: MACDPayload) -> Sequence[dict]: | |
macd_df = Indicator.get_macd( | |
payload.symbol | |
) | |
if macd_df is None: | |
return [{"message": "Error"}] | |
return json.loads(macd_df.to_json(orient="records")) | |
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) | |
if ichimoku_df is None: | |
return [{"message": "Error"}] | |
return json.loads(ichimoku_df.to_json(orient="records")) | |