修改生成member数据后 连续数据重复生成的问题 修改交易公式 盈利公式

pull/1/head
yz 2 years ago
parent e1b6b9af40
commit 13af3adad2

@ -87,6 +87,9 @@ public class MemberController {
member.setPositionProfitLoss(positionProfitLoss); //设置持仓盈亏
Double initialCapital = member.getInitialCapital();//初始资金
Double cumulativeProfitLoss = member.getCumulativeProfitLoss(); //累计盈亏
if(cumulativeProfitLoss==null){
cumulativeProfitLoss=0.0;
}
if(cumulativeProfitLoss==null){
member.setCumulativeProfitLoss(0.0);
}
@ -104,6 +107,9 @@ public class MemberController {
member.setMarginLevel(bigDecimalUtils.div(netValue, marginUsed, 2)); //设置保证金水平
}
member.setAvailableFunds(bigDecimalUtils.sub(netValue, marginUsed)); //设置可用资金
//特殊处理 占用ReportScore 传递美元转换rmb
ForexMarketData usdcnh = forexMarketDateUtil.getForexMarketDateByCode("USDCNY");
member.setReportScore(bigDecimalUtils.mul(Double.parseDouble(forexMarketDateUtil.getForexMarketDateByCode("USDCNY").getSellPic())*totalAssets,1,2));
return new ResultEntity(HttpStatus.OK, "获取成员ID", member);
}

@ -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();

@ -104,6 +104,9 @@ public class TradingController {
Double stopWin = jsonObject.getDouble("stopWin");
String memberId = jsonObject.getString("memberId");
String trainingId = jsonObject.getString("trainingId");
if(trainingId==null){
trainingId="999999999";
}
Double priceCommission = jsonObject.getDouble("priceCommission"); //获取挂单开仓用户输入的价位
ForexMarketData forexData = getMarketQuotationByCode(tradingCode).getBody().getData();//获取当前买卖价格
Double buyPic = forexData.getBuyPic();//当前买价
@ -483,15 +486,15 @@ public class TradingController {
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;

@ -241,25 +241,34 @@ public class TrainingController {
}
private void buildPracticeMembers(List<Member> members) {
List<Member> memberList=new ArrayList<>();
for (int i = 0; i < members.size(); i++) {
Member member = members.get(i);
if (memberService.checkUser("999999999", member.getStudentNumber())) { //解决相同账号会出现生成多个练习账号的问题
continue;
}
member.setMemberId(IdUtil.simpleUUID());
member.setTrainingId("999999999");
member.setTrainingName("AdminStudentPractice");
member.setSchoolId(999999999);
memberList.add(member);
}
if (memberList.size()>0){
memberService.insertAll(memberList);
}
memberService.insertAll(members);
}
private void buildPracticeMember(Member member) {
member.setMemberId(IdUtil.simpleUUID());
member.setTrainingId("999999999");
member.setTrainingName("AdminStudentPractice");
member.setSchoolId(999999999);
memberService.insert(member);
if (memberService.checkUser("999999999", member.getStudentNumber())) {
}else {
member.setMemberId(IdUtil.simpleUUID());
member.setTrainingId("999999999");
member.setTrainingName("AdminStudentPractice");
member.setSchoolId(999999999);
memberService.insert(member);
}
}
@Permission(codes = PermissionType.TRAINING_MANAGEMENT_SEARCH)
@ApiOperation("获取我的任务列表")
@GetMapping("/findTrainingList")

@ -197,21 +197,21 @@ public class ScheduledTask {
if ("buy".equals(buySellType)) { //开仓方式为买 则平仓方式为卖 先获取卖价
Double sellPic = Double.valueOf(forexMarketData.getSellPic());
if(stopLoss!=-1 && sellPic<=stopLoss){
Double profitLoss=(stopLoss-priceTransaction)*transactionVolume*Constant.LEVERQUANTITY/stopLoss; //止损盈利
Double profitLoss=(stopLoss-priceTransaction)*transactionVolume*Constant.PEACEQUANTITY/stopLoss; //止损盈利
takeStashController.updateMemberAndTakeStash(memberId,stashId,profitLoss,margin);
}
if(stopWin!=-1 && sellPic>=stopWin){
Double profitLoss=(stopWin-priceTransaction)*transactionVolume*Constant.LEVERQUANTITY/stopWin; //止盈盈利
Double profitLoss=(stopWin-priceTransaction)*transactionVolume*Constant.PEACEQUANTITY/stopWin; //止盈盈利
takeStashController.updateMemberAndTakeStash(memberId,stashId,profitLoss,margin);
}
}else { //开仓方式为卖 则平仓方式为买 先获取买价
Double buyPic = forexMarketData.getBuyPic();
if(stopLoss!=-1 && buyPic<=stopLoss){
Double profitLoss=(priceTransaction-stopLoss)*transactionVolume*Constant.LEVERQUANTITY/stopLoss;
Double profitLoss=(priceTransaction-stopLoss)*transactionVolume*Constant.PEACEQUANTITY/stopLoss;
takeStashController.updateMemberAndTakeStash(memberId,stashId,profitLoss,margin);
}
if(stopWin!=-1 && buyPic>=stopWin){
Double profitLoss=(priceTransaction-stopWin)*transactionVolume*Constant.LEVERQUANTITY/stopWin;
Double profitLoss=(priceTransaction-stopWin)*transactionVolume*Constant.PEACEQUANTITY/stopWin;
takeStashController.updateMemberAndTakeStash(memberId,stashId,profitLoss,margin);
}
}
@ -220,21 +220,21 @@ public class ScheduledTask {
if ("buy".equals(buySellType)) { //开仓方式为买 则平仓方式为卖 先获取卖价
Double sellPic = Double.valueOf(forexMarketData.getSellPic());
if(stopLoss!=-1 && sellPic<=stopLoss){
Double profitLoss=(stopLoss-priceTransaction)*transactionVolume*Constant.LEVERQUANTITY;
Double profitLoss=(stopLoss-priceTransaction)*transactionVolume*Constant.PEACEQUANTITY;
takeStashController.updateMemberAndTakeStash(memberId,stashId,profitLoss,margin);
}
if(stopWin!=-1 && sellPic>=stopWin){
Double profitLoss=(stopWin-priceTransaction)*transactionVolume*Constant.LEVERQUANTITY;
Double profitLoss=(stopWin-priceTransaction)*transactionVolume*Constant.PEACEQUANTITY;
takeStashController.updateMemberAndTakeStash(memberId,stashId,profitLoss,margin);
}
}else { //开仓方式为卖 则平仓方式为买 先获取买价
Double buyPic = forexMarketData.getBuyPic();
if(stopLoss!=-1 && buyPic<=stopLoss){
Double profitLoss=(stopLoss-priceTransaction)*transactionVolume*Constant.LEVERQUANTITY;
Double profitLoss=(priceTransaction-stopLoss)*transactionVolume*Constant.PEACEQUANTITY;
takeStashController.updateMemberAndTakeStash(memberId,stashId,profitLoss,margin);
}
if(stopWin!=-1 && buyPic>=stopWin){
Double profitLoss=(stopWin-priceTransaction)*transactionVolume*Constant.LEVERQUANTITY;
Double profitLoss=(priceTransaction-stopWin)*transactionVolume*Constant.PEACEQUANTITY;
takeStashController.updateMemberAndTakeStash(memberId,stashId,profitLoss,margin);
}
}

Loading…
Cancel
Save