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
16dc092d
Commit
16dc092d
authored
Mar 27, 2023
by
confusion
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1.基金查询添加机构id
2.添加删除基金接口
parent
800eadd2
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
12 deletions
+35
-12
fund.py
api/fund.py
+21
-3
scheduler.py
service/scheduler.py
+14
-9
No files found.
api/fund.py
View file @
16dc092d
import
datetime
from
typing
import
Union
from
typing
import
Union
,
Optional
from
apscheduler.schedulers.asyncio
import
AsyncIOScheduler
from
fastapi
import
APIRouter
,
Depends
from
fastapi
import
APIRouter
,
Depends
,
Query
from
motor.core
import
AgnosticCollection
from
pymongo
import
ReturnDocument
...
...
@@ -10,7 +10,7 @@ from exception.db import NotFundError
from
model
import
Response
,
PageResponse
,
Page
from
model.fund
import
FundType
,
CreateFund
,
StakingFund
,
NormalFund
,
UpdateFund
,
FundStatus
from
dependencies
import
get_current_user
,
get_fund_collect
,
get_scheduler
from
service.scheduler
import
calculate_nav_task
from
service.scheduler
import
calculate_nav_task
,
delete_nav_task
from
tools.jwt_tools
import
User
router
=
APIRouter
()
...
...
@@ -41,6 +41,21 @@ async def create(
return
Response
[
response_model
](
data
=
response_model
(
**
data
))
@
router
.
delete
(
'/{fund_id}/'
,
response_model
=
Response
,
summary
=
'删除基金'
,
description
=
'删除基金'
)
async
def
delete_fund
(
fund_id
:
str
,
user
:
User
=
Depends
(
get_current_user
),
fund_collect
:
AgnosticCollection
=
Depends
(
get_fund_collect
),
scheduler
:
AsyncIOScheduler
=
Depends
(
get_scheduler
)
):
await
fund_collect
.
delete_one
({
'id'
:
fund_id
,
'user_id'
:
user
.
id
})
await
delete_nav_task
(
fund_id
,
scheduler
)
return
Response
()
@
router
.
put
(
'/{fund_id}/'
,
response_model
=
Union
[
Response
[
StakingFund
],
Response
[
NormalFund
]],
summary
=
'更新基金'
,
description
=
'更新基金'
)
async
def
update
(
...
...
@@ -81,6 +96,7 @@ async def get(
description
=
'查询所有基金'
)
async
def
get
(
page
:
Page
=
Depends
(
Page
),
org_id
:
Optional
[
int
]
=
Query
(
default
=
None
,
description
=
'机构id'
),
fund_type
:
FundType
=
FundType
.
staking
,
fund_status
:
FundStatus
=
None
,
user
:
User
=
Depends
(
get_current_user
),
...
...
@@ -89,6 +105,8 @@ async def get(
query
=
{
"user_id"
:
user
.
id
,
"fund_type"
:
fund_type
}
if
fund_status
:
query
.
update
({
"fund_status"
:
fund_status
})
if
org_id
is
not
None
:
query
.
update
({
"org_id"
:
org_id
})
skip
=
(
page
.
page
-
1
)
*
page
.
page_size
cursor
=
fund_collect
.
find
(
query
)
cursor
=
cursor
.
skip
(
skip
)
.
sort
([(
'create_time'
,
-
1
)])
.
limit
(
page
.
page_size
)
...
...
service/scheduler.py
View file @
16dc092d
...
...
@@ -7,18 +7,23 @@ from exception.schecular import TaskExistError
from
service.nav
import
calculate_nav
async
def
delete_task
(
job_id
,
schedul
a
r
):
if
schedul
a
r
.
get_job
(
job_id
):
schedul
a
r
.
remove_job
(
job_id
)
async
def
delete_task
(
job_id
,
schedul
e
r
):
if
schedul
e
r
.
get_job
(
job_id
):
schedul
e
r
.
remove_job
(
job_id
)
else
:
raise
NotFundError
()
schedul
a
r
.
print_jobs
()
schedul
e
r
.
print_jobs
()
async
def
calculate_nav_task
(
fund_id
,
schedular
,
fund_collect
:
AgnosticCollection
,
user_id
=
None
):
async
def
delete_nav_task
(
fund_id
,
scheduler
):
job_id
=
f
'calculate_nav_{fund_id}'
await
delete_task
(
job_id
,
scheduler
)
async
def
calculate_nav_task
(
fund_id
,
scheduler
,
fund_collect
:
AgnosticCollection
,
user_id
=
None
):
"""
创建净值计算任务
:param schedul
a
r:
:param schedul
e
r:
:param fund_id:
:param fund_collect:
:param user_id:
...
...
@@ -31,10 +36,10 @@ async def calculate_nav_task(fund_id, schedular, fund_collect: AgnosticCollectio
assert
res
,
NotFundError
()
job_id
=
f
'calculate_nav_{fund_id}'
if
schedul
a
r
.
get_job
(
job_id
):
if
schedul
e
r
.
get_job
(
job_id
):
raise
TaskExistError
schedul
a
r
.
add_job
(
func
=
calculate_nav
,
id
=
job_id
,
args
=
(
fund_id
,),
schedul
e
r
.
add_job
(
func
=
calculate_nav
,
id
=
job_id
,
args
=
(
fund_id
,),
trigger
=
interval
.
IntervalTrigger
(
seconds
=
5
,
timezone
=
pytz
.
UTC
),
misfire_grace_time
=
10
)
schedul
a
r
.
print_jobs
()
schedul
e
r
.
print_jobs
()
return
job_id
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