| | |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import java.math.BigDecimal; |
| | | import java.math.RoundingMode; |
| | | import java.text.DecimalFormat; |
| | | import java.util.ArrayList; |
| | |
| | | map.put("close_price", order.getClosePrice()); |
| | | map.put("close_time", order.getCloseTime()); |
| | | map.put("close_time_ts", order.getCloseTime() == null ? "" : order.getCloseTime().getTime()); |
| | | |
| | | if (ExchangeApplyOrder.OFFSET_CLOSE.equals(order.getOffset())) { |
| | | List<ExchangeSymbolDto> exchangeSymbolDtos = exchangeApplyOrderService.querySpotTradPosition(order.getPartyId(), order.getSymbol()); |
| | | if (exchangeSymbolDtos != null && !exchangeSymbolDtos.isEmpty()) { |
| | | ExchangeSymbolDto exchangeSymbolDto = exchangeSymbolDtos.get(0); |
| | | double costPrice = exchangeSymbolDto.getPrice(); |
| | | //单个收益 |
| | | double profitLoss = order.getClosePrice() - costPrice; |
| | | double profitLossPercentage = (profitLoss / costPrice ) * 100; |
| | | profitLossPercentage = new BigDecimal(profitLossPercentage).setScale(2, RoundingMode.HALF_UP).doubleValue(); |
| | | //总收益 |
| | | double profitLossSum = new BigDecimal(profitLoss * order.getVolume()).setScale(4, RoundingMode.HALF_UP).doubleValue(); |
| | | |
| | | map.put("costPrice", costPrice); |
| | | map.put("profitLoss", profitLossSum); |
| | | map.put("profitLossPercentage", profitLossPercentage); |
| | | } |
| | | } |
| | | return map; |
| | | } |
| | | |