| | |
| | | BigDecimal pos = PositionsWs.POSITIONSWSMAP.get("pos"); |
| | | if (BigDecimal.ZERO.compareTo( pos) >= 0) { |
| | | log.error("持仓数量为零,进行初始化订单"); |
| | | return OrderParamEnums.INIT.getValue(); |
| | | return null; |
| | | } |
| | | // 判断是否保证金超标 |
| | | if (PositionsWs.POSITIONSWSMAP.get("imr") == null){ |
| | |
| | | log.info("开始减仓...平仓队列价格小于当前价格{}<={}", pingCang.getValue(), markPx); |
| | | // 手续费 |
| | | BigDecimal feeValue = PositionsWs.POSITIONSWSMAP.get("fee").multiply(new BigDecimal("2")); |
| | | // 资金费用 |
| | | BigDecimal fundingFeeValue = PositionsWs.POSITIONSWSMAP.get("fundingFee"); |
| | | //未实现收益 |
| | | BigDecimal uplValue = PositionsWs.POSITIONSWSMAP.get("upl"); |
| | | //已实现收益 |
| | | BigDecimal realizedPnlValue = PositionsWs.POSITIONSWSMAP.get("realizedPnl"); |
| | | realizedPnlValue = realizedPnlValue.add(feeValue).add(fundingFeeValue); |
| | | realizedPnlValue = realizedPnlValue.add(feeValue); |
| | | |
| | | //持仓保证金 |
| | | BigDecimal imr = PositionsWs.POSITIONSWSMAP.get("imr"); |
| | |
| | | if (realizedPnlValue.compareTo(BigDecimal.ZERO) <= 0) { |
| | | BigDecimal realizedPnlValueZheng = realizedPnlValue.multiply(new BigDecimal("-1")); |
| | | if (uplValue.compareTo(realizedPnlValue) > 0 && uplValue.compareTo(imrValue.add(realizedPnlValueZheng)) >= 0) { |
| | | log.info("当前未实现盈亏:{}大于预计收益>{},赚钱咯", uplValue, imrValue); |
| | | log.info("当前未实现盈亏:{}大于预计收益>{},赚钱咯", uplValue, imrValue.add(realizedPnlValueZheng)); |
| | | WsMapBuild.saveStringToMap(OrderInfoWs.ORDERINFOWSMAP, "orderPrice", String.valueOf(markPx)); |
| | | return OrderParamEnums.SELL.getValue(); |
| | | }else{ |
| | | log.info("当前未实现盈亏:{}没有大于预计收益>{},钱在路上了", uplValue, imrValue); |
| | | log.info("当前未实现盈亏:{}没有大于预计收益>{},钱在路上了", uplValue, imrValue.add(realizedPnlValueZheng)); |
| | | return OrderParamEnums.HOLDING.getValue(); |
| | | } |
| | | }else { |
| | | if (uplValue.compareTo(imrValue) >= 0) { |
| | | if (uplValue.compareTo(imrValue.add(feeValue)) >= 0) { |
| | | WsMapBuild.saveStringToMap(OrderInfoWs.ORDERINFOWSMAP, "orderPrice", String.valueOf(markPx)); |
| | | log.info("当前未实现盈亏:{}大于预计收益>{},赚钱咯", uplValue, imrValue); |
| | | log.info("当前未实现盈亏:{}大于预计收益>{},赚钱咯", uplValue, imrValue.add(feeValue)); |
| | | return OrderParamEnums.SELL.getValue(); |
| | | }else{ |
| | | log.info("当前未实现盈亏:{}没有大于预计收益>{},钱在路上了", uplValue, imrValue); |
| | | log.info("当前未实现盈亏:{}没有大于预计收益>{},钱在路上了", uplValue, imrValue.add(feeValue)); |
| | | return OrderParamEnums.HOLDING.getValue(); |
| | | } |
| | | } |
| | |
| | | //判断当前价格和开仓价格直接间隔除以间距,取整,获取的数量是否大于等于0,如果大于0,则下单基础张数*倍数 |
| | | String buyCntTime = InstrumentsWs.INSTRUMENTSWSMAP.get(CoinEnums.BUY_CNT_TIME.name()); |
| | | BigDecimal subtract = avgPx.subtract(markPx); |
| | | BigDecimal divide = subtract.divide(new BigDecimal(buyCntTime), 0, RoundingMode.DOWN).add(BigDecimal.ONE); |
| | | BigDecimal divide = subtract.divide(new BigDecimal(buyCntTime), 0, RoundingMode.DOWN); |
| | | if (divide.compareTo(BigDecimal.ZERO) <= 0){ |
| | | log.warn("加仓次数间隔时间小于0,不加仓"); |
| | | return false; |
| | | } |
| | | return WsMapBuild.saveStringToMap(TradeOrderWs.TRADEORDERWSMAP, "buyCntTime",String.valueOf(divide)); |
| | | } |
| | | |