Commit dd3aff4b authored by 陈涛's avatar 陈涛

增加节点总收益,完善计算节点净值逻辑

parent 076a454c
...@@ -15,8 +15,8 @@ def make_dburi(schema, sock_path, user_name='', pwd=''): ...@@ -15,8 +15,8 @@ def make_dburi(schema, sock_path, user_name='', pwd=''):
env = os.getenv("MATRIXONE_ENVIRONMENT", "LOCAL") env = os.getenv("MATRIXONE_ENVIRONMENT", "LOCAL")
if env == 'LOCAL': if env == 'LOCAL':
from configs.LOCAL import Settings from configs.LOCAL import Settings
elif env == 'S': # elif env == 'S':
from configs.S import Settings # from configs.S import Settings
elif env == 'TEST': elif env == 'TEST':
from configs.TEST import Settings from configs.TEST import Settings
else: else:
......
...@@ -44,7 +44,6 @@ def get_bill_collect(mongodb_manager: AioMongodbManager = Depends(get_mongodb_ma ...@@ -44,7 +44,6 @@ def get_bill_collect(mongodb_manager: AioMongodbManager = Depends(get_mongodb_ma
def get_hour_price_collect(mongodb_manager: AioMongodbManager = Depends(get_mongodb_manager)) -> AgnosticCollection: def get_hour_price_collect(mongodb_manager: AioMongodbManager = Depends(get_mongodb_manager)) -> AgnosticCollection:
# return mongodb_manager.get_client(name='jasper', db='TradeCenter_c', collect='HourMarketQuotes') # todo 数据库版本问题
return mongodb_manager.get_client(name='pyfund', db='Market', collect='HourOHLCV') return mongodb_manager.get_client(name='pyfund', db='Market', collect='HourOHLCV')
......
...@@ -55,7 +55,8 @@ class ValidatorIncome(BaseModel): ...@@ -55,7 +55,8 @@ class ValidatorIncome(BaseModel):
performance365d: float = Field(None, title="年收益") performance365d: float = Field(None, title="年收益")
rank7d: int = Field(None, title="7日排名") rank7d: int = Field(None, title="7日排名")
validator_index: int = Field(None, title="节点编号") validator_index: int = Field(None, title="节点编号")
performancetoday: float = Field(None, title="当日收益")
performancetotal: float = Field(None, title="总收益")
class Epoch(BaseModel): class Epoch(BaseModel):
attestations_count: int = Field(None, title="证明计数") attestations_count: int = Field(None, title="证明计数")
......
...@@ -122,7 +122,9 @@ class BeaconChaService: ...@@ -122,7 +122,9 @@ class BeaconChaService:
performance31d=item["performance31d"] / self.eth_decimal, performance31d=item["performance31d"] / self.eth_decimal,
performance365d=item["performance365d"] / self.eth_decimal, performance365d=item["performance365d"] / self.eth_decimal,
rank7d=item["rank7d"], rank7d=item["rank7d"],
validatorindex=item["validatorindex"] validatorindex=item["validatorindex"],
performancetoday=item["performancetoday"],
performancetotal=item["performancetotal"]
) for item in response["data"]] ) for item in response["data"]]
async def get_validator_blocks(self, index: int, start: int = 0, length: int = 10) -> ValidatorBlocks: async def get_validator_blocks(self, index: int, start: int = 0, length: int = 10) -> ValidatorBlocks:
......
import datetime import datetime
import pytz import pytz
from fastapi import Depends
from loguru import logger from loguru import logger
from dependencies import get_fund_collect, get_cmc_price_redis, get_hour_price_collect from dependencies import get_fund_collect, get_cmc_price_redis, get_hour_price_collect
from model.fund import FundStatus from model.fund import FundStatus
from service.beacon import BeaconChaService
from service.price import get_price from service.price import get_price
async def calculate_nav(fund_id, calc_time=None): async def calculate_nav(fund_id, calc_time=None, beach_service: BeaconChaService = Depends(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) - datetime.timedelta(hours=2) tzinfo=pytz.UTC) - datetime.timedelta(hours=2)
...@@ -17,13 +19,33 @@ async def calculate_nav(fund_id, calc_time=None): ...@@ -17,13 +19,33 @@ async def calculate_nav(fund_id, calc_time=None):
logger.info(f'[定时任务开始执行] [计算净值] {fund_id} ') logger.info(f'[定时任务开始执行] [计算净值] {fund_id} ')
fund_data = await fund_collect.find_one({'id': fund_id, 'fund_status': FundStatus.active.value}) fund_data = await fund_collect.find_one({'id': fund_id, 'fund_status': FundStatus.active.value})
amount = {} amount = {}
for item in fund_data['assets']: # 查询asset资产
amount.setdefault(item['currency'], 0) for key, value in fund_data['assets'].items():
amount[item['currency']] += item['volume'] amount.setdefault(key, 0)
amount[key] += value
for item in fund_data.get('nodes', []): # 查询在途资产
amount.setdefault(item['currency'], 0) for key, value in fund_data['assets'].items():
amount[item['currency']] += item['volume'] amount.setdefault(key, 0)
amount[key] += value
#
# 查询节点收益
for key, value in fund_data["nodes"].items():
if value["status"] == "active":
income = await beach_service.get_validator_income(key)
amount.setdefault("ETH", 0)
amount["ETH"] += income[0].performancetotal / (10 ** 9) if income else 0
# 节点质押资产
for key, value in fund_data["staking_assets"].items():
amount.setdefault(key, 0)
amount[key] += value
# for item in fund_data.get('nodes', []):
# amount.setdefault(item['currency'], 0)
# amount[item['currency']] += item['volume']
if calc_time: if calc_time:
# mongodb 查询历史数据 # mongodb 查询历史数据
......
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