|
|
@ -21,10 +21,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.http.HttpStatus;
|
|
|
|
import org.springframework.http.HttpStatus;
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
import org.springframework.util.StringUtils;
|
|
|
|
import org.springframework.util.StringUtils;
|
|
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
|
|
|
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
|
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
|
import java.math.BigDecimal;
|
|
|
|
import java.text.DecimalFormat;
|
|
|
|
import java.text.DecimalFormat;
|
|
|
@ -64,28 +61,28 @@ public class TakeStashController {
|
|
|
|
public ResultEntity getTakeStashList(@RequestBody JSONObject jsonObject) {
|
|
|
|
public ResultEntity getTakeStashList(@RequestBody JSONObject jsonObject) {
|
|
|
|
Integer pageIndex = jsonObject.getInteger("index");
|
|
|
|
Integer pageIndex = jsonObject.getInteger("index");
|
|
|
|
Integer pageSize = jsonObject.getInteger("size");
|
|
|
|
Integer pageSize = jsonObject.getInteger("size");
|
|
|
|
String trainingStatus=jsonObject.getString("trainingStatus");
|
|
|
|
String trainingStatus = jsonObject.getString("trainingStatus");
|
|
|
|
TakeStash takeStash = jsonObject.getObject("takeStash", TakeStash.class);
|
|
|
|
TakeStash takeStash = jsonObject.getObject("takeStash", TakeStash.class);
|
|
|
|
String trainingId = takeStash.getTrainingId();
|
|
|
|
String trainingId = takeStash.getTrainingId();
|
|
|
|
if(trainingId==null || "".equals(trainingId)){
|
|
|
|
if (trainingId == null || "".equals(trainingId)) {
|
|
|
|
trainingId=Constant.PRACTICE_TRAINING_ID;
|
|
|
|
trainingId = Constant.PRACTICE_TRAINING_ID;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
PageInfo<TakeStash> pageInfo = takeStashService.findTakeStashByTrainingIdAndMemberIdAndStatus(trainingId, takeStash.getMemberId(), takeStash.getStatus(), pageIndex, pageSize);
|
|
|
|
PageInfo<TakeStash> pageInfo = takeStashService.findTakeStashByTrainingIdAndMemberIdAndStatus(trainingId, takeStash.getMemberId(), takeStash.getStatus(), pageIndex, pageSize);
|
|
|
|
List<TakeStash> takeStashList = pageInfo.getList();
|
|
|
|
List<TakeStash> takeStashList = pageInfo.getList();
|
|
|
|
List<TakeStashVO> takeStashVOList = new ArrayList<>();
|
|
|
|
List<TakeStashVO> takeStashVOList = new ArrayList<>();
|
|
|
|
for (int i = 0; i < takeStashList.size(); i++) {
|
|
|
|
for (int i = 0; i < takeStashList.size(); i++) {
|
|
|
|
TakeStashVO takeStashVO = new TakeStashVO(takeStashList.get(i));
|
|
|
|
TakeStashVO takeStashVO = new TakeStashVO(takeStashList.get(i));
|
|
|
|
if(Constant.TRAINING_STATUS_FINISHED.equals(trainingStatus)){ //实训结束后
|
|
|
|
if (Constant.TRAINING_STATUS_FINISHED.equals(trainingStatus)) { //实训结束后
|
|
|
|
takeStashVO.setCurrentPrice(takeStashList.get(i).getTradingMargin()); //将trading_margin保存到CurrentPrice返回 trading_margin为实训结束后的价格 记录实训结束后实时价格
|
|
|
|
takeStashVO.setCurrentPrice(takeStashList.get(i).getTradingMargin()); //将trading_margin保存到CurrentPrice返回 trading_margin为实训结束后的价格 记录实训结束后实时价格
|
|
|
|
takeStashVO.setProfitAndLoss(takeStashList.get(i).getProfitAndLossByClose()); //profit_and_loss_by_close 保存实训结束后的盈亏
|
|
|
|
takeStashVO.setProfitAndLoss(takeStashList.get(i).getProfitAndLossByClose()); //profit_and_loss_by_close 保存实训结束后的盈亏
|
|
|
|
}
|
|
|
|
}
|
|
|
|
takeStashVOList.add(takeStashVO);
|
|
|
|
takeStashVOList.add(takeStashVO);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(!Constant.TRAINING_STATUS_FINISHED.equals(trainingStatus)){
|
|
|
|
if (!Constant.TRAINING_STATUS_FINISHED.equals(trainingStatus)) {
|
|
|
|
if (takeStash.getStatus() == 0) {
|
|
|
|
if (takeStash.getStatus() == 0) {
|
|
|
|
takeStashVOList = flashProfitAndLoss(takeStashVOList).getBody().getData();
|
|
|
|
takeStashVOList = flashProfitAndLoss(takeStashVOList).getBody().getData();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}else {
|
|
|
|
} else {
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
PageInfo<TakeStashVO> voPageInfo = new PageInfo<>();
|
|
|
|
PageInfo<TakeStashVO> voPageInfo = new PageInfo<>();
|
|
|
@ -134,7 +131,7 @@ public class TakeStashController {
|
|
|
|
profitAndLoss = (nowSellPic - priceTransaction) * volumeTransaction * Constant.PEACEQUANTITY;
|
|
|
|
profitAndLoss = (nowSellPic - priceTransaction) * volumeTransaction * Constant.PEACEQUANTITY;
|
|
|
|
takeStashVO.setCurrentPrice(nowSellPic);
|
|
|
|
takeStashVO.setCurrentPrice(nowSellPic);
|
|
|
|
} else { //卖
|
|
|
|
} else { //卖
|
|
|
|
profitAndLoss = (priceTransaction-nowBuyPic) * volumeTransaction * Constant.PEACEQUANTITY;
|
|
|
|
profitAndLoss = (priceTransaction - nowBuyPic) * volumeTransaction * Constant.PEACEQUANTITY;
|
|
|
|
takeStashVO.setCurrentPrice(nowBuyPic);
|
|
|
|
takeStashVO.setCurrentPrice(nowBuyPic);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -171,7 +168,7 @@ public class TakeStashController {
|
|
|
|
if (Constant.BUY_BUYSELLTYPE.equals(buySellType)) { //买
|
|
|
|
if (Constant.BUY_BUYSELLTYPE.equals(buySellType)) { //买
|
|
|
|
profitAndLoss = (nowSellPic - priceTransaction) * volumeTransaction * Constant.PEACEQUANTITY;
|
|
|
|
profitAndLoss = (nowSellPic - priceTransaction) * volumeTransaction * Constant.PEACEQUANTITY;
|
|
|
|
} else { //卖
|
|
|
|
} else { //卖
|
|
|
|
profitAndLoss = (priceTransaction-nowBuyPic) * volumeTransaction * Constant.PEACEQUANTITY;
|
|
|
|
profitAndLoss = (priceTransaction - nowBuyPic) * volumeTransaction * Constant.PEACEQUANTITY;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
totalProfitAndLoss = totalProfitAndLoss + profitAndLoss;
|
|
|
|
totalProfitAndLoss = totalProfitAndLoss + profitAndLoss;
|
|
|
@ -192,7 +189,7 @@ public class TakeStashController {
|
|
|
|
ForexMarketData forexData = tradingController.getMarketQuotationByCode(tradingCode).getBody().getData();
|
|
|
|
ForexMarketData forexData = tradingController.getMarketQuotationByCode(tradingCode).getBody().getData();
|
|
|
|
TakeStash takeStash = new TakeStash();
|
|
|
|
TakeStash takeStash = new TakeStash();
|
|
|
|
takeStash.setStashId(stashId);
|
|
|
|
takeStash.setStashId(stashId);
|
|
|
|
boolean flag=false;
|
|
|
|
boolean flag = false;
|
|
|
|
if (null != stopLoss || null != stopWin) { //判断止损止赢是否合理 如果stopLoss stopWin都为null则跳过
|
|
|
|
if (null != stopLoss || null != stopWin) { //判断止损止赢是否合理 如果stopLoss stopWin都为null则跳过
|
|
|
|
boolean winOrLossStopBoolean = tradingController.getWinOrLossStop(stopLoss, stopWin, buySellType, forexData);
|
|
|
|
boolean winOrLossStopBoolean = tradingController.getWinOrLossStop(stopLoss, stopWin, buySellType, forexData);
|
|
|
|
if (winOrLossStopBoolean == false) {
|
|
|
|
if (winOrLossStopBoolean == false) {
|
|
|
@ -200,43 +197,159 @@ public class TakeStashController {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (null != stopLoss) {
|
|
|
|
if (null != stopLoss) {
|
|
|
|
takeStash.setStopLoss(stopLoss);
|
|
|
|
takeStash.setStopLoss(stopLoss);
|
|
|
|
flag=true;
|
|
|
|
flag = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (null != stopWin) {
|
|
|
|
if (null != stopWin) {
|
|
|
|
takeStash.setStopWin(stopWin);
|
|
|
|
takeStash.setStopWin(stopWin);
|
|
|
|
flag=true;
|
|
|
|
flag = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
TakeStash takeStashGet = takeStashService.selectByPrimaryKey(stashId);
|
|
|
|
TakeStash takeStashGet = takeStashService.selectByPrimaryKey(stashId);
|
|
|
|
if(flag==true){ //代表需要新增到redis中
|
|
|
|
if (flag == true) { //代表需要新增到redis中
|
|
|
|
redisUtil.del("*stashId_" + stashId + "*");
|
|
|
|
redisUtil.del("*stashId_" + stashId + "*");
|
|
|
|
Set<String> keys = redisUtil.keys("*stashId_" + stashId + "*");
|
|
|
|
Set<String> keys = redisUtil.keys("*stashId_" + stashId + "*");
|
|
|
|
Map map=new HashMap();
|
|
|
|
Map map = new HashMap();
|
|
|
|
if(stopLoss==null){
|
|
|
|
if (stopLoss == null) {
|
|
|
|
map.put("stopLoss",-1.0);
|
|
|
|
map.put("stopLoss", -1.0);
|
|
|
|
}else {
|
|
|
|
} else {
|
|
|
|
map.put("stopLoss",stopLoss);
|
|
|
|
map.put("stopLoss", stopLoss);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(stopWin==null){
|
|
|
|
if (stopWin == null) {
|
|
|
|
map.put("stopWin",-1.0);
|
|
|
|
map.put("stopWin", -1.0);
|
|
|
|
}else {
|
|
|
|
} else {
|
|
|
|
map.put("stopWin",stopWin);
|
|
|
|
map.put("stopWin", stopWin);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
map.put("stashId",stashId);
|
|
|
|
map.put("stashId", stashId);
|
|
|
|
map.put("buySellType",buySellType);
|
|
|
|
map.put("buySellType", buySellType);
|
|
|
|
map.put("tradingCode",tradingCode);
|
|
|
|
map.put("tradingCode", tradingCode);
|
|
|
|
map.put("transactionVolume",takeStashGet.getVolumeTransaction());
|
|
|
|
map.put("transactionVolume", takeStashGet.getVolumeTransaction());
|
|
|
|
map.put("priceTransaction",takeStashGet.getPriceTransaction());
|
|
|
|
map.put("priceTransaction", takeStashGet.getPriceTransaction());
|
|
|
|
map.put("memberId",takeStashGet.getMemberId());
|
|
|
|
map.put("memberId", takeStashGet.getMemberId());
|
|
|
|
map.put("trainingId",takeStashGet.getTrainingId());
|
|
|
|
map.put("trainingId", takeStashGet.getTrainingId());
|
|
|
|
redisUtil.hmset("trainingId_"+takeStashGet.getTrainingId()+"_stashId_"+stashId,map);
|
|
|
|
redisUtil.hmset("trainingId_" + takeStashGet.getTrainingId() + "_stashId_" + stashId, map);
|
|
|
|
}else {
|
|
|
|
} else {
|
|
|
|
redisUtil.del("trainingId_"+takeStashGet.getTrainingId()+"_stashId_"+stashId);
|
|
|
|
redisUtil.del("trainingId_" + takeStashGet.getTrainingId() + "_stashId_" + stashId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
takeStashService.updateWinLossByPrimaryKey(takeStash);
|
|
|
|
takeStashService.updateWinLossByPrimaryKey(takeStash);
|
|
|
|
return new ResultEntity(HttpStatus.OK, "修改持仓成功");
|
|
|
|
return new ResultEntity(HttpStatus.OK, "修改持仓成功");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//当前持仓部分平仓
|
|
|
|
|
|
|
|
//1生成新的历史记录
|
|
|
|
|
|
|
|
//2修改该持仓的持仓量
|
|
|
|
|
|
|
|
@AnonymousAccess
|
|
|
|
|
|
|
|
@PostMapping("sectionCloseTakeStash")
|
|
|
|
|
|
|
|
public ResultEntity sectionCloseTakeStash(@RequestBody JSONObject jsonObject, @RequestParam Double volumeTransaction) {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
Thread.sleep(1000);
|
|
|
|
|
|
|
|
} catch (InterruptedException e) {
|
|
|
|
|
|
|
|
return new ResultEntity(HttpStatus.BAD_REQUEST, "请稍后再试");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
String stashId = jsonObject.getString("stashId");
|
|
|
|
|
|
|
|
String memberId = jsonObject.getString("memberId");
|
|
|
|
|
|
|
|
TakeStash takeStashNew = takeStashService.selectByPrimaryKey(stashId);
|
|
|
|
|
|
|
|
Member member = memberService.selectByPrimaryKey(memberId);
|
|
|
|
|
|
|
|
String buySellType = takeStashNew.getBuySellType();
|
|
|
|
|
|
|
|
String tradingCode = takeStashNew.getTradingCode();
|
|
|
|
|
|
|
|
if (volumeTransaction.compareTo(takeStashNew.getVolumeTransaction()) >= 0 || volumeTransaction <= 0) {
|
|
|
|
|
|
|
|
return new ResultEntity(HttpStatus.BAD_REQUEST, "部分平仓交易量有误");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// Double volumeTransaction = takeStashNew.getVolumeTransaction();
|
|
|
|
|
|
|
|
Double priceTransaction = takeStashNew.getPriceTransaction(); //获取进仓时交易价格
|
|
|
|
|
|
|
|
String trainingId = takeStashNew.getTrainingId();
|
|
|
|
|
|
|
|
Double priceTransactionCloser = 0.0; //记录出仓时交易价格
|
|
|
|
|
|
|
|
ForexMarketData forexData = forexMarketDateUtil.getForexMarketDateByCode(tradingCode);
|
|
|
|
|
|
|
|
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 (Constant.BUY_BUYSELLTYPE.equals(buySellType)) { //如果持仓方向为买 则平仓方向为卖
|
|
|
|
|
|
|
|
priceTransactionCloser = nowSellPic;
|
|
|
|
|
|
|
|
profitAndLoss = (nowSellPic - priceTransaction) * volumeTransaction * Constant.PEACEQUANTITY / nowSellPic;
|
|
|
|
|
|
|
|
} else if (Constant.SELL_BUYSELLTYPE.equals(buySellType)) { //如果持仓方向为卖 则平仓方向为买 可用资金=可用资金+当前买价*1000*买卖手
|
|
|
|
|
|
|
|
priceTransactionCloser = nowBuyPic;
|
|
|
|
|
|
|
|
profitAndLoss = (priceTransaction - nowBuyPic) * volumeTransaction * Constant.PEACEQUANTITY / nowBuyPic;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else { //美元在后
|
|
|
|
|
|
|
|
margin = endUSDMarginNeed(trainingId, memberId, 0, tradingCode, buySellType, takeStashNew.getVolumeTransaction(), priceTransaction);
|
|
|
|
|
|
|
|
if (Constant.BUY_BUYSELLTYPE.equals(buySellType)) { //如果持仓方向为买 则平仓方向为卖 可用资金=可用资金+1000*买卖手
|
|
|
|
|
|
|
|
priceTransactionCloser = nowSellPic;
|
|
|
|
|
|
|
|
profitAndLoss = (nowSellPic - priceTransaction) * volumeTransaction * Constant.PEACEQUANTITY;
|
|
|
|
|
|
|
|
} else if (Constant.SELL_BUYSELLTYPE.equals(buySellType)) { //如果持仓方向为卖 则平仓方向为买 可用资金=可用资金+当前买价*1000*买卖手
|
|
|
|
|
|
|
|
priceTransactionCloser = nowBuyPic;
|
|
|
|
|
|
|
|
profitAndLoss = (priceTransaction - nowBuyPic) * volumeTransaction * Constant.PEACEQUANTITY;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Double marginUsed = member.getMarginUsed();//未修改前member表中成员保证金
|
|
|
|
|
|
|
|
marginUsed = bigDecimalUtils.mul(marginUsed - margin, 1, 2); //修改成员保证金
|
|
|
|
|
|
|
|
//处理保证金为负数的情况和保证金未释放的情况
|
|
|
|
|
|
|
|
List<TakeStash> takeStashList = takeStashService.selectAllByMemberIdAndStatus(memberId, 0);
|
|
|
|
|
|
|
|
if (takeStashList == null || takeStashList.size() == 0 || takeStashList.size() == 1) {
|
|
|
|
|
|
|
|
marginUsed = 0.0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (marginUsed < 0) {
|
|
|
|
|
|
|
|
marginUsed = 0.0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
member.setMarginUsed(marginUsed);
|
|
|
|
|
|
|
|
Integer closingTrades = member.getClosingTrades();
|
|
|
|
|
|
|
|
if (closingTrades == null) {
|
|
|
|
|
|
|
|
closingTrades = 1;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
member.setClosingTrades(closingTrades++);
|
|
|
|
|
|
|
|
Double cumulativeProfitLoss = member.getCumulativeProfitLoss(); //为修改前member表中的累积盈亏
|
|
|
|
|
|
|
|
cumulativeProfitLoss = cumulativeProfitLoss + profitAndLoss;
|
|
|
|
|
|
|
|
member.setCumulativeProfitLoss(bigDecimalUtils.mul(cumulativeProfitLoss, 1, 2)); //修改累计盈亏
|
|
|
|
|
|
|
|
member.setYield(bigDecimalUtils.div(cumulativeProfitLoss, member.getInitialCapital(), 8)); //修改收益率
|
|
|
|
|
|
|
|
memberService.updateByPrimaryKeySelective(member);
|
|
|
|
|
|
|
|
flashTotalPositionProfitLoss(member.getMemberId());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//修改部分平仓的持有量
|
|
|
|
|
|
|
|
TakeStash takeStash = new TakeStash();
|
|
|
|
|
|
|
|
takeStash.setStashId(stashId);
|
|
|
|
|
|
|
|
takeStash.setVolumeTransaction(bigDecimalUtils.sub(takeStashNew.getVolumeTransaction(), volumeTransaction));
|
|
|
|
|
|
|
|
takeStashService.updateByPrimaryKeySelective(takeStash);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
takeStashNew.setStashId(String.valueOf(UUID.randomUUID()));
|
|
|
|
|
|
|
|
takeStashNew.setOrderNumber(String.valueOf(UUID.randomUUID()));
|
|
|
|
|
|
|
|
takeStashNew.setStatus(2);
|
|
|
|
|
|
|
|
takeStashNew.setPriceTransactionClose(priceTransactionCloser);
|
|
|
|
|
|
|
|
takeStashNew.setProfitAndLossByClose(bigDecimalUtils.mul(profitAndLoss, 1, 2));
|
|
|
|
|
|
|
|
takeStashNew.setTimeTransactionClose(new Date());
|
|
|
|
|
|
|
|
takeStashService.updateByPrimaryKeySelective(takeStashNew);
|
|
|
|
|
|
|
|
redisUtil.del("trainingId_" + takeStashNew.getTrainingId() + "_stashId_" + stashId);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//判断该持仓是否有止损止盈
|
|
|
|
|
|
|
|
if (takeStashNew.getStopLoss() != null || takeStashNew.getStopWin() != null) {
|
|
|
|
|
|
|
|
Map map = new HashMap();
|
|
|
|
|
|
|
|
if (takeStashNew.getStopLoss() == null) {
|
|
|
|
|
|
|
|
map.put("stopLoss", -1.0);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
map.put("stopLoss", takeStashNew.getStopLoss());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (takeStashNew.getStopWin() == null) {
|
|
|
|
|
|
|
|
map.put("stopWin", -1.0);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
map.put("stopWin", takeStashNew.getStopWin());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
map.put("stashId", stashId);
|
|
|
|
|
|
|
|
map.put("buySellType", buySellType);
|
|
|
|
|
|
|
|
map.put("tradingCode", takeStashNew.getTradingCode());
|
|
|
|
|
|
|
|
map.put("transactionVolume", bigDecimalUtils.mul(profitAndLoss, 1, 2));
|
|
|
|
|
|
|
|
map.put("priceTransaction", takeStashNew.getPriceTransaction());
|
|
|
|
|
|
|
|
map.put("memberId", memberId);
|
|
|
|
|
|
|
|
map.put("trainingId", trainingId);
|
|
|
|
|
|
|
|
redisUtil.hmset("trainingId_" + trainingId + "_stashId_" + stashId, map);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// wainingService.compareMarginLevels(member.getMemberId(), member.getTrainingId());//更改可用保证金后 调用预警
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return new ResultEntity(HttpStatus.OK, "平仓成功");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//当前持仓平仓 status设置为2
|
|
|
|
//当前持仓平仓 status设置为2
|
|
|
|
@Transactional
|
|
|
|
@Transactional
|
|
|
@ -261,10 +374,10 @@ public class TakeStashController {
|
|
|
|
Double profitAndLoss = 0.0; //盈亏
|
|
|
|
Double profitAndLoss = 0.0; //盈亏
|
|
|
|
Double nowSellPic = Double.valueOf(forexData.getSellPic());//当前卖价
|
|
|
|
Double nowSellPic = Double.valueOf(forexData.getSellPic());//当前卖价
|
|
|
|
Double nowBuyPic = forexData.getBuyPic(); //当前买价
|
|
|
|
Double nowBuyPic = forexData.getBuyPic(); //当前买价
|
|
|
|
Double margin=0.0; //记录保证金变化量
|
|
|
|
Double margin = 0.0; //记录保证金变化量
|
|
|
|
if (tradingCode.startsWith("USD")) { //美元在前 返还资金表达式为
|
|
|
|
if (tradingCode.startsWith("USD")) { //美元在前 返还资金表达式为
|
|
|
|
//可用保证金计算
|
|
|
|
//可用保证金计算
|
|
|
|
margin = startUSDMarginNeed(trainingId,memberId,0,tradingCode,buySellType,volumeTransaction);
|
|
|
|
margin = startUSDMarginNeed(trainingId, memberId, 0, tradingCode, buySellType, volumeTransaction);
|
|
|
|
if (Constant.BUY_BUYSELLTYPE.equals(buySellType)) { //如果持仓方向为买 则平仓方向为卖
|
|
|
|
if (Constant.BUY_BUYSELLTYPE.equals(buySellType)) { //如果持仓方向为买 则平仓方向为卖
|
|
|
|
priceTransactionCloser = nowSellPic;
|
|
|
|
priceTransactionCloser = nowSellPic;
|
|
|
|
profitAndLoss = (nowSellPic - priceTransaction) * volumeTransaction * Constant.PEACEQUANTITY / nowSellPic;
|
|
|
|
profitAndLoss = (nowSellPic - priceTransaction) * volumeTransaction * Constant.PEACEQUANTITY / nowSellPic;
|
|
|
@ -273,36 +386,36 @@ public class TakeStashController {
|
|
|
|
profitAndLoss = (priceTransaction - nowBuyPic) * volumeTransaction * Constant.PEACEQUANTITY / nowBuyPic;
|
|
|
|
profitAndLoss = (priceTransaction - nowBuyPic) * volumeTransaction * Constant.PEACEQUANTITY / nowBuyPic;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else { //美元在后
|
|
|
|
} else { //美元在后
|
|
|
|
margin =endUSDMarginNeed(trainingId,memberId,0,tradingCode,buySellType,takeStashNew.getVolumeTransaction(),priceTransaction);
|
|
|
|
margin = endUSDMarginNeed(trainingId, memberId, 0, tradingCode, buySellType, takeStashNew.getVolumeTransaction(), priceTransaction);
|
|
|
|
if (Constant.BUY_BUYSELLTYPE.equals(buySellType)) { //如果持仓方向为买 则平仓方向为卖 可用资金=可用资金+1000*买卖手
|
|
|
|
if (Constant.BUY_BUYSELLTYPE.equals(buySellType)) { //如果持仓方向为买 则平仓方向为卖 可用资金=可用资金+1000*买卖手
|
|
|
|
priceTransactionCloser = nowSellPic;
|
|
|
|
priceTransactionCloser = nowSellPic;
|
|
|
|
profitAndLoss = (nowSellPic - priceTransaction) * volumeTransaction * Constant.PEACEQUANTITY;
|
|
|
|
profitAndLoss = (nowSellPic - priceTransaction) * volumeTransaction * Constant.PEACEQUANTITY;
|
|
|
|
} else if (Constant.SELL_BUYSELLTYPE.equals(buySellType)) { //如果持仓方向为卖 则平仓方向为买 可用资金=可用资金+当前买价*1000*买卖手
|
|
|
|
} else if (Constant.SELL_BUYSELLTYPE.equals(buySellType)) { //如果持仓方向为卖 则平仓方向为买 可用资金=可用资金+当前买价*1000*买卖手
|
|
|
|
priceTransactionCloser = nowBuyPic;
|
|
|
|
priceTransactionCloser = nowBuyPic;
|
|
|
|
profitAndLoss = ( priceTransaction - nowBuyPic ) * volumeTransaction * Constant.PEACEQUANTITY;
|
|
|
|
profitAndLoss = (priceTransaction - nowBuyPic) * volumeTransaction * Constant.PEACEQUANTITY;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Double marginUsed = member.getMarginUsed();//未修改前member表中成员保证金
|
|
|
|
Double marginUsed = member.getMarginUsed();//未修改前member表中成员保证金
|
|
|
|
marginUsed = bigDecimalUtils.mul(marginUsed-margin,1,2); //修改成员保证金
|
|
|
|
marginUsed = bigDecimalUtils.mul(marginUsed - margin, 1, 2); //修改成员保证金
|
|
|
|
//处理保证金为负数的情况和保证金未释放的情况
|
|
|
|
//处理保证金为负数的情况和保证金未释放的情况
|
|
|
|
List<TakeStash> takeStashList = takeStashService.selectAllByMemberIdAndStatus(memberId, 0);
|
|
|
|
List<TakeStash> takeStashList = takeStashService.selectAllByMemberIdAndStatus(memberId, 0);
|
|
|
|
if (takeStashList==null || takeStashList.size()==0 || takeStashList.size()==1){
|
|
|
|
if (takeStashList == null || takeStashList.size() == 0 || takeStashList.size() == 1) {
|
|
|
|
marginUsed=0.0;
|
|
|
|
marginUsed = 0.0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(marginUsed<0){
|
|
|
|
if (marginUsed < 0) {
|
|
|
|
marginUsed=0.0;
|
|
|
|
marginUsed = 0.0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
member.setMarginUsed(marginUsed);
|
|
|
|
member.setMarginUsed(marginUsed);
|
|
|
|
Integer closingTrades = member.getClosingTrades();
|
|
|
|
Integer closingTrades = member.getClosingTrades();
|
|
|
|
if(closingTrades==null){
|
|
|
|
if (closingTrades == null) {
|
|
|
|
closingTrades=1;
|
|
|
|
closingTrades = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
member.setClosingTrades(closingTrades++);
|
|
|
|
member.setClosingTrades(closingTrades++);
|
|
|
|
Double cumulativeProfitLoss = member.getCumulativeProfitLoss(); //为修改前member表中的累积盈亏
|
|
|
|
Double cumulativeProfitLoss = member.getCumulativeProfitLoss(); //为修改前member表中的累积盈亏
|
|
|
|
cumulativeProfitLoss=cumulativeProfitLoss+profitAndLoss;
|
|
|
|
cumulativeProfitLoss = cumulativeProfitLoss + profitAndLoss;
|
|
|
|
member.setCumulativeProfitLoss(bigDecimalUtils.mul(cumulativeProfitLoss,1,2)); //修改累计盈亏
|
|
|
|
member.setCumulativeProfitLoss(bigDecimalUtils.mul(cumulativeProfitLoss, 1, 2)); //修改累计盈亏
|
|
|
|
member.setYield(bigDecimalUtils.div(cumulativeProfitLoss,member.getInitialCapital(),8)); //修改收益率
|
|
|
|
member.setYield(bigDecimalUtils.div(cumulativeProfitLoss, member.getInitialCapital(), 8)); //修改收益率
|
|
|
|
memberService.updateByPrimaryKeySelective(member);
|
|
|
|
memberService.updateByPrimaryKeySelective(member);
|
|
|
|
flashTotalPositionProfitLoss(member.getMemberId());
|
|
|
|
flashTotalPositionProfitLoss(member.getMemberId());
|
|
|
|
|
|
|
|
|
|
|
@ -311,10 +424,10 @@ public class TakeStashController {
|
|
|
|
takeStash.setStashId(stashId);
|
|
|
|
takeStash.setStashId(stashId);
|
|
|
|
takeStash.setStatus(2);
|
|
|
|
takeStash.setStatus(2);
|
|
|
|
takeStash.setPriceTransactionClose(priceTransactionCloser);
|
|
|
|
takeStash.setPriceTransactionClose(priceTransactionCloser);
|
|
|
|
takeStash.setProfitAndLossByClose(bigDecimalUtils.mul(profitAndLoss,1,2));
|
|
|
|
takeStash.setProfitAndLossByClose(bigDecimalUtils.mul(profitAndLoss, 1, 2));
|
|
|
|
takeStash.setTimeTransactionClose(new Date());
|
|
|
|
takeStash.setTimeTransactionClose(new Date());
|
|
|
|
takeStashService.updateByPrimaryKeySelective(takeStash);
|
|
|
|
takeStashService.updateByPrimaryKeySelective(takeStash);
|
|
|
|
redisUtil.del("trainingId_"+takeStashNew.getTrainingId()+"_stashId_"+stashId);
|
|
|
|
redisUtil.del("trainingId_" + takeStashNew.getTrainingId() + "_stashId_" + stashId);
|
|
|
|
|
|
|
|
|
|
|
|
// wainingService.compareMarginLevels(member.getMemberId(), member.getTrainingId());//更改可用保证金后 调用预警
|
|
|
|
// wainingService.compareMarginLevels(member.getMemberId(), member.getTrainingId());//更改可用保证金后 调用预警
|
|
|
|
|
|
|
|
|
|
|
@ -322,130 +435,130 @@ public class TakeStashController {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//美元在后 返回保证金变化量 公式((sell交易量*交易价格+sell交易量*价格+...)/交易总量+(buy交易量*交易价格+buy交易量*价格+...)/交易总量)*合约量/杠杆倍数*sellbuy最高交易量
|
|
|
|
//美元在后 返回保证金变化量 公式((sell交易量*交易价格+sell交易量*价格+...)/交易总量+(buy交易量*交易价格+buy交易量*价格+...)/交易总量)*合约量/杠杆倍数*sellbuy最高交易量
|
|
|
|
public Double endUSDMarginNeed(String trainingId,String memberId,int status,String tradingCode,String buySellType,Double transactionVolume,Double priceTransaction){
|
|
|
|
public Double endUSDMarginNeed(String trainingId, String memberId, int status, String tradingCode, String buySellType, Double transactionVolume, Double priceTransaction) {
|
|
|
|
Double margin=0.0;
|
|
|
|
Double margin = 0.0;
|
|
|
|
//获取持仓表中tradingCode所有buysell情况 根据trainingId和memberId查询交易品种=tradingCode的所有数据
|
|
|
|
//获取持仓表中tradingCode所有buysell情况 根据trainingId和memberId查询交易品种=tradingCode的所有数据
|
|
|
|
List<TakeStash> takeStashList=takeStashService.findTakeStashByTrainingIdAndMemberIdAndStatusAndTradingCode(trainingId,memberId,status,tradingCode);
|
|
|
|
List<TakeStash> takeStashList = takeStashService.findTakeStashByTrainingIdAndMemberIdAndStatusAndTradingCode(trainingId, memberId, status, tradingCode);
|
|
|
|
Double buyTotalMargin=0.0; //类型为买的 交易量*交易价格之和
|
|
|
|
Double buyTotalMargin = 0.0; //类型为买的 交易量*交易价格之和
|
|
|
|
Double sellTotalMargin=0.0; //类型为卖的 交易量*交易价格之和
|
|
|
|
Double sellTotalMargin = 0.0; //类型为卖的 交易量*交易价格之和
|
|
|
|
Double totalVolumeTransaction=0.0; //交易总量
|
|
|
|
Double totalVolumeTransaction = 0.0; //交易总量
|
|
|
|
Double buyTotalVolumeTransaction=0.0; //buy类型交易总量
|
|
|
|
Double buyTotalVolumeTransaction = 0.0; //buy类型交易总量
|
|
|
|
Double sellTotalVolumeTransaction=0.0; //sell类型交易总量
|
|
|
|
Double sellTotalVolumeTransaction = 0.0; //sell类型交易总量
|
|
|
|
Double highVolumeTransaction=0.0; //记录buy/sell类型交易总量中较高的一个
|
|
|
|
Double highVolumeTransaction = 0.0; //记录buy/sell类型交易总量中较高的一个
|
|
|
|
if(takeStashList.size()==1){
|
|
|
|
if (takeStashList.size() == 1) {
|
|
|
|
if(Constant.BUY_BUYSELLTYPE.equals(buySellType)){
|
|
|
|
if (Constant.BUY_BUYSELLTYPE.equals(buySellType)) {
|
|
|
|
margin=transactionVolume*priceTransaction*Constant.LEVERQUANTITY;
|
|
|
|
margin = transactionVolume * priceTransaction * Constant.LEVERQUANTITY;
|
|
|
|
}else {
|
|
|
|
} else {
|
|
|
|
margin=transactionVolume*priceTransaction*Constant.LEVERQUANTITY;
|
|
|
|
margin = transactionVolume * priceTransaction * Constant.LEVERQUANTITY;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return margin;
|
|
|
|
return margin;
|
|
|
|
}else if(takeStashList.size()>1){
|
|
|
|
} else if (takeStashList.size() > 1) {
|
|
|
|
for (int i = 0; i < takeStashList.size(); i++) {
|
|
|
|
for (int i = 0; i < takeStashList.size(); i++) {
|
|
|
|
TakeStash takeStash = takeStashList.get(i);
|
|
|
|
TakeStash takeStash = takeStashList.get(i);
|
|
|
|
String buySellTypeTakeStash = takeStash.getBuySellType();
|
|
|
|
String buySellTypeTakeStash = takeStash.getBuySellType();
|
|
|
|
Double volumeTransactionTakeStash = takeStash.getVolumeTransaction(); //持仓交易量
|
|
|
|
Double volumeTransactionTakeStash = takeStash.getVolumeTransaction(); //持仓交易量
|
|
|
|
Double priceTransactionTakeStash = takeStash.getPriceTransaction(); //持仓交易价格
|
|
|
|
Double priceTransactionTakeStash = takeStash.getPriceTransaction(); //持仓交易价格
|
|
|
|
if(Constant.BUY_BUYSELLTYPE.equals(buySellTypeTakeStash)){
|
|
|
|
if (Constant.BUY_BUYSELLTYPE.equals(buySellTypeTakeStash)) {
|
|
|
|
buyTotalMargin=buyTotalMargin+volumeTransactionTakeStash*priceTransactionTakeStash;
|
|
|
|
buyTotalMargin = buyTotalMargin + volumeTransactionTakeStash * priceTransactionTakeStash;
|
|
|
|
buyTotalVolumeTransaction=buyTotalVolumeTransaction+volumeTransactionTakeStash;
|
|
|
|
buyTotalVolumeTransaction = buyTotalVolumeTransaction + volumeTransactionTakeStash;
|
|
|
|
}else {
|
|
|
|
} else {
|
|
|
|
sellTotalMargin=sellTotalMargin+volumeTransactionTakeStash*priceTransactionTakeStash;
|
|
|
|
sellTotalMargin = sellTotalMargin + volumeTransactionTakeStash * priceTransactionTakeStash;
|
|
|
|
sellTotalVolumeTransaction=sellTotalVolumeTransaction+volumeTransactionTakeStash;
|
|
|
|
sellTotalVolumeTransaction = sellTotalVolumeTransaction + volumeTransactionTakeStash;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
totalVolumeTransaction=totalVolumeTransaction+volumeTransactionTakeStash;
|
|
|
|
totalVolumeTransaction = totalVolumeTransaction + volumeTransactionTakeStash;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}else {
|
|
|
|
} else {
|
|
|
|
return 0.0;
|
|
|
|
return 0.0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (buyTotalVolumeTransaction>=sellTotalVolumeTransaction){ //设置平仓前 sell\buy的最高交易交易总量
|
|
|
|
if (buyTotalVolumeTransaction >= sellTotalVolumeTransaction) { //设置平仓前 sell\buy的最高交易交易总量
|
|
|
|
highVolumeTransaction=buyTotalVolumeTransaction;
|
|
|
|
highVolumeTransaction = buyTotalVolumeTransaction;
|
|
|
|
}else {
|
|
|
|
} else {
|
|
|
|
highVolumeTransaction=sellTotalVolumeTransaction;
|
|
|
|
highVolumeTransaction = sellTotalVolumeTransaction;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//获取相同tradingCode持仓表总使用保证金
|
|
|
|
//获取相同tradingCode持仓表总使用保证金
|
|
|
|
Double totalMargin=(buyTotalMargin+sellTotalMargin)/totalVolumeTransaction*Constant.LEVERQUANTITY*highVolumeTransaction;
|
|
|
|
Double totalMargin = (buyTotalMargin + sellTotalMargin) / totalVolumeTransaction * Constant.LEVERQUANTITY * highVolumeTransaction;
|
|
|
|
//获取去除平仓数据后的相同tradingCode持仓表总使用保证金
|
|
|
|
//获取去除平仓数据后的相同tradingCode持仓表总使用保证金
|
|
|
|
if(Constant.BUY_BUYSELLTYPE.equals(buySellType)){
|
|
|
|
if (Constant.BUY_BUYSELLTYPE.equals(buySellType)) {
|
|
|
|
if (buyTotalVolumeTransaction-transactionVolume>=sellTotalVolumeTransaction){ //设置平仓后 sell\buy的最高交易交易总量
|
|
|
|
if (buyTotalVolumeTransaction - transactionVolume >= sellTotalVolumeTransaction) { //设置平仓后 sell\buy的最高交易交易总量
|
|
|
|
highVolumeTransaction=buyTotalVolumeTransaction;
|
|
|
|
highVolumeTransaction = buyTotalVolumeTransaction;
|
|
|
|
}else {
|
|
|
|
} else {
|
|
|
|
highVolumeTransaction=sellTotalVolumeTransaction;
|
|
|
|
highVolumeTransaction = sellTotalVolumeTransaction;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}else {
|
|
|
|
} else {
|
|
|
|
if ( sellTotalVolumeTransaction-transactionVolume>=buyTotalVolumeTransaction){ //设置平仓后 sell\buy的最高交易交易总量
|
|
|
|
if (sellTotalVolumeTransaction - transactionVolume >= buyTotalVolumeTransaction) { //设置平仓后 sell\buy的最高交易交易总量
|
|
|
|
highVolumeTransaction=sellTotalVolumeTransaction;
|
|
|
|
highVolumeTransaction = sellTotalVolumeTransaction;
|
|
|
|
}else {
|
|
|
|
} else {
|
|
|
|
highVolumeTransaction=buyTotalVolumeTransaction;
|
|
|
|
highVolumeTransaction = buyTotalVolumeTransaction;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Double totalMarginRemoveCloseTakeStash=0.0;
|
|
|
|
Double totalMarginRemoveCloseTakeStash = 0.0;
|
|
|
|
totalMarginRemoveCloseTakeStash=(buyTotalMargin+sellTotalMargin-transactionVolume*priceTransaction)/(totalVolumeTransaction-transactionVolume)*Constant.LEVERQUANTITY*highVolumeTransaction;
|
|
|
|
totalMarginRemoveCloseTakeStash = (buyTotalMargin + sellTotalMargin - transactionVolume * priceTransaction) / (totalVolumeTransaction - transactionVolume) * Constant.LEVERQUANTITY * highVolumeTransaction;
|
|
|
|
margin=totalMargin-totalMarginRemoveCloseTakeStash;
|
|
|
|
margin = totalMargin - totalMarginRemoveCloseTakeStash;
|
|
|
|
return margin;
|
|
|
|
return margin;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//美元在前 返回保证金变化量
|
|
|
|
//美元在前 返回保证金变化量
|
|
|
|
public Double startUSDMarginNeed(String trainingId,String memberId,int status,String tradingCode,String buySellType,Double transactionVolume){
|
|
|
|
public Double startUSDMarginNeed(String trainingId, String memberId, int status, String tradingCode, String buySellType, Double transactionVolume) {
|
|
|
|
Double margin=0.0;
|
|
|
|
Double margin = 0.0;
|
|
|
|
//获取持仓表中tradingCode所有buysell情况 根据trainingId和memberId查询交易品种=tradingCode的所有数据
|
|
|
|
//获取持仓表中tradingCode所有buysell情况 根据trainingId和memberId查询交易品种=tradingCode的所有数据
|
|
|
|
List<TakeStash> takeStashList=takeStashService.findTakeStashByTrainingIdAndMemberIdAndStatusAndTradingCode(trainingId,memberId,status,tradingCode);
|
|
|
|
List<TakeStash> takeStashList = takeStashService.findTakeStashByTrainingIdAndMemberIdAndStatusAndTradingCode(trainingId, memberId, status, tradingCode);
|
|
|
|
Double buyTotalVolumeTransaction=0.0;
|
|
|
|
Double buyTotalVolumeTransaction = 0.0;
|
|
|
|
Double sellTotalVolumeTransaction=0.0;
|
|
|
|
Double sellTotalVolumeTransaction = 0.0;
|
|
|
|
if(takeStashList.size()==1){
|
|
|
|
if (takeStashList.size() == 1) {
|
|
|
|
margin=transactionVolume*Constant.LEVERQUANTITY;
|
|
|
|
margin = transactionVolume * Constant.LEVERQUANTITY;
|
|
|
|
return margin;
|
|
|
|
return margin;
|
|
|
|
}else if (takeStashList.size()>1){
|
|
|
|
} else if (takeStashList.size() > 1) {
|
|
|
|
for (int i = 0; i < takeStashList.size(); i++) {
|
|
|
|
for (int i = 0; i < takeStashList.size(); i++) {
|
|
|
|
TakeStash takeStash = takeStashList.get(i);
|
|
|
|
TakeStash takeStash = takeStashList.get(i);
|
|
|
|
String buySellTypeTakeStash = takeStash.getBuySellType();
|
|
|
|
String buySellTypeTakeStash = takeStash.getBuySellType();
|
|
|
|
if(Constant.BUY_BUYSELLTYPE.equals(buySellTypeTakeStash)){
|
|
|
|
if (Constant.BUY_BUYSELLTYPE.equals(buySellTypeTakeStash)) {
|
|
|
|
buyTotalVolumeTransaction=buyTotalVolumeTransaction+takeStash.getVolumeTransaction();
|
|
|
|
buyTotalVolumeTransaction = buyTotalVolumeTransaction + takeStash.getVolumeTransaction();
|
|
|
|
}else {
|
|
|
|
} else {
|
|
|
|
sellTotalVolumeTransaction=sellTotalVolumeTransaction+takeStash.getVolumeTransaction();
|
|
|
|
sellTotalVolumeTransaction = sellTotalVolumeTransaction + takeStash.getVolumeTransaction();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}else {
|
|
|
|
} else {
|
|
|
|
margin=0.0;
|
|
|
|
margin = 0.0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(Constant.BUY_BUYSELLTYPE.equals(buySellType)){
|
|
|
|
if (Constant.BUY_BUYSELLTYPE.equals(buySellType)) {
|
|
|
|
if(buyTotalVolumeTransaction>=sellTotalVolumeTransaction){
|
|
|
|
if (buyTotalVolumeTransaction >= sellTotalVolumeTransaction) {
|
|
|
|
if(buyTotalVolumeTransaction-transactionVolume>=sellTotalVolumeTransaction){
|
|
|
|
if (buyTotalVolumeTransaction - transactionVolume >= sellTotalVolumeTransaction) {
|
|
|
|
margin=transactionVolume*Constant.LEVERQUANTITY;
|
|
|
|
margin = transactionVolume * Constant.LEVERQUANTITY;
|
|
|
|
}else {
|
|
|
|
} else {
|
|
|
|
margin=(buyTotalVolumeTransaction-sellTotalVolumeTransaction)*Constant.LEVERQUANTITY;
|
|
|
|
margin = (buyTotalVolumeTransaction - sellTotalVolumeTransaction) * Constant.LEVERQUANTITY;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}else {
|
|
|
|
} else {
|
|
|
|
margin=0.0;
|
|
|
|
margin = 0.0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}else {
|
|
|
|
} else {
|
|
|
|
if(sellTotalVolumeTransaction>=buyTotalVolumeTransaction){
|
|
|
|
if (sellTotalVolumeTransaction >= buyTotalVolumeTransaction) {
|
|
|
|
if(sellTotalVolumeTransaction-transactionVolume>=buyTotalVolumeTransaction){
|
|
|
|
if (sellTotalVolumeTransaction - transactionVolume >= buyTotalVolumeTransaction) {
|
|
|
|
margin=transactionVolume*Constant.LEVERQUANTITY;
|
|
|
|
margin = transactionVolume * Constant.LEVERQUANTITY;
|
|
|
|
}else {
|
|
|
|
} else {
|
|
|
|
margin=(sellTotalVolumeTransaction-buyTotalVolumeTransaction)*Constant.LEVERQUANTITY;
|
|
|
|
margin = (sellTotalVolumeTransaction - buyTotalVolumeTransaction) * Constant.LEVERQUANTITY;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}else {
|
|
|
|
} else {
|
|
|
|
margin=0.0;
|
|
|
|
margin = 0.0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return margin;
|
|
|
|
return margin;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void updateMemberAndTakeStash(String memberId, String stashId , Double profitLoss,Double margin,Double priceTransactionCloser) { //margin平仓后保证金变化量
|
|
|
|
public void updateMemberAndTakeStash(String memberId, String stashId, Double profitLoss, Double margin, Double priceTransactionCloser) { //margin平仓后保证金变化量
|
|
|
|
Member member = memberService.selectByPrimaryKey(memberId);
|
|
|
|
Member member = memberService.selectByPrimaryKey(memberId);
|
|
|
|
Double marginUsed = member.getMarginUsed();//未修改前member表中成员保证金
|
|
|
|
Double marginUsed = member.getMarginUsed();//未修改前member表中成员保证金
|
|
|
|
|
|
|
|
|
|
|
|
marginUsed = bigDecimalUtils.sub(marginUsed, margin); //修改成员保证金
|
|
|
|
marginUsed = bigDecimalUtils.sub(marginUsed, margin); //修改成员保证金
|
|
|
|
member.setMarginUsed(bigDecimalUtils.mul(marginUsed,1,2));
|
|
|
|
member.setMarginUsed(bigDecimalUtils.mul(marginUsed, 1, 2));
|
|
|
|
Integer closingTrades = member.getClosingTrades();
|
|
|
|
Integer closingTrades = member.getClosingTrades();
|
|
|
|
member.setClosingTrades(closingTrades++);
|
|
|
|
member.setClosingTrades(closingTrades++);
|
|
|
|
Double cumulativeProfitLoss = member.getCumulativeProfitLoss(); //为修改前member表中的累积盈亏
|
|
|
|
Double cumulativeProfitLoss = member.getCumulativeProfitLoss(); //为修改前member表中的累积盈亏
|
|
|
|
cumulativeProfitLoss=bigDecimalUtils.add(cumulativeProfitLoss, profitLoss);
|
|
|
|
cumulativeProfitLoss = bigDecimalUtils.add(cumulativeProfitLoss, profitLoss);
|
|
|
|
member.setCumulativeProfitLoss(bigDecimalUtils.mul(cumulativeProfitLoss,1,2)); //修改累计盈亏
|
|
|
|
member.setCumulativeProfitLoss(bigDecimalUtils.mul(cumulativeProfitLoss, 1, 2)); //修改累计盈亏
|
|
|
|
member.setYield(bigDecimalUtils.mul(bigDecimalUtils.div(cumulativeProfitLoss,member.getInitialCapital()),1,8)); //修改收益率
|
|
|
|
member.setYield(bigDecimalUtils.mul(bigDecimalUtils.div(cumulativeProfitLoss, member.getInitialCapital()), 1, 8)); //修改收益率
|
|
|
|
memberService.updateByPrimaryKeySelective(member);
|
|
|
|
memberService.updateByPrimaryKeySelective(member);
|
|
|
|
flashTotalPositionProfitLoss(member.getMemberId());
|
|
|
|
flashTotalPositionProfitLoss(member.getMemberId());
|
|
|
|
|
|
|
|
|
|
|
@ -453,7 +566,7 @@ public class TakeStashController {
|
|
|
|
takeStash.setStashId(stashId);
|
|
|
|
takeStash.setStashId(stashId);
|
|
|
|
takeStash.setStatus(2);
|
|
|
|
takeStash.setStatus(2);
|
|
|
|
takeStash.setPriceTransactionClose(priceTransactionCloser);
|
|
|
|
takeStash.setPriceTransactionClose(priceTransactionCloser);
|
|
|
|
takeStash.setProfitAndLossByClose(bigDecimalUtils.mul(profitLoss,1,2)); //盈亏=返还资金-进仓时使用的保证金
|
|
|
|
takeStash.setProfitAndLossByClose(bigDecimalUtils.mul(profitLoss, 1, 2)); //盈亏=返还资金-进仓时使用的保证金
|
|
|
|
takeStash.setTimeTransactionClose(new Date());
|
|
|
|
takeStash.setTimeTransactionClose(new Date());
|
|
|
|
takeStashService.updateByPrimaryKeySelective(takeStash);
|
|
|
|
takeStashService.updateByPrimaryKeySelective(takeStash);
|
|
|
|
|
|
|
|
|
|
|
|