Commit 390ab468 authored by 1486327116's avatar 1486327116

添加代理相关接口

parent 4a0c6305
......@@ -10,7 +10,7 @@ let isIp = require('is-ip');
/**
* 金融部-其他管理-合约接单账户配置列表
* @param req
* @param infoVO
* @param AgentPageVO
*/
export const agentList = async (req: any, pageVO: AgentPageVO) => {
let func_name = "contractAgent.control.agentList";
......@@ -36,11 +36,33 @@ export const agentSet = async (req: any, agentVO: AgentVO) => {
try {
let ip = isIp(req.ip) ? req.ip : '*.*.*.*';
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
}
let res = await contractAgentService.agentSet(agentVO, currentUserId, ip);
let res = await contractAgentService.hedgeRatioList(vo.agent_id);
return Res3Utils.result(res);
}
catch (e) {
......@@ -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);
}
};
/**
* 金融部-其他管理-合约接单账户关联列表
......
import { userApikeyStrict, } from "@madex/ex-ts-dao";
import { userAgent, } from "@madex/ex-ts-dao";
import { ErrorCode } from "../../../constant/errorCode";
import { addOptLog } from "./userOptLog.service";
import { addAgentSetting, getAgentSettings, setAgent } from "../../../utils/coreSystemUtils";
let _ = require('lodash');
let { logger } = require('@madex/ex-js-public');
let { authCommon: AuthCommon, redisUtilsCommon: RedisClient, } = require('@madex/ex-js-common');
......@@ -30,6 +32,10 @@ export interface AgentUserVO {
agent_id?: number;
ratio?: number;
symbol?: string;
createdAt?: Date | any,
updatedAt?: Date | any,
......@@ -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) {
let key = 'contractAgent.service.agentList';
//TODO:目前在缓存里 方便调试 后期撮合搞定之后再修改
let list = await RedisClient.getSync(key);
let res = {
count: list ? list.length : 0,
rows: list ? list : []
let where = {};
if (pageVO.user_id) {
where["user_id"] = pageVO.user_id;
}
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;
}
export async function agentSet(agentVO: AgentVO, currentUserId: any, ip: string | undefined) {
//TODO:目前在缓存里 方便调试 后期撮合搞定之后再修改
agentVO.createdAt = new Date();
agentVO.updatedAt = new Date();
let key = 'contractAgent.service.agentList';
let list = await RedisClient.getSync(key);
if (list) {
agentVO.id = list.length + 1;
list.push(agentVO);
export async function agentSet(user_id: any, currentUserId: any, ip: string | undefined) {
let exist = await userAgent.prototype.find({
where: {
user_id
},
raw: true
});
if (exist && exist.agent_id != 0) {
throw ErrorCode.DATA_EXIST;
}else {
await setAgent(user_id, user_id);
}
else {
agentVO.id = 1;
list = [];
list.push(agentVO);
addOptLog(currentUserId, 0, '合约接单账户配置', ip, user_id, '合约接单账户配置');
return 'success';
}
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);
//管理后台操作日志
addOptLog(currentUserId, 0, '合约接单账户配置', ip, JSON.stringify(agentVO), '合约接单账户配置');
await addAgentSetting(agent_id, market, symbol, ratio);
addOptLog(currentUserId, 0, '合约接单账户配置对冲', ip, JSON.stringify(agentUserVO), '合约接单账户配置对冲');
return 'success';
}
export async function agentUserList(pageVO: AgentPageVO) {
let key = 'contractAgent.service.agentUserList';
//TODO:目前在缓存里 方便调试 后期撮合搞定之后再修改
let list = await RedisClient.getSync(key);
let res = {
count: list ? list.length : 0,
rows: list ? list : []
let where = {};
if (pageVO.user_id) {
where["user_id"] = pageVO.user_id;
}
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;
}
export async function agentUserSet(agentUserVO: AgentUserVO, currentUserId: any, ip: string | undefined) {
//TODO:目前在缓存里 方便调试 后期撮合搞定之后再修改
agentUserVO.createdAt = new Date();
agentUserVO.updatedAt = new Date();
let key = 'contractAgent.service.agentUserList';
let list = await RedisClient.getSync(key);
if (list) {
agentUserVO.id = list.length + 1;
list.push(agentUserVO);
}
else {
agentUserVO.id = 1;
list = [];
list.push(agentUserVO);
let user_id = agentUserVO.user_id;
let agent_id = agentUserVO.agent_id;
let exist = await userAgent.prototype.find({
where: {
user_id,
agent_id
},
raw: true
});
if (exist && exist.agent_id != 0) {
throw ErrorCode.DATA_EXIST;
}else {
await setAgent(user_id, agent_id);
}
await RedisClient.writeSync(key, list);
//管理后台操作日志
addOptLog(currentUserId, 0, '合约接单账户关联配置', ip, JSON.stringify(agentUserVO), '合约接单账户关联');
return 'success';
......
......@@ -226,6 +226,9 @@ const postFunc = {
//金融部-其他管理-合约接单账户配置(代理商)
'fiance/other/contract/agent/set': contractAgentCtrl.agentSet,
'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/list': contractAgentCtrl.agentUserList,
......
......@@ -234,9 +234,9 @@ export const removeAgent = async (user_id) => {
// 添加代理对冲配置
// exp:1110,spot,BTC_USDT,0.5
// 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 = {
user_id, market, symbol, ratio
agent_id, market, symbol, ratio
};
let res = {
is_success: true,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment