|
@@ -50,22 +50,16 @@ public class UserPositionServiceImpl implements IUserPositionService {
|
|
|
private static final Logger log = LoggerFactory.getLogger(UserPositionServiceImpl.class);
|
|
|
@Resource
|
|
|
IUserPositionService iUserPositionService;
|
|
|
-
|
|
|
@Autowired
|
|
|
UserPositionMapper userPositionMapper;
|
|
|
-
|
|
|
@Autowired
|
|
|
IUserService iUserService;
|
|
|
-
|
|
|
@Autowired
|
|
|
ISiteSettingService iSiteSettingService;
|
|
|
-
|
|
|
@Autowired
|
|
|
IStockService iStockService;
|
|
|
-
|
|
|
@Autowired
|
|
|
UserMapper userMapper;
|
|
|
-
|
|
|
@Autowired
|
|
|
UserCashDetailMapper userCashDetailMapper;
|
|
|
@Autowired
|
|
@@ -82,28 +76,43 @@ public class UserPositionServiceImpl implements IUserPositionService {
|
|
|
|
|
|
/**
|
|
|
* 判断当前货币当前价格可成交挂单
|
|
|
- * @param code 货币code
|
|
|
- * @param buyOrderPrice 当前价格
|
|
|
* @return
|
|
|
*/
|
|
|
@Override
|
|
|
@Transactional
|
|
|
- public boolean fulfill(String code, BigDecimal buyOrderPrice){
|
|
|
- Stock stock = (Stock)this.iStockService.findStockByCode(code).getData();
|
|
|
- List<UserPosition> userPositions = this.userPositionMapper.listByCodeAndState(code,2,null);
|
|
|
+ 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) {
|
|
|
+ try {
|
|
|
+ //每支code获取现价
|
|
|
+ StockListVO stockListVO = dbStockService.getStockListVO(indexInfo.getCode());
|
|
|
+ nowPrice = new BigDecimal(stockListVO.getNowPrice());
|
|
|
+ indexMap.put(indexInfo.getCnName(), nowPrice);
|
|
|
+ spreadMap.put(indexInfo.getCnName() , indexInfo.getSpread());
|
|
|
+ } catch (Exception e) {
|
|
|
+ // 数据库不存在
|
|
|
+ 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 (buyOrderPrice.compareTo(userPosition.getBuyOrderPrice()) < 1){
|
|
|
- buyOrderPrice = buyOrderPrice.add(stock.getSpread());
|
|
|
- toFulfill(userPosition, buyOrderPrice);
|
|
|
+ if (nowPrice.compareTo(userPosition.getBuyOrderPrice()) < 1){
|
|
|
+ nowPrice = userPosition.getBuyOrderPrice().add(spread);
|
|
|
+ toFulfill(userPosition, nowPrice);
|
|
|
}
|
|
|
}else{
|
|
|
// 现价大于等于委托价
|
|
|
- if (buyOrderPrice.compareTo(userPosition.getBuyOrderPrice()) > -1){
|
|
|
- buyOrderPrice = buyOrderPrice.subtract(stock.getSpread());
|
|
|
- toFulfill(userPosition, buyOrderPrice);
|
|
|
+ if (nowPrice.compareTo(userPosition.getBuyOrderPrice()) > -1){
|
|
|
+ nowPrice = userPosition.getBuyOrderPrice().subtract(spread);
|
|
|
+ toFulfill(userPosition, nowPrice);
|
|
|
}
|
|
|
}
|
|
|
}
|