Commit d519456a authored by 陈涛's avatar 陈涛

当结算时间为00:00时,结算前一天的净值

parent e01ae898
...@@ -13,9 +13,7 @@ from service.price import get_price ...@@ -13,9 +13,7 @@ from service.price import get_price
async def calculate_nav(fund_id, calc_time=None, beach_service=BeaconChaService()): async def calculate_nav(fund_id, calc_time=None, beach_service=BeaconChaService()):
# todo 测试 # todo 测试
calc_time = datetime.datetime.utcnow().replace(minute=0, second=0, microsecond=0, calc_time = datetime.datetime.utcnow().replace(minute=0, second=0, microsecond=0, tzinfo=pytz.UTC)
tzinfo=pytz.UTC) - datetime.timedelta(hours=2)
date = datetime.datetime.utcnow().replace(hour=0, minute=0, second=0, microsecond=0, tzinfo=pytz.UTC)
from main import app from main import app
fund_collect = get_fund_collect(app.state.mongodb_manager) fund_collect = get_fund_collect(app.state.mongodb_manager)
logger.info(f'[定时任务开始执行] [计算净值] {fund_id} ') logger.info(f'[定时任务开始执行] [计算净值] {fund_id} ')
...@@ -66,11 +64,15 @@ async def calculate_nav(fund_id, calc_time=None, beach_service=BeaconChaService( ...@@ -66,11 +64,15 @@ async def calculate_nav(fund_id, calc_time=None, beach_service=BeaconChaService(
"bill_type": {"$in": ["adjust", "sub", "redemption"]} "bill_type": {"$in": ["adjust", "sub", "redemption"]}
}) })
result = await cursor.to_list(length=None) result = await cursor.to_list(length=None)
total_fund_share = sum(-item["fund_share"] if item["bill_type"] == "redemption" else item["fund_share"] for item in result) total_fund_share = sum(
-item["fund_share"] if item["bill_type"] == "redemption" else item["fund_share"] for item in result)
value = sum(nav.values()) value = sum(nav.values())
net_value = round(value / total_fund_share, 2) if total_fund_share else fund_data["base_nav"] net_value = round(value / total_fund_share, 2) if total_fund_share > 0 else fund_data["base_nav"]
await fund_collect.update_one({'id': fund_id}, {"$set": {"nva": net_value}}) await fund_collect.update_one({'id': fund_id}, {"$set": {"nva": net_value}})
nav_collect = get_nav_collect(app.state.mongodb_manager) nav_collect = get_nav_collect(app.state.mongodb_manager)
date = datetime.datetime.utcnow().replace(hour=0, minute=0, second=0, microsecond=0, tzinfo=pytz.UTC)
if fund_data["settlement_time"] == "00:00":
date -= datetime.timedelta(days=1)
nav_record = await nav_collect.find_one({"fund_id": fund_id, "record_date": date}) nav_record = await nav_collect.find_one({"fund_id": fund_id, "record_date": date})
if nav_record: if nav_record:
error = f'重复净值记录 [{nav_record}] [mongo] [{date}]' error = f'重复净值记录 [{nav_record}] [mongo] [{date}]'
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment