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
390ab468
Commit
390ab468
authored
Nov 19, 2024
by
1486327116
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
添加代理相关接口
parent
4a0c6305
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
143 additions
and
49 deletions
+143
-49
contractAgent.control.ts
src/functional/mvc/control/contractAgent.control.ts
+47
-3
contractAgent.service.ts
src/functional/mvc/service/contractAgent.service.ts
+91
-44
index.ts
src/functional/router/v1/index.ts
+3
-0
coreSystemUtils.ts
src/utils/coreSystemUtils.ts
+2
-2
No files found.
src/functional/mvc/control/contractAgent.control.ts
View file @
390ab468
...
@@ -10,7 +10,7 @@ let isIp = require('is-ip');
...
@@ -10,7 +10,7 @@ let isIp = require('is-ip');
/**
/**
* 金融部-其他管理-合约接单账户配置列表
* 金融部-其他管理-合约接单账户配置列表
* @param req
* @param req
* @param
info
VO
* @param
AgentPage
VO
*/
*/
export
const
agentList
=
async
(
req
:
any
,
pageVO
:
AgentPageVO
)
=>
{
export
const
agentList
=
async
(
req
:
any
,
pageVO
:
AgentPageVO
)
=>
{
let
func_name
=
"contractAgent.control.agentList"
;
let
func_name
=
"contractAgent.control.agentList"
;
...
@@ -36,11 +36,33 @@ export const agentSet = async (req: any, agentVO: AgentVO) => {
...
@@ -36,11 +36,33 @@ export const agentSet = async (req: any, agentVO: AgentVO) => {
try
{
try
{
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
);
if
(
!
agentVO
.
adl_type
||
!
agentVO
.
user_id
)
{
if
(
!
agentVO
.
user_id
)
{
throw
ErrorCode
.
PARAM_MISS
}
let
res
=
await
contractAgentService
.
agentSet
(
agentVO
.
user_id
,
currentUserId
,
ip
);
return
Res3Utils
.
result
(
res
);
}
catch
(
e
)
{
logger
.
error
(
`
${
func_name
}
error:
${
e
}
`
);
return
Res3Utils
.
getErrorResult
(
e
);
}
};
/**
* 金融部-其他管理-合约接单账户对冲列表
* @param req
* @param AgentPageVO
*/
export
const
hedgeRatioList
=
async
(
req
:
any
,
vo
:
AgentUserVO
)
=>
{
let
func_name
=
"contractAgent.control.agentList"
;
try
{
if
(
!
vo
.
agent_id
)
{
throw
ErrorCode
.
PARAM_MISS
throw
ErrorCode
.
PARAM_MISS
}
}
let
res
=
await
contractAgentService
.
agentSet
(
agentVO
,
currentUserId
,
ip
);
let
res
=
await
contractAgentService
.
hedgeRatioList
(
vo
.
agent_id
);
return
Res3Utils
.
result
(
res
);
return
Res3Utils
.
result
(
res
);
}
}
catch
(
e
)
{
catch
(
e
)
{
...
@@ -49,6 +71,28 @@ export const agentSet = async (req: any, agentVO: AgentVO) => {
...
@@ -49,6 +71,28 @@ export const agentSet = async (req: any, agentVO: AgentVO) => {
}
}
};
};
/**
* 金融部-其他管理-合约接单账户配置对冲
* @param req
* @param AgentUserVO
*/
export
const
hedgeRatioSet
=
async
(
req
:
any
,
agentUserVO
:
AgentUserVO
)
=>
{
let
func_name
=
"contractAgent.control.hedgeRatioSet"
;
try
{
let
ip
=
isIp
(
req
.
ip
)
?
req
.
ip
:
'*.*.*.*'
;
let
currentUserId
=
await
getCurrentUserId
(
req
.
cookies
.
session_id
);
if
(
!
agentUserVO
.
agent_id
||
!
agentUserVO
.
symbol
||
!
agentUserVO
.
ratio
)
{
throw
ErrorCode
.
PARAM_MISS
}
let
res
=
await
contractAgentService
.
hedgeRatioSet
(
agentUserVO
,
currentUserId
,
ip
);
return
Res3Utils
.
result
(
res
);
}
catch
(
e
)
{
logger
.
error
(
`
${
func_name
}
error:
${
e
}
`
);
return
Res3Utils
.
getErrorResult
(
e
);
}
};
/**
/**
* 金融部-其他管理-合约接单账户关联列表
* 金融部-其他管理-合约接单账户关联列表
...
...
src/functional/mvc/service/contractAgent.service.ts
View file @
390ab468
import
{
userA
pikeyStric
t
,
}
from
"@madex/ex-ts-dao"
;
import
{
userA
gen
t
,
}
from
"@madex/ex-ts-dao"
;
import
{
ErrorCode
}
from
"../../../constant/errorCode"
;
import
{
ErrorCode
}
from
"../../../constant/errorCode"
;
import
{
addOptLog
}
from
"./userOptLog.service"
;
import
{
addOptLog
}
from
"./userOptLog.service"
;
import
{
addAgentSetting
,
getAgentSettings
,
setAgent
}
from
"../../../utils/coreSystemUtils"
;
let
_
=
require
(
'lodash'
);
let
_
=
require
(
'lodash'
);
let
{
logger
}
=
require
(
'@madex/ex-js-public'
);
let
{
logger
}
=
require
(
'@madex/ex-js-public'
);
let
{
authCommon
:
AuthCommon
,
redisUtilsCommon
:
RedisClient
,
}
=
require
(
'@madex/ex-js-common'
);
let
{
authCommon
:
AuthCommon
,
redisUtilsCommon
:
RedisClient
,
}
=
require
(
'@madex/ex-js-common'
);
...
@@ -30,6 +32,10 @@ export interface AgentUserVO {
...
@@ -30,6 +32,10 @@ export interface AgentUserVO {
agent_id
?:
number
;
agent_id
?:
number
;
ratio
?:
number
;
symbol
?:
string
;
createdAt
?:
Date
|
any
,
createdAt
?:
Date
|
any
,
updatedAt
?:
Date
|
any
,
updatedAt
?:
Date
|
any
,
...
@@ -46,68 +52,109 @@ export interface AgentPageVO extends AgentVO, AgentUserVO {
...
@@ -46,68 +52,109 @@ export interface AgentPageVO extends AgentVO, AgentUserVO {
}
}
export
async
function
hedgeRatioList
(
agent_id
:
any
)
{
return
await
getAgentSettings
(
agent_id
);
}
export
async
function
agentList
(
pageVO
:
AgentPageVO
)
{
export
async
function
agentList
(
pageVO
:
AgentPageVO
)
{
let
key
=
'contractAgent.service.agentList'
;
let
where
=
{};
//TODO:目前在缓存里 方便调试 后期撮合搞定之后再修改
if
(
pageVO
.
user_id
)
{
let
list
=
await
RedisClient
.
getSync
(
key
);
where
[
"user_id"
]
=
pageVO
.
user_id
;
let
res
=
{
count
:
list
?
list
.
length
:
0
,
rows
:
list
?
list
:
[]
}
}
if
(
pageVO
.
agent_id
)
{
where
[
"agent_id"
]
=
pageVO
.
agent_id
;
}
let
page
=
Number
(
pageVO
.
page
);
let
size
=
Number
(
pageVO
.
size
);
let
res
=
await
userAgent
.
prototype
.
findAndCount
({
where
:
where
,
offset
:
page
*
size
-
size
,
limit
:
size
,
raw
:
true
});
return
res
;
return
res
;
}
}
export
async
function
agentSet
(
user_id
:
any
,
currentUserId
:
any
,
ip
:
string
|
undefined
)
{
export
async
function
agentSet
(
agentVO
:
AgentVO
,
currentUserId
:
any
,
ip
:
string
|
undefined
)
{
let
exist
=
await
userAgent
.
prototype
.
find
({
//TODO:目前在缓存里 方便调试 后期撮合搞定之后再修改
where
:
{
agentVO
.
createdAt
=
new
Date
();
user_id
agentVO
.
updatedAt
=
new
Date
();
},
let
key
=
'contractAgent.service.agentList'
;
raw
:
true
let
list
=
await
RedisClient
.
getSync
(
key
);
});
if
(
list
)
{
if
(
exist
&&
exist
.
agent_id
!=
0
)
{
agentVO
.
id
=
list
.
length
+
1
;
throw
ErrorCode
.
DATA_EXIST
;
list
.
push
(
agentVO
);
}
else
{
await
setAgent
(
user_id
,
user_id
);
}
}
else
{
agentVO
.
id
=
1
;
addOptLog
(
currentUserId
,
0
,
'合约接单账户配置'
,
ip
,
user_id
,
'合约接单账户配置'
);
list
=
[];
return
'success'
;
list
.
push
(
agentVO
);
}
export
async
function
hedgeRatioSet
(
agentUserVO
:
AgentUserVO
,
currentUserId
:
any
,
ip
:
string
|
undefined
)
{
let
agent_id
=
agentUserVO
.
agent_id
;
let
symbol
=
agentUserVO
.
symbol
;
let
ratio
=
agentUserVO
.
ratio
;
let
market
=
"lpc"
// 固定 只有合约才对冲设置
let
exist
=
await
userAgent
.
prototype
.
find
({
where
:
{
user_id
:
agent_id
,
agent_id
},
raw
:
true
});
if
(
!
exist
)
{
throw
ErrorCode
.
DATA_NOT_EXIST
;
}
}
await
RedisClient
.
writeSync
(
key
,
list
);
await
addAgentSetting
(
agent_id
,
market
,
symbol
,
ratio
);
//管理后台操作日志
addOptLog
(
currentUserId
,
0
,
'合约接单账户配置
'
,
ip
,
JSON
.
stringify
(
agentVO
),
'合约接单账户配置
'
);
addOptLog
(
currentUserId
,
0
,
'合约接单账户配置
对冲'
,
ip
,
JSON
.
stringify
(
agentUserVO
),
'合约接单账户配置对冲
'
);
return
'success'
;
return
'success'
;
}
}
export
async
function
agentUserList
(
pageVO
:
AgentPageVO
)
{
export
async
function
agentUserList
(
pageVO
:
AgentPageVO
)
{
let
key
=
'contractAgent.service.agentUserList'
;
let
where
=
{}
;
//TODO:目前在缓存里 方便调试 后期撮合搞定之后再修改
if
(
pageVO
.
user_id
)
{
let
list
=
await
RedisClient
.
getSync
(
key
)
;
where
[
"user_id"
]
=
pageVO
.
user_id
;
let
res
=
{
}
count
:
list
?
list
.
length
:
0
,
if
(
pageVO
.
agent_id
)
{
rows
:
list
?
list
:
[]
where
[
"agent_id"
]
=
pageVO
.
agent_id
;
}
}
let
page
=
Number
(
pageVO
.
page
);
let
size
=
Number
(
pageVO
.
size
);
let
res
=
await
userAgent
.
prototype
.
findAndCount
({
where
:
where
,
offset
:
page
*
size
-
size
,
limit
:
size
,
raw
:
true
});
return
res
;
return
res
;
}
}
export
async
function
agentUserSet
(
agentUserVO
:
AgentUserVO
,
currentUserId
:
any
,
ip
:
string
|
undefined
)
{
export
async
function
agentUserSet
(
agentUserVO
:
AgentUserVO
,
currentUserId
:
any
,
ip
:
string
|
undefined
)
{
//TODO:目前在缓存里 方便调试 后期撮合搞定之后再修改
agentUserVO
.
createdAt
=
new
Date
();
let
user_id
=
agentUserVO
.
user_id
;
agentUserVO
.
updatedAt
=
new
Date
();
let
agent_id
=
agentUserVO
.
agent_id
;
let
key
=
'contractAgent.service.agentUserList'
;
let
exist
=
await
userAgent
.
prototype
.
find
({
let
list
=
await
RedisClient
.
getSync
(
key
);
where
:
{
if
(
list
)
{
user_id
,
agentUserVO
.
id
=
list
.
length
+
1
;
agent_id
list
.
push
(
agentUserVO
);
},
}
raw
:
true
else
{
});
agentUserVO
.
id
=
1
;
if
(
exist
&&
exist
.
agent_id
!=
0
)
{
list
=
[];
throw
ErrorCode
.
DATA_EXIST
;
list
.
push
(
agentUserVO
);
}
else
{
await
setAgent
(
user_id
,
agent_id
);
}
}
await
RedisClient
.
writeSync
(
key
,
list
);
//管理后台操作日志
//管理后台操作日志
addOptLog
(
currentUserId
,
0
,
'合约接单账户关联配置'
,
ip
,
JSON
.
stringify
(
agentUserVO
),
'合约接单账户关联'
);
addOptLog
(
currentUserId
,
0
,
'合约接单账户关联配置'
,
ip
,
JSON
.
stringify
(
agentUserVO
),
'合约接单账户关联'
);
return
'success'
;
return
'success'
;
...
...
src/functional/router/v1/index.ts
View file @
390ab468
...
@@ -226,6 +226,9 @@ const postFunc = {
...
@@ -226,6 +226,9 @@ const postFunc = {
//金融部-其他管理-合约接单账户配置(代理商)
//金融部-其他管理-合约接单账户配置(代理商)
'fiance/other/contract/agent/set'
:
contractAgentCtrl
.
agentSet
,
'fiance/other/contract/agent/set'
:
contractAgentCtrl
.
agentSet
,
'fiance/other/contract/agent/list'
:
contractAgentCtrl
.
agentList
,
'fiance/other/contract/agent/list'
:
contractAgentCtrl
.
agentList
,
'fiance/other/contract/agent/hedgeRatio/set'
:
contractAgentCtrl
.
hedgeRatioSet
,
'fiance/other/contract/agent/hedgeRatio/list'
:
contractAgentCtrl
.
hedgeRatioList
,
//金融部-其他管理-合约接单账户关联(代理用户)
//金融部-其他管理-合约接单账户关联(代理用户)
'fiance/other/contract/agent/user/set'
:
contractAgentCtrl
.
agentUserSet
,
'fiance/other/contract/agent/user/set'
:
contractAgentCtrl
.
agentUserSet
,
'fiance/other/contract/agent/user/list'
:
contractAgentCtrl
.
agentUserList
,
'fiance/other/contract/agent/user/list'
:
contractAgentCtrl
.
agentUserList
,
...
...
src/utils/coreSystemUtils.ts
View file @
390ab468
...
@@ -234,9 +234,9 @@ export const removeAgent = async (user_id) => {
...
@@ -234,9 +234,9 @@ export const removeAgent = async (user_id) => {
// 添加代理对冲配置
// 添加代理对冲配置
// exp:1110,spot,BTC_USDT,0.5
// exp:1110,spot,BTC_USDT,0.5
// exp:1110,lpc,BTC_USDT_USDT,0.6
// exp:1110,lpc,BTC_USDT_USDT,0.6
export
const
addAgentSetting
=
async
(
user
_id
,
market
,
symbol
,
ratio
)
=>
{
export
const
addAgentSetting
=
async
(
agent
_id
,
market
,
symbol
,
ratio
)
=>
{
let
body
=
{
let
body
=
{
user
_id
,
market
,
symbol
,
ratio
agent
_id
,
market
,
symbol
,
ratio
};
};
let
res
=
{
let
res
=
{
is_success
:
true
,
is_success
:
true
,
...
...
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