-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* clean up model usage Signed-off-by: Lu Ken <[email protected]> * create model for Market Signed-off-by: Lu Ken <[email protected]> * add more model for restful API Signed-off-by: Lu Ken <[email protected]> --------- Signed-off-by: Lu Ken <[email protected]>
- Loading branch information
1 parent
12585fe
commit 6fa7bb9
Showing
7 changed files
with
134 additions
and
95 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
""" | ||
Model | ||
""" | ||
from typing import List | ||
|
||
from pydantic import BaseModel, Field, field_validator | ||
from pydantic_settings import BaseSettings, SettingsConfigDict | ||
|
||
class HealthCheck(BaseModel): | ||
""" | ||
Response model to validate and return when performing a health check. | ||
""" | ||
status: str = Field("OK") | ||
|
||
class Settings(BaseSettings): | ||
""" | ||
Settings | ||
""" | ||
model_config = SettingsConfigDict(enable_decoding=False) | ||
|
||
openai_api_key: str = "" | ||
openai_api_url: str = "" | ||
openai_api_model: str = "gpt-3.5-turbo" | ||
|
||
ntp_servers : List[str] = Field( | ||
"ntp.ntsc.ac.cn,ntp.sjtu.edu.cn,cn.ntp.org.cn,cn.pool.ntp.org,ntp.aliyun.com", | ||
description="The string list of NTP server splitted via comma") | ||
|
||
@field_validator('ntp_servers', mode='before') | ||
@classmethod | ||
def decode_ntp_servers(cls, v: str) -> List[str]: | ||
"""decode function override | ||
Args: | ||
v (str): input string | ||
Returns: | ||
List[str]: splitted list for all NTP servers | ||
""" | ||
return v.split(',') | ||
|
||
settings = Settings() | ||
|
||
class Market(BaseModel): | ||
""" | ||
Response model to validate and return when performing a health check. | ||
""" | ||
name: str = Field(...) | ||
type: str = Field(...) | ||
|
||
class Asset(BaseModel): | ||
""" | ||
Asset Model_ | ||
""" | ||
name: str = Field(...) | ||
type: str = Field(...) | ||
market: str = Field(...) | ||
quote: str = Field(...) | ||
cik: int = Field(None, description="only for US stock") | ||
symbol: str = Field(None, description="only for crypto") | ||
base: str = Field(None, description="only for crypto") | ||
|
||
class OHLCV(BaseModel): | ||
""" | ||
OHLCV model | ||
""" | ||
time: int = Field(..., description="UTC timestamp in seconds") | ||
open: float = Field(...) | ||
high: float = Field(...) | ||
low: float = Field(...) | ||
close: float = Field(...) | ||
vol: float = Field(...) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
''' | ||
Admin portal | ||
''' | ||
import logging | ||
|
||
from fastapi import APIRouter, Depends | ||
from ..model import settings, Settings | ||
from ..auth import get_user | ||
|
||
LOG = logging.getLogger(__name__) | ||
|
||
router = APIRouter() | ||
|
||
@router.get("/settings") | ||
async def get_settings(user: dict = Depends(get_user)) -> Settings: | ||
""" | ||
Get server settings | ||
""" | ||
LOG.info(user) | ||
return settings |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.