|
@@ -76,50 +76,54 @@ public class UserPositionServiceImpl implements IUserPositionService {
|
|
|
|
|
|
/**
|
|
/**
|
|
* 判断当前货币当前价格可成交挂单
|
|
* 判断当前货币当前价格可成交挂单
|
|
|
|
+ *
|
|
* @return
|
|
* @return
|
|
*/
|
|
*/
|
|
@Override
|
|
@Override
|
|
@Transactional
|
|
@Transactional
|
|
- public boolean fulfill(){
|
|
|
|
- List<IndexInfo> indexInfoList = stockMapper.selectStockList();
|
|
|
|
- Map<String, BigDecimal> indexMap = new HashMap<>();
|
|
|
|
- Map<String, Integer> spreadMap = new HashMap<>();
|
|
|
|
- BigDecimal nowPrice;
|
|
|
|
- for (IndexInfo indexInfo : indexInfoList) {
|
|
|
|
|
|
+ public boolean fulfill() {
|
|
|
|
+ List<UserPosition> userPositions = this.userPositionMapper.listByCodeAndState(null, 2, null);
|
|
|
|
+ log.info("挂单=" + userPositions.size());
|
|
|
|
+ if (userPositions.size() > 0) {
|
|
|
|
+ List<IndexInfo> indexInfoList = stockMapper.selectStockList();
|
|
|
|
+ Map<String, BigDecimal> indexMap = new HashMap<>();
|
|
|
|
+ Map<String, BigDecimal> spreadMap = new HashMap<>();
|
|
|
|
+ BigDecimal nowPrice;
|
|
|
|
+ for (IndexInfo indexInfo : indexInfoList) {
|
|
try {
|
|
try {
|
|
//每支code获取现价
|
|
//每支code获取现价
|
|
StockListVO stockListVO = dbStockService.getStockListVO(indexInfo.getCode());
|
|
StockListVO stockListVO = dbStockService.getStockListVO(indexInfo.getCode());
|
|
|
|
+ stockListVO.setId(Integer.parseInt(indexInfo.getId()));
|
|
nowPrice = new BigDecimal(stockListVO.getNowPrice());
|
|
nowPrice = new BigDecimal(stockListVO.getNowPrice());
|
|
indexMap.put(indexInfo.getCnName(), nowPrice);
|
|
indexMap.put(indexInfo.getCnName(), nowPrice);
|
|
- spreadMap.put(indexInfo.getCnName() , indexInfo.getSpread());
|
|
|
|
|
|
+ spreadMap.put(indexInfo.getCnName(), indexInfo.getSpread());
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
// 数据库不存在
|
|
// 数据库不存在
|
|
log.info("数据库不存在");
|
|
log.info("数据库不存在");
|
|
}
|
|
}
|
|
- }
|
|
|
|
- List<UserPosition> userPositions = this.userPositionMapper.listByCodeAndState(null,2,null);
|
|
|
|
- log.info("挂单="+userPositions.size());
|
|
|
|
- for(UserPosition userPosition : userPositions){
|
|
|
|
- nowPrice = indexMap.get(userPosition.getStockName());
|
|
|
|
- BigDecimal spread = new BigDecimal(spreadMap.get(userPosition.getStockName()));
|
|
|
|
- if("做多".equals(userPosition.getOrderDirection())){
|
|
|
|
- // 现价小于等于委托价
|
|
|
|
- if (nowPrice.compareTo(userPosition.getBuyOrderPrice()) < 1){
|
|
|
|
- nowPrice = userPosition.getBuyOrderPrice().add(spread);
|
|
|
|
- toFulfill(userPosition, nowPrice);
|
|
|
|
- }
|
|
|
|
- }else{
|
|
|
|
- // 现价大于等于委托价
|
|
|
|
- if (nowPrice.compareTo(userPosition.getBuyOrderPrice()) > -1){
|
|
|
|
- nowPrice = userPosition.getBuyOrderPrice().subtract(spread);
|
|
|
|
- toFulfill(userPosition, nowPrice);
|
|
|
|
|
|
+ }
|
|
|
|
+ for (UserPosition userPosition : userPositions) {
|
|
|
|
+ nowPrice = indexMap.get(userPosition.getStockName());
|
|
|
|
+ BigDecimal spread = spreadMap.get(userPosition.getStockName());
|
|
|
|
+ if ("做多".equals(userPosition.getOrderDirection())) {
|
|
|
|
+ // 现价小于等于委托价
|
|
|
|
+ if (nowPrice.compareTo(userPosition.getBuyOrderPrice()) < 1) {
|
|
|
|
+ nowPrice = userPosition.getBuyOrderPrice().add(spread);
|
|
|
|
+ toFulfill(userPosition, nowPrice);
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ // 现价大于等于委托价
|
|
|
|
+ if (nowPrice.compareTo(userPosition.getBuyOrderPrice()) > -1) {
|
|
|
|
+ nowPrice = userPosition.getBuyOrderPrice().subtract(spread);
|
|
|
|
+ toFulfill(userPosition, nowPrice);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return true;
|
|
return true;
|
|
}
|
|
}
|
|
|
|
|
|
- private void toFulfill(UserPosition userPosition, BigDecimal buyOrderPrice){
|
|
|
|
|
|
+ private void toFulfill(UserPosition userPosition, BigDecimal buyOrderPrice) {
|
|
User user = userMapper.findById(userPosition.getUserId());
|
|
User user = userMapper.findById(userPosition.getUserId());
|
|
userPositionMapper.updatePositionStatus(userPosition.getId(), buyOrderPrice, buyOrderPrice.multiply(BigDecimal.valueOf(Double.valueOf(userPosition.getOrderNum()))));
|
|
userPositionMapper.updatePositionStatus(userPosition.getId(), buyOrderPrice, buyOrderPrice.multiply(BigDecimal.valueOf(Double.valueOf(userPosition.getOrderNum()))));
|
|
ThreadUtil.executeInThread(obj -> {
|
|
ThreadUtil.executeInThread(obj -> {
|
|
@@ -212,10 +216,10 @@ public class UserPositionServiceImpl implements IUserPositionService {
|
|
Integer buyNum;
|
|
Integer buyNum;
|
|
if (null != orderNum && orderNum > buyNumAll) {
|
|
if (null != orderNum && orderNum > buyNumAll) {
|
|
return ServerResponse.createByErrorMsg("卖出数量大于购买数量");
|
|
return ServerResponse.createByErrorMsg("卖出数量大于购买数量");
|
|
- }else if(null == orderNum || orderNum == buyNumAll){
|
|
|
|
|
|
+ } else if (null == orderNum || orderNum == buyNumAll) {
|
|
buyNum = buyNumAll;
|
|
buyNum = buyNumAll;
|
|
isAll = true;
|
|
isAll = true;
|
|
- }else{
|
|
|
|
|
|
+ } else {
|
|
buyNum = orderNum;
|
|
buyNum = orderNum;
|
|
}
|
|
}
|
|
// 购买所使用金额
|
|
// 购买所使用金额
|
|
@@ -252,11 +256,11 @@ public class UserPositionServiceImpl implements IUserPositionService {
|
|
userPosition.setOrderNum(buyNum);
|
|
userPosition.setOrderNum(buyNum);
|
|
userPosition.setOrderTotalPrice(userPosition.getBuyOrderPrice().multiply(new BigDecimal(buyNum)));
|
|
userPosition.setOrderTotalPrice(userPosition.getBuyOrderPrice().multiply(new BigDecimal(buyNum)));
|
|
// 用原本的手续费计算出单笔的手续费 再得出总体的手续费
|
|
// 用原本的手续费计算出单笔的手续费 再得出总体的手续费
|
|
- userPosition.setOrderFee(userPosition.getOrderFee().divide(new BigDecimal(buyNumAll),4,4).multiply(new BigDecimal(buyNum)));
|
|
|
|
|
|
+ userPosition.setOrderFee(userPosition.getOrderFee().divide(new BigDecimal(buyNumAll), 4, 4).multiply(new BigDecimal(buyNum)));
|
|
//冻结保证金
|
|
//冻结保证金
|
|
- userPosition.setDepositFreezeAmt(userPosition.getDepositFreezeAmt().divide(new BigDecimal(buyNumAll),4,4).multiply(new BigDecimal(buyNum)));
|
|
|
|
|
|
+ userPosition.setDepositFreezeAmt(userPosition.getDepositFreezeAmt().divide(new BigDecimal(buyNumAll), 4, 4).multiply(new BigDecimal(buyNum)));
|
|
int updatePositionCount = this.userPositionMapper.updateByPrimaryKeySelective(userPosition);
|
|
int updatePositionCount = this.userPositionMapper.updateByPrimaryKeySelective(userPosition);
|
|
- if(!isAll) {
|
|
|
|
|
|
+ if (!isAll) {
|
|
UserPosition userPositionInsert = new UserPosition();
|
|
UserPosition userPositionInsert = new UserPosition();
|
|
userPositionInsert.setPositionType(userPosition.getPositionType());
|
|
userPositionInsert.setPositionType(userPosition.getPositionType());
|
|
userPositionInsert.setPositionSn(KeyUtils.getUniqueKey());
|
|
userPositionInsert.setPositionSn(KeyUtils.getUniqueKey());
|
|
@@ -279,13 +283,13 @@ public class UserPositionServiceImpl implements IUserPositionService {
|
|
userPositionInsert.setBuyOrderPrice(userPosition.getBuyOrderPrice());
|
|
userPositionInsert.setBuyOrderPrice(userPosition.getBuyOrderPrice());
|
|
userPositionInsert.setOrderTotalPrice(userPosition.getBuyOrderPrice().multiply(new BigDecimal(num)));
|
|
userPositionInsert.setOrderTotalPrice(userPosition.getBuyOrderPrice().multiply(new BigDecimal(num)));
|
|
// 用原本的手续费计算出单笔的手续费 再得出总体的手续费
|
|
// 用原本的手续费计算出单笔的手续费 再得出总体的手续费
|
|
- userPositionInsert.setOrderFee(userPosition.getOrderFee().divide(new BigDecimal(buyNum),4,4).multiply(new BigDecimal(num)));
|
|
|
|
|
|
+ userPositionInsert.setOrderFee(userPosition.getOrderFee().divide(new BigDecimal(buyNum), 4, 4).multiply(new BigDecimal(num)));
|
|
userPositionInsert.setProfitAndLose(BigDecimal.ZERO);
|
|
userPositionInsert.setProfitAndLose(BigDecimal.ZERO);
|
|
userPositionInsert.setOrderStayDays(0);
|
|
userPositionInsert.setOrderStayDays(0);
|
|
userPositionInsert.setOrderStayFee(BigDecimal.ZERO);
|
|
userPositionInsert.setOrderStayFee(BigDecimal.ZERO);
|
|
userPositionInsert.setOrderSpread(BigDecimal.ZERO);
|
|
userPositionInsert.setOrderSpread(BigDecimal.ZERO);
|
|
//冻结保证金
|
|
//冻结保证金
|
|
- userPositionInsert.setDepositFreezeAmt(userPosition.getDepositFreezeAmt().divide(new BigDecimal(buyNum),4,4).multiply(new BigDecimal(num)));
|
|
|
|
|
|
+ userPositionInsert.setDepositFreezeAmt(userPosition.getDepositFreezeAmt().divide(new BigDecimal(buyNum), 4, 4).multiply(new BigDecimal(num)));
|
|
//是否挂单
|
|
//是否挂单
|
|
userPositionInsert.setEntryOrders(0);
|
|
userPositionInsert.setEntryOrders(0);
|
|
this.userPositionMapper.insertSelective(userPositionInsert);
|
|
this.userPositionMapper.insertSelective(userPositionInsert);
|
|
@@ -339,7 +343,7 @@ public class UserPositionServiceImpl implements IUserPositionService {
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public ServerResponse closeOutList(List<Integer> list) throws Exception {
|
|
public ServerResponse closeOutList(List<Integer> list) throws Exception {
|
|
- for (Integer userId:list){
|
|
|
|
|
|
+ for (Integer userId : list) {
|
|
iUserPositionService.closeOut(userId, null);
|
|
iUserPositionService.closeOut(userId, null);
|
|
}
|
|
}
|
|
return ServerResponse.createBySuccessMsg("平仓成功!");
|
|
return ServerResponse.createBySuccessMsg("平仓成功!");
|
|
@@ -348,7 +352,7 @@ public class UserPositionServiceImpl implements IUserPositionService {
|
|
@Override
|
|
@Override
|
|
public ServerResponse oneKeyCloseOut(HttpServletRequest request) {
|
|
public ServerResponse oneKeyCloseOut(HttpServletRequest request) {
|
|
User user = this.iUserService.getCurrentRefreshUser(request);
|
|
User user = this.iUserService.getCurrentRefreshUser(request);
|
|
- if(iUserService.ForceSellByUserId(user.getId())){
|
|
|
|
|
|
+ if (iUserService.ForceSellByUserId(user.getId())) {
|
|
return ServerResponse.createBySuccessMsg("一键平仓成功!");
|
|
return ServerResponse.createBySuccessMsg("一键平仓成功!");
|
|
}
|
|
}
|
|
return ServerResponse.createByErrorMsg("平仓失败!!!");
|
|
return ServerResponse.createByErrorMsg("平仓失败!!!");
|
|
@@ -375,7 +379,7 @@ public class UserPositionServiceImpl implements IUserPositionService {
|
|
// 获取有设置止盈的账号
|
|
// 获取有设置止盈的账号
|
|
UserPosition userPosition = userPositionMapper.selectByPrimaryKey(id);
|
|
UserPosition userPosition = userPositionMapper.selectByPrimaryKey(id);
|
|
nowPrice = indexMap.get(userPosition.getStockName());
|
|
nowPrice = indexMap.get(userPosition.getStockName());
|
|
- if(judgeIsCloseOut(userPosition, nowPrice)){
|
|
|
|
|
|
+ if (judgeIsCloseOut(userPosition, nowPrice)) {
|
|
closeOut(userPosition.getId(), null);
|
|
closeOut(userPosition.getId(), null);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -401,31 +405,29 @@ public class UserPositionServiceImpl implements IUserPositionService {
|
|
}
|
|
}
|
|
// 获取有设置止盈的账号
|
|
// 获取有设置止盈的账号
|
|
List<UserPosition> userPositionList = userPositionMapper.selectPositionByStopProfitTarget();
|
|
List<UserPosition> userPositionList = userPositionMapper.selectPositionByStopProfitTarget();
|
|
- for(UserPosition userPosition : userPositionList){
|
|
|
|
|
|
+ for (UserPosition userPosition : userPositionList) {
|
|
nowPrice = indexMap.get(userPosition.getStockName());
|
|
nowPrice = indexMap.get(userPosition.getStockName());
|
|
- if(judgeIsCloseOut(userPosition, nowPrice)){
|
|
|
|
|
|
+ if (judgeIsCloseOut(userPosition, nowPrice)) {
|
|
closeOut(userPosition.getId(), null);
|
|
closeOut(userPosition.getId(), null);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- private boolean judgeIsCloseOut(UserPosition userPosition, BigDecimal nowPrice){
|
|
|
|
|
|
+ private boolean judgeIsCloseOut(UserPosition userPosition, BigDecimal nowPrice) {
|
|
//判断做多 做空
|
|
//判断做多 做空
|
|
- if("做多".equals(userPosition.getOrderDirection())){
|
|
|
|
- if(!(userPosition.getTargetprofit().compareTo(BigDecimal.ZERO) == 0) && nowPrice.compareTo(userPosition.getTargetprofit()) > -1){
|
|
|
|
|
|
+ if ("做多".equals(userPosition.getOrderDirection())) {
|
|
|
|
+ if (!(userPosition.getTargetprofit().compareTo(BigDecimal.ZERO) == 0) && nowPrice.compareTo(userPosition.getTargetprofit()) > -1) {
|
|
// 当前价格 大于等于 止盈价格 进行平仓操作
|
|
// 当前价格 大于等于 止盈价格 进行平仓操作
|
|
return true;
|
|
return true;
|
|
- }
|
|
|
|
- else if(!(userPosition.getStoploss().compareTo(BigDecimal.ZERO) == 0) && nowPrice.compareTo(userPosition.getStoploss()) < 1){
|
|
|
|
|
|
+ } else if (!(userPosition.getStoploss().compareTo(BigDecimal.ZERO) == 0) && nowPrice.compareTo(userPosition.getStoploss()) < 1) {
|
|
// 当前价格 小于等于 止损价格 进行平仓操作
|
|
// 当前价格 小于等于 止损价格 进行平仓操作
|
|
return true;
|
|
return true;
|
|
}
|
|
}
|
|
- }else{
|
|
|
|
- if(!(userPosition.getStoploss().compareTo(BigDecimal.ZERO) == 0) && nowPrice.compareTo(userPosition.getStoploss()) > -1){
|
|
|
|
|
|
+ } else {
|
|
|
|
+ if (!(userPosition.getStoploss().compareTo(BigDecimal.ZERO) == 0) && nowPrice.compareTo(userPosition.getStoploss()) > -1) {
|
|
// 当前价格 大于等于 止损价格 进行平仓操作
|
|
// 当前价格 大于等于 止损价格 进行平仓操作
|
|
return true;
|
|
return true;
|
|
- }
|
|
|
|
- else if(!(userPosition.getTargetprofit().compareTo(BigDecimal.ZERO) == 0) && nowPrice.compareTo(userPosition.getTargetprofit()) < 1){
|
|
|
|
|
|
+ } else if (!(userPosition.getTargetprofit().compareTo(BigDecimal.ZERO) == 0) && nowPrice.compareTo(userPosition.getTargetprofit()) < 1) {
|
|
// 当前价格 小于等于 止盈价格 进行平仓操作
|
|
// 当前价格 小于等于 止盈价格 进行平仓操作
|
|
return true;
|
|
return true;
|
|
}
|
|
}
|
|
@@ -440,17 +442,17 @@ public class UserPositionServiceImpl implements IUserPositionService {
|
|
// 获取各货币过夜费
|
|
// 获取各货币过夜费
|
|
List<IndexInfo> indexInfoList = stockMapper.selectStockList();
|
|
List<IndexInfo> indexInfoList = stockMapper.selectStockList();
|
|
Map<String, Integer> indexMap = new HashMap<>();
|
|
Map<String, Integer> indexMap = new HashMap<>();
|
|
- for (IndexInfo indexInfo : indexInfoList){
|
|
|
|
|
|
+ for (IndexInfo indexInfo : indexInfoList) {
|
|
indexMap.put(indexInfo.getCnName(), indexInfo.getDemurrage());
|
|
indexMap.put(indexInfo.getCnName(), indexInfo.getDemurrage());
|
|
}
|
|
}
|
|
- for(Integer userId : userIdList){
|
|
|
|
|
|
+ for (Integer userId : userIdList) {
|
|
// 获取用户余额
|
|
// 获取用户余额
|
|
User user = userMapper.selectByPrimaryKey(userId);
|
|
User user = userMapper.selectByPrimaryKey(userId);
|
|
BigDecimal enableAmt = user.getEnableAmt();
|
|
BigDecimal enableAmt = user.getEnableAmt();
|
|
BigDecimal allAmt = user.getUserAmt();
|
|
BigDecimal allAmt = user.getUserAmt();
|
|
// 当前用户需要的总过夜费
|
|
// 当前用户需要的总过夜费
|
|
int demurrageSum = userPositionMapper.selectUserDemurrageSum(userId);
|
|
int demurrageSum = userPositionMapper.selectUserDemurrageSum(userId);
|
|
- if(-1 == enableAmt.compareTo(new BigDecimal(demurrageSum))){
|
|
|
|
|
|
+ if (-1 == enableAmt.compareTo(new BigDecimal(demurrageSum))) {
|
|
// 用户余额小于需要扣除的过夜费
|
|
// 用户余额小于需要扣除的过夜费
|
|
// 平仓操作
|
|
// 平仓操作
|
|
iUserService.ForceSellByUserId(userId);
|
|
iUserService.ForceSellByUserId(userId);
|
|
@@ -460,7 +462,7 @@ public class UserPositionServiceImpl implements IUserPositionService {
|
|
List<UserPosition> userPositionList = userPositionMapper.selectPositionByUserId(userId);
|
|
List<UserPosition> userPositionList = userPositionMapper.selectPositionByUserId(userId);
|
|
// 计算过夜费修改数据
|
|
// 计算过夜费修改数据
|
|
BigDecimal orderStayFee;
|
|
BigDecimal orderStayFee;
|
|
- for(UserPosition userPosition : userPositionList){
|
|
|
|
|
|
+ for (UserPosition userPosition : userPositionList) {
|
|
orderStayFee = new BigDecimal(indexMap.get(userPosition.getStockName())).multiply(BigDecimal.valueOf(userPosition.getOrderNum()));
|
|
orderStayFee = new BigDecimal(indexMap.get(userPosition.getStockName())).multiply(BigDecimal.valueOf(userPosition.getOrderNum()));
|
|
userPosition.setOrderStayFee(userPosition.getOrderStayFee().add(orderStayFee));
|
|
userPosition.setOrderStayFee(userPosition.getOrderStayFee().add(orderStayFee));
|
|
// 修改持仓表过夜费
|
|
// 修改持仓表过夜费
|
|
@@ -486,21 +488,21 @@ public class UserPositionServiceImpl implements IUserPositionService {
|
|
public ServerResponse revoke(Integer positionId, HttpServletRequest request) throws Exception {
|
|
public ServerResponse revoke(Integer positionId, HttpServletRequest request) throws Exception {
|
|
try {
|
|
try {
|
|
User user = this.iUserService.getCurrentRefreshUser(request);
|
|
User user = this.iUserService.getCurrentRefreshUser(request);
|
|
- if (null == user || null == user.getId()){
|
|
|
|
|
|
+ if (null == user || null == user.getId()) {
|
|
return ServerResponse.createByErrorMsg("用户未登录!");
|
|
return ServerResponse.createByErrorMsg("用户未登录!");
|
|
}
|
|
}
|
|
- if (null == positionId || positionId < 0){
|
|
|
|
|
|
+ if (null == positionId || positionId < 0) {
|
|
return ServerResponse.createByErrorMsg("挂单号错误!");
|
|
return ServerResponse.createByErrorMsg("挂单号错误!");
|
|
}
|
|
}
|
|
UserPosition userPosition = this.userPositionMapper.selectByPrimaryKeyAndStatus(positionId);
|
|
UserPosition userPosition = this.userPositionMapper.selectByPrimaryKeyAndStatus(positionId);
|
|
- if (null == userPosition || userPosition.getDepositFreezeAmt()==null){
|
|
|
|
|
|
+ if (null == userPosition || userPosition.getDepositFreezeAmt() == null) {
|
|
return ServerResponse.createByErrorMsg("挂单不存在!");
|
|
return ServerResponse.createByErrorMsg("挂单不存在!");
|
|
}
|
|
}
|
|
user.setEnableAmt(user.getEnableAmt().add(userPosition.getDepositFreezeAmt()).add(userPosition.getOrderFee()));
|
|
user.setEnableAmt(user.getEnableAmt().add(userPosition.getDepositFreezeAmt()).add(userPosition.getOrderFee()));
|
|
- log.info("冻结保证金 = "+userPosition.getDepositFreezeAmt());
|
|
|
|
- log.info("可用余额 = "+user.getEnableAmt());
|
|
|
|
- // user.setUserAmt(user.getUserAmt().add(userPosition.getDepositFreezeAmt()));
|
|
|
|
- // log.info("总资金 = "+user.getUserAmt());
|
|
|
|
|
|
+ log.info("冻结保证金 = " + userPosition.getDepositFreezeAmt());
|
|
|
|
+ log.info("可用余额 = " + user.getEnableAmt());
|
|
|
|
+ // user.setUserAmt(user.getUserAmt().add(userPosition.getDepositFreezeAmt()));
|
|
|
|
+ // log.info("总资金 = "+user.getUserAmt());
|
|
user.setUserAmt(user.getUserAmt().add(userPosition.getOrderFee()));
|
|
user.setUserAmt(user.getUserAmt().add(userPosition.getOrderFee()));
|
|
int updateUserCount = this.userMapper.updateByPrimaryKeySelective(user);
|
|
int updateUserCount = this.userMapper.updateByPrimaryKeySelective(user);
|
|
if (updateUserCount > 0) {
|
|
if (updateUserCount > 0) {
|
|
@@ -510,10 +512,10 @@ public class UserPositionServiceImpl implements IUserPositionService {
|
|
throw new Exception("用户撤单】修改用户金额出错");
|
|
throw new Exception("用户撤单】修改用户金额出错");
|
|
}
|
|
}
|
|
int res = this.userPositionMapper.deleteByPrimaryKey(positionId);
|
|
int res = this.userPositionMapper.deleteByPrimaryKey(positionId);
|
|
- if (res>0){
|
|
|
|
|
|
+ if (res > 0) {
|
|
return ServerResponse.createBySuccess("撤单成功");
|
|
return ServerResponse.createBySuccess("撤单成功");
|
|
}
|
|
}
|
|
- }catch (Exception e){
|
|
|
|
|
|
+ } catch (Exception e) {
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
log.error(e.toString());
|
|
log.error(e.toString());
|
|
}
|
|
}
|
|
@@ -551,9 +553,9 @@ public class UserPositionServiceImpl implements IUserPositionService {
|
|
if (buyNum > stock.getBuyMaxNum()) {
|
|
if (buyNum > stock.getBuyMaxNum()) {
|
|
return ServerResponse.createByErrorMsg("挂单失败,购买数量大于" + stock.getBuyMaxNum() + "手");
|
|
return ServerResponse.createByErrorMsg("挂单失败,购买数量大于" + stock.getBuyMaxNum() + "手");
|
|
}
|
|
}
|
|
- Integer userPositionAmt = findUserPositionAmt(user.getId(),stock.getStockCode());
|
|
|
|
- if((userPositionAmt+buyNum) > stock.getPositionsMax()){
|
|
|
|
- return ServerResponse.createByErrorMsg("挂单失败,本次挂单手数:"+buyNum+",持仓手数大于" + stock.getPositionsMax() + "手,目前持仓手数:"+ userPositionAmt);
|
|
|
|
|
|
+ Integer userPositionAmt = findUserPositionAmt(user.getId(), stock.getStockCode());
|
|
|
|
+ if ((userPositionAmt + buyNum) > stock.getPositionsMax()) {
|
|
|
|
+ return ServerResponse.createByErrorMsg("挂单失败,本次挂单手数:" + buyNum + ",持仓手数大于" + stock.getPositionsMax() + "手,目前持仓手数:" + userPositionAmt);
|
|
}
|
|
}
|
|
//每支code获取现价
|
|
//每支code获取现价
|
|
StockListVO stockListVO = dbStockService.getStockListVO(stock.getStockGid());
|
|
StockListVO stockListVO = dbStockService.getStockListVO(stock.getStockGid());
|
|
@@ -561,9 +563,9 @@ public class UserPositionServiceImpl implements IUserPositionService {
|
|
if (now_price.compareTo(new BigDecimal("0")) == 0) {
|
|
if (now_price.compareTo(new BigDecimal("0")) == 0) {
|
|
return ServerResponse.createByErrorMsg("报价0,请稍后再试");
|
|
return ServerResponse.createByErrorMsg("报价0,请稍后再试");
|
|
}
|
|
}
|
|
- log.info("挂单现价="+now_price);
|
|
|
|
- log.info("挂单价="+buyOrderPrice);
|
|
|
|
- log.info("价差="+stock.getEntryOrdersAgio());
|
|
|
|
|
|
+ log.info("挂单现价=" + now_price);
|
|
|
|
+ log.info("挂单价=" + buyOrderPrice);
|
|
|
|
+ log.info("价差=" + stock.getEntryOrdersAgio());
|
|
BigDecimal addNowprice = new BigDecimal(0);
|
|
BigDecimal addNowprice = new BigDecimal(0);
|
|
// BigDecimal subNowprice = new BigDecimal(0);
|
|
// BigDecimal subNowprice = new BigDecimal(0);
|
|
addNowprice = now_price.add(stock.getEntryOrdersAgio());
|
|
addNowprice = now_price.add(stock.getEntryOrdersAgio());
|
|
@@ -572,17 +574,17 @@ public class UserPositionServiceImpl implements IUserPositionService {
|
|
// if(!(buyOrderPrice.compareTo(addNowprice) > -1 || buyOrderPrice.compareTo(subNowprice) < 1)){
|
|
// if(!(buyOrderPrice.compareTo(addNowprice) > -1 || buyOrderPrice.compareTo(subNowprice) < 1)){
|
|
// return ServerResponse.createByErrorMsg("挂单价格不在价差范围内");
|
|
// return ServerResponse.createByErrorMsg("挂单价格不在价差范围内");
|
|
// }
|
|
// }
|
|
- if(buyType == 0){
|
|
|
|
|
|
+ if (buyType == 0) {
|
|
// 做多
|
|
// 做多
|
|
// 委托价 大于 现价+价格差 才可以设置
|
|
// 委托价 大于 现价+价格差 才可以设置
|
|
- if(buyOrderPrice.compareTo(addNowprice) == 1){
|
|
|
|
|
|
+ if (buyOrderPrice.compareTo(addNowprice) == 1) {
|
|
// 不可以设置
|
|
// 不可以设置
|
|
return ServerResponse.createByErrorMsg("挂单价格不在价差范围内");
|
|
return ServerResponse.createByErrorMsg("挂单价格不在价差范围内");
|
|
}
|
|
}
|
|
- }else{
|
|
|
|
|
|
+ } else {
|
|
// 做空
|
|
// 做空
|
|
// 委托价 小于 现价+价格差 才可以设置
|
|
// 委托价 小于 现价+价格差 才可以设置
|
|
- if(buyOrderPrice.compareTo(addNowprice) == -1){
|
|
|
|
|
|
+ if (buyOrderPrice.compareTo(addNowprice) == -1) {
|
|
return ServerResponse.createByErrorMsg("挂单价格不在价差范围内");
|
|
return ServerResponse.createByErrorMsg("挂单价格不在价差范围内");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -592,17 +594,17 @@ public class UserPositionServiceImpl implements IUserPositionService {
|
|
BigDecimal buy_amt_autual = buyOrderPrice.multiply(new BigDecimal(buyNum));
|
|
BigDecimal buy_amt_autual = buyOrderPrice.multiply(new BigDecimal(buyNum));
|
|
log.info("用户可用金额 = {} 实际购买金额 = {}", user_enable_amt, buy_amt_autual);
|
|
log.info("用户可用金额 = {} 实际购买金额 = {}", user_enable_amt, buy_amt_autual);
|
|
// 手续费
|
|
// 手续费
|
|
- BigDecimal position_freez = new BigDecimal(buyNum*stock.getTransFee());
|
|
|
|
|
|
+ BigDecimal position_freez = buyOrderPrice.multiply(new BigDecimal(buyNum)).multiply(stock.getTransFee()).multiply(new BigDecimal(stock.getContractSize()));
|
|
//冻结保证金
|
|
//冻结保证金
|
|
- BigDecimal depositFreezeAmt = buyOrderPrice.multiply(new BigDecimal(stock.getContractSize())).multiply(new BigDecimal(buyNum)).divide(new BigDecimal(stock.getSiteLever()),2,4);
|
|
|
|
- log.info("冻结保证金 = "+depositFreezeAmt);
|
|
|
|
|
|
+ BigDecimal depositFreezeAmt = buyOrderPrice.multiply(new BigDecimal(stock.getContractSize())).multiply(new BigDecimal(buyNum)).divide(new BigDecimal(stock.getSiteLever()), 2, 4);
|
|
|
|
+ log.info("冻结保证金 = " + depositFreezeAmt);
|
|
BigDecimal subtractDepositFreezeAmt = user_enable_amt.subtract(depositFreezeAmt).subtract(position_freez);
|
|
BigDecimal subtractDepositFreezeAmt = user_enable_amt.subtract(depositFreezeAmt).subtract(position_freez);
|
|
- log.info("挂单冻结保证金="+depositFreezeAmt);
|
|
|
|
|
|
+ log.info("挂单冻结保证金=" + depositFreezeAmt);
|
|
// depositFreezeAmt = depositFreezeAmt.add(position_freez);
|
|
// depositFreezeAmt = depositFreezeAmt.add(position_freez);
|
|
- log.info("挂单冻结手续费="+position_freez);
|
|
|
|
- log.info("挂单冻结金额="+depositFreezeAmt);
|
|
|
|
|
|
+ log.info("挂单冻结手续费=" + position_freez);
|
|
|
|
+ log.info("挂单冻结金额=" + depositFreezeAmt);
|
|
// 保证金和手续费 大于 用户可用资金 挂单失败
|
|
// 保证金和手续费 大于 用户可用资金 挂单失败
|
|
- if ((depositFreezeAmt.add(position_freez)).compareTo(user.getEnableAmt()) > -1){
|
|
|
|
|
|
+ if ((depositFreezeAmt.add(position_freez)).compareTo(user.getEnableAmt()) > -1) {
|
|
log.info("用户余额不足冻结保证金");
|
|
log.info("用户余额不足冻结保证金");
|
|
return ServerResponse.createByErrorMsg("挂单失败,用户余额不足冻结保证金:" + depositFreezeAmt);
|
|
return ServerResponse.createByErrorMsg("挂单失败,用户余额不足冻结保证金:" + depositFreezeAmt);
|
|
}
|
|
}
|
|
@@ -652,7 +654,7 @@ public class UserPositionServiceImpl implements IUserPositionService {
|
|
log.error("用户交易挂单】保存持仓记录出错");
|
|
log.error("用户交易挂单】保存持仓记录出错");
|
|
throw new Exception("用户交易挂单】保存持仓记录出错");
|
|
throw new Exception("用户交易挂单】保存持仓记录出错");
|
|
}
|
|
}
|
|
- }catch (Exception e){
|
|
|
|
|
|
+ } catch (Exception e) {
|
|
log.error(e.toString());
|
|
log.error(e.toString());
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
return ServerResponse.createByErrorMsg("挂单失败,请重试!");
|
|
return ServerResponse.createByErrorMsg("挂单失败,请重试!");
|
|
@@ -698,9 +700,9 @@ public class UserPositionServiceImpl implements IUserPositionService {
|
|
return ServerResponse.createByErrorMsg("下单失败,购买数量大于" + stock.getBuyMaxNum() + "手");
|
|
return ServerResponse.createByErrorMsg("下单失败,购买数量大于" + stock.getBuyMaxNum() + "手");
|
|
}
|
|
}
|
|
// 判断用户持仓数
|
|
// 判断用户持仓数
|
|
- Integer userPositionAmt = findUserPositionAmt(user.getId(),stock.getStockCode());
|
|
|
|
- if((userPositionAmt + buyNum) > (stock.getPositionsMax() == null ? 0 : stock.getPositionsMax())){
|
|
|
|
- return ServerResponse.createByErrorMsg("下单失败,本次下单手数:"+buyNum+",持仓手数大于" + stock.getPositionsMax() + "手,目前持仓手数:"+ userPositionAmt);
|
|
|
|
|
|
+ Integer userPositionAmt = findUserPositionAmt(user.getId(), stock.getStockCode());
|
|
|
|
+ if ((userPositionAmt + buyNum) > (stock.getPositionsMax() == null ? 0 : stock.getPositionsMax())) {
|
|
|
|
+ return ServerResponse.createByErrorMsg("下单失败,本次下单手数:" + buyNum + ",持仓手数大于" + stock.getPositionsMax() + "手,目前持仓手数:" + userPositionAmt);
|
|
}
|
|
}
|
|
// 获取股票最新价格
|
|
// 获取股票最新价格
|
|
StockListVO stockListVO = dbStockService.getStockListVO(stock.getStockGid());
|
|
StockListVO stockListVO = dbStockService.getStockListVO(stock.getStockGid());
|
|
@@ -708,10 +710,10 @@ public class UserPositionServiceImpl implements IUserPositionService {
|
|
if (nowPrice.compareTo(new BigDecimal("0")) == 0) {
|
|
if (nowPrice.compareTo(new BigDecimal("0")) == 0) {
|
|
return ServerResponse.createByErrorMsg("报价0,请稍后再试");
|
|
return ServerResponse.createByErrorMsg("报价0,请稍后再试");
|
|
}
|
|
}
|
|
- if(buyType == 0){
|
|
|
|
|
|
+ if (buyType == 0) {
|
|
// 做多
|
|
// 做多
|
|
nowPrice = nowPrice.add(stock.getSpread());
|
|
nowPrice = nowPrice.add(stock.getSpread());
|
|
- }else{
|
|
|
|
|
|
+ } else {
|
|
nowPrice = nowPrice.subtract(stock.getSpread());
|
|
nowPrice = nowPrice.subtract(stock.getSpread());
|
|
}
|
|
}
|
|
log.info("用户 {} 下单,货币id = {} ,数量 = {} , 方向 = {}", user.getId(), stockId, buyNum, buyType);
|
|
log.info("用户 {} 下单,货币id = {} ,数量 = {} , 方向 = {}", user.getId(), stockId, buyNum, buyType);
|
|
@@ -720,17 +722,17 @@ public class UserPositionServiceImpl implements IUserPositionService {
|
|
BigDecimal user_amt = user.getUserAmt();
|
|
BigDecimal user_amt = user.getUserAmt();
|
|
// 判断金额是否能够买得起 用 可用金额 > 冻结金额 + 手续费 则标示可以购买
|
|
// 判断金额是否能够买得起 用 可用金额 > 冻结金额 + 手续费 则标示可以购买
|
|
// 手续费
|
|
// 手续费
|
|
- BigDecimal position_freez = new BigDecimal(buyNum * stock.getTransFee());
|
|
|
|
- log.info("手续费 = "+position_freez);
|
|
|
|
|
|
+ BigDecimal position_freez = nowPrice.multiply(new BigDecimal(buyNum)).multiply(stock.getTransFee()).multiply(new BigDecimal(stock.getContractSize()));
|
|
|
|
+ log.info("手续费 = " + position_freez);
|
|
//冻结保证金 = 现价* 合约单位 * 手数 / 杠杆
|
|
//冻结保证金 = 现价* 合约单位 * 手数 / 杠杆
|
|
- BigDecimal depositFreezeAmt = nowPrice.multiply(new BigDecimal(stock.getContractSize())).multiply(new BigDecimal(buyNum)).divide(new BigDecimal(stock.getSiteLever()),2,4);
|
|
|
|
- log.info("冻结保证金 = "+depositFreezeAmt);
|
|
|
|
|
|
+ BigDecimal depositFreezeAmt = nowPrice.multiply(new BigDecimal(stock.getContractSize())).multiply(new BigDecimal(buyNum)).divide(new BigDecimal(stock.getSiteLever()), 2, 4);
|
|
|
|
+ log.info("冻结保证金 = " + depositFreezeAmt);
|
|
BigDecimal buy_amt = position_freez.add(depositFreezeAmt);
|
|
BigDecimal buy_amt = position_freez.add(depositFreezeAmt);
|
|
- if(user_enable_amt.compareTo(buy_amt) == -1){
|
|
|
|
|
|
+ if (user_enable_amt.compareTo(buy_amt) == -1) {
|
|
return ServerResponse.createByErrorMsg("下单失败,余额可用金额小于" + buy_amt + "元");
|
|
return ServerResponse.createByErrorMsg("下单失败,余额可用金额小于" + buy_amt + "元");
|
|
}
|
|
}
|
|
user.setEnableAmt(user_enable_amt.subtract(position_freez).subtract(depositFreezeAmt));
|
|
user.setEnableAmt(user_enable_amt.subtract(position_freez).subtract(depositFreezeAmt));
|
|
- log.info("可用余额 = "+ user_enable_amt.subtract(position_freez).subtract(depositFreezeAmt));
|
|
|
|
|
|
+ log.info("可用余额 = " + user_enable_amt.subtract(position_freez).subtract(depositFreezeAmt));
|
|
user.setUserAmt(user_amt.subtract(position_freez));
|
|
user.setUserAmt(user_amt.subtract(position_freez));
|
|
int updateUserCount = this.userMapper.updateByPrimaryKeySelective(user);
|
|
int updateUserCount = this.userMapper.updateByPrimaryKeySelective(user);
|
|
if (updateUserCount > 0) {
|
|
if (updateUserCount > 0) {
|
|
@@ -808,7 +810,7 @@ public class UserPositionServiceImpl implements IUserPositionService {
|
|
userPosition.setOrderStayDays(0);
|
|
userPosition.setOrderStayDays(0);
|
|
userPosition.setOrderStayFee(new BigDecimal("0"));
|
|
userPosition.setOrderStayFee(new BigDecimal("0"));
|
|
userPosition.setOrderSpread(stock.getSpread().multiply(new BigDecimal(buyNum)));
|
|
userPosition.setOrderSpread(stock.getSpread().multiply(new BigDecimal(buyNum)));
|
|
- log.info("点差"+(stock.getSpread().multiply(new BigDecimal(buyNum))));
|
|
|
|
|
|
+ log.info("点差" + (stock.getSpread().multiply(new BigDecimal(buyNum))));
|
|
//冻结保证金
|
|
//冻结保证金
|
|
userPosition.setDepositFreezeAmt(depositFreezeAmt);
|
|
userPosition.setDepositFreezeAmt(depositFreezeAmt);
|
|
//是否挂单
|
|
//是否挂单
|
|
@@ -1036,7 +1038,7 @@ public class UserPositionServiceImpl implements IUserPositionService {
|
|
UserPositionVO userPositionVO = assembleUserPositionVO(position);
|
|
UserPositionVO userPositionVO = assembleUserPositionVO(position);
|
|
IndexInfo indexInfo = indexMap.get(position.getStockName());
|
|
IndexInfo indexInfo = indexMap.get(position.getStockName());
|
|
userPositionVO.setNow_price(indexInfo.getNowPrice().toString());
|
|
userPositionVO.setNow_price(indexInfo.getNowPrice().toString());
|
|
- if(1 != state) {
|
|
|
|
|
|
+ if (1 != state) {
|
|
BigDecimal yk = new BigDecimal(0);
|
|
BigDecimal yk = new BigDecimal(0);
|
|
//盈亏公式 做多 (现价—开仓价)*合约单位*手数 做空 (开仓价-现价)*合约单位*手数
|
|
//盈亏公式 做多 (现价—开仓价)*合约单位*手数 做空 (开仓价-现价)*合约单位*手数
|
|
if ("做多".equals(position.getOrderDirection())) {
|
|
if ("做多".equals(position.getOrderDirection())) {
|
|
@@ -1072,16 +1074,16 @@ public class UserPositionServiceImpl implements IUserPositionService {
|
|
IndexInfo indexInfo = indexMap.get(position.getStockName());
|
|
IndexInfo indexInfo = indexMap.get(position.getStockName());
|
|
BigDecimal yk = new BigDecimal(0);
|
|
BigDecimal yk = new BigDecimal(0);
|
|
//盈亏公式 做多 (现价—开仓价)*合约单位*手数 - 点差 做空 (开仓价-现价)*合约单位*手数 - 点差
|
|
//盈亏公式 做多 (现价—开仓价)*合约单位*手数 - 点差 做空 (开仓价-现价)*合约单位*手数 - 点差
|
|
- if("做多".equals(position.getOrderDirection())){
|
|
|
|
|
|
+ if ("做多".equals(position.getOrderDirection())) {
|
|
yk = indexInfo.getNowPrice().subtract(position.getBuyOrderPrice()).multiply(BigDecimal.valueOf(position.getOrderNum() * indexInfo.getContractSize()));
|
|
yk = indexInfo.getNowPrice().subtract(position.getBuyOrderPrice()).multiply(BigDecimal.valueOf(position.getOrderNum() * indexInfo.getContractSize()));
|
|
- }else {
|
|
|
|
|
|
+ } else {
|
|
yk = position.getBuyOrderPrice().subtract(indexInfo.getNowPrice()).multiply(BigDecimal.valueOf(position.getOrderNum() * indexInfo.getContractSize()));
|
|
yk = position.getBuyOrderPrice().subtract(indexInfo.getNowPrice()).multiply(BigDecimal.valueOf(position.getOrderNum() * indexInfo.getContractSize()));
|
|
}
|
|
}
|
|
// yk = yk.subtract(position.getOrderSpread());
|
|
// yk = yk.subtract(position.getOrderSpread());
|
|
ykSum = ykSum.add(yk);
|
|
ykSum = ykSum.add(yk);
|
|
}
|
|
}
|
|
BigDecimal hazardRate = new BigDecimal(0);
|
|
BigDecimal hazardRate = new BigDecimal(0);
|
|
- if(0 != userPositionAll.size()) {
|
|
|
|
|
|
+ if (0 != userPositionAll.size()) {
|
|
hazardRate = hazardRate.add(enableAmt).add(depositFreezeAmt).add(ykSum).subtract(sxfSum);
|
|
hazardRate = hazardRate.add(enableAmt).add(depositFreezeAmt).add(ykSum).subtract(sxfSum);
|
|
hazardRate = hazardRate.divide(depositFreezeAmt, 2, BigDecimal.ROUND_HALF_UP);
|
|
hazardRate = hazardRate.divide(depositFreezeAmt, 2, BigDecimal.ROUND_HALF_UP);
|
|
}
|
|
}
|
|
@@ -1089,7 +1091,7 @@ public class UserPositionServiceImpl implements IUserPositionService {
|
|
for (UserPosition position : userPositionAll) {
|
|
for (UserPosition position : userPositionAll) {
|
|
depositFreezeAmt = depositFreezeAmt.add(position.getDepositFreezeAmt());
|
|
depositFreezeAmt = depositFreezeAmt.add(position.getDepositFreezeAmt());
|
|
}
|
|
}
|
|
- if(hazardRate.compareTo(BigDecimal.ZERO) == -1){
|
|
|
|
|
|
+ if (hazardRate.compareTo(BigDecimal.ZERO) == -1) {
|
|
hazardRate = BigDecimal.ZERO;
|
|
hazardRate = BigDecimal.ZERO;
|
|
}
|
|
}
|
|
PageInfo pageInfo = new PageInfo(userPositions);
|
|
PageInfo pageInfo = new PageInfo(userPositions);
|
|
@@ -1129,9 +1131,9 @@ public class UserPositionServiceImpl implements IUserPositionService {
|
|
IndexInfo indexInfo = indexMap.get(position.getStockName());
|
|
IndexInfo indexInfo = indexMap.get(position.getStockName());
|
|
BigDecimal yk = new BigDecimal(0);
|
|
BigDecimal yk = new BigDecimal(0);
|
|
//盈亏公式 做多 (现价—开仓价)*合约单位*手数 - 点差 做空 (开仓价-现价)*合约单位*手数 - 点差
|
|
//盈亏公式 做多 (现价—开仓价)*合约单位*手数 - 点差 做空 (开仓价-现价)*合约单位*手数 - 点差
|
|
- if("做多".equals(position.getOrderDirection())){
|
|
|
|
|
|
+ if ("做多".equals(position.getOrderDirection())) {
|
|
yk = indexInfo.getNowPrice().subtract(position.getBuyOrderPrice()).multiply(BigDecimal.valueOf(position.getOrderNum() * indexInfo.getContractSize()));
|
|
yk = indexInfo.getNowPrice().subtract(position.getBuyOrderPrice()).multiply(BigDecimal.valueOf(position.getOrderNum() * indexInfo.getContractSize()));
|
|
- }else {
|
|
|
|
|
|
+ } else {
|
|
yk = position.getBuyOrderPrice().subtract(indexInfo.getNowPrice()).multiply(BigDecimal.valueOf(position.getOrderNum() * indexInfo.getContractSize()));
|
|
yk = position.getBuyOrderPrice().subtract(indexInfo.getNowPrice()).multiply(BigDecimal.valueOf(position.getOrderNum() * indexInfo.getContractSize()));
|
|
}
|
|
}
|
|
// yk = yk.subtract(position.getOrderSpread());
|
|
// yk = yk.subtract(position.getOrderSpread());
|
|
@@ -1227,7 +1229,7 @@ public class UserPositionServiceImpl implements IUserPositionService {
|
|
BigDecimal order_profit_and_lose_all = new BigDecimal("0");
|
|
BigDecimal order_profit_and_lose_all = new BigDecimal("0");
|
|
for (UserPosition position : userPositions) {
|
|
for (UserPosition position : userPositions) {
|
|
// 挂单的不计算
|
|
// 挂单的不计算
|
|
- if(1 != position.getEntryOrders()) {
|
|
|
|
|
|
+ if (1 != position.getEntryOrders()) {
|
|
order_fee_amt = order_fee_amt.add(position.getOrderFee()).add(position.getOrderSpread()).add(position.getOrderStayFee());
|
|
order_fee_amt = order_fee_amt.add(position.getOrderFee()).add(position.getOrderSpread()).add(position.getOrderStayFee());
|
|
// 平仓的数据 直接用数据库中的数据
|
|
// 平仓的数据 直接用数据库中的数据
|
|
if (StringUtils.isNotEmpty(position.getSellOrderId())) {
|
|
if (StringUtils.isNotEmpty(position.getSellOrderId())) {
|
|
@@ -1514,13 +1516,13 @@ public class UserPositionServiceImpl implements IUserPositionService {
|
|
adminPositionVO.setLockMsg(position.getLockMsg());
|
|
adminPositionVO.setLockMsg(position.getLockMsg());
|
|
adminPositionVO.setStockPlate(position.getStockPlate());
|
|
adminPositionVO.setStockPlate(position.getStockPlate());
|
|
// 计算浮动盈亏 如果是平仓的就不需要计算了 直接去数据库中的
|
|
// 计算浮动盈亏 如果是平仓的就不需要计算了 直接去数据库中的
|
|
- if(1 != state){
|
|
|
|
|
|
+ if (1 != state) {
|
|
PositionProfitVO positionProfitVO = getPositionProfitVO(position, indexMap);
|
|
PositionProfitVO positionProfitVO = getPositionProfitVO(position, indexMap);
|
|
adminPositionVO.setProfitAndLose(positionProfitVO.getProfitAndLose());
|
|
adminPositionVO.setProfitAndLose(positionProfitVO.getProfitAndLose());
|
|
adminPositionVO.setAllProfitAndLose(positionProfitVO.getAllProfitAndLose());
|
|
adminPositionVO.setAllProfitAndLose(positionProfitVO.getAllProfitAndLose());
|
|
adminPositionVO.setNow_price(positionProfitVO.getNowPrice());
|
|
adminPositionVO.setNow_price(positionProfitVO.getNowPrice());
|
|
adminPositionVO.setHazardRate(positionProfitVO.getHazardRate());
|
|
adminPositionVO.setHazardRate(positionProfitVO.getHazardRate());
|
|
- }else {
|
|
|
|
|
|
+ } else {
|
|
adminPositionVO.setProfitAndLose(position.getProfitAndLose());
|
|
adminPositionVO.setProfitAndLose(position.getProfitAndLose());
|
|
adminPositionVO.setAllProfitAndLose(position.getAllProfitAndLose());
|
|
adminPositionVO.setAllProfitAndLose(position.getAllProfitAndLose());
|
|
}
|
|
}
|
|
@@ -1560,13 +1562,13 @@ public class UserPositionServiceImpl implements IUserPositionService {
|
|
agentPositionVO.setStockPlate(position.getStockPlate());
|
|
agentPositionVO.setStockPlate(position.getStockPlate());
|
|
// PositionProfitVO positionProfitVO = getPositionProfitVO(position, indexMap);
|
|
// PositionProfitVO positionProfitVO = getPositionProfitVO(position, indexMap);
|
|
// 计算浮动盈亏 如果是平仓的就不需要计算了 直接去数据库中的
|
|
// 计算浮动盈亏 如果是平仓的就不需要计算了 直接去数据库中的
|
|
- if(1 != state){
|
|
|
|
|
|
+ if (1 != state) {
|
|
PositionProfitVO positionProfitVO = getPositionProfitVO(position, indexMap);
|
|
PositionProfitVO positionProfitVO = getPositionProfitVO(position, indexMap);
|
|
agentPositionVO.setProfitAndLose(positionProfitVO.getProfitAndLose());
|
|
agentPositionVO.setProfitAndLose(positionProfitVO.getProfitAndLose());
|
|
agentPositionVO.setAllProfitAndLose(positionProfitVO.getAllProfitAndLose());
|
|
agentPositionVO.setAllProfitAndLose(positionProfitVO.getAllProfitAndLose());
|
|
agentPositionVO.setNow_price(positionProfitVO.getNowPrice());
|
|
agentPositionVO.setNow_price(positionProfitVO.getNowPrice());
|
|
agentPositionVO.setHazardRate(positionProfitVO.getHazardRate());
|
|
agentPositionVO.setHazardRate(positionProfitVO.getHazardRate());
|
|
- }else {
|
|
|
|
|
|
+ } else {
|
|
agentPositionVO.setProfitAndLose(position.getProfitAndLose());
|
|
agentPositionVO.setProfitAndLose(position.getProfitAndLose());
|
|
agentPositionVO.setAllProfitAndLose(position.getAllProfitAndLose());
|
|
agentPositionVO.setAllProfitAndLose(position.getAllProfitAndLose());
|
|
}
|
|
}
|
|
@@ -1647,19 +1649,19 @@ public class UserPositionServiceImpl implements IUserPositionService {
|
|
indexInfo = indexMap.get(positionTemp.getStockName());
|
|
indexInfo = indexMap.get(positionTemp.getStockName());
|
|
yk = new BigDecimal(0);
|
|
yk = new BigDecimal(0);
|
|
//盈亏公式 做多 (现价—开仓价)*合约单位*手数 - 点差 做空 (开仓价-现价)*合约单位*手数 - 点差
|
|
//盈亏公式 做多 (现价—开仓价)*合约单位*手数 - 点差 做空 (开仓价-现价)*合约单位*手数 - 点差
|
|
- if("做多".equals(positionTemp.getOrderDirection())){
|
|
|
|
|
|
+ if ("做多".equals(positionTemp.getOrderDirection())) {
|
|
yk = indexInfo.getNowPrice().subtract(positionTemp.getBuyOrderPrice()).multiply(BigDecimal.valueOf(positionTemp.getOrderNum() * indexInfo.getContractSize()));
|
|
yk = indexInfo.getNowPrice().subtract(positionTemp.getBuyOrderPrice()).multiply(BigDecimal.valueOf(positionTemp.getOrderNum() * indexInfo.getContractSize()));
|
|
- }else {
|
|
|
|
|
|
+ } else {
|
|
yk = positionTemp.getBuyOrderPrice().subtract(indexInfo.getNowPrice()).multiply(BigDecimal.valueOf(positionTemp.getOrderNum() * indexInfo.getContractSize()));
|
|
yk = positionTemp.getBuyOrderPrice().subtract(indexInfo.getNowPrice()).multiply(BigDecimal.valueOf(positionTemp.getOrderNum() * indexInfo.getContractSize()));
|
|
}
|
|
}
|
|
// yk = yk.subtract(positionTemp.getOrderSpread());
|
|
// yk = yk.subtract(positionTemp.getOrderSpread());
|
|
ykSum = ykSum.add(yk);
|
|
ykSum = ykSum.add(yk);
|
|
}
|
|
}
|
|
BigDecimal hazardRate = new BigDecimal(0);
|
|
BigDecimal hazardRate = new BigDecimal(0);
|
|
- if(0 != userPositionAll.size()) {
|
|
|
|
|
|
+ if (0 != userPositionAll.size()) {
|
|
hazardRate = hazardRate.add(user.getEnableAmt()).add(depositFreezeAmt).add(ykSum).subtract(sxfSum);
|
|
hazardRate = hazardRate.add(user.getEnableAmt()).add(depositFreezeAmt).add(ykSum).subtract(sxfSum);
|
|
hazardRate = hazardRate.divide(depositFreezeAmt, 2, BigDecimal.ROUND_HALF_UP);
|
|
hazardRate = hazardRate.divide(depositFreezeAmt, 2, BigDecimal.ROUND_HALF_UP);
|
|
- if(hazardRate.compareTo(BigDecimal.ZERO) == -1){
|
|
|
|
|
|
+ if (hazardRate.compareTo(BigDecimal.ZERO) == -1) {
|
|
hazardRate = BigDecimal.ZERO;
|
|
hazardRate = BigDecimal.ZERO;
|
|
}
|
|
}
|
|
hazardRate = hazardRate.multiply(new BigDecimal(100));
|
|
hazardRate = hazardRate.multiply(new BigDecimal(100));
|
|
@@ -1673,8 +1675,8 @@ public class UserPositionServiceImpl implements IUserPositionService {
|
|
}
|
|
}
|
|
|
|
|
|
//获取持仓数
|
|
//获取持仓数
|
|
- public Integer findUserPositionAmt(Integer userId,String stockCode) {
|
|
|
|
- List<UserPosition> userPositions = this.userPositionMapper.findPositionAmt(userId,stockCode);
|
|
|
|
|
|
+ public Integer findUserPositionAmt(Integer userId, String stockCode) {
|
|
|
|
+ List<UserPosition> userPositions = this.userPositionMapper.findPositionAmt(userId, stockCode);
|
|
Integer allPositionAmt = 0;
|
|
Integer allPositionAmt = 0;
|
|
for (UserPosition position : userPositions) {
|
|
for (UserPosition position : userPositions) {
|
|
allPositionAmt += position.getOrderNum();
|
|
allPositionAmt += position.getOrderNum();
|
|
@@ -1682,7 +1684,7 @@ public class UserPositionServiceImpl implements IUserPositionService {
|
|
return allPositionAmt;
|
|
return allPositionAmt;
|
|
}
|
|
}
|
|
|
|
|
|
- public void stopProfitTargetTask(int id){
|
|
|
|
|
|
+ public void stopProfitTargetTask(int id) {
|
|
// 开始计算止盈操作
|
|
// 开始计算止盈操作
|
|
try {
|
|
try {
|
|
toStopProfitTargetById(id);
|
|
toStopProfitTargetById(id);
|
|
@@ -1744,7 +1746,7 @@ public class UserPositionServiceImpl implements IUserPositionService {
|
|
// }
|
|
// }
|
|
// }
|
|
// }
|
|
|
|
|
|
- public Integer getTodayOrderNum(String stockName){
|
|
|
|
|
|
+ public Integer getTodayOrderNum(String stockName) {
|
|
return userPositionMapper.selectTodayOrderNum(stockName);
|
|
return userPositionMapper.selectTodayOrderNum(stockName);
|
|
}
|
|
}
|
|
}
|
|
}
|