Commit 6eb87824 authored by 杨明橙's avatar 杨明橙

修改查询资产 没有查询到抛出异常

parent 816af025
from typing import Tuple
from exception.db import NotFundError
from schema.fund import FundStatus
async def query_fund_assets(fund_collect, fund_id, user_id=None, fund_status=None):
async def query_fund_assets(fund_collect, fund_id, user_id=None, fund_status=None) -> Tuple[dict, dict, dict, dict]:
query = {'id': fund_id}
if user_id:
query.update({"user_id": user_id})
if fund_status:
query.update({"fund_status": FundStatus.active})
fund = await fund_collect.find_one(query)
if not fund:
raise NotFundError()
return fund['assets'], fund['adjust_assets'], fund['pending_assets'], fund['staking_assets']
# 修改资产
async def update_assets(fund_collect, fund_id, assets=None, adjust_assets=None, pending_assets=None, staking_assets=None):
async def update_assets(fund_collect, fund_id, assets=None, adjust_assets=None, pending_assets=None,
staking_assets=None):
query = {'id': fund_id}
update_data = {}
if assets:
......
from motor.core import AgnosticCollection
from exception.db import NotFundError
from model.bill import StakingBill
from schema.fund import FundStatus
from service.fund import query_fund_assets, update_assets
from service.nav import calculate_nav
from loguru import logger
from pymongo import ReturnDocument
from db import AioMongodbManager
from dependencies import get_bill_collect
from dependencies import get_bill_collect, get_fund_collect
from exception.http import RequestInvalidParamsError
from schema.bill import StakingBillStatus, AllBillType
from service.beacon import BeaconChaService
......@@ -49,7 +51,8 @@ async def update_staking_bill_status_task(beacon_service: BeaconChaService, mong
data = bill_collect.find({'bill_type': AllBillType.staking, "status": StakingBillStatus.pending})
staking_bill_list = await data.to_list(length=None)
for bill_item in staking_bill_list:
pub_key = bill_item['pub_key']
bill_item = StakingBill(**bill_item)
pub_key = bill_item.pub_key
try:
validator_detail = await beacon_service.get_validator(pub_key)
if validator_detail.status == 'active_online':
......@@ -59,14 +62,23 @@ async def update_staking_bill_status_task(beacon_service: BeaconChaService, mong
except RequestInvalidParamsError as e:
status = StakingBillStatus.error
except Exception as e:
logger.error(f"[更新质押账单状态任务] [接口请求异常] [{bill_item['id']}] {e}")
logger.error(f"[更新质押账单状态任务] [接口请求异常] [{bill_item.id}] {e}")
continue
if status:
await bill_collect.find_one_and_update(
{'id': bill_item["id"]},
{'id': bill_item.id},
{'$set': {"status": status, "update_time": utc_now()}},
return_document=ReturnDocument.AFTER)
logger.info(f"[更新质押账单状态任务] [已更新] [{bill_item['id']}] {status}")
else:
logger.info(f"[更新质押账单状态任务] [无变化] [{bill_item['id']}] {status}")
if status == StakingBillStatus.finish:
fund_collect = get_fund_collect(mongodb_manager)
assets, adjust_assets, pending_assets, staking_assets = await query_fund_assets(fund_collect,
bill_item.fund_id,
fund_status=FundStatus.active)
staking_assets.setdefault(bill_item.currency, 0)
staking_assets[bill_item.currency] += bill_item.volume
pending_assets[bill_item.currency] -= bill_item.volume
await update_assets(fund_collect, bill_item.fund_id, pending_assets=pending_assets, staking_assets=staking_assets)
logger.info(f"[更新质押账单状态任务] [已更新] [{bill_item.id}] {status}")
else:
logger.info(f"[更新质押账单状态任务] [无变化] [{bill_item.id}] {status}")
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