Skip to content

Commit

Permalink
create model for Market
Browse files Browse the repository at this point in the history
Signed-off-by: Lu Ken <[email protected]>
  • Loading branch information
kenplusplus committed Jan 2, 2025
1 parent f4f7f7c commit 35a61e2
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 20 deletions.
17 changes: 14 additions & 3 deletions src/gentrade_server/model.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
from pydantic import BaseModel, Field
from pydantic_settings import BaseSettings, SettingsConfigDict
from pydantic import Field, field_validator
'''
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.
Expand Down Expand Up @@ -30,3 +33,11 @@ def decode_ntp_servers(cls, v: str) -> List[str]:
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(...)
4 changes: 3 additions & 1 deletion src/gentrade_server/routers/admin.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
'''
Admin portal
'''
import logging

from fastapi import APIRouter, Depends
from pydantic import BaseModel, Field
from ..model import settings, Settings
from ..auth import get_user

Expand Down
18 changes: 2 additions & 16 deletions src/gentrade_server/routers/public.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@
from dateutil.tz import tzlocal

from fastapi import APIRouter
from pydantic import BaseModel, Field

from ..datahub import DataHub
from ..model import HealthCheck, settings
from ..model import HealthCheck, Market

LOG = logging.getLogger(__name__)

Expand Down Expand Up @@ -42,20 +41,7 @@ async def get_server_time():
}

@router.get("/markets/")
async def get_markets():
"""
Get markets
"""
retval = {}
for _, market in DataHub.inst().markets.items():
retval[market.market_id] = {
"name": market.name,
"type": market.market_type,
}
return retval

@router.get("/markets/")
async def get_markets2():
async def get_markets() -> Market:
"""
Get markets
"""
Expand Down

0 comments on commit 35a61e2

Please sign in to comment.