Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
PyFund
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
陈涛
PyFund
Commits
c1500f8b
Commit
c1500f8b
authored
Jun 20, 2023
by
陈涛
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改重新计算净值bug
parent
04239b59
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
45 additions
and
24 deletions
+45
-24
nav.py
api/nav.py
+7
-7
nav.py
service/nav.py
+38
-17
No files found.
api/nav.py
View file @
c1500f8b
...
...
@@ -100,14 +100,14 @@ async def recalculate_nav(
start
:
datetime
.
datetime
=
Query
(
...
,
title
=
"开始时间"
),
end
:
datetime
.
datetime
=
Query
(
None
,
title
=
"结束时间"
),
fund_collect
:
AgnosticCollection
=
Depends
(
get_fund_collect
),
#
user: User = Depends(get_current_user),
#
permission_user_collect: AgnosticCollection = Depends(get_permission_user_collect),
#
permission_role_collect: AgnosticCollection = Depends(get_permission_role_collect)
user
:
User
=
Depends
(
get_current_user
),
permission_user_collect
:
AgnosticCollection
=
Depends
(
get_permission_user_collect
),
permission_role_collect
:
AgnosticCollection
=
Depends
(
get_permission_role_collect
)
):
#
await check_permission(['data_permission.nav.recalculate'],
#
fund_id,
#
user.email, permission_user_collect,
#
permission_role_collect)
await
check_permission
([
'data_permission.nav.recalculate'
],
fund_id
,
user
.
email
,
permission_user_collect
,
permission_role_collect
)
fund_data
=
await
fund_collect
.
find_one
({
"id"
:
fund_id
})
end
=
end
or
datetime
.
datetime
.
utcnow
()
delta
=
end
-
start
...
...
service/nav.py
View file @
c1500f8b
...
...
@@ -5,7 +5,7 @@ import uuid
import
pytz
from
loguru
import
logger
from
pymongo
import
ReturnDocument
from
pymongo
import
ReturnDocument
,
UpdateOne
from
dependencies
import
get_fund_collect
,
get_cmc_price_redis
,
get_hour_price_collect
,
get_bill_collect
,
\
get_nav_collect
...
...
@@ -57,8 +57,8 @@ async def calculate_nav(fund_id, calc_time: datetime.datetime = None, beach_serv
amount
[
key
]
+=
value
# 查询节点收益, 如果是重新计算净值,则不查询收益
if
update_fund
:
node_income_assets
=
fund_data
.
get
(
"node_income_assets"
,
{})
if
update_fund
:
for
key
,
value
in
fund_data
[
"nodes"
]
.
items
():
if
value
[
"status"
]
==
"active"
:
income
=
beach_service
.
get_rewards
(
key
)
...
...
@@ -66,7 +66,7 @@ async def calculate_nav(fund_id, calc_time: datetime.datetime = None, beach_serv
node_income_assets
[
"ETH"
]
+=
income
.
total_rewards
.
total
if
income
else
0
fund_data
[
"node_income_assets"
]
=
node_income_assets
else
:
pas
s
fund_data
[
"node_income_assets"
]
=
node_income_asset
s
for
key
,
value
in
fund_data
[
"node_income_assets"
]
.
items
():
amount
.
setdefault
(
key
,
0
)
amount
[
key
]
+=
value
...
...
@@ -134,17 +134,38 @@ async def query_nav_record(nav_collect, fund_id, record_time, settlement_time):
return
nav_result
# async def update_history_records():
# nav_record = await query_nav_record(
# nav_collect=nav_collect, fund_id=create_adjust_bill.fund_id,
# record_time=create_adjust_bill.record_time, settlement_time=fund_data["settlement_time"]
# )
# bulk_list = []
# for nav in nav_record:
# nav["assets"].setdefault(create_adjust_bill.currency, 0)
# nav["assets"][create_adjust_bill.currency] += create_adjust_bill.volume
# bulk_list.append(UpdateOne({"_id": nav["_id"]}, {"$set": {"assets": nav["assets"]}}))
#
# await update_fund(fund_collect, create_adjust_bill.fund_id, adjust_assets=adjust_assets)
# if bulk_list:
# await nav_collect.bulk_write(bulk_list)
async
def
build_nav_bulk_list
(
nav_collect
,
fund_id
,
record_time
,
settlement_time
,
*
,
asset_changed
=
None
,
adjust_assets_changed
=
None
,
pending_assets_changed
=
None
,
staking_assets_changed
=
None
,
nodes_changed
=
None
):
def
build_update_data
(
nav
):
update_data
=
{}
if
asset_changed
:
for
key
,
value
in
asset_changed
.
items
():
nav
[
"assets"
]
.
setdefault
(
key
,
0
)
nav
[
"assets"
][
key
]
+=
value
update_data
.
update
({
"assets"
:
nav
[
"assets"
]})
if
adjust_assets_changed
:
for
key
,
value
in
adjust_assets_changed
.
item
():
nav
[
"adjust_assets"
]
.
setdefault
(
key
,
0
)
nav
[
"adjust_assets"
][
key
]
+=
value
update_data
.
update
({
"adjust_assets"
:
nav
[
"adjust_assets"
]})
if
pending_assets_changed
:
for
key
,
value
in
adjust_assets_changed
.
item
():
nav
[
"pending_assets"
]
.
setdefault
(
key
,
0
)
nav
[
"pending_assets"
][
key
]
+=
value
update_data
.
update
({
"pending_assets"
:
nav
[
"pending_assets"
]})
if
staking_assets_changed
:
for
key
,
value
in
adjust_assets_changed
.
item
():
nav
[
"staking_assets"
]
.
setdefault
(
key
,
0
)
nav
[
"staking_assets"
][
key
]
+=
value
update_data
.
update
({
"staking_assets"
:
nav
[
"staking_assets"
]})
return
UpdateOne
({
"_id"
:
nav
[
"_id"
]},
{
"$set"
:
update_data
})
nav_record
=
await
query_nav_record
(
nav_collect
=
nav_collect
,
fund_id
=
fund_id
,
record_time
=
record_time
,
settlement_time
=
settlement_time
)
bulk_list
=
[
build_update_data
(
nav
)
for
nav
in
nav_record
]
return
bulk_list
# bulk_list.append(UpdateOne({"_id": nav["_id"]}, {"$set": {"assets": nav["assets"]}}))
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment