Commit d41ae882 authored by ml's avatar ml

上交易对申请逻辑调整、增加接口、部分逻辑接口调整

parent 17c356ce
...@@ -75,4 +75,5 @@ export const ErrorCode = { ...@@ -75,4 +75,5 @@ export const ErrorCode = {
NO_TRIGGER_DEL:'30071',//只有未触发的任务可以删除 NO_TRIGGER_DEL:'30071',//只有未触发的任务可以删除
EXIST_ACTIVE_PAIR:'30072',//已存在生效或即将生效的该交易对费率配置 EXIST_ACTIVE_PAIR:'30072',//已存在生效或即将生效的该交易对费率配置
FEE_EX_OR_DEL:'30073',//费率设置已过期或已删除,不可以修改 FEE_EX_OR_DEL:'30073',//费率设置已过期或已删除,不可以修改
PAIR_FORMAT_ERR:'30074',//交易对格式错误
} }
...@@ -25,14 +25,22 @@ export const save = async (req: any, param: AddParam) => { ...@@ -25,14 +25,22 @@ export const save = async (req: any, param: AddParam) => {
let func_name = "contactPairCtl.save"; let func_name = "contactPairCtl.save";
let cmd = req.path; let cmd = req.path;
try { try {
ApiAssert.notNull('3000', param.base);
ApiAssert.notNull('3000', param.quote);
ApiAssert.notNull('3000', param.symbol); ApiAssert.notNull('3000', param.symbol);
ApiAssert.notNull('3000', param.name); ApiAssert.notNull('3000', param.name);
ApiAssert.notNull('3000', param.index);
ApiAssert.notNull('3000', param.settlement_asset);
ApiAssert.notNull('3000', param.price_scale); ApiAssert.notNull('3000', param.price_scale);
ApiAssert.notNull('3000', param.quantity_scale); ApiAssert.notNull('3000', param.quantity_scale);
ApiAssert.notNull('3000', param.maker_fee); ApiAssert.notNull('3000', param.maker_fee);
ApiAssert.notNull('3000', param.taker_fee); ApiAssert.notNull('3000', param.taker_fee);
ApiAssert.notNull('3000', param.default_initial_margin);
ApiAssert.notNull('3000', param.base_initial_margin);
ApiAssert.notNull('3000', param.base_maintenance_margin);
ApiAssert.notNull('3000', param.base_interest);
ApiAssert.notNull('3000', param.quote_interest);
ApiAssert.notNull('3000', param.impact_notional);
ApiAssert.notNull('3000', param.base_risk_limit);
ApiAssert.notNull('3000', param.risk_limit_step);
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 service.save(param, currentUserId, ip);
......
...@@ -70,3 +70,51 @@ export const tradeAssetsDetail = async (req: any, queryVO: QueryVO) => { ...@@ -70,3 +70,51 @@ export const tradeAssetsDetail = async (req: any, queryVO: QueryVO) => {
} }
}; };
/**
* 充值记录
* @param req
* @param infoVO
*/
export const depositList = async (req: any, queryVO: QueryVO) => {
let func_name = "mUserAssetsCtrl.depositList";
try {
queryVO.page = Optional.opt(queryVO, 'page', 1);
queryVO.size = Optional.opt(queryVO, 'size', 20);
if (!queryVO.user_id){
throw ErrorCode.PARAM_MISS
}
let res = await mUserAssetsService.depositList(queryVO.user_id, Number(queryVO.page), Number(queryVO.size));
return Res3Utils.result(res);
}
catch (e) {
logger.error(`${func_name} error:${e}`);
return Res3Utils.getErrorResult(e);
}
};
/**
* 提现记录
* @param req
* @param infoVO
*/
export const withdrawList = async (req: any, queryVO: QueryVO) => {
let func_name = "mUserAssetsCtrl.withdrawList";
try {
queryVO.page = Optional.opt(queryVO, 'page', 1);
queryVO.size = Optional.opt(queryVO, 'size', 20);
if (!queryVO.user_id){
throw ErrorCode.PARAM_MISS
}
let res = await mUserAssetsService.withdrawList(queryVO.user_id, Number(queryVO.page), Number(queryVO.size));
return Res3Utils.result(res);
}
catch (e) {
logger.error(`${func_name} error:${e}`);
return Res3Utils.getErrorResult(e);
}
};
...@@ -46,25 +46,6 @@ export const listed = async (req: any, pageVO: PairApplyPageVO) => { ...@@ -46,25 +46,6 @@ export const listed = async (req: any, pageVO: PairApplyPageVO) => {
} }
}; };
/**
* 技术部-交易上下线管理-已有交易区列表
* @param req
* @param infoVO
*/
export const tradeAreaList = async (req: any, pageVO: PairApplyPageVO) => {
let func_name = "pairApply.control.tradeAreaList";
try {
pageVO.page = Optional.opt(pageVO, 'page', 1);
pageVO.size = Optional.opt(pageVO, 'size', 20);
let res = await pairApplyService.tradeAreaList(pageVO);
return Res3Utils.result(res);
}
catch (e) {
logger.error(`${func_name} error:${e}`);
return Res3Utils.getErrorResult(e);
}
};
/** /**
* 技术部-交易上下线管理-申请上新交易对 * 技术部-交易上下线管理-申请上新交易对
* @param req * @param req
...@@ -201,18 +182,23 @@ export const review = async (req: any, pairApplyVO: PairApplyVO) => { ...@@ -201,18 +182,23 @@ export const review = async (req: any, pairApplyVO: PairApplyVO) => {
async function paramValid(pairApplyVO: PairApplyVO) { async function paramValid(pairApplyVO: PairApplyVO) {
if (!pairApplyVO.coin_symbol || !pairApplyVO.currency_symbol if (!pairApplyVO.type || !pairApplyVO.symbol
|| !pairApplyVO.decimal || !pairApplyVO.qtyPrecision || !pairApplyVO.name || !pairApplyVO.price_scale
|| !pairApplyVO.weight || !pairApplyVO.baseMinValue || !pairApplyVO.quantity_scale || !pairApplyVO.maker_fee
|| !pairApplyVO.quoteMinValue) { || !pairApplyVO.taker_fee) {
throw ErrorCode.PARAM_MISS; throw ErrorCode.PARAM_MISS;
} }
if (!pairApplyVO.pair_type) { //申请上合约交易对
pairApplyVO.pair_type = 0 if (pairApplyVO.type == 2) {
} if (!pairApplyVO.settlement_asset || !pairApplyVO.default_initial_margin
if (!pairApplyVO.area_id) { || !pairApplyVO.base_initial_margin || !pairApplyVO.base_maintenance_margin
pairApplyVO.area_id = 0 || !pairApplyVO.base_interest || !pairApplyVO.quote_interest
|| !pairApplyVO.impact_notional || !pairApplyVO.base_risk_limit
|| !pairApplyVO.risk_limit_step) {
throw ErrorCode.PARAM_MISS;
}
} }
if (!pairApplyVO.business_area_id) { if (!pairApplyVO.business_area_id) {
pairApplyVO.business_area_id = 0 pairApplyVO.business_area_id = 0
} }
......
...@@ -24,6 +24,8 @@ export interface AppVersionVO { ...@@ -24,6 +24,8 @@ export interface AppVersionVO {
comment_en?: string; comment_en?: string;
comment_ja?: string;
platform?: number, platform?: number,
grayscale_value?: number, grayscale_value?: number,
......
// @madex/ex-ts-dao 是 ts 的 dao, 代码在 bitbucket/ex-js-dao 的 ts 分支上 // @madex/ex-ts-dao 是 ts 的 dao, 代码在 bitbucket/ex-js-dao 的 ts 分支上
import { coinType, ormDB, spotPairs } from "@madex/ex-ts-dao"; import { coinType, ormDB, spotPairs } from "@madex/ex-ts-dao";
import { addCoin2Core, addPairToCore } from "../../../utils/coreSystemUtils"; import { addCoin2Core } from "../../../utils/coreSystemUtils";
import { ErrorCode } from "../../../constant/errorCode"; import { ErrorCode } from "../../../constant/errorCode";
import { addOptLog } from "./userOptLog.service"; import { addOptLog } from "./userOptLog.service";
......
...@@ -4,6 +4,7 @@ import { NUMBER } from "sequelize"; ...@@ -4,6 +4,7 @@ import { NUMBER } from "sequelize";
import { addPairToCore } from "../../../utils/coreSystemUtils"; 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";
import { checkPairInCoinType } from "../../../utils/coinTypeUtils";
let { logger, datetimeUtils } = require('@madex/ex-js-public'); let { logger, datetimeUtils } = require('@madex/ex-js-public');
...@@ -109,6 +110,9 @@ export async function list(param: ListParam) { ...@@ -109,6 +110,9 @@ export async function list(param: ListParam) {
} }
export const save = async (param: AddParam, currentUserId: any, ip: any) => { export const save = async (param: AddParam, currentUserId: any, ip: any) => {
//检查交易对中的币种是否存在于coin_type 中
await checkPairInCoinType(String(param.symbol));
param.updatedAt = new Date(); param.updatedAt = new Date();
param.createdAt = new Date(); param.createdAt = new Date();
let dbInfo = await contractPairs.prototype.findOne({ let dbInfo = await contractPairs.prototype.findOne({
......
import { exPairApply, coinType, ormDB, systemTrigger, spotPairs, exTradeArea, exBusinessAreaRouter } from "@madex/ex-ts-dao"; import { exPairApply, coinType, ormDB, systemTrigger, spotPairs, exTradeArea, exBusinessAreaRouter } 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 { addCoin2Core, addPairToCore } from "../../../utils/coreSystemUtils";
import { PAIR_APPLY_STATUS } from "../../../constant/pairApplyConst"; import { PAIR_APPLY_STATUS } from "../../../constant/pairApplyConst";
......
...@@ -102,7 +102,7 @@ export async function withdrawList(pageVO: QueryVO) { ...@@ -102,7 +102,7 @@ export async function withdrawList(pageVO: QueryVO) {
return resList; return resList;
} }
async function dealReturnData(resList: any) { export async function dealReturnData(resList: any) {
if (resList.rows.length) { if (resList.rows.length) {
let usdtTickerMap = {}; let usdtTickerMap = {};
for (let item of resList.rows) { for (let item of resList.rows) {
......
import { ormDB, mainUserAsset } from "@madex/ex-ts-dao"; import { ormDB, mainUserAsset, coinTx, coinWithdraw } from "@madex/ex-ts-dao";
import { ErrorCode } from "../../../constant/errorCode"; import { ErrorCode } from "../../../constant/errorCode";
import BigNumber from "bignumber.js"; import BigNumber from "bignumber.js";
import { any } from "async"; import { any } from "async";
import { getUserAccountFromCore } from "../../../utils/coreSystemUtils"; import { getUserAccountFromCore } from "../../../utils/coreSystemUtils";
import { dealReturnData } from "./depositAndWithdraw.service";
let _ = require('lodash'); let _ = require('lodash');
...@@ -288,6 +289,42 @@ export async function tradeAssetByUids(uids: number[]) { ...@@ -288,6 +289,42 @@ export async function tradeAssetByUids(uids: number[]) {
} }
export async function depositList(user_id: number, page: number, size: number) {
let where = {
user_id: user_id
};
let resList = await coinTx.prototype.findAndCount({
where: where,
limit: size,
offset: (Number(page) - 1) * Number(size),
order: [["createdAt", "desc"]],
raw: true
});
await dealReturnData(resList);
return resList;
}
export async function withdrawList(user_id: number, page: number, size: number) {
let where = {
user_id: user_id
};
let resList = await coinWithdraw.prototype.findAndCount({
where: where,
limit: size,
offset: (Number(page) - 1) * Number(size),
order: [["createdAt", "desc"]],
raw: true
});
await dealReturnData(resList);
return resList;
}
......
import { exPairApply, coinType, ormDB, systemTrigger, spotPairs, exTradeArea, exBusinessAreaRouter } from "@madex/ex-ts-dao"; import { exPairApply, coinType, ormDB, systemTrigger, spotPairs, exTradeArea, exBusinessAreaRouter, contractPairs } 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 { addCoin2Core, addPairToCore } from "../../../utils/coreSystemUtils"; import { addCoin2Core, addPairToCore } from "../../../utils/coreSystemUtils";
import { PAIR_APPLY_STATUS } from "../../../constant/pairApplyConst"; import { PAIR_APPLY_STATUS } from "../../../constant/pairApplyConst";
import { checkPairInCoinType } from "../../../utils/coinTypeUtils";
import { pairs } from "rxjs";
let _ = require('lodash'); let _ = require('lodash');
...@@ -12,37 +14,57 @@ let { logger, datetimeUtils } = require('@madex/ex-js-public'); ...@@ -12,37 +14,57 @@ let { logger, datetimeUtils } = require('@madex/ex-js-public');
export interface PairApplyVO { export interface PairApplyVO {
id?: number; id?: number;
coin_symbol?: string; type?: number;
currency_symbol?: string; symbol?: string;
maker_rate?: string; name?: string;
taker_rate?: string; business_area_id?: number;
pair_type?: number; price_scale?: number;
area_id?: number; quantity_scale?: number;
business_area_id?: number; maker_fee?: string;
decimal?: number; taker_fee?: string;
qtyPrecision?: number; price_increment?: number;
weight?: number; quantity_increment?: number;
tm_active?: Date | any; view_precision?: number
min_order_size?: number
max_order_size?: number
min_order_value?: number
max_order_value?: number
settlement_asset?: string;
funding_times_perday?: number;
default_initial_margin?: number; //"0.01",
base_initial_margin?: number;//"0.01",
baseMinValue?: string; base_maintenance_margin?: number;//"0.01",
baseMaxValue?: string; base_interest: number; //"0.0003",
quoteMinValue?: string; quote_interest?: number; //"0.0006",
quoteMaxValue?: string; impact_notional?: number; // "600000",
quoteIncrement?: string; base_risk_limit?: number; // "1000000",
risk_limit_step?: number; //"1000000",
tm_active?: Date | any;
applyer?: number; applyer?: number;
...@@ -98,48 +120,12 @@ export async function listed(pageVO: PairApplyPageVO) { ...@@ -98,48 +120,12 @@ export async function listed(pageVO: PairApplyPageVO) {
return resList; return resList;
} }
export async function tradeAreaList(pageVO: PairApplyPageVO) {
let where = {};
if (pageVO.coin_symbol) {
where['coin_symbol'] = pageVO.coin_symbol;
}
if (pageVO.is_active || pageVO.is_active === 0) {
where['is_active'] = pageVO.is_active;
}
let resList = await exTradeArea.prototype.findAndCount({
where: where,
limit: pageVO.size,
offset: (Number(pageVO.page) - 1) * Number(pageVO.size),
order: [["id", "desc"]],
raw: true
});
return resList;
}
export async function apply(pairApplyVO: PairApplyVO, currentUser: any, ip: string | undefined) { export async function apply(pairApplyVO: PairApplyVO, currentUser: any, ip: string | undefined) {
//检查交易对中的币种是否存在于coin_type 中
let dbSymbol = await coinType.prototype.findOne({ await checkPairInCoinType(String(pairApplyVO.symbol));
where: { symbol: pairApplyVO.coin_symbol },
raw: true
});
if (!dbSymbol) {
throw ErrorCode.COIN_DATA_NOT_EXIST;
}
let dbCurrency = await coinType.prototype.findOne({
where: { symbol: pairApplyVO.currency_symbol },
raw: true
});
if (!dbCurrency) {
throw ErrorCode.CURRENT_COIN_DATA_NOT_EXIST;
}
pairApplyVO.maker_rate = "0.001";
pairApplyVO.taker_rate = "0.002";
pairApplyVO.baseMaxValue = "100000000";
pairApplyVO.quoteMaxValue = "100000000";
pairApplyVO.applyer = currentUser.account; pairApplyVO.applyer = currentUser.account;
pairApplyVO.status = PAIR_APPLY_STATUS.WAIT_VIEW; pairApplyVO.status = PAIR_APPLY_STATUS.WAIT_VIEW;
...@@ -165,8 +151,8 @@ export async function apply(pairApplyVO: PairApplyVO, currentUser: any, ip: stri ...@@ -165,8 +151,8 @@ export async function apply(pairApplyVO: PairApplyVO, currentUser: any, ip: stri
else { else {
await exPairApply.prototype.create(pairApplyVO); await exPairApply.prototype.create(pairApplyVO);
} }
sendMsg(pairApplyVO.status, pairApplyVO.coin_symbol + '_' + pairApplyVO.currency_symbol); sendMsg(pairApplyVO.status, String(pairApplyVO.symbol));
//管理后台操作日志 //管理后台操作日志
addOptLog(currentUser.userId, 0, '新增上新交易对申请', ip, JSON.stringify(pairApplyVO), '交易上下线管理'); addOptLog(currentUser.userId, 0, '新增上新交易对申请', ip, JSON.stringify(pairApplyVO), '交易上下线管理');
return 'success'; return 'success';
} }
...@@ -181,22 +167,17 @@ export async function edit(pairApplyVO: PairApplyVO, currentUser: any, ip: strin ...@@ -181,22 +167,17 @@ export async function edit(pairApplyVO: PairApplyVO, currentUser: any, ip: strin
if (!dbApply) { if (!dbApply) {
throw ErrorCode.DATA_NOT_EXIST; throw ErrorCode.DATA_NOT_EXIST;
} }
if (Number(pairApplyVO.status) >= PAIR_APPLY_STATUS.CREATE_PAIR) { let dbApply2 = await exPairApply.prototype.findOne({
let dbSymbol = await coinType.prototype.findOne({ where: { symbol: pairApplyVO.symbol, id: { [ormDB.Op.ne]: pairApplyVO.id } },
where: { symbol: pairApplyVO.coin_symbol }, raw: true
raw: true });
}); if (dbApply2) {
if (!dbSymbol) { throw ErrorCode.DATA_EXIST;
throw ErrorCode.COIN_DATA_NOT_EXIST;
}
let dbCurrency = await coinType.prototype.findOne({
where: { symbol: pairApplyVO.currency_symbol },
raw: true
});
if (!dbCurrency) {
throw ErrorCode.CURRENT_COIN_DATA_NOT_EXIST;
}
} }
//检查交易对中的币种是否存在于coin_type 中
await checkPairInCoinType(String(pairApplyVO.symbol));
pairApplyVO.applyer = dbApply.applyer; pairApplyVO.applyer = dbApply.applyer;
pairApplyVO.updatedAt = new Date(); pairApplyVO.updatedAt = new Date();
...@@ -205,7 +186,7 @@ export async function edit(pairApplyVO: PairApplyVO, currentUser: any, ip: strin ...@@ -205,7 +186,7 @@ export async function edit(pairApplyVO: PairApplyVO, currentUser: any, ip: strin
id: Number(pairApplyVO.id) id: Number(pairApplyVO.id)
} }
}); });
sendMsg(Number(pairApplyVO.status), pairApplyVO.coin_symbol + '_' + pairApplyVO.currency_symbol); sendMsg(Number(pairApplyVO.status), String(pairApplyVO.symbol));
//管理后台操作日志 //管理后台操作日志
addOptLog(currentUser.userId, 0, '上新交易对申请编辑', ip, JSON.stringify(pairApplyVO), '交易上下线管理'); addOptLog(currentUser.userId, 0, '上新交易对申请编辑', ip, JSON.stringify(pairApplyVO), '交易上下线管理');
return 'success'; return 'success';
...@@ -223,7 +204,7 @@ export async function cancelSelf(id: any, reason: any, currentUser: any, ip: str ...@@ -223,7 +204,7 @@ export async function cancelSelf(id: any, reason: any, currentUser: any, ip: str
if (dbApply.status >= PAIR_APPLY_STATUS.PASS) { if (dbApply.status >= PAIR_APPLY_STATUS.PASS) {
throw ErrorCode.NO_CANCEL; throw ErrorCode.NO_CANCEL;
} }
await updateApply(Number(id), PAIR_APPLY_STATUS.CANCEL, currentUser.account, String(reason), dbApply.coin_symbol, dbApply.currency_symbol); await updateApply(Number(id), PAIR_APPLY_STATUS.CANCEL, currentUser.account, String(reason), dbApply.symbol);
//管理后台操作日志 //管理后台操作日志
addOptLog(currentUser.userId, 0, '撤销上新交易对申请', ip, JSON.stringify(dbApply), '交易上下线管理'); addOptLog(currentUser.userId, 0, '撤销上新交易对申请', ip, JSON.stringify(dbApply), '交易上下线管理');
return 'success'; return 'success';
...@@ -238,7 +219,7 @@ export async function rewrite(id: any, reason: any, currentUser: any, ip: string ...@@ -238,7 +219,7 @@ export async function rewrite(id: any, reason: any, currentUser: any, ip: string
if (!dbApply) { if (!dbApply) {
throw ErrorCode.DATA_NOT_EXIST; throw ErrorCode.DATA_NOT_EXIST;
} }
await updateApply(Number(id), PAIR_APPLY_STATUS.RE_WRITE, currentUser.account, String(reason), dbApply.coin_symbol, dbApply.currency_symbol); await updateApply(Number(id), PAIR_APPLY_STATUS.RE_WRITE, currentUser.account, String(reason), dbApply.symbol);
//管理后台操作日志 //管理后台操作日志
addOptLog(currentUser.userId, 0, '驳回上新交易对申请', ip, JSON.stringify(dbApply), '交易上下线管理'); addOptLog(currentUser.userId, 0, '驳回上新交易对申请', ip, JSON.stringify(dbApply), '交易上下线管理');
return 'success'; return 'success';
...@@ -253,7 +234,7 @@ export async function cancel(id: any, reason: any, currentUser: any, ip: string ...@@ -253,7 +234,7 @@ export async function cancel(id: any, reason: any, currentUser: any, ip: string
if (!dbApply) { if (!dbApply) {
throw ErrorCode.DATA_NOT_EXIST; throw ErrorCode.DATA_NOT_EXIST;
} }
await updateApply(Number(id), PAIR_APPLY_STATUS.CANCEL, currentUser.account, String(reason), dbApply.coin_symbol, dbApply.currency_symbol); await updateApply(Number(id), PAIR_APPLY_STATUS.CANCEL, currentUser.account, String(reason), dbApply.symbol);
//管理后台操作日志 //管理后台操作日志
addOptLog(currentUser.userId, 0, '管理员取消上新交易对申请', ip, JSON.stringify(dbApply), '交易上下线管理'); addOptLog(currentUser.userId, 0, '管理员取消上新交易对申请', ip, JSON.stringify(dbApply), '交易上下线管理');
return 'success'; return 'success';
...@@ -271,126 +252,163 @@ export async function review(id: any, currentUser: any, ip: string | undefined) ...@@ -271,126 +252,163 @@ export async function review(id: any, currentUser: any, ip: string | undefined)
let reason = ""; let reason = "";
//1被驳回 2申请待审批 3审批通过 4交易对创建完成 5交易对增加到撮合完成 6等待撮合系统重启 7发布交易对到撮合完成 8交易对激活定时器完成 9取消 //1被驳回 2申请待审批 3审批通过 4交易对创建完成 5交易对增加到撮合完成 6等待撮合系统重启 7发布交易对到撮合完成 8交易对激活定时器完成 9取消
let status = Number(dbApply.status) let status = Number(dbApply.status)
let pair = dbApply.coin_symbol + '_' + dbApply.currency_symbol; let pair = dbApply.symbol;
let base = pair.split('_')[0];
let quote = pair.split('_')[1];
//1 现货 2 合约
let type = dbApply.type;
if (status == PAIR_APPLY_STATUS.WAIT_VIEW) {//2-3 if (status == PAIR_APPLY_STATUS.WAIT_VIEW) {//2-3
reason = "审核通过"; reason = "审核通过";
await updateApply(Number(id), PAIR_APPLY_STATUS.PASS, currentUser.account, reason, dbApply.coin_symbol, dbApply.currency_symbol); await updateApply(Number(id), PAIR_APPLY_STATUS.PASS, currentUser.account, reason, pair);
} }
else if (status == PAIR_APPLY_STATUS.PASS) {//3-4 else if (status == PAIR_APPLY_STATUS.PASS) {//3-4
let dbSymbol = await coinType.prototype.findOne({ //检查交易对中的币种是否存在于coin_type 中
where: { symbol: dbApply.coin_symbol }, await checkPairInCoinType(pair);
raw: true //检查交易对是否存在
}); await checkPairExist(pair, type);
if (!dbSymbol) {
throw ErrorCode.COIN_DATA_NOT_EXIST;
}
let dbCurrency = await coinType.prototype.findOne({
where: { symbol: dbApply.currency_symbol },
raw: true
});
if (!dbCurrency) {
throw ErrorCode.CURRENT_COIN_DATA_NOT_EXIST;
}
//TODO:确定是否查此表 原逻辑 查询ex_pair
let dbPair = await spotPairs.prototype.findOne({
where: { symbol: pair },
raw: true
});
if (dbPair) {
throw ErrorCode.PAIR_EXIST;
}
let insertInfo = { let insertInfo = {
symbol: pair, symbol: pair,
base: dbApply.coin_symbol,
quote: dbApply.currency_symbol,
name: pair, name: pair,
price_scale: dbApply.decimal, price_scale: dbApply.price_scale,
quantity_scale: dbApply.qtyPrecision, quantity_scale: dbApply.quantity_scale,
maker_fee: dbApply.maker_fee, maker_fee: dbApply.maker_fee,
taker_fee: dbApply.taker_fee, taker_fee: dbApply.taker_fee,
price_increment: dbApply.price_increment,
quantity_increment: dbApply.quantity_increment,
view_precision: dbApply.view_precision,
min_order_size: dbApply.min_order_size,
max_order_size: dbApply.max_order_size,
min_order_value: dbApply.min_order_value,
max_order_value: dbApply.max_order_value,
status: 0, status: 0,
createdAt: new Date(), createdAt: new Date(),
updatedAt: new Date(), updatedAt: new Date(),
} }
//TODO:是否插入此表 //现货
await spotPairs.prototype.create(insertInfo); if (type == 1) {
insertInfo['base'] = base;
insertInfo['quote'] = quote;
await spotPairs.prototype.create(insertInfo);
}
else {//合约
insertInfo['index'] = pair;
insertInfo['settlement_asset'] = dbApply.settlement_asset;
insertInfo['funding_times_perday'] = dbApply.funding_times_perday;
insertInfo['default_initial_margin'] = dbApply.default_initial_margin;
insertInfo['base_initial_margin'] = dbApply.base_initial_margin;
insertInfo['base_maintenance_margin'] = dbApply.base_maintenance_margin;
insertInfo['base_interest'] = dbApply.base_interest;
insertInfo['quote_interest'] = dbApply.quote_interest;
insertInfo['impact_notional'] = dbApply.impact_notional;
insertInfo['base_risk_limit'] = dbApply.base_risk_limit;
insertInfo['risk_limit_step'] = dbApply.risk_limit_step;
await contractPairs.prototype.create(insertInfo);
}
let areaRouterInfo = { let areaRouterInfo = {
pair: pair, pair: pair,
area_id: dbApply.business_area_id, area_id: dbApply.business_area_id,
weight: dbApply.weight,
createdAt: new Date(), createdAt: new Date(),
updatedAt: new Date(), updatedAt: new Date(),
} }
await exBusinessAreaRouter.prototype.create(areaRouterInfo); await exBusinessAreaRouter.prototype.create(areaRouterInfo);
reason = "交易对创建完成"; reason = "交易对创建完成";
await updateApply(Number(id), PAIR_APPLY_STATUS.CREATE_PAIR, currentUser.account, reason, dbApply.coin_symbol, dbApply.currency_symbol); await updateApply(Number(id), PAIR_APPLY_STATUS.CREATE_PAIR, currentUser.account, reason, pair);
} }
else if (status == PAIR_APPLY_STATUS.CREATE_PAIR) {//4-5 else if (status == PAIR_APPLY_STATUS.CREATE_PAIR) {//4-5
//TODO:确定是否查此表 原逻辑 查询ex_pair //检查交易对是否存在
let dbPair = await spotPairs.prototype.findOne({ let dbPair = await checkPairExist(pair, type);
where: { symbol: pair }, let param: any;
raw: true //现货
}); if (type == 1) {
if (!dbPair) { param = {
throw ErrorCode.PAIR_NOT_EXIST; "base": dbPair.base, "quote": dbPair.quote, "symbol": dbPair.symbol, "name": dbPair.symbol,
"price_scale": dbPair.price_scale, "quantity_scale": dbPair.quantity_scale,
"maker_fee": dbPair.maker_fee, "taker_fee": dbPair.taker_fee
}
} }
let param = { else {
"base": dbPair.base, "quote": dbPair.quote, "symbol": dbPair.symbol, "name": dbPair.symbol, param = {
"price_scale": dbPair.price_scale, "quantity_scale": dbPair.quantity_scale, "market_type": 2,
"maker_fee": dbPair.maker_fee, "taker_fee": dbPair.taker_fee "base": base, "quote": quote, "symbol": dbPair.symbol, "name": dbPair.symbol,
"price_scale": dbPair.price_scale, "quantity_scale": dbPair.quantity_scale,
"maker_fee": dbPair.maker_fee, "taker_fee": dbPair.taker_fee,
"default_initial_margin": dbPair.default_initial_margin,
"base_initial_margin": dbPair.base_initial_margin,
"base_maintenance_margin": dbPair.base_maintenance_margin,
"settlement_asset": dbPair.settlement_asset,
"index": dbPair.symbol,
"base_interest": dbPair.base_interest,
"quote_interest": dbPair.quote_interest,
"impact_notional": dbPair.impact_notional,
"base_risk_limit": dbPair.base_risk_limit,
"risk_limit_step": dbPair.risk_limit_step,
"funding_times_perday": dbPair.funding_times_perday
}
}
if (dbPair.min_order_size) {
param["min_order_size"] = dbPair.min_order_size;
}
if (dbPair.max_order_size) {
param["max_order_size"] = dbPair.max_order_size;
}
if (dbPair.min_order_value) {
param["min_order_value"] = dbPair.min_order_value;
}
if (dbPair.max_order_value) {
param["max_order_value"] = dbPair.max_order_value;
} }
let optResult = await addPairToCore(param); let optResult = await addPairToCore(param);
if (!optResult.is_success) { if (!optResult.is_success) {
throw ErrorCode.ADD_PAIR_TO_CORE_ERR; throw ErrorCode.ADD_PAIR_TO_CORE_ERR;
} }
//现货
if (type == 1) {
await spotPairs.prototype.update({ status: 1 }, {
where: {
id: dbPair.id
}
});
}
else {//合约
await contractPairs.prototype.update({ status: 1 }, {
where: {
id: dbPair.id
}
});
}
await spotPairs.prototype.update({ status: 1 }, {
where: {
id: dbPair.id
}
});
reason = "交易对增加到撮合完成"; reason = "交易对增加到撮合完成";
await updateApply(Number(id), PAIR_APPLY_STATUS.ADMIN_ADD_PAIR, currentUser.account, reason, dbApply.coin_symbol, dbApply.currency_symbol); await updateApply(Number(id), PAIR_APPLY_STATUS.ADMIN_ADD_PAIR, currentUser.account, reason, pair);
} }
else if (status == PAIR_APPLY_STATUS.ADMIN_ADD_PAIR) {//5-6 else if (status == PAIR_APPLY_STATUS.ADMIN_ADD_PAIR) {//5-6
reason = "等待撮合系统重启"; reason = "等待撮合系统重启";
await updateApply(Number(id), PAIR_APPLY_STATUS.WAIT_ADMIN_RESTART, currentUser.account, reason, dbApply.coin_symbol, dbApply.currency_symbol); await updateApply(Number(id), PAIR_APPLY_STATUS.WAIT_ADMIN_RESTART, currentUser.account, reason, pair);
} }
else if (status == PAIR_APPLY_STATUS.WAIT_ADMIN_RESTART) {//6-7 else if (status == PAIR_APPLY_STATUS.WAIT_ADMIN_RESTART) {//6-7
//TODO:确定是否查此表 原逻辑 查询ex_pair //检查交易对是否存在
let dbPair = await spotPairs.prototype.findOne({ await checkPairExist(pair, type);
where: { symbol: pair },
raw: true
});
if (!dbPair) {
throw ErrorCode.PAIR_NOT_EXIST;
}
//TODO:新撮合是否需要此操作 初始化 //TODO:新撮合是否需要此操作 初始化
/*String errStr = spotRpcService.initPair1(dbpair); /*String errStr = spotRpcService.initPair1(dbpair);
if (errStr != null) { if (errStr != null) {
return ResponseResult.failure("admin rpc fail: " + errStr); return ResponseResult.failure("admin rpc fail: " + errStr);
}*/ }*/
reason = "发布交易对到撮合完成"; reason = "发布交易对到撮合完成";
await updateApply(Number(id), PAIR_APPLY_STATUS.ADMIN_ISSUE_PAIR, currentUser.account, reason, dbApply.coin_symbol, dbApply.currency_symbol); await updateApply(Number(id), PAIR_APPLY_STATUS.ADMIN_ISSUE_PAIR, currentUser.account, reason, pair);
} }
else if (status == PAIR_APPLY_STATUS.ADMIN_ISSUE_PAIR) {//7-8 else if (status == PAIR_APPLY_STATUS.ADMIN_ISSUE_PAIR) {//7-8
//TODO:确定是否查此表 原逻辑 查询ex_pair //检查交易对是否存在
let dbPair = await spotPairs.prototype.findOne({ await checkPairExist(pair, type);
where: { symbol: pair },
raw: true
});
if (!dbPair) {
throw ErrorCode.PAIR_NOT_EXIST;
}
let tm = datetimeUtils.add(new Date(), datetimeUtils.SECONED); let tm = datetimeUtils.add(new Date(), datetimeUtils.SECONED);
let tm_active = dbApply.tm_active; let tm_active = dbApply.tm_active;
if (datetimeUtils.between(tm_active, tm) < 0) { if (datetimeUtils.between(tm_active, tm) < 0) {
throw ErrorCode.ACTIVE_TM_EXPIRE; throw ErrorCode.ACTIVE_TM_EXPIRE;
} }
//TODO:需要确认 trigger_type 等字段
await systemTrigger.prototype.create({ await systemTrigger.prototype.create({
trigger_symbol: pair, trigger_symbol: pair,
trigger_type: 2, trigger_type: 2,
...@@ -401,7 +419,7 @@ export async function review(id: any, currentUser: any, ip: string | undefined) ...@@ -401,7 +419,7 @@ export async function review(id: any, currentUser: any, ip: string | undefined)
updatedAt: new Date(), updatedAt: new Date(),
}); });
reason = "交易对激活定时器完成"; reason = "交易对激活定时器完成";
await updateApply(Number(id), PAIR_APPLY_STATUS.TIMER_ACTIVE, currentUser.account, reason, dbApply.coin_symbol, dbApply.currency_symbol); await updateApply(Number(id), PAIR_APPLY_STATUS.TIMER_ACTIVE, currentUser.account, reason, pair);
} }
else { else {
throw ErrorCode.CURRENT_STATUS_NOT_APPLY throw ErrorCode.CURRENT_STATUS_NOT_APPLY
...@@ -412,7 +430,7 @@ export async function review(id: any, currentUser: any, ip: string | undefined) ...@@ -412,7 +430,7 @@ export async function review(id: any, currentUser: any, ip: string | undefined)
return 'success'; return 'success';
} }
async function updateApply(id: number, status: number, checker: string, reason: string, coin_symbol: string, currency_symbol: string) { async function updateApply(id: number, status: number, checker: string, reason: string, symbol: string) {
let updateInfo = { let updateInfo = {
status: status, status: status,
checker: checker, checker: checker,
...@@ -424,7 +442,7 @@ async function updateApply(id: number, status: number, checker: string, reason: ...@@ -424,7 +442,7 @@ async function updateApply(id: number, status: number, checker: string, reason:
id: id id: id
} }
}); });
sendMsg(status, coin_symbol + '_' + currency_symbol); sendMsg(status, symbol);
} }
//TODO:发送lark消息 //TODO:发送lark消息
...@@ -463,3 +481,28 @@ async function sendMsg(status: number, symbol: string) { ...@@ -463,3 +481,28 @@ async function sendMsg(status: number, symbol: string) {
} }
} }
/**
* 检查交易对是否存在
* @param pair
*/
async function checkPairExist(pair: string, type: number) {
let dbPair: any;
//现货
if (type == 1) {
dbPair = await spotPairs.prototype.findOne({
where: { symbol: pair },
raw: true
});
}
else {//合约
dbPair = await contractPairs.prototype.findOne({
where: { symbol: pair },
raw: true
});
}
if (!dbPair) {
throw ErrorCode.PAIR_NOT_EXIST;
}
return dbPair;
}
...@@ -4,6 +4,7 @@ import { NUMBER } from "sequelize"; ...@@ -4,6 +4,7 @@ import { NUMBER } from "sequelize";
import { addPairToCore } from "../../../utils/coreSystemUtils"; 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";
import { checkPairInCoinType } from "../../../utils/coinTypeUtils";
let { logger, datetimeUtils } = require('@madex/ex-js-public'); let { logger, datetimeUtils } = require('@madex/ex-js-public');
...@@ -86,6 +87,10 @@ export async function list(param: ListParam) { ...@@ -86,6 +87,10 @@ export async function list(param: ListParam) {
} }
export const save = async (param: AddParam, currentUserId: any, ip: any) => { export const save = async (param: AddParam, currentUserId: any, ip: any) => {
//检查交易对中的币种是否存在于coin_type 中
await checkPairInCoinType(String(param.symbol));
param.updatedAt = new Date(); param.updatedAt = new Date();
param.createdAt = new Date(); param.createdAt = new Date();
let dbInfo = await spotPairs.prototype.findOne({ let dbInfo = await spotPairs.prototype.findOne({
......
...@@ -149,6 +149,8 @@ const postFunc = { ...@@ -149,6 +149,8 @@ const postFunc = {
'mUser/manage/walletAsset/detail': mUserAssetsCtrl.walletAssetDetail,//Madex 用户管理 ->钱包账户资产详情 'mUser/manage/walletAsset/detail': mUserAssetsCtrl.walletAssetDetail,//Madex 用户管理 ->钱包账户资产详情
'mUser/manage/asset/distribution': mUserAssetsCtrl.assetDistribution,//Madex 用户管理 ->资产分布 'mUser/manage/asset/distribution': mUserAssetsCtrl.assetDistribution,//Madex 用户管理 ->资产分布
'mUser/manage/tradeAsset/detail': mUserAssetsCtrl.tradeAssetsDetail,//Madex 用户管理 ->交易账户资产详情 'mUser/manage/tradeAsset/detail': mUserAssetsCtrl.tradeAssetsDetail,//Madex 用户管理 ->交易账户资产详情
'mUser/manage/deposit/list': mUserAssetsCtrl.depositList,//Madex 用户管理 -> 充值记录
'mUser/manage/withdraw/list': mUserAssetsCtrl.withdrawList,//Madex 用户管理 -> 提现记录
'mUser/manage/order/pending/list': orderPendingAndHistoryCtrl.pendingList,//Madex 用户管理 ->当前委托 'mUser/manage/order/pending/list': orderPendingAndHistoryCtrl.pendingList,//Madex 用户管理 ->当前委托
'mUser/manage/order/history/list': orderPendingAndHistoryCtrl.historyList,//Madex 用户管理 ->历史委托 'mUser/manage/order/history/list': orderPendingAndHistoryCtrl.historyList,//Madex 用户管理 ->历史委托
'mUser/manage/order/detail/list': orderPendingAndHistoryCtrl.detailList,//Madex 用户管理 ->成交记录 'mUser/manage/order/detail/list': orderPendingAndHistoryCtrl.detailList,//Madex 用户管理 ->成交记录
...@@ -251,8 +253,8 @@ const postFunc = { ...@@ -251,8 +253,8 @@ const postFunc = {
'tech/apply/new/pair/apply/review': pairApplyCtrl.review,//审核申请上新交易对 'tech/apply/new/pair/apply/review': pairApplyCtrl.review,//审核申请上新交易对
'tech/apply/new/pair/apply/rewrite': pairApplyCtrl.rewrite,//驳回申请上新交易对 'tech/apply/new/pair/apply/rewrite': pairApplyCtrl.rewrite,//驳回申请上新交易对
'tech/apply/new/pair/apply/cancel': pairApplyCtrl.cancel,//管理员取消申请上新交易对 'tech/apply/new/pair/apply/cancel': pairApplyCtrl.cancel,//管理员取消申请上新交易对
'tech/apply/new/pair/trade/area/list': pairApplyCtrl.tradeAreaList,//已有交易区列表 //'tech/apply/new/pair/trade/area/list': pairApplyCtrl.tradeAreaList,//已有交易区列表
'tech/apply/new/pair/listed': pairApplyCtrl.listed,//已有交易对列表 //'tech/apply/new/pair/listed': pairApplyCtrl.listed,//已有交易对列表
//技术部-交易上下线管理-申请审核定时器 //技术部-交易上下线管理-申请审核定时器
'tech/apply/new/cron/list': cronApplyCtrl.list,//审核上币定时器信息列表 'tech/apply/new/cron/list': cronApplyCtrl.list,//审核上币定时器信息列表
'tech/apply/new/cron/delete': cronApplyCtrl.del,//删除审核上币定时器 'tech/apply/new/cron/delete': cronApplyCtrl.del,//删除审核上币定时器
......
...@@ -100,6 +100,8 @@ let cmdWhiteList = { ...@@ -100,6 +100,8 @@ let cmdWhiteList = {
'mUser/manage/walletAsset/detail': 1, 'mUser/manage/walletAsset/detail': 1,
'mUser/manage/asset/distribution': 1, 'mUser/manage/asset/distribution': 1,
'mUser/manage/tradeAsset/detail': 1, 'mUser/manage/tradeAsset/detail': 1,
'mUser/manage/deposit/list': 1,
'mUser/manage/withdraw/list': 1,
'mUser/manage/order/pending/list': 1, 'mUser/manage/order/pending/list': 1,
'mUser/manage/order/history/list': 1, 'mUser/manage/order/history/list': 1,
'mUser/manage/order/detail/list': 1, 'mUser/manage/order/detail/list': 1,
...@@ -196,8 +198,8 @@ let cmdWhiteList = { ...@@ -196,8 +198,8 @@ let cmdWhiteList = {
'tech/apply/new/pair/apply/review': 1, 'tech/apply/new/pair/apply/review': 1,
'tech/apply/new/pair/apply/rewrite': 1, 'tech/apply/new/pair/apply/rewrite': 1,
'tech/apply/new/pair/apply/cancel': 1, 'tech/apply/new/pair/apply/cancel': 1,
'tech/apply/new/pair/trade/area/list': 1, //'tech/apply/new/pair/trade/area/list': 1,
'tech/apply/new/pair/listed': 1, //'tech/apply/new/pair/listed': 1,
//技术部-交易上下线管理-申请审核定时器 //技术部-交易上下线管理-申请审核定时器
'tech/apply/new/cron/list': 1, 'tech/apply/new/cron/list': 1,
'tech/apply/new/cron/delete': 1, 'tech/apply/new/cron/delete': 1,
......
import { ErrorCode } from "../constant/errorCode";
import { coinType } from "@madex/ex-ts-dao";
/**
* 检查交易对中的币种是否存在于coin_type 中
* @param pair
*/
export const checkPairInCoinType = async function (pair: string) {
if (!pair) {
throw ErrorCode.PARAM_MISS;
}
let coin_symbol = pair.split('_')[0];
let currency_symbol = pair.split('_')[1];
if (!coin_symbol || !currency_symbol) {
throw ErrorCode.PAIR_FORMAT_ERR;
}
let dbSymbolTask = coinType.prototype.findOne({
where: { symbol: coin_symbol },
raw: true
});
let dbCurrencyTask = coinType.prototype.findOne({
where: { symbol: currency_symbol },
raw: true
});
let [dbSymbol, dbCurrency] = await Promise.all([dbSymbolTask, dbCurrencyTask]);
if (!dbSymbol) {
throw ErrorCode.COIN_DATA_NOT_EXIST;
}
if (!dbCurrency) {
throw ErrorCode.CURRENT_COIN_DATA_NOT_EXIST;
}
}
\ No newline at end of file
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