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
dd3aff4b
Commit
dd3aff4b
authored
May 16, 2023
by
陈涛
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
增加节点总收益,完善计算节点净值逻辑
parent
076a454c
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
36 additions
and
12 deletions
+36
-12
__init__.py
configs/__init__.py
+2
-2
dependencies.py
dependencies.py
+0
-1
beacon.py
schema/beacon.py
+2
-1
beacon.py
service/beacon.py
+3
-1
nav.py
service/nav.py
+29
-7
No files found.
configs/__init__.py
View file @
dd3aff4b
...
@@ -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
:
...
...
dependencies.py
View file @
dd3aff4b
...
@@ -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'
)
...
...
schema/beacon.py
View file @
dd3aff4b
...
@@ -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
=
"证明计数"
)
...
...
service/beacon.py
View file @
dd3aff4b
...
@@ -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
:
...
...
service/nav.py
View file @
dd3aff4b
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 查询历史数据
...
...
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