|
|
|
@ -19,6 +19,7 @@ import com.sztzjy.forex.trading_trading.util.RedisUtil;
|
|
|
|
|
import com.sztzjy.forex.trading_trading.util.ResultEntity;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.http.HttpStatus;
|
|
|
|
|
import org.springframework.util.StringUtils;
|
|
|
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
|
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
@ -62,7 +63,11 @@ public class TakeStashController {
|
|
|
|
|
Integer pageIndex = jsonObject.getInteger("index");
|
|
|
|
|
Integer pageSize = jsonObject.getInteger("size");
|
|
|
|
|
TakeStash takeStash = jsonObject.getObject("takeStash", TakeStash.class);
|
|
|
|
|
PageInfo<TakeStash> pageInfo = takeStashService.findTakeStashByTrainingIdAndMemberIdAndStatus(takeStash.getTrainingId(), takeStash.getMemberId(), takeStash.getStatus(), pageIndex, pageSize);
|
|
|
|
|
String trainingId = takeStash.getTrainingId();
|
|
|
|
|
if(trainingId==null){
|
|
|
|
|
trainingId="999999999";
|
|
|
|
|
}
|
|
|
|
|
PageInfo<TakeStash> pageInfo = takeStashService.findTakeStashByTrainingIdAndMemberIdAndStatus(trainingId, takeStash.getMemberId(), takeStash.getStatus(), pageIndex, pageSize);
|
|
|
|
|
List<TakeStash> takeStashList = pageInfo.getList();
|
|
|
|
|
List<TakeStashVO> takeStashVOList = new ArrayList<>();
|
|
|
|
|
for (int i = 0; i < takeStashList.size(); i++) {
|
|
|
|
@ -107,18 +112,18 @@ public class TakeStashController {
|
|
|
|
|
Double profitAndLoss;
|
|
|
|
|
if (tradingCode.startsWith("USD")) { //美元在前
|
|
|
|
|
if ("buy".equals(buySellType)) { //买
|
|
|
|
|
profitAndLoss = (nowSellPic - priceTransaction) * volumeTransaction * Constant.LEVERQUANTITY / nowSellPic;
|
|
|
|
|
profitAndLoss = (nowSellPic - priceTransaction) * volumeTransaction * Constant.PEACEQUANTITY / nowSellPic;
|
|
|
|
|
takeStashVO.setCurrentPrice(nowSellPic);
|
|
|
|
|
} else { //卖
|
|
|
|
|
profitAndLoss = (priceTransaction - nowBuyPic) * volumeTransaction * Constant.LEVERQUANTITY / nowBuyPic;
|
|
|
|
|
profitAndLoss = (priceTransaction - nowBuyPic) * volumeTransaction * Constant.PEACEQUANTITY / nowBuyPic;
|
|
|
|
|
takeStashVO.setCurrentPrice(nowBuyPic);
|
|
|
|
|
}
|
|
|
|
|
} else { //美元在后
|
|
|
|
|
if ("buy".equals(buySellType)) { //买
|
|
|
|
|
profitAndLoss = (nowSellPic - priceTransaction) * volumeTransaction * Constant.LEVERQUANTITY;
|
|
|
|
|
profitAndLoss = (nowSellPic - priceTransaction) * volumeTransaction * Constant.PEACEQUANTITY;
|
|
|
|
|
takeStashVO.setCurrentPrice(nowSellPic);
|
|
|
|
|
} else { //卖
|
|
|
|
|
profitAndLoss = (nowBuyPic - priceTransaction) * volumeTransaction * Constant.LEVERQUANTITY;
|
|
|
|
|
profitAndLoss = (priceTransaction-nowBuyPic) * volumeTransaction * Constant.PEACEQUANTITY;
|
|
|
|
|
takeStashVO.setCurrentPrice(nowBuyPic);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -147,15 +152,15 @@ public class TakeStashController {
|
|
|
|
|
Double profitAndLoss;
|
|
|
|
|
if (tradingCode.startsWith("USD")) { //美元在前
|
|
|
|
|
if ("buy".equals(buySellType)) { //买
|
|
|
|
|
profitAndLoss = (nowSellPic - priceTransaction) * volumeTransaction * Constant.LEVERQUANTITY / nowSellPic;
|
|
|
|
|
profitAndLoss = (nowSellPic - priceTransaction) * volumeTransaction * Constant.PEACEQUANTITY / nowSellPic;
|
|
|
|
|
} else { //卖
|
|
|
|
|
profitAndLoss = (priceTransaction - nowBuyPic) * volumeTransaction * Constant.LEVERQUANTITY / nowBuyPic;
|
|
|
|
|
profitAndLoss = (priceTransaction - nowBuyPic) * volumeTransaction * Constant.PEACEQUANTITY / nowBuyPic;
|
|
|
|
|
}
|
|
|
|
|
} else { //美元在后
|
|
|
|
|
if ("buy".equals(buySellType)) { //买
|
|
|
|
|
profitAndLoss = (nowSellPic - priceTransaction) * volumeTransaction * Constant.LEVERQUANTITY;
|
|
|
|
|
profitAndLoss = (nowSellPic - priceTransaction) * volumeTransaction * Constant.PEACEQUANTITY;
|
|
|
|
|
} else { //卖
|
|
|
|
|
profitAndLoss = (nowBuyPic - priceTransaction) * volumeTransaction * Constant.LEVERQUANTITY;
|
|
|
|
|
profitAndLoss = (priceTransaction-nowBuyPic) * volumeTransaction * Constant.PEACEQUANTITY;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
totalProfitAndLoss = totalProfitAndLoss + profitAndLoss;
|
|
|
|
@ -217,19 +222,19 @@ public class TakeStashController {
|
|
|
|
|
margin = startUSDMarginNeed(trainingId,memberId,0,tradingCode,buySellType,volumeTransaction);
|
|
|
|
|
if ("buy".equals(buySellType)) { //如果持仓方向为买 则平仓方向为卖
|
|
|
|
|
priceTransactionCloser = nowSellPic;
|
|
|
|
|
profitAndLoss = (nowSellPic - priceTransaction) * volumeTransaction * Constant.LEVERQUANTITY / nowSellPic;
|
|
|
|
|
profitAndLoss = (nowSellPic - priceTransaction) * volumeTransaction * Constant.PEACEQUANTITY / nowSellPic;
|
|
|
|
|
} else if ("sell".equals(buySellType)) { //如果持仓方向为卖 则平仓方向为买 可用资金=可用资金+当前买价*1000*买卖手
|
|
|
|
|
priceTransactionCloser = nowBuyPic;
|
|
|
|
|
profitAndLoss = (priceTransaction - nowBuyPic) * volumeTransaction * Constant.LEVERQUANTITY / nowBuyPic;
|
|
|
|
|
profitAndLoss = (priceTransaction - nowBuyPic) * volumeTransaction * Constant.PEACEQUANTITY / nowBuyPic;
|
|
|
|
|
}
|
|
|
|
|
} else { //美元在后
|
|
|
|
|
margin =endUSDMarginNeed(trainingId,memberId,0,tradingCode,buySellType,takeStashNew.getVolumeTransaction(),priceTransaction);
|
|
|
|
|
if ("buy".equals(buySellType)) { //如果持仓方向为买 则平仓方向为卖 可用资金=可用资金+1000*买卖手
|
|
|
|
|
priceTransactionCloser = nowSellPic;
|
|
|
|
|
profitAndLoss = (nowSellPic - priceTransaction) * volumeTransaction * Constant.LEVERQUANTITY;
|
|
|
|
|
profitAndLoss = (nowSellPic - priceTransaction) * volumeTransaction * Constant.PEACEQUANTITY;
|
|
|
|
|
} else if ("sell".equals(buySellType)) { //如果持仓方向为卖 则平仓方向为买 可用资金=可用资金+当前买价*1000*买卖手
|
|
|
|
|
priceTransactionCloser = nowBuyPic;
|
|
|
|
|
profitAndLoss = (nowBuyPic - priceTransaction) * volumeTransaction * Constant.LEVERQUANTITY;
|
|
|
|
|
profitAndLoss = ( priceTransaction - nowBuyPic ) * volumeTransaction * Constant.PEACEQUANTITY;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -242,8 +247,10 @@ public class TakeStashController {
|
|
|
|
|
}
|
|
|
|
|
member.setClosingTrades(closingTrades++);
|
|
|
|
|
Double cumulativeProfitLoss = member.getCumulativeProfitLoss(); //为修改前member表中的累积盈亏
|
|
|
|
|
member.setCumulativeProfitLoss(bigDecimalUtils.add(cumulativeProfitLoss, profitAndLoss)); //修改累计盈亏
|
|
|
|
|
member.setTotalAssets(bigDecimalUtils.add(bigDecimalUtils.add(member.getInitialCapital(), cumulativeProfitLoss), profitAndLoss)); //设置总资产
|
|
|
|
|
cumulativeProfitLoss=cumulativeProfitLoss+profitAndLoss;
|
|
|
|
|
member.setCumulativeProfitLoss(bigDecimalUtils.mul(cumulativeProfitLoss,1,2)); //修改累计盈亏
|
|
|
|
|
member.setYield(bigDecimalUtils.div(cumulativeProfitLoss,member.getInitialCapital(),8)); //修改收益率
|
|
|
|
|
System.out.println(bigDecimalUtils.mul(bigDecimalUtils.div(cumulativeProfitLoss,member.getInitialCapital()),1,10));
|
|
|
|
|
memberService.updateByPrimaryKeySelective(member);
|
|
|
|
|
flashTotalPositionProfitLoss(member.getMemberId());
|
|
|
|
|
|
|
|
|
@ -379,7 +386,9 @@ public class TakeStashController {
|
|
|
|
|
Integer closingTrades = member.getClosingTrades();
|
|
|
|
|
member.setClosingTrades(closingTrades++);
|
|
|
|
|
Double cumulativeProfitLoss = member.getCumulativeProfitLoss(); //为修改前member表中的累积盈亏
|
|
|
|
|
member.setCumulativeProfitLoss(bigDecimalUtils.mul(bigDecimalUtils.add(cumulativeProfitLoss, CumulativeProfitLoss),1,2)); //修改累计盈亏
|
|
|
|
|
cumulativeProfitLoss=bigDecimalUtils.add(cumulativeProfitLoss, CumulativeProfitLoss);
|
|
|
|
|
member.setCumulativeProfitLoss(bigDecimalUtils.mul(cumulativeProfitLoss,1,2)); //修改累计盈亏
|
|
|
|
|
member.setYield(bigDecimalUtils.mul(bigDecimalUtils.div(cumulativeProfitLoss,member.getInitialCapital()),1,4)); //修改收益率
|
|
|
|
|
memberService.updateByPrimaryKeySelective(member);
|
|
|
|
|
|
|
|
|
|
TakeStash takeStash = new TakeStash();
|
|
|
|
|