Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
T
ts-api-demo
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
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
wmvm
ts-api-demo
Commits
c1e4573a
Commit
c1e4573a
authored
Oct 09, 2024
by
1486327116
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update
parent
55654328
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
247 additions
and
107 deletions
+247
-107
contractPair.control.ts
src/functional/mvc/control/contractPair.control.ts
+58
-35
contractPair.service.ts
src/functional/mvc/service/contractPair.service.ts
+163
-66
spotPair.service.ts
src/functional/mvc/service/spotPair.service.ts
+19
-6
index.ts
src/functional/router/v1/index.ts
+7
-0
No files found.
src/functional/mvc/control/contractPair.control.ts
View file @
c1e4573a
import
*
as
contractPairService
from
"../service/contractPair.service"
;
import
*
as
service
from
"../service/contractPair.service"
;
import
{
ContractPairPageVO
,
ContractPairVO
}
from
"../service/contractPair.service"
;
import
{
AddParam
,
ListParam
}
from
"../service/contractPair.service"
;
let
{
logger
,
Res3Utils
,
optionalUtils
:
Optional
,
apiAssertUtils
:
ApiAssert
,
datetimeUtils
}
=
require
(
'@madex/ex-js-public'
);
import
{
ErrorCode
}
from
"../../../constant/errorCode"
;
import
{
getCurrentUserId
}
from
"../../../utils/aclUserUtils"
;
import
{
getCurrentUserId
}
from
"../../../utils/aclUserUtils"
;
let
{
logger
,
Res3Utils
,
optionalUtils
:
Optional
,
apiAssertUtils
:
ApiAssert
}
=
require
(
'@madex/ex-js-public'
);
let
isIp
=
require
(
'is-ip'
);
let
isIp
=
require
(
'is-ip'
);
/**
* 金融部-交易管理-合约查询交易对
* @param req
export
const
list
=
async
(
req
:
any
,
param
:
ListParam
)
=>
{
* @param infoVO
let
func_name
=
"contactPairCtl.list"
;
*/
let
cmd
=
req
.
path
;
export
const
query
=
async
(
req
:
any
,
pageVO
:
ContractPairPageVO
)
=>
{
let
func_name
=
"contractPair.control.query"
;
try
{
try
{
pa
geVO
.
page
=
Optional
.
opt
(
pageVO
,
'page'
,
1
);
pa
ram
.
page
=
Optional
.
opt
(
param
,
'page'
,
1
);
pa
geVO
.
size
=
Optional
.
opt
(
pageVO
,
'size'
,
2
0
);
pa
ram
.
size
=
Optional
.
opt
(
param
,
'size'
,
5
0
);
let
res
=
await
contractPairService
.
query
(
pageVO
);
let
res
=
await
service
.
list
(
param
);
return
Res3Utils
.
result
(
res
);
return
Res3Utils
.
result
(
res
);
}
}
catch
(
e
)
{
catch
(
e
)
{
...
@@ -25,19 +20,22 @@ export const query = async (req: any, pageVO: ContractPairPageVO) => {
...
@@ -25,19 +20,22 @@ export const query = async (req: any, pageVO: ContractPairPageVO) => {
return
Res3Utils
.
getErrorResult
(
e
);
return
Res3Utils
.
getErrorResult
(
e
);
}
}
};
};
//新增
/**
export
const
save
=
async
(
req
:
any
,
param
:
AddParam
)
=>
{
* 金融部-交易管理-合约设置交易对
let
func_name
=
"contactPairCtl.save"
;
* @param req
let
cmd
=
req
.
path
;
* @param authConfigVO
*/
export
const
set
=
async
(
req
:
any
,
contractPairVO
:
ContractPairVO
)
=>
{
let
func_name
=
"contractPair.control.set"
;
try
{
try
{
ApiAssert
.
notNull
(
'3000'
,
param
.
base
);
ApiAssert
.
notNull
(
'3000'
,
param
.
quote
);
ApiAssert
.
notNull
(
'3000'
,
param
.
symbol
);
ApiAssert
.
notNull
(
'3000'
,
param
.
name
);
ApiAssert
.
notNull
(
'3000'
,
param
.
price_scale
);
ApiAssert
.
notNull
(
'3000'
,
param
.
quantity_scale
);
ApiAssert
.
notNull
(
'3000'
,
param
.
maker_fee
);
ApiAssert
.
notNull
(
'3000'
,
param
.
taker_fee
);
let
ip
=
isIp
(
req
.
ip
)
?
req
.
ip
:
'*.*.*.*'
;
let
ip
=
isIp
(
req
.
ip
)
?
req
.
ip
:
'*.*.*.*'
;
let
currentUserId
=
await
getCurrentUserId
(
req
.
cookies
.
session_id
);
let
currentUserId
=
await
getCurrentUserId
(
req
.
cookies
.
session_id
);
let
res
=
await
service
.
save
(
param
,
currentUserId
,
ip
);
let
res
=
await
contractPairService
.
set
(
contractPairVO
,
currentUserId
,
ip
);
return
Res3Utils
.
result
(
res
);
return
Res3Utils
.
result
(
res
);
}
}
catch
(
e
)
{
catch
(
e
)
{
...
@@ -45,19 +43,32 @@ export const set = async (req: any, contractPairVO: ContractPairVO) => {
...
@@ -45,19 +43,32 @@ export const set = async (req: any, contractPairVO: ContractPairVO) => {
return
Res3Utils
.
getErrorResult
(
e
);
return
Res3Utils
.
getErrorResult
(
e
);
}
}
};
};
//修改
/**
export
const
update
=
async
(
req
:
any
,
param
:
AddParam
)
=>
{
* 金融部-交易管理-合约更新交易对
let
func_name
=
"contactPairCtl.save"
;
* @param req
let
cmd
=
req
.
path
;
* @param authConfigVO
*/
export
const
update
=
async
(
req
:
any
,
contractPairVO
:
ContractPairVO
)
=>
{
let
func_name
=
"contractPair.control.update"
;
try
{
try
{
ApiAssert
.
notNull
(
'3000'
,
param
.
id
);
let
ip
=
isIp
(
req
.
ip
)
?
req
.
ip
:
'*.*.*.*'
;
let
ip
=
isIp
(
req
.
ip
)
?
req
.
ip
:
'*.*.*.*'
;
let
currentUserId
=
await
getCurrentUserId
(
req
.
cookies
.
session_id
);
let
currentUserId
=
await
getCurrentUserId
(
req
.
cookies
.
session_id
);
let
res
=
await
service
.
update
(
param
,
currentUserId
,
ip
);
return
Res3Utils
.
result
(
res
);
}
catch
(
e
)
{
logger
.
error
(
`
${
func_name
}
error:
${
e
}
`
);
return
Res3Utils
.
getErrorResult
(
e
);
}
};
let
res
=
await
contractPairService
.
update
(
contractPairVO
,
currentUserId
,
ip
);
//提交到撮合
export
const
pushToCoreSystem
=
async
(
req
:
any
,
param
:
AddParam
)
=>
{
let
func_name
=
"contactPairCtl.pushToCoreSystem"
;
let
cmd
=
req
.
path
;
try
{
ApiAssert
.
notNull
(
'3000'
,
param
.
id
);
let
ip
=
isIp
(
req
.
ip
)
?
req
.
ip
:
'*.*.*.*'
;
let
currentUserId
=
await
getCurrentUserId
(
req
.
cookies
.
session_id
);
let
res
=
await
service
.
pushToCoreSystem
(
param
.
id
,
currentUserId
,
ip
);
return
Res3Utils
.
result
(
res
);
return
Res3Utils
.
result
(
res
);
}
}
catch
(
e
)
{
catch
(
e
)
{
...
@@ -66,3 +77,15 @@ export const update = async (req: any, contractPairVO: ContractPairVO) => {
...
@@ -66,3 +77,15 @@ export const update = async (req: any, contractPairVO: ContractPairVO) => {
}
}
};
};
export
const
getAllSubmitSuccess
=
async
(
req
:
any
,
param
:
ListParam
)
=>
{
let
func_name
=
"contactPairCtl.getAllSubmitSuccess"
;
let
cmd
=
req
.
path
;
try
{
let
res
=
await
service
.
getAllSubmitSuccess
();
return
Res3Utils
.
result
(
res
);
}
catch
(
e
)
{
logger
.
error
(
`
${
func_name
}
error:
${
e
}
`
);
return
Res3Utils
.
getErrorResult
(
e
);
}
};
src/functional/mvc/service/contractPair.service.ts
View file @
c1e4573a
import
{
userApikeyStrict
,
}
from
"@madex/ex-ts-dao"
;
// @madex/ex-ts-dao 是 ts 的 dao, 代码在 bitbucket/ex-js-dao 的 ts 分支上
import
{
contractPairs
,
madContractOrmDB
,
coinType
}
from
"@madex/ex-ts-dao"
;
import
{
NUMBER
}
from
"sequelize"
;
import
{
addPairToCore
}
from
"../../../utils/coreSystemUtils"
;
import
{
ErrorCode
}
from
"../../../constant/errorCode"
;
import
{
ErrorCode
}
from
"../../../constant/errorCode"
;
import
{
addOptLog
}
from
"./userOptLog.service"
;
import
{
addOptLog
}
from
"./userOptLog.service"
;
let
{
logger
,
datetimeUtils
}
=
require
(
'@madex/ex-js-public'
);
let
_
=
require
(
'lodash'
);
export
interface
ListParam
{
let
{
logger
}
=
require
(
'@madex/ex-js-public'
);
symbol
?:
string
|
any
;
let
{
authCommon
:
AuthCommon
,
redisUtilsCommon
:
RedisClient
,
}
=
require
(
'@madex/ex-js-common'
);
page
:
number
;
export
interface
ContractPairVO
{
size
:
number
;
id
?:
number
,
s
ymbol
?:
string
;
s
tatus
?:
number
base
?:
string
;
from_time
?:
Date
|
any
quote
?:
string
;
to_time
?:
Date
|
any
}
leverage_init
?:
number
;
// name symbol index 都保持一致 比如BTC_USDT_SWAP
export
interface
AddParam
{
id
?:
number
;
leverage_min
?:
number
;
symbol
?:
string
;
product_id
?:
number
;
leverage_max
?:
number
;
base
?:
string
;
margin_rate_maintain
?:
string
,
quote
?:
string
;
margin_rate_init
?:
string
,
name
?:
string
;
risk_level_base
?:
number
,
price_scale
?:
number
;
maker_fee
?:
string
,
quantity_scale
?:
number
;
taker_fee
?:
string
,
maker_fee
?:
string
;
createdAt
?:
Date
|
any
,
taker_fee
?:
string
;
updatedAt
?:
Date
|
any
,
price_increment
?:
number
;
}
quantity_increment
?:
number
;
default_initial_margin
?:
number
;
//"0.01",
base_initial_margin
?:
number
;
//"0.01",
base_maintenance_margin
?:
number
;
//"0.01",
settlement_asset
?:
number
;
// "USDT", 结算币种
index
?:
string
;
base_interest
:
number
;
//"0.0003",
quote_interest
?:
number
;
//"0.0006",
impact_notional
?:
number
;
// "600000",
base_risk_limit
?:
number
;
// "1000000",
risk_limit_step
?:
number
;
//"1000000",
funding_times_perday
:
number
;
// 3
export
interface
ContractPairPageVO
extends
ContractPairVO
{
status
?:
number
page
?:
number
,
view_precision
?:
number
size
?:
number
,
createdAt
?:
Date
|
any
,
updatedAt
?:
Date
|
any
,
}
}
export
async
function
query
(
pageVO
:
ContractPairPageVO
)
{
export
async
function
list
(
param
:
ListParam
)
{
let
key
=
'contract.pair.query'
;
let
where
=
{}
;
//TODO:目前在缓存里 方便调试 后期撮合搞定之后再修改
if
(
param
.
symbol
)
{
let
list
=
await
RedisClient
.
getSync
(
key
)
;
where
[
"symbol"
]
=
{
[
madContractOrmDB
.
Op
.
like
]:
`%
${
param
.
symbol
}
%`
}
;
let
res
=
{
}
count
:
list
?
list
.
length
:
0
,
if
(
param
.
status
||
param
.
status
===
0
)
{
rows
:
list
?
list
:
[]
where
[
"status"
]
=
param
.
status
}
}
return
res
;
if
(
param
.
from_time
&&
param
.
to_time
)
{
where
[
'createdAt'
]
=
{
[
madContractOrmDB
.
Op
.
between
]:
[
param
.
from_time
,
param
.
to_time
]
}
}
let
resList
=
await
contractPairs
.
prototype
.
findAndCount
({
where
:
where
,
limit
:
param
.
size
,
offset
:
(
Number
(
param
.
page
)
-
1
)
*
Number
(
param
.
size
),
order
:
[[
"id"
,
"desc"
]],
raw
:
true
});
return
resList
;
}
}
export
const
save
=
async
(
param
:
AddParam
,
currentUserId
:
any
,
ip
:
any
)
=>
{
param
.
updatedAt
=
new
Date
();
param
.
createdAt
=
new
Date
();
export
async
function
set
(
contractPairVO
:
ContractPairVO
,
currentUserId
:
any
,
ip
:
string
|
undefined
)
{
await
contractPairs
.
prototype
.
create
(
param
);
//TODO:目前在缓存里 方便调试 后期撮合搞定之后再修改
//管理后台操作日志
contractPairVO
.
createdAt
=
new
Date
();
addOptLog
(
currentUserId
,
0
,
'交易对配置新增'
,
ip
,
JSON
.
stringify
(
param
),
'交易对配置'
);
contractPairVO
.
updatedAt
=
new
Date
();
return
'ok'
;
let
key
=
'contract.pair.query'
;
};
let
list
=
await
RedisClient
.
getSync
(
key
);
if
(
list
)
{
contractPairVO
.
id
=
list
.
length
+
1
;
export
const
update
=
async
(
param
:
AddParam
,
currentUserId
:
any
,
ip
:
any
)
=>
{
list
.
push
(
contractPairVO
);
let
dbInfo
=
await
contractPairs
.
prototype
.
findOne
({
where
:
{
id
:
param
.
id
},
raw
:
true
});
if
(
!
dbInfo
)
{
throw
ErrorCode
.
DATA_NOT_EXIST
}
}
else
{
let
updateInfo
=
{
updatedAt
:
new
Date
()
};
contractPairVO
.
id
=
1
;
if
(
param
.
view_precision
||
param
.
view_precision
===
0
)
{
list
=
[];
updateInfo
[
'view_precision'
]
=
param
.
view_precision
list
.
push
(
contractPairVO
);
}
}
await
RedisClient
.
writeSync
(
key
,
list
);
// if (param.price_increment || param.price_increment === 0) {
// updateInfo['price_increment'] = param.price_increment
// }
// if (param.quantity_increment || param.quantity_increment === 0) {
// updateInfo['quantity_increment'] = param.quantity_increment
// }
await
contractPairs
.
prototype
.
update
(
updateInfo
,
{
where
:
{
id
:
Number
(
param
.
id
)
}
});
//管理后台操作日志
//管理后台操作日志
addOptLog
(
currentUserId
,
0
,
'新增合约交易对'
,
ip
,
JSON
.
stringify
(
contractPairVO
),
'交易管理'
);
addOptLog
(
currentUserId
,
0
,
'交易对配置更新'
,
ip
,
JSON
.
stringify
(
param
),
'交易对配置'
);
return
'success'
;
return
'ok'
;
}
};
export
const
pushToCoreSystem
=
async
(
id
:
any
,
currentUserId
:
any
,
ip
:
any
)
=>
{
export
async
function
update
(
contractPairVO
:
ContractPairVO
,
currentUserId
:
any
,
ip
:
string
|
undefined
)
{
let
where
=
{
id
:
id
,
status
:
0
};
//TODO:目前在缓存里 方便调试 后期撮合搞定之后再修改
let
key
=
'contract.pair.query'
;
let
cfg
=
await
contractPairs
.
prototype
.
find
({
let
list
=
await
RedisClient
.
getSync
(
key
);
where
:
where
,
raw
:
true
let
nList
:
any
[]
=
[];
});
for
(
let
item
of
list
)
{
if
(
!
cfg
)
{
let
one
=
item
;
throw
ErrorCode
.
SUBMIT_STATUS_ERR
;
if
(
item
.
id
==
contractPairVO
.
id
){
}
one
=
contractPairVO
;
let
symbol
=
cfg
.
symbol
;
let
sps
=
symbol
.
split
(
"_"
);
let
base
=
sps
[
0
];
let
quote
=
sps
[
1
]
let
param
=
{
"market_type"
:
2
,
"base"
:
base
,
"quote"
:
quote
,
"symbol"
:
symbol
,
"name"
:
symbol
,
"price_scale"
:
cfg
.
price_scale
,
"quantity_scale"
:
cfg
.
quantity_scale
,
"maker_fee"
:
cfg
.
maker_fee
,
"taker_fee"
:
cfg
.
taker_fee
"default_initial_margin"
:
cfg
.
default_initial_margin
,
"base_initial_margin"
:
cfg
.
base_initial_margin
,
"base_maintenance_margin"
:
cfg
.
base_maintenance_margin
,
"settlement_asset"
:
cfg
.
settlement_asset
,
"index"
:
cfg
.
settlement_asset
,
"base_interest"
:
cfg
.
base_interest
,
"quote_interest"
:
cfg
.
quote_interest
,
"impact_notional"
:
cfg
.
impact_notional
,
"base_risk_limit"
:
cfg
.
base_risk_limit
,
"risk_limit_step"
:
cfg
.
risk_limit_step
,
"funding_times_perday"
:
cfg
.
funding_times_perday
}
}
nList
.
push
(
one
);
if
(
cfg
.
min_order_size
)
{
param
[
"min_order_size"
]
=
cfg
.
min_order_size
;
}
}
await
RedisClient
.
writeSync
(
key
,
nList
);
if
(
cfg
.
max_order_size
)
{
param
[
"max_order_size"
]
=
cfg
.
max_order_size
;
}
if
(
cfg
.
min_order_value
)
{
param
[
"min_order_value"
]
=
cfg
.
min_order_value
;
}
if
(
cfg
.
max_order_value
)
{
param
[
"max_order_value"
]
=
cfg
.
max_order_value
;
}
let
optResult
=
await
addPairToCore
(
param
);
if
(
!
optResult
.
is_success
)
{
//管理后台操作日志
//管理后台操作日志
addOptLog
(
currentUserId
,
0
,
'修改合约交易对'
,
ip
,
JSON
.
stringify
(
contractPairVO
),
'交易管理'
);
addOptLog
(
currentUserId
,
0
,
'提交交易对到撮合-失败'
,
ip
,
`pair:
${
symbol
}
,error_msg:
${
optResult
.
err_msg
}
`
,
'交易对配置'
);
throw
ErrorCode
.
ADD_PAIR_TO_CORE_ERR
;
}
return
'success'
;
await
contractPairs
.
prototype
.
update
({
status
:
1
},
{
where
:
where
});
//管理后台操作日志
addOptLog
(
currentUserId
,
0
,
'提交交易对到撮合-成功'
,
ip
,
JSON
.
stringify
(
param
),
'交易对配置'
);
return
'ok'
;
};
export
async
function
getAllSubmitSuccess
()
{
let
resList
=
await
contractPairs
.
prototype
.
findAll
({
where
:
{
status
:
2
},
order
:
[[
"id"
,
"desc"
]],
raw
:
true
});
return
resList
;
}
}
src/functional/mvc/service/spotPair.service.ts
View file @
c1e4573a
...
@@ -102,12 +102,12 @@ export const update = async (param: AddParam, currentUserId: any, ip: any) => {
...
@@ -102,12 +102,12 @@ export const update = async (param: AddParam, currentUserId: any, ip: any) => {
if
(
param
.
view_precision
||
param
.
view_precision
===
0
)
{
if
(
param
.
view_precision
||
param
.
view_precision
===
0
)
{
updateInfo
[
'view_precision'
]
=
param
.
view_precision
updateInfo
[
'view_precision'
]
=
param
.
view_precision
}
}
if
(
param
.
price_increment
||
param
.
price_increment
===
0
)
{
//
if (param.price_increment || param.price_increment === 0) {
updateInfo
[
'price_increment'
]
=
param
.
price_increment
//
updateInfo['price_increment'] = param.price_increment
}
//
}
if
(
param
.
quantity_increment
||
param
.
quantity_increment
===
0
)
{
//
if (param.quantity_increment || param.quantity_increment === 0) {
updateInfo
[
'quantity_increment'
]
=
param
.
quantity_increment
//
updateInfo['quantity_increment'] = param.quantity_increment
}
//
}
await
spotPairs
.
prototype
.
update
(
updateInfo
,
{
await
spotPairs
.
prototype
.
update
(
updateInfo
,
{
where
:
{
where
:
{
...
@@ -137,6 +137,19 @@ export const pushToCoreSystem = async (id: any, currentUserId: any, ip: any) =>
...
@@ -137,6 +137,19 @@ export const pushToCoreSystem = async (id: any, currentUserId: any, ip: any) =>
"price_scale"
:
cfg
.
price_scale
,
"quantity_scale"
:
cfg
.
quantity_scale
,
"price_scale"
:
cfg
.
price_scale
,
"quantity_scale"
:
cfg
.
quantity_scale
,
"maker_fee"
:
cfg
.
maker_fee
,
"taker_fee"
:
cfg
.
taker_fee
"maker_fee"
:
cfg
.
maker_fee
,
"taker_fee"
:
cfg
.
taker_fee
}
}
if
(
cfg
.
min_order_size
)
{
param
[
"min_order_size"
]
=
cfg
.
min_order_size
;
}
if
(
cfg
.
max_order_size
)
{
param
[
"max_order_size"
]
=
cfg
.
max_order_size
;
}
if
(
cfg
.
min_order_value
)
{
param
[
"min_order_value"
]
=
cfg
.
min_order_value
;
}
if
(
cfg
.
max_order_value
)
{
param
[
"max_order_value"
]
=
cfg
.
max_order_value
;
}
let
optResult
=
await
addPairToCore
(
param
);
let
optResult
=
await
addPairToCore
(
param
);
if
(
!
optResult
.
is_success
)
{
if
(
!
optResult
.
is_success
)
{
//管理后台操作日志
//管理后台操作日志
...
...
src/functional/router/v1/index.ts
View file @
c1e4573a
...
@@ -64,6 +64,13 @@ const postFunc = {
...
@@ -64,6 +64,13 @@ const postFunc = {
'spotPair/list'
:
spotPairCtrl
.
list
,
'spotPair/list'
:
spotPairCtrl
.
list
,
'spotPair/pushToCoreSystem'
:
spotPairCtrl
.
pushToCoreSystem
,
'spotPair/pushToCoreSystem'
:
spotPairCtrl
.
pushToCoreSystem
,
'spotPair/getAllSubmitSuccess'
:
spotPairCtrl
.
getAllSubmitSuccess
,
'spotPair/getAllSubmitSuccess'
:
spotPairCtrl
.
getAllSubmitSuccess
,
'contractPair/save'
:
contractPairCtrl
.
save
,
//新增
'contractPair/update'
:
contractPairCtrl
.
update
,
//修改
'contractPair/list'
:
contractPairCtrl
.
list
,
'contractPair/pushToCoreSystem'
:
contractPairCtrl
.
pushToCoreSystem
,
'contractPair/getAllSubmitSuccess'
:
contractPairCtrl
.
getAllSubmitSuccess
,
//运营部-其他管理-币种管理
//运营部-其他管理-币种管理
'coinType/save'
:
coinTypeCtrl
.
save
,
'coinType/save'
:
coinTypeCtrl
.
save
,
'coinType/update'
:
coinTypeCtrl
.
update
,
'coinType/update'
:
coinTypeCtrl
.
update
,
...
...
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