|
|
|
@ -4,6 +4,7 @@ package com.sztzjy.forex.trading_trading.controller;
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
|
import com.github.pagehelper.PageInfo;
|
|
|
|
|
import com.sztzjy.forex.trading_trading.annotation.AnonymousAccess;
|
|
|
|
|
import com.sztzjy.forex.trading_trading.config.Constant;
|
|
|
|
|
import com.sztzjy.forex.trading_trading.dto.TakeStashVO;
|
|
|
|
|
import com.sztzjy.forex.trading_trading.entity.ForexMarketData;
|
|
|
|
|
import com.sztzjy.forex.trading_trading.entity.Member;
|
|
|
|
@ -106,26 +107,22 @@ public class TakeStashController {
|
|
|
|
|
Double profitAndLoss;
|
|
|
|
|
if (tradingCode.startsWith("USD")) { //美元在前
|
|
|
|
|
if ("buy".equals(buySellType)) { //买
|
|
|
|
|
// profitAndLoss =(nowBuyPic - priceTransaction) * volumeTransaction * 100000.0 / nowBuyPic;
|
|
|
|
|
profitAndLoss = bigDecimalUtils.div(bigDecimalUtils.mul(bigDecimalUtils.mul(bigDecimalUtils.sub(nowSellPic, priceTransaction), volumeTransaction), 100000), nowSellPic, 2);
|
|
|
|
|
profitAndLoss = (nowSellPic - priceTransaction) * volumeTransaction * Constant.LEVERQUANTITY / nowSellPic;
|
|
|
|
|
takeStashVO.setCurrentPrice(nowSellPic);
|
|
|
|
|
} else { //卖
|
|
|
|
|
// profitAndLoss = (nowSellPic - priceTransaction) * volumeTransaction * 100000.0 / nowSellPic;
|
|
|
|
|
profitAndLoss = bigDecimalUtils.div(bigDecimalUtils.mul(bigDecimalUtils.mul(bigDecimalUtils.sub(nowBuyPic, priceTransaction), volumeTransaction), 100000), nowBuyPic, 2);
|
|
|
|
|
profitAndLoss = (priceTransaction - nowBuyPic) * volumeTransaction * Constant.LEVERQUANTITY / nowBuyPic;
|
|
|
|
|
takeStashVO.setCurrentPrice(nowBuyPic);
|
|
|
|
|
}
|
|
|
|
|
} else { //美元在后
|
|
|
|
|
if ("buy".equals(buySellType)) { //买
|
|
|
|
|
// profitAndLoss = (nowBuyPic - priceTransaction) * volumeTransaction * 100000.0;
|
|
|
|
|
profitAndLoss = bigDecimalUtils.mul(bigDecimalUtils.mul(bigDecimalUtils.sub(nowSellPic, priceTransaction), volumeTransaction), 100000, 2);
|
|
|
|
|
profitAndLoss = (nowSellPic - priceTransaction) * volumeTransaction * Constant.LEVERQUANTITY;
|
|
|
|
|
takeStashVO.setCurrentPrice(nowSellPic);
|
|
|
|
|
} else { //卖
|
|
|
|
|
// profitAndLoss = (nowSellPic - priceTransaction) * volumeTransaction * 100000.0;
|
|
|
|
|
profitAndLoss = bigDecimalUtils.mul(bigDecimalUtils.mul(bigDecimalUtils.sub(nowBuyPic, priceTransaction), volumeTransaction), 100000, 2);
|
|
|
|
|
profitAndLoss = (nowBuyPic - priceTransaction) * volumeTransaction * Constant.LEVERQUANTITY;
|
|
|
|
|
takeStashVO.setCurrentPrice(nowBuyPic);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
takeStashVO.setProfitAndLoss(profitAndLoss);
|
|
|
|
|
takeStashVO.setProfitAndLoss(bigDecimalUtils.mul(profitAndLoss, 1, 2));
|
|
|
|
|
takeStashVOS.add(takeStashVO);
|
|
|
|
|
}
|
|
|
|
|
if (0 == takeStashVOS.size()) {
|
|
|
|
@ -150,26 +147,21 @@ public class TakeStashController {
|
|
|
|
|
Double profitAndLoss;
|
|
|
|
|
if (tradingCode.startsWith("USD")) { //美元在前
|
|
|
|
|
if ("buy".equals(buySellType)) { //买
|
|
|
|
|
// profitAndLoss =(nowBuyPic - priceTransaction) * volumeTransaction * 100000.0 / nowBuyPic;
|
|
|
|
|
profitAndLoss = bigDecimalUtils.div(bigDecimalUtils.mul(bigDecimalUtils.mul(bigDecimalUtils.sub(nowSellPic, priceTransaction), volumeTransaction), 100000), nowSellPic, 2);
|
|
|
|
|
profitAndLoss = (nowSellPic - priceTransaction) * volumeTransaction * Constant.LEVERQUANTITY / nowSellPic;
|
|
|
|
|
} else { //卖
|
|
|
|
|
// profitAndLoss = (nowSellPic - priceTransaction) * volumeTransaction * 100000.0 / nowSellPic;
|
|
|
|
|
profitAndLoss = bigDecimalUtils.div(bigDecimalUtils.mul(bigDecimalUtils.mul(bigDecimalUtils.sub(nowBuyPic, priceTransaction), volumeTransaction), 100000), nowBuyPic, 2);
|
|
|
|
|
profitAndLoss = (priceTransaction - nowBuyPic) * volumeTransaction * Constant.LEVERQUANTITY / nowBuyPic;
|
|
|
|
|
}
|
|
|
|
|
} else { //美元在后
|
|
|
|
|
if ("buy".equals(buySellType)) { //买
|
|
|
|
|
// profitAndLoss = (nowBuyPic - priceTransaction) * volumeTransaction * 100000.0;
|
|
|
|
|
profitAndLoss = bigDecimalUtils.mul(bigDecimalUtils.mul(bigDecimalUtils.sub(nowSellPic, priceTransaction), volumeTransaction), 100000, 2);
|
|
|
|
|
profitAndLoss = (nowSellPic - priceTransaction) * volumeTransaction * Constant.LEVERQUANTITY;
|
|
|
|
|
} else { //卖
|
|
|
|
|
// profitAndLoss = (nowSellPic - priceTransaction) * volumeTransaction * 100000.0;
|
|
|
|
|
profitAndLoss = bigDecimalUtils.mul(bigDecimalUtils.mul(bigDecimalUtils.sub(nowBuyPic, priceTransaction), volumeTransaction), 100000, 2);
|
|
|
|
|
profitAndLoss = (nowBuyPic - priceTransaction) * volumeTransaction * Constant.LEVERQUANTITY;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// totalProfitAndLoss = totalProfitAndLoss + profitAndLoss;
|
|
|
|
|
totalProfitAndLoss=bigDecimalUtils.add(totalProfitAndLoss,profitAndLoss);
|
|
|
|
|
totalProfitAndLoss = totalProfitAndLoss + profitAndLoss;
|
|
|
|
|
totalProfitAndLoss = bigDecimalUtils.mul(totalProfitAndLoss, 1, 2);
|
|
|
|
|
}
|
|
|
|
|
return totalProfitAndLoss;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//修改当前持仓
|
|
|
|
@ -208,58 +200,49 @@ public class TakeStashController {
|
|
|
|
|
String stashId = jsonObject.getString("stashId");
|
|
|
|
|
String memberId = jsonObject.getString("memberId");
|
|
|
|
|
TakeStash takeStashNew = takeStashService.selectByPrimaryKey(stashId);
|
|
|
|
|
//member方面 设置可用资金和保证金 可用资金=可用资金+买/卖所得钱 保证金=保证金-交易使用的保证金
|
|
|
|
|
Member member = memberService.selectByPrimaryKey(memberId);
|
|
|
|
|
Double availableFunds = member.getAvailableFunds(); //可用资金
|
|
|
|
|
String buySellType = takeStashNew.getBuySellType();
|
|
|
|
|
String tradingCode = takeStashNew.getTradingCode();
|
|
|
|
|
Double volumeTransaction = takeStashNew.getVolumeTransaction();
|
|
|
|
|
Double priceTransaction = takeStashNew.getPriceTransaction(); //获取进仓时交易价格
|
|
|
|
|
String trainingId = takeStashNew.getTrainingId();
|
|
|
|
|
Double priceTransactionCloser = 0.0; //记录出仓时交易价格
|
|
|
|
|
ForexMarketData forexData = forexMarketDateController.getForexMarketDateByCode(tradingCode);
|
|
|
|
|
Double backFund = 0.0; //返还资金
|
|
|
|
|
Double profitAndLoss = 0.0; //盈亏
|
|
|
|
|
Double nowSellPic = Double.valueOf(forexData.getSellPic());//当前卖价
|
|
|
|
|
Double nowBuyPic = forexData.getBuyPic(); //当前买价
|
|
|
|
|
Double margin=0.0; //记录保证金变化量
|
|
|
|
|
if (tradingCode.startsWith("USD")) { //美元在前 返还资金表达式为
|
|
|
|
|
//可用保证金计算
|
|
|
|
|
margin = startUSDMarginNeed(trainingId,memberId,0,tradingCode,buySellType,volumeTransaction);
|
|
|
|
|
if ("buy".equals(buySellType)) { //如果持仓方向为买 则平仓方向为卖
|
|
|
|
|
priceTransactionCloser = nowSellPic;
|
|
|
|
|
// CumulativeProfitLoss = (nowSellPic - priceTransaction) * volumeTransaction * 100000.0 / nowSellPic;
|
|
|
|
|
profitAndLoss = bigDecimalUtils.div(bigDecimalUtils.mul(bigDecimalUtils.mul(bigDecimalUtils.sub(nowSellPic, priceTransaction), volumeTransaction), 100000), nowSellPic, 2);
|
|
|
|
|
backFund = bigDecimalUtils.add(bigDecimalUtils.mul(priceTransaction,bigDecimalUtils.mul(1000,volumeTransaction),2),profitAndLoss);
|
|
|
|
|
availableFunds = bigDecimalUtils.add(availableFunds,backFund);
|
|
|
|
|
profitAndLoss = (nowSellPic - priceTransaction) * volumeTransaction * Constant.LEVERQUANTITY / nowSellPic;
|
|
|
|
|
} else if ("sell".equals(buySellType)) { //如果持仓方向为卖 则平仓方向为买 可用资金=可用资金+当前买价*1000*买卖手
|
|
|
|
|
priceTransactionCloser = nowBuyPic;
|
|
|
|
|
profitAndLoss = bigDecimalUtils.div(bigDecimalUtils.mul(bigDecimalUtils.mul(bigDecimalUtils.sub(nowBuyPic, priceTransaction), volumeTransaction), 100000), nowBuyPic, 2);
|
|
|
|
|
backFund = bigDecimalUtils.add(bigDecimalUtils.mul(priceTransaction,bigDecimalUtils.mul(1000,volumeTransaction),2),profitAndLoss);
|
|
|
|
|
availableFunds = bigDecimalUtils.add(availableFunds,backFund);
|
|
|
|
|
profitAndLoss = (priceTransaction - nowBuyPic) * volumeTransaction * Constant.LEVERQUANTITY / nowBuyPic;
|
|
|
|
|
}
|
|
|
|
|
} else { //美元在后
|
|
|
|
|
backFund = 1000 * volumeTransaction;
|
|
|
|
|
margin =endUSDMarginNeed(trainingId,memberId,0,tradingCode,buySellType,takeStashNew.getVolumeTransaction(),priceTransaction);
|
|
|
|
|
if ("buy".equals(buySellType)) { //如果持仓方向为买 则平仓方向为卖 可用资金=可用资金+1000*买卖手
|
|
|
|
|
priceTransactionCloser = nowSellPic;
|
|
|
|
|
profitAndLoss = bigDecimalUtils.mul(bigDecimalUtils.mul(bigDecimalUtils.sub(nowSellPic, priceTransaction), volumeTransaction), 100000, 2);
|
|
|
|
|
backFund = bigDecimalUtils.add(bigDecimalUtils.mul(priceTransaction,bigDecimalUtils.mul(1000,volumeTransaction),2),profitAndLoss);
|
|
|
|
|
availableFunds = bigDecimalUtils.add(availableFunds,backFund);
|
|
|
|
|
profitAndLoss = (nowSellPic - priceTransaction) * volumeTransaction * Constant.LEVERQUANTITY;
|
|
|
|
|
} else if ("sell".equals(buySellType)) { //如果持仓方向为卖 则平仓方向为买 可用资金=可用资金+当前买价*1000*买卖手
|
|
|
|
|
priceTransactionCloser = nowBuyPic;
|
|
|
|
|
profitAndLoss = bigDecimalUtils.mul(bigDecimalUtils.mul(bigDecimalUtils.sub(nowBuyPic, priceTransaction), volumeTransaction), 100000, 2);
|
|
|
|
|
backFund = bigDecimalUtils.add(bigDecimalUtils.mul(priceTransaction,bigDecimalUtils.mul(1000,volumeTransaction),2),profitAndLoss);
|
|
|
|
|
availableFunds = bigDecimalUtils.add(availableFunds,backFund);
|
|
|
|
|
profitAndLoss = (nowBuyPic - priceTransaction) * volumeTransaction * Constant.LEVERQUANTITY;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Double marginUsed = member.getMarginUsed();//未修改前member表中成员保证金
|
|
|
|
|
Double tradingMargin = takeStashNew.getTradingMargin(); //进仓时使用的保证金
|
|
|
|
|
marginUsed = bigDecimalUtils.sub(marginUsed,tradingMargin); //修改成员保证金
|
|
|
|
|
member.setAvailableFunds(availableFunds);
|
|
|
|
|
marginUsed = bigDecimalUtils.mul(marginUsed-margin,1,2); //修改成员保证金
|
|
|
|
|
member.setMarginUsed(marginUsed);
|
|
|
|
|
Integer closingTrades = member.getClosingTrades();
|
|
|
|
|
member.setClosingTrades(closingTrades++);
|
|
|
|
|
Double cumulativeProfitLoss = member.getCumulativeProfitLoss(); //为修改前member表中的累积盈亏
|
|
|
|
|
member.setCumulativeProfitLoss(bigDecimalUtils.add(cumulativeProfitLoss,profitAndLoss)); //修改累计盈亏
|
|
|
|
|
member.setTotalAssets(bigDecimalUtils.add(bigDecimalUtils.add(member.getInitialCapital(),cumulativeProfitLoss),profitAndLoss)); //设置总资产
|
|
|
|
|
member.setCumulativeProfitLoss(bigDecimalUtils.add(cumulativeProfitLoss, profitAndLoss)); //修改累计盈亏
|
|
|
|
|
member.setTotalAssets(bigDecimalUtils.add(bigDecimalUtils.add(member.getInitialCapital(), cumulativeProfitLoss), profitAndLoss)); //设置总资产
|
|
|
|
|
memberService.updateByPrimaryKeySelective(member);
|
|
|
|
|
flashTotalPositionProfitLoss(member.getMemberId());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
TakeStash takeStash = new TakeStash();
|
|
|
|
@ -270,45 +253,132 @@ public class TakeStashController {
|
|
|
|
|
takeStash.setTimeTransactionClose(new Date());
|
|
|
|
|
takeStashService.updateByPrimaryKeySelective(takeStash);
|
|
|
|
|
|
|
|
|
|
wainingService.compareMarginLevels(member.getMemberId(),member.getTrainingId());//更改可用保证金后 调用预警
|
|
|
|
|
wainingService.compareMarginLevels(member.getMemberId(), member.getTrainingId());//更改可用保证金后 调用预警
|
|
|
|
|
|
|
|
|
|
return new ResultEntity(HttpStatus.OK, "平仓成功");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//美元在后 返回保证金变化量 公式((sell交易量*交易价格+sell交易量*价格+...)/交易总量+(buy交易量*交易价格+buy交易量*价格+...)/交易总量)*合约量/杠杆倍数*sellbuy最高交易量
|
|
|
|
|
public Double endUSDMarginNeed(String trainingId,String memberId,int status,String tradingCode,String buySellType,Double transactionVolume,Double priceTransaction){
|
|
|
|
|
Double margin=0.0;
|
|
|
|
|
//获取持仓表中tradingCode所有buysell情况 根据trainingId和memberId查询交易品种=tradingCode的所有数据
|
|
|
|
|
List<TakeStash> takeStashList=takeStashService.findTakeStashByTrainingIdAndMemberIdAndStatusAndTradingCode(trainingId,memberId,status,tradingCode);
|
|
|
|
|
Double buyTotalMargin=0.0; //类型为买的 交易量*交易价格之和
|
|
|
|
|
Double sellTotalMargin=0.0; //类型为卖的 交易量*交易价格之和
|
|
|
|
|
Double totalVolumeTransaction=0.0; //交易总量
|
|
|
|
|
Double buyTotalVolumeTransaction=0.0; //buy类型交易总量
|
|
|
|
|
Double sellTotalVolumeTransaction=0.0; //sell类型交易总量
|
|
|
|
|
Double highVolumeTransaction=0.0; //记录buy/sell类型交易总量中较高的一个
|
|
|
|
|
if(takeStashList.size()==1){
|
|
|
|
|
if("buy".equals(buySellType)){
|
|
|
|
|
margin=transactionVolume*priceTransaction*Constant.LEVERQUANTITY;
|
|
|
|
|
}else {
|
|
|
|
|
margin=transactionVolume*priceTransaction*Constant.LEVERQUANTITY;
|
|
|
|
|
}
|
|
|
|
|
return margin;
|
|
|
|
|
}else {
|
|
|
|
|
for (int i = 0; i < takeStashList.size(); i++) {
|
|
|
|
|
TakeStash takeStash = takeStashList.get(i);
|
|
|
|
|
String buySellTypeTakeStash = takeStash.getBuySellType();
|
|
|
|
|
Double volumeTransactionTakeStash = takeStash.getVolumeTransaction(); //持仓交易量
|
|
|
|
|
Double priceTransactionTakeStash = takeStash.getPriceTransaction(); //持仓交易价格
|
|
|
|
|
if("buy".equals(buySellTypeTakeStash)){
|
|
|
|
|
buyTotalMargin=buyTotalMargin+volumeTransactionTakeStash*priceTransactionTakeStash;
|
|
|
|
|
buyTotalVolumeTransaction=buyTotalVolumeTransaction+volumeTransactionTakeStash;
|
|
|
|
|
}else {
|
|
|
|
|
sellTotalMargin=sellTotalMargin+volumeTransactionTakeStash*priceTransactionTakeStash;
|
|
|
|
|
sellTotalVolumeTransaction=sellTotalVolumeTransaction+volumeTransactionTakeStash;
|
|
|
|
|
}
|
|
|
|
|
totalVolumeTransaction=totalVolumeTransaction+volumeTransactionTakeStash;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (buyTotalVolumeTransaction>=sellTotalVolumeTransaction){ //设置带sell\buy的最高交易交易总量
|
|
|
|
|
highVolumeTransaction=buyTotalVolumeTransaction;
|
|
|
|
|
}else {
|
|
|
|
|
highVolumeTransaction=sellTotalVolumeTransaction;
|
|
|
|
|
}
|
|
|
|
|
//获取相同tradingCode持仓表总使用保证金
|
|
|
|
|
Double totalMargin=(buyTotalMargin+sellTotalMargin)/totalVolumeTransaction*Constant.LEVERQUANTITY*highVolumeTransaction;
|
|
|
|
|
//获取去除平仓数据后的相同tradingCode持仓表总使用保证金
|
|
|
|
|
Double totalMarginRemoveCloseTakeStash=0.0;
|
|
|
|
|
if("buy".equals(buySellType)){
|
|
|
|
|
totalMarginRemoveCloseTakeStash=((buyTotalMargin-transactionVolume*priceTransaction)+sellTotalMargin)/totalVolumeTransaction*Constant.LEVERQUANTITY*highVolumeTransaction;
|
|
|
|
|
}else {
|
|
|
|
|
totalMarginRemoveCloseTakeStash=(buyTotalMargin+(sellTotalMargin-transactionVolume*priceTransaction))/totalVolumeTransaction*Constant.LEVERQUANTITY*highVolumeTransaction;
|
|
|
|
|
}
|
|
|
|
|
margin=totalMargin-totalMarginRemoveCloseTakeStash;
|
|
|
|
|
return margin;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void updateMemberAndTakeStash(String memberId, String stashId, Double backFund, Double CumulativeProfitLoss) {
|
|
|
|
|
TakeStash takeStashNew = takeStashService.selectByPrimaryKey(stashId);
|
|
|
|
|
Member member = memberService.selectByPrimaryKey(memberId);
|
|
|
|
|
|
|
|
|
|
Double marginUsed = member.getMarginUsed();//未修改前member表中成员保证金
|
|
|
|
|
Double tradingMargin;//进仓时使用的保证金
|
|
|
|
|
if (takeStashNew.getTradingMargin()!=null){
|
|
|
|
|
tradingMargin=0.0;
|
|
|
|
|
//美元在前 返回保证金变化量
|
|
|
|
|
public Double startUSDMarginNeed(String trainingId,String memberId,int status,String tradingCode,String buySellType,Double transactionVolume){
|
|
|
|
|
Double margin=0.0;
|
|
|
|
|
//获取持仓表中tradingCode所有buysell情况 根据trainingId和memberId查询交易品种=tradingCode的所有数据
|
|
|
|
|
List<TakeStash> takeStashList=takeStashService.findTakeStashByTrainingIdAndMemberIdAndStatusAndTradingCode(trainingId,memberId,status,tradingCode);
|
|
|
|
|
Double buyTotalVolumeTransaction=0.0;
|
|
|
|
|
Double sellTotalVolumeTransaction=0.0;
|
|
|
|
|
if(takeStashList.size()==1){
|
|
|
|
|
margin=transactionVolume*Constant.LEVERQUANTITY;
|
|
|
|
|
return margin;
|
|
|
|
|
}else {
|
|
|
|
|
for (int i = 0; i < takeStashList.size(); i++) {
|
|
|
|
|
TakeStash takeStash = takeStashList.get(i);
|
|
|
|
|
String buySellTypeTakeStash = takeStash.getBuySellType();
|
|
|
|
|
if("buy".equals(buySellTypeTakeStash)){
|
|
|
|
|
buyTotalVolumeTransaction=buyTotalVolumeTransaction+takeStash.getVolumeTransaction();
|
|
|
|
|
}else {
|
|
|
|
|
tradingMargin = takeStashNew.getTradingMargin();
|
|
|
|
|
sellTotalVolumeTransaction=sellTotalVolumeTransaction+takeStash.getVolumeTransaction();
|
|
|
|
|
}
|
|
|
|
|
marginUsed = bigDecimalUtils.sub(marginUsed,tradingMargin); //修改成员保证金
|
|
|
|
|
Double availableFunds = member.getAvailableFunds(); //可用资金
|
|
|
|
|
availableFunds = bigDecimalUtils.add(availableFunds,backFund);
|
|
|
|
|
member.setAvailableFunds(availableFunds);
|
|
|
|
|
member.setMarginUsed(marginUsed);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if("buy".equals(buySellType)){
|
|
|
|
|
if(buyTotalVolumeTransaction>=sellTotalVolumeTransaction){
|
|
|
|
|
if(buyTotalVolumeTransaction-transactionVolume>=sellTotalVolumeTransaction){
|
|
|
|
|
margin=(buyTotalVolumeTransaction-transactionVolume)*Constant.LEVERQUANTITY;
|
|
|
|
|
}else {
|
|
|
|
|
margin=(buyTotalVolumeTransaction-sellTotalVolumeTransaction)*Constant.LEVERQUANTITY;
|
|
|
|
|
}
|
|
|
|
|
}else {
|
|
|
|
|
margin=0.0;
|
|
|
|
|
}
|
|
|
|
|
}else {
|
|
|
|
|
if(sellTotalVolumeTransaction>=buyTotalVolumeTransaction){
|
|
|
|
|
if(sellTotalVolumeTransaction-transactionVolume>=buyTotalVolumeTransaction){
|
|
|
|
|
margin=(sellTotalVolumeTransaction-transactionVolume)*Constant.LEVERQUANTITY;
|
|
|
|
|
}else {
|
|
|
|
|
margin=(sellTotalVolumeTransaction-buyTotalVolumeTransaction)*Constant.LEVERQUANTITY;
|
|
|
|
|
}
|
|
|
|
|
}else {
|
|
|
|
|
margin=0.0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return margin;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void updateMemberAndTakeStash(String memberId, String stashId , Double CumulativeProfitLoss,Double margin) { //margin平仓后保证金变化量
|
|
|
|
|
Member member = memberService.selectByPrimaryKey(memberId);
|
|
|
|
|
Double marginUsed = member.getMarginUsed();//未修改前member表中成员保证金
|
|
|
|
|
|
|
|
|
|
marginUsed = bigDecimalUtils.sub(marginUsed, margin); //修改成员保证金
|
|
|
|
|
member.setMarginUsed(bigDecimalUtils.mul(marginUsed,1,2));
|
|
|
|
|
Integer closingTrades = member.getClosingTrades();
|
|
|
|
|
member.setClosingTrades(closingTrades++);
|
|
|
|
|
Double cumulativeProfitLoss = member.getCumulativeProfitLoss(); //为修改前member表中的累积盈亏
|
|
|
|
|
member.setCumulativeProfitLoss(bigDecimalUtils.add(cumulativeProfitLoss,CumulativeProfitLoss)); //修改累计盈亏
|
|
|
|
|
member.setTotalAssets(bigDecimalUtils.add(CumulativeProfitLoss,bigDecimalUtils.add(member.getInitialCapital(),cumulativeProfitLoss))); //设置总资产
|
|
|
|
|
member.setCumulativeProfitLoss(bigDecimalUtils.mul(bigDecimalUtils.add(cumulativeProfitLoss, CumulativeProfitLoss),1,2)); //修改累计盈亏
|
|
|
|
|
memberService.updateByPrimaryKeySelective(member);
|
|
|
|
|
|
|
|
|
|
TakeStash takeStash = new TakeStash();
|
|
|
|
|
takeStash.setStashId(stashId);
|
|
|
|
|
takeStash.setStatus(2);
|
|
|
|
|
takeStash.setProfitAndLossByClose(bigDecimalUtils.sub(backFund,tradingMargin)); //盈亏=返还资金-进仓时使用的保证金
|
|
|
|
|
takeStash.setProfitAndLossByClose(bigDecimalUtils.mul(CumulativeProfitLoss,1,2)); //盈亏=返还资金-进仓时使用的保证金
|
|
|
|
|
takeStashService.updateByPrimaryKeySelective(takeStash);
|
|
|
|
|
|
|
|
|
|
wainingService.compareMarginLevels(member.getMemberId(),member.getTrainingId());//更改可用保证金后 调用预警
|
|
|
|
|
wainingService.compareMarginLevels(member.getMemberId(), member.getTrainingId());//更改可用保证金后 调用预警
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|