28 lines
769 B
Python
28 lines
769 B
Python
from fastapi import APIRouter
|
||
from pydantic import BaseModel
|
||
|
||
INDEX = "高流动性资产占比(%)"
|
||
|
||
router = APIRouter()
|
||
|
||
|
||
class Params(BaseModel):
|
||
货币资金: float
|
||
以公允价值且其变动计入其他综合收益的金融资产: float
|
||
买入返售金融资产: float
|
||
一年内到期的定期存款: float
|
||
总资产: float
|
||
|
||
|
||
@router.post("/{}".format(INDEX))
|
||
def func(p: Params):
|
||
try:
|
||
d = p.货币资金 + p.以公允价值且其变动计入其他综合收益的金融资产 + p.买入返售金融资产 + p.一年内到期的定期存款
|
||
result = d / p.总资产 * 100
|
||
return round(result, 6)
|
||
|
||
except ZeroDivisionError:
|
||
return "算式无意义"
|
||
except Exception:
|
||
return "计算错误"
|