Commit c1e4573a authored by 1486327116's avatar 1486327116

update

parent 55654328
import * as contractPairService from "../service/contractPair.service";
import { ContractPairPageVO, ContractPairVO } from "../service/contractPair.service";
let { logger, Res3Utils, optionalUtils: Optional, apiAssertUtils: ApiAssert, datetimeUtils } = require('@madex/ex-js-public');
import { ErrorCode } from "../../../constant/errorCode";
import * as service from "../service/contractPair.service";
import { AddParam, ListParam } from "../service/contractPair.service";
import { getCurrentUserId } from "../../../utils/aclUserUtils";
let { logger, Res3Utils, optionalUtils: Optional, apiAssertUtils: ApiAssert } = require('@madex/ex-js-public');
let isIp = require('is-ip');
/**
* 金融部-交易管理-合约查询交易对
* @param req
* @param infoVO
*/
export const query = async (req: any, pageVO: ContractPairPageVO) => {
let func_name = "contractPair.control.query";
export const list = async (req: any, param: ListParam) => {
let func_name = "contactPairCtl.list";
let cmd = req.path;
try {
pageVO.page = Optional.opt(pageVO, 'page', 1);
pageVO.size = Optional.opt(pageVO, 'size', 20);
let res = await contractPairService.query(pageVO);
param.page = Optional.opt(param, 'page', 1);
param.size = Optional.opt(param, 'size', 50);
let res = await service.list(param);
return Res3Utils.result(res);
}
catch (e) {
......@@ -25,19 +20,22 @@ export const query = async (req: any, pageVO: ContractPairPageVO) => {
return Res3Utils.getErrorResult(e);
}
};
/**
* 金融部-交易管理-合约设置交易对
* @param req
* @param authConfigVO
*/
export const set = async (req: any, contractPairVO: ContractPairVO) => {
let func_name = "contractPair.control.set";
//新增
export const save = async (req: any, param: AddParam) => {
let func_name = "contactPairCtl.save";
let cmd = req.path;
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 currentUserId = await getCurrentUserId(req.cookies.session_id);
let res = await contractPairService.set(contractPairVO, currentUserId, ip);
let res = await service.save(param, currentUserId, ip);
return Res3Utils.result(res);
}
catch (e) {
......@@ -45,19 +43,32 @@ export const set = async (req: any, contractPairVO: ContractPairVO) => {
return Res3Utils.getErrorResult(e);
}
};
/**
* 金融部-交易管理-合约更新交易对
* @param req
* @param authConfigVO
*/
export const update = async (req: any, contractPairVO: ContractPairVO) => {
let func_name = "contractPair.control.update";
//修改
export const update = async (req: any, param: AddParam) => {
let func_name = "contactPairCtl.save";
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.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);
}
catch (e) {
......@@ -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);
}
};
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 { addOptLog } from "./userOptLog.service";
let { logger, datetimeUtils } = require('@madex/ex-js-public');
let _ = require('lodash');
let { logger } = require('@madex/ex-js-public');
let { authCommon: AuthCommon, redisUtilsCommon: RedisClient, } = require('@madex/ex-js-common');
export interface ListParam {
symbol?: string | any;
page: number;
export interface ContractPairVO {
id?: number,
size: number;
symbol?: string;
status?: 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;
leverage_max?: number;
product_id?: number;
margin_rate_maintain?: string,
base?: string;
margin_rate_init?: string,
quote?: string;
risk_level_base?: number,
name?: string;
maker_fee?: string,
price_scale?: number;
taker_fee?: string,
quantity_scale?: number;
createdAt?: Date | any,
maker_fee?: string;
updatedAt?: Date | any,
}
taker_fee?: string;
price_increment?: number;
export interface ContractPairPageVO extends ContractPairVO {
quantity_increment?: number;
page?: 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
size?: number,
status?: number
}
view_precision?: number
createdAt?: Date | any,
export async function query(pageVO: ContractPairPageVO) {
let key = 'contract.pair.query';
//TODO:目前在缓存里 方便调试 后期撮合搞定之后再修改
let list = await RedisClient.getSync(key);
let res = {
count: list ? list.length : 0,
rows: list ? list : []
}
return res;
updatedAt?: Date | any,
}
export async function set(contractPairVO: ContractPairVO, currentUserId: any, ip: string | undefined) {
//TODO:目前在缓存里 方便调试 后期撮合搞定之后再修改
contractPairVO.createdAt = new Date();
contractPairVO.updatedAt = new Date();
let key = 'contract.pair.query';
let list = await RedisClient.getSync(key);
if (list) {
contractPairVO.id = list.length + 1;
list.push(contractPairVO);
export async function list(param: ListParam) {
let where = {};
if (param.symbol) {
where["symbol"] = { [madContractOrmDB.Op.like]: `%${param.symbol}%` };
}
else {
contractPairVO.id = 1;
list = [];
list.push(contractPairVO);
if (param.status || param.status === 0) {
where["status"] = param.status
}
await RedisClient.writeSync(key,list);
//管理后台操作日志
addOptLog(currentUserId, 0, '新增合约交易对', ip, JSON.stringify(contractPairVO), '交易管理');
return 'success';
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 update(contractPairVO: ContractPairVO, currentUserId: any, ip: string | undefined) {
//TODO:目前在缓存里 方便调试 后期撮合搞定之后再修改
let key = 'contract.pair.query';
let list = await RedisClient.getSync(key);
let nList:any[] = [];
for (let item of list) {
let one = item;
if (item.id == contractPairVO.id){
one = contractPairVO;
}
nList.push(one);
await contractPairs.prototype.create(param);
//管理后台操作日志
addOptLog(currentUserId, 0, '交易对配置新增', ip, JSON.stringify(param), '交易对配置');
return 'ok';
};
export const update = async (param: AddParam, currentUserId: any, ip: any) => {
let dbInfo = await contractPairs.prototype.findOne({
where: {
id: param.id
},
raw: true
});
if (!dbInfo) {
throw ErrorCode.DATA_NOT_EXIST
}
await RedisClient.writeSync(key,nList);
let updateInfo = { updatedAt: new Date() };
if (param.view_precision || param.view_precision === 0) {
updateInfo['view_precision'] = param.view_precision
}
// 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 'ok';
};
export const pushToCoreSystem = async (id: any, currentUserId: any, ip: any) => {
let where = { id: id, status: 0 };
let cfg = await contractPairs.prototype.find({
where: where, raw: true
});
if (!cfg) {
throw ErrorCode.SUBMIT_STATUS_ERR;
}
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
}
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);
if (!optResult.is_success) {
//管理后台操作日志
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;
}
......@@ -102,12 +102,12 @@ export const update = async (param: AddParam, currentUserId: any, ip: any) => {
if (param.view_precision || param.view_precision === 0) {
updateInfo['view_precision'] = param.view_precision
}
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
}
// 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 spotPairs.prototype.update(updateInfo, {
where: {
......@@ -137,6 +137,19 @@ export const pushToCoreSystem = async (id: any, currentUserId: any, ip: any) =>
"price_scale": cfg.price_scale, "quantity_scale": cfg.quantity_scale,
"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);
if (!optResult.is_success) {
//管理后台操作日志
......
......@@ -64,6 +64,13 @@ const postFunc = {
'spotPair/list': spotPairCtrl.list,
'spotPair/pushToCoreSystem': spotPairCtrl.pushToCoreSystem,
'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/update': coinTypeCtrl.update,
......
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