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
114a8541
Commit
114a8541
authored
Mar 23, 2023
by
陈涛
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
提交asset
parent
c68a6346
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
103 additions
and
21 deletions
+103
-21
bill.py
api/bill.py
+48
-1
main.py
main.py
+5
-0
asset.py
model/asset.py
+13
-10
bill.py
model/bill.py
+37
-10
No files found.
api/bill.py
View file @
114a8541
from
fastapi
import
APIRouter
from
fastapi
import
APIRouter
,
Depends
from
motor.core
import
AgnosticCollection
from
dependencies
import
get_current_user
,
get_fund_collect
,
get_asset_collect
,
get_bill_collect
from
model
import
Response
from
model.asset
import
AssetType
from
model.bill
import
PCFBill
,
ExchangeBill
,
BillType
,
CreatePCFBill
from
tools.jwt_tools
import
User
router
=
APIRouter
()
@
router
.
post
(
'/pcf/'
,
response_model
=
Response
[
PCFBill
],
summary
=
'添加申购赎回账目'
,
description
=
'添加申购赎回账目'
)
async
def
create_pcf
(
item
:
CreatePCFBill
,
user
:
User
=
Depends
(
get_current_user
),
fund_collect
:
AgnosticCollection
=
Depends
(
get_fund_collect
),
asset_collect
:
AgnosticCollection
=
Depends
(
get_asset_collect
),
bill_collect
:
AgnosticCollection
=
Depends
(
get_bill_collect
)
):
assert
item
.
bill_type
==
BillType
.
sub
or
item
.
bill_type
==
BillType
.
redemption
,
"枚举错误"
fund_asset
=
await
asset_collect
.
find_one
({
'fund_id'
:
item
.
fund_id
})
assert
fund_asset
,
"没有该资产记录"
query
=
{
"fund_id"
:
item
.
fund_id
,
"assets.currency"
:
item
.
currency
,
"assets.asset_type"
:
AssetType
.
vault
}
update
=
{
"$inc"
:
{
"assets.volume"
:
1
},
"$push"
:
{
"data"
:
{
"name"
:
"BTC"
,
"volume"
:
1
}}
# "$push": {"assets": {"name": "BTC", "volume": 1}}
}
# result = mycol.update_one(query, update, upsert=True)
result
=
await
asset_collect
.
update_one
(
query
,
update
,
upsert
=
True
)
# 判断是否插入新数据
if
result
.
upserted_id
:
await
asset_collect
.
update_one
({},
{
"$push"
:
{
"assets"
:
{
"name"
:
"BTC"
,
"volume"
:
1
}}})
return
Response
[
PCFBill
](
data
=
None
)
@
router
.
post
(
'/exchange/'
,
response_model
=
Response
[
ExchangeBill
],
summary
=
'添加置换币账目'
,
description
=
'添加置换币账目'
)
async
def
create_exchange
(
):
pass
main.py
View file @
114a8541
...
...
@@ -31,6 +31,11 @@ async def not_fund_exception_handler(request: Request, exc: MyException):
return
JSONResponse
(
ErrorResponse
(
message
=
str
(
exc
),
status
=
exc
.
status
)
.
dict
())
@
app
.
exception_handler
(
AssertionError
)
async
def
assert_exception_handler
(
request
:
Request
,
exc
:
AssertionError
):
return
JSONResponse
(
ErrorResponse
(
message
=
str
(
exc
),
status
=
status
.
HTTP_400_BAD_REQUEST
)
.
dict
())
@
app
.
exception_handler
(
RequestValidationError
)
async
def
request_validation_exception_handler
(
request
:
Request
,
exc
:
RequestValidationError
):
"""
...
...
model/asset.py
View file @
114a8541
from
enum
import
Enum
from
typing
import
List
from
pydantic
import
BaseModel
,
Field
from
model
import
BaseCreateModel
class
AssetType
(
str
,
Enum
):
normal
=
"normal
"
vault
=
"vault
"
adjust
=
"adjust"
node
=
"node"
other
=
"other"
class
BaseAssetItem
(
BaseModel
):
class
Base
Coin
AssetItem
(
BaseModel
):
fund_id
:
str
=
Field
(
...
,
description
=
'基金id'
)
currency
:
str
=
Field
(
...
,
description
=
'币种'
)
v
alu
e
:
float
=
Field
(
...
,
description
=
'资产数量'
)
asset_type
:
AssetType
=
Field
(
default
=
AssetType
.
normal
,
description
=
'资产类型'
)
v
olum
e
:
float
=
Field
(
...
,
description
=
'资产数量'
)
asset_type
:
AssetType
=
Field
(
default
=
AssetType
.
vault
,
description
=
'资产类型'
)
# 传入数据库类型 / 接口返回类型
class
NormalAsset
(
BaseAssetItem
,
BaseCreateModel
):
pass
class
NormalAsset
(
BaseCreateModel
):
fund_id
:
str
=
Field
(
...
,
description
=
'基金id'
)
assets
:
List
[
BaseCoinAssetItem
]
=
Field
(
default
=
[],
description
=
'基金id'
)
# 传入数据库类型 / 接口返回类型
...
...
@@ -29,12 +30,14 @@ class NormalAssetRecord(NormalAsset):
# 接口传入模型
class
CreateAsset
(
BaseAssetItem
):
class
CreateAsset
(
Base
Coin
AssetItem
):
pass
class
UpdateAsset
(
BaseModel
):
v
alu
e
:
float
=
Field
(
...
,
description
=
'资产数量'
)
v
olum
e
:
float
=
Field
(
...
,
description
=
'资产数量'
)
class
Config
:
orm_mode
=
True
model/bill.py
View file @
114a8541
...
...
@@ -12,30 +12,57 @@ class BillType(str, Enum):
redemption
=
"redemption"
# 兑换
exchange
=
"exchange"
# 质押
staking
=
"staking"
# 其他
other
=
"other"
class
BaseBillItem
(
BaseModel
):
# 接口传入模型
# 创建申购赎回记录
class
CreatePCFBill
(
BaseModel
):
fund_id
:
str
=
Field
(
None
,
description
=
'基金id'
)
email
:
str
=
Field
(
None
,
description
=
'客户邮箱'
)
bill_type
:
BillType
=
Field
(
...
,
description
=
'账目类型'
)
currency
:
str
=
Field
(
None
,
description
=
'币种'
)
v
alu
e
:
float
=
Field
(
...
,
description
=
'资产数量'
)
v
olum
e
:
float
=
Field
(
...
,
description
=
'资产数量'
)
price
:
float
=
Field
(
None
,
description
=
"价格"
)
market_value
:
float
=
Field
(
None
,
description
=
"市值"
)
# 传入数据库类型 / 接口返回类型
class
NormalBill
(
BaseBillItem
,
BaseCreateModel
):
fund_id
:
str
=
Field
(
None
,
description
=
'基金id'
)
email
:
str
=
Field
(
None
,
description
=
'客户邮箱'
)
class
PCFBill
(
BaseCreateModel
):
"""申购赎回"""
user_id
:
str
fund_share
:
float
=
Field
(
None
,
description
=
"基金份额"
)
bill_type
:
BillType
=
Field
(
...
,
description
=
'账目记录'
)
market_value
:
float
=
Field
(
None
,
description
=
"市值"
)
# 置换币记录 传入数据库类型 / 接口返回类型
class
ExchangeBill
(
BaseBillItem
,
BaseCreat
eModel
):
class
CreateExchangeBill
(
Bas
eModel
):
fund_id
:
str
=
Field
(
None
,
description
=
'基金id'
)
bill_type
:
BillType
=
Field
(
...
,
description
=
'账目记录'
)
exchange_detail
:
List
[
BaseBillItem
]
=
Field
(
default
=
[],
description
=
'置换详情'
)
bill_type
:
BillType
=
Field
(
default
=
BillType
.
exchange
,
description
=
'账目类型'
)
input_currency
:
str
=
Field
(
...
,
description
=
"投入币种"
)
input_price
:
float
=
Field
(
...
,
description
=
"投入币种价格"
)
input_volume
:
float
=
Field
(
...
,
description
=
"投入数量"
)
output_currency
:
str
=
Field
(
...
,
description
=
"输出币种"
)
output_price
:
float
=
Field
(
...
,
description
=
"输出币种价格"
)
output_volume
:
float
=
Field
(
...
,
description
=
"输出数量"
)
class
ExchangeBill
(
BaseCreateModel
):
"""置换账户"""
user_id
:
str
input_value
:
float
=
Field
(
...
,
description
=
"投入价值"
)
output_value
:
float
=
Field
(
...
,
description
=
"输出价值"
)
profit
:
float
=
Field
(
0
,
description
=
"置换产生的价差"
)
class
StakingBill
(
BaseCreateModel
):
"""质押账目"""
user_id
:
str
fund_id
:
str
=
Field
(
None
,
description
=
'基金id'
)
bill_type
:
BillType
=
Field
(
default
=
BillType
.
staking
,
description
=
'账目类型'
)
market_value
:
float
=
Field
(
None
,
description
=
"市值"
)
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