| | |
| | | package com.xcong.excoin.modules.okxNewPrice.celue; |
| | | |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.xcong.excoin.modules.okxNewPrice.okxWs.InstrumentsWs; |
| | | import com.xcong.excoin.modules.okxNewPrice.okxWs.PositionsWs; |
| | | import com.xcong.excoin.modules.okxNewPrice.okxWs.enums.CoinEnums; |
| | |
| | | log.info(OrderParamEnums.getNameByValue(state)); |
| | | |
| | | // 获取标记价格和平均持仓价格 |
| | | Object markPxObj = redisUtils.get(positionsMarkPxKey); |
| | | Object avgPxObj = redisUtils.get(positionsAvgPxKey); |
| | | String markPxObj = (String) redisUtils.get(positionsMarkPxKey); |
| | | String avgPxObj = (String) redisUtils.get(positionsAvgPxKey); |
| | | |
| | | if (markPxObj == null || avgPxObj == null) { |
| | | if (StrUtil.isBlank(markPxObj) || StrUtil.isBlank(avgPxObj)) { |
| | | return OrderParamEnums.INIT.getValue(); |
| | | } |
| | | |
| | | try { |
| | | BigDecimal markPx = new BigDecimal((String) markPxObj); |
| | | BigDecimal avgPx = new BigDecimal((String) avgPxObj); |
| | | BigDecimal markPx = new BigDecimal( markPxObj); |
| | | BigDecimal avgPx = new BigDecimal( avgPxObj); |
| | | |
| | | log.info("开仓价格: {}, 当前价格:{},匹配队列中......", avgPx, markPx); |
| | | |
| | |
| | | if (realizedPnlValue.compareTo(BigDecimal.ZERO) <= 0) { |
| | | if (uplValue.compareTo(realizedPnlValue) < 0) { |
| | | log.info("当前未实现盈亏:{}没有大于已实现收益>{},等待中", uplValue, realizedPnlValue); |
| | | redisUtils.set(positionsOrderPriceKey, String.valueOf(pingCang.getValue()), 0); |
| | | return OrderParamEnums.HOLDING.getValue(); |
| | | }else if (uplValue.compareTo(realizedPnlValue) > 0 && uplValue.compareTo(imrValue) >= 0) { |
| | | log.info("当前未实现盈亏:{}大于预计收益>{},赚钱咯", uplValue, imrValue); |
| | |
| | | return OrderParamEnums.SELL.getValue(); |
| | | }else{ |
| | | log.info("当前未实现盈亏:{}没有大于预计收益>{},钱在路上了", uplValue, imrValue); |
| | | redisUtils.set(positionsOrderPriceKey, String.valueOf(pingCang.getValue()), 0); |
| | | return OrderParamEnums.HOLDING.getValue(); |
| | | } |
| | | }else { |
| | |
| | | return OrderParamEnums.SELL.getValue(); |
| | | }else{ |
| | | log.info("当前未实现盈亏:{}没有大于预计收益>{},钱在路上了", uplValue, imrValue); |
| | | redisUtils.set(positionsOrderPriceKey, String.valueOf(pingCang.getValue()), 0); |
| | | return OrderParamEnums.HOLDING.getValue(); |
| | | } |
| | | } |
| | |
| | | queueKaiCang.removeIf(item -> item.getValue().equals(priceDecimal)); |
| | | } |
| | | // 打印开仓队列 |
| | | log.info("开仓队列: {}", queueKaiCang); |
| | | StringBuilder kaiCangStr = new StringBuilder(); |
| | | kaiCangStr.append("开仓队列: ["); |
| | | boolean first = true; |
| | | for (DescBigDecimal item : queueKaiCang) { |
| | | if (!first) { |
| | | kaiCangStr.append(", "); |
| | | } |
| | | kaiCangStr.append(item.getValue()); |
| | | first = false; |
| | | } |
| | | kaiCangStr.append("]"); |
| | | log.info(kaiCangStr.toString()); |
| | | |
| | | boolean pingCangExists = queuePingCang.stream().anyMatch(item -> item.getValue().equals(priceDecimal)); |
| | | if (!pingCangExists) { |
| | |
| | | } else { |
| | | queuePingCang.removeIf(item -> item.getValue().equals(priceDecimal)); |
| | | } |
| | | // 打印平仓队列 |
| | | log.info("平仓队列: {}", queuePingCang); |
| | | |
| | | // 打印平仓队列 |
| | | StringBuilder pingCangStr = new StringBuilder(); |
| | | pingCangStr.append("平仓队列: ["); |
| | | first = true; |
| | | for (AscBigDecimal item : queuePingCang) { |
| | | if (!first) { |
| | | pingCangStr.append(", "); |
| | | } |
| | | pingCangStr.append(item.getValue()); |
| | | first = false; |
| | | } |
| | | pingCangStr.append("]"); |
| | | log.info(pingCangStr.toString()); |
| | | } |
| | | } |
| | | |