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
6eb87824
Commit
6eb87824
authored
Mar 29, 2023
by
杨明橙
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改查询资产 没有查询到抛出异常
parent
816af025
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
27 additions
and
9 deletions
+27
-9
fund.py
service/fund.py
+8
-2
scheduler.py
service/scheduler.py
+19
-7
No files found.
service/fund.py
View file @
6eb87824
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
:
...
...
service/scheduler.py
View file @
6eb87824
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}"
)
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