| | |
| | | return null; |
| | | } |
| | | String markPx = ObjectUtil.isEmpty(redisUtils.getString(CoinEnums.HE_YUE.getCode())) ? "0" : redisUtils.getString(CoinEnums.HE_YUE.getCode()); |
| | | log.info("当前价格: {}", markPx); |
| | | WangGeListEnum gridByPrice = WangGeListEnum.getGridByPrice(new BigDecimal(markPx)); |
| | | if (gridByPrice == null){ |
| | | log.error("没有获取到网格参数......"); |
| | |
| | | if (StrUtil.isNotEmpty(wanggeName) && !wanggeName.equals(gridByPrice.name())){ |
| | | log.error("正在止损老的网格仓位......"); |
| | | WangGeListEnum oldWangge = WangGeListEnum.getByName(wanggeName); |
| | | WsMapBuild.saveStringToMap(accountMap, CoinEnums.POSSIDE.name(), oldWangge.getFang_xiang()); |
| | | return OrderParamEnums.OUT.getValue(); |
| | | if (oldWangge != null){ |
| | | WsMapBuild.saveStringToMap(accountMap, CoinEnums.POSSIDE.name(), oldWangge.getFang_xiang()); |
| | | return OrderParamEnums.OUT.getValue(); |
| | | } |
| | | } |
| | | String posSide = gridByPrice.getFang_xiang(); |
| | | log.info("仓位方向: {}", posSide); |
| | |
| | | BigDecimal pos = PositionsWs.getAccountMap(positionAccountName).get("pos"); |
| | | if (BigDecimal.ZERO.compareTo( pos) >= 0) { |
| | | log.error("持仓数量为零,进行初始化订单"); |
| | | return OrderParamEnums.INIT.getValue(); |
| | | return null; |
| | | } |
| | | // 判断是否保证金超标 |
| | | if (PositionsWs.getAccountMap(positionAccountName).get("imr") == null){ |
| | |
| | | return null; |
| | | } |
| | | if (CoinEnums.POSSIDE_LONG.getCode().equals(posSide)){ |
| | | return caoZuoLong(accountName); |
| | | return caoZuoLong(accountName,markPx); |
| | | }else if (CoinEnums.POSSIDE_SHORT.getCode().equals(posSide)){ |
| | | return caoZuoShort(accountName); |
| | | return caoZuoShort(accountName,markPx); |
| | | }else{ |
| | | log.error("账户未设置持仓方向......"); |
| | | return null; |
| | |
| | | } |
| | | |
| | | @Override |
| | | public String caoZuoLong(String accountName) { |
| | | public String caoZuoLong(String accountName,String markPxStr) { |
| | | log.info("开始看涨执行操作CaoZuoServiceImpl......"); |
| | | try { |
| | | |
| | | String positionAccountName = PositionsWs.initAccountName(accountName, CoinEnums.POSSIDE_LONG.getCode()); |
| | | // 获取标记价格和平均持仓价格 |
| | | BigDecimal markPx = PositionsWs.getAccountMap(positionAccountName).get("markPx"); |
| | | // BigDecimal markPx = PositionsWs.getAccountMap(positionAccountName).get("markPx"); |
| | | BigDecimal markPx = new BigDecimal(markPxStr); |
| | | BigDecimal avgPx = PositionsWs.getAccountMap(positionAccountName).get("avgPx"); |
| | | log.info("开仓价格: {}, 当前价格:{},匹配队列中......", avgPx, markPx); |
| | | |
| | |
| | | |
| | | // 处理订单价格在队列中的情况 |
| | | String orderPrice = OrderInfoWs.getAccountMap(accountName).get("orderPrice"); |
| | | log.info("订单价格: {}", orderPrice); |
| | | handleOrderPriceInQueues(orderPrice, queueKaiCang, queuePingCang); |
| | | // 判断是加仓还是减仓 |
| | | if (avgPx.compareTo(markPx) > 0) { |
| | | log.info("开始加仓..."); |
| | | if (queueKaiCang.isEmpty()) { |
| | | // 队列为空 |
| | | // log.info("开始加仓,但是超出了网格设置..."); |
| | | log.info("开始加仓,但是超出了网格设置..."); |
| | | return OrderParamEnums.HOLDING.getValue(); |
| | | } |
| | | DescBigDecimal kaiCang = queueKaiCang.peek(); |
| | | log.info("下限队列价格{}", kaiCang.getValue()); |
| | | if (kaiCang != null && markPx.compareTo(kaiCang.getValue()) <= 0 && avgPx.compareTo(kaiCang.getValue()) >= 0) { |
| | | log.info("开始加仓...下限队列价格大于当前价格{}>{}", kaiCang.getValue(), markPx); |
| | | WsMapBuild.saveStringToMap(OrderInfoWs.getAccountMap(accountName), "orderPrice", String.valueOf(markPx)); |
| | |
| | | return OrderParamEnums.HOLDING.getValue(); |
| | | } |
| | | AscBigDecimal pingCang = queuePingCang.peek(); |
| | | log.info("上限队列价格:{}", pingCang.getValue()); |
| | | if (pingCang != null && avgPx.compareTo(pingCang.getValue()) < 0) { |
| | | log.info("开始减仓...上限队列价格大于开仓价格{}>{}", pingCang.getValue(), avgPx); |
| | | // 手续费 |
| | |
| | | } |
| | | |
| | | @Override |
| | | public String caoZuoShort(String accountName) { |
| | | public String caoZuoShort(String accountName,String markPxStr) { |
| | | log.info("开始看空执行操作CaoZuoServiceImpl......"); |
| | | try { |
| | | |
| | | |
| | | String positionAccountName = PositionsWs.initAccountName(accountName, CoinEnums.POSSIDE_SHORT.getCode()); |
| | | // 获取标记价格和平均持仓价格 |
| | | BigDecimal markPx = PositionsWs.getAccountMap(positionAccountName).get("markPx"); |
| | | // BigDecimal markPx = PositionsWs.getAccountMap(positionAccountName).get("markPx"); |
| | | BigDecimal markPx = new BigDecimal(markPxStr); |
| | | BigDecimal avgPx = PositionsWs.getAccountMap(positionAccountName).get("avgPx"); |
| | | log.info("开仓价格: {}, 当前价格:{},匹配队列中......", avgPx, markPx); |
| | | |
| | |
| | | |
| | | // 处理订单价格在队列中的情况 |
| | | String orderPrice = OrderInfoWs.getAccountMap(accountName).get("orderPrice"); |
| | | log.info("订单价格:{}", orderPrice); |
| | | handleOrderPriceInQueues(orderPrice, queueKaiCang, queuePingCang); |
| | | // 判断是加仓还是减仓 |
| | | if (avgPx.compareTo(markPx) > 0) { |
| | | log.info("开始减仓..."); |
| | | if (queueKaiCang.isEmpty()) { |
| | | // 队列为空 |
| | | // log.info("开始加仓,但是超出了网格设置..."); |
| | | log.info("开始减仓,但是超出了网格设置..."); |
| | | return OrderParamEnums.HOLDING.getValue(); |
| | | } |
| | | DescBigDecimal kaiCang = queueKaiCang.peek(); |
| | | log.info("下限队列价格{}", kaiCang.getValue()); |
| | | if (kaiCang != null && avgPx.compareTo(kaiCang.getValue()) >= 0) { |
| | | log.info("开始减仓...下限队列价格小于开仓价格{}<{}", kaiCang.getValue(), avgPx); |
| | | |
| | |
| | | return OrderParamEnums.HOLDING.getValue(); |
| | | } |
| | | AscBigDecimal pingCang = queuePingCang.peek(); |
| | | log.info("上限队列价格: {}", pingCang.getValue()); |
| | | if (pingCang != null && markPx.compareTo(pingCang.getValue()) >= 0 && avgPx.compareTo(pingCang.getValue()) < 0) { |
| | | log.info("开始加仓...上限队列价格小于当前价格{}<={}", pingCang.getValue(), markPx); |
| | | WsMapBuild.saveStringToMap(OrderInfoWs.getAccountMap(accountName), "orderPrice", String.valueOf(markPx)); |
| | |
| | | queueKaiCang.removeIf(item -> item.getValue().compareTo(priceDecimal) >= 0); |
| | | |
| | | // 打印开仓队列 |
| | | // 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()); |
| | | 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()); |
| | | |
| | | // 删除比该价格小的数据 |
| | | queuePingCang.removeIf(item -> item.getValue().compareTo(priceDecimal) <= 0); |
| | | |
| | | // 打印平仓队列 |
| | | // 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()); |
| | | 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()); |
| | | } |
| | | } |