| | |
| | | |
| | | import cn.hutool.core.util.ObjectUtil; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.xcong.excoin.modules.okxNewPrice.indicator.strategy.CoreTechnicalStrategy; |
| | | import com.xcong.excoin.modules.okxNewPrice.indicator.strategy.TechnicalIndicatorStrategy; |
| | | import com.xcong.excoin.modules.okxNewPrice.okxWs.*; |
| | | import com.xcong.excoin.modules.okxNewPrice.okxWs.enums.CoinEnums; |
| | | import com.xcong.excoin.modules.okxNewPrice.okxWs.enums.OrderParamEnums; |
| | |
| | | |
| | | private final WangGeListService wangGeListService; |
| | | private final RedisUtils redisUtils; |
| | | private final TechnicalIndicatorStrategy technicalIndicatorStrategy; |
| | | |
| | | /** |
| | | * 执行主要的操作逻辑,包括读取合约状态、获取市场价格信息, |
| | |
| | | public TradeRequestParam caoZuoInitEvent(String accountName, String markPx, String posSide) { |
| | | |
| | | log.info("当前网格初始化:操作账户:{},当前价格: {},仓位方向: {}", accountName,markPx,posSide); |
| | | /** |
| | | * 初始化订单请求参数 |
| | | * 获取仓位数量 |
| | | * 获取仓位方向 |
| | | */ |
| | | |
| | | // 根据技术指标策略获取开仓信号 |
| | | TradeRequestParam strategySignal = technicalIndicatorStrategy.getSignal(accountName, markPx, posSide); |
| | | |
| | | // 如果策略返回无信号或无效信号,则不进行开仓 |
| | | if (strategySignal == null || "NO_SIGNAL".equals(strategySignal.getTradeType())) { |
| | | log.info("技术指标策略无开仓信号,不进行初始化开仓"); |
| | | TradeRequestParam tradeRequestParam = new TradeRequestParam(); |
| | | tradeRequestParam.setTradeType(OrderParamEnums.TRADE_NO.getValue()); |
| | | return tradeRequestParam; |
| | | } |
| | | |
| | | // 使用策略信号进行开仓 |
| | | TradeRequestParam tradeRequestParam = new TradeRequestParam(); |
| | | tradeRequestParam.setAccountName(accountName); |
| | | tradeRequestParam.setMarkPx(markPx); |
| | | tradeRequestParam.setInstId(CoinEnums.HE_YUE.getCode()); |
| | | tradeRequestParam.setTdMode(CoinEnums.CROSS.getCode()); |
| | | tradeRequestParam.setPosSide(posSide); |
| | | tradeRequestParam.setPosSide(strategySignal.getPosSide()); |
| | | tradeRequestParam.setOrdType(CoinEnums.ORDTYPE_MARKET.getCode()); |
| | | |
| | | tradeRequestParam.setTradeType(OrderParamEnums.TRADE_YES.getValue()); |
| | | String side = null; |
| | | if (CoinEnums.POSSIDE_LONG.getCode().equals(posSide)){ |
| | | side = CoinEnums.SIDE_BUY.getCode(); |
| | | } |
| | | if (CoinEnums.POSSIDE_SHORT.getCode().equals(posSide)){ |
| | | side = CoinEnums.SIDE_SELL.getCode(); |
| | | } |
| | | tradeRequestParam.setSide(side); |
| | | tradeRequestParam.setSide(strategySignal.getSide()); |
| | | |
| | | String clOrdId = WsParamBuild.getOrderNum(side); |
| | | String clOrdId = WsParamBuild.getOrderNum(strategySignal.getSide()); |
| | | tradeRequestParam.setClOrdId(clOrdId); |
| | | String sz = InstrumentsWs.getAccountMap(accountName).get(CoinEnums.BUY_CNT_INIT.name()); |
| | | tradeRequestParam.setSz(sz); |
| | |
| | | BigDecimal markPx = new BigDecimal(markPxStr); |
| | | BigDecimal avgPx = PositionsWs.getAccountMap(positionAccountName).get("avgPx"); |
| | | log.info("持仓价格: {}, 当前价格:{},匹配队列中......", avgPx, markPx); |
| | | // 初始化网格队列 |
| | | PriorityBlockingQueue<AscBigDecimal> queueAsc = WangGeListQueue.getQueueAsc(); |
| | | PriorityBlockingQueue<DescBigDecimal> queueKaiCang = wangGeListService.initKaiCang(avgPx, queueAsc); |
| | | PriorityBlockingQueue<AscBigDecimal> queuePingCang = wangGeListService.initPingCang(avgPx, queueAsc); |
| | | |
| | | // 处理订单价格在队列中的情况 |
| | | String orderPrice = OrderInfoWs.getAccountMap(accountName).get("orderPrice"); |
| | | log.info("上一次网格触发价格: {}", orderPrice); |
| | | handleOrderPriceInQueues(orderPrice, queueKaiCang, queuePingCang); |
| | | // 判断是加仓还是减仓 |
| | | if (avgPx.compareTo(markPx) > 0) { |
| | | log.info("开始买入开多..."); |
| | | if (!queueKaiCang.isEmpty()) { |
| | | 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)); |
| | | String side = CoinEnums.SIDE_BUY.getCode(); |
| | | tradeRequestParam.setSide(side); |
| | | String clOrdId = WsParamBuild.getOrderNum(side); |
| | | tradeRequestParam.setClOrdId(clOrdId); |
| | | String sz = buyCntTimeLongEvent(accountName, avgPx, markPx); |
| | | tradeRequestParam.setSz(sz); |
| | | log.info("买入开多参数准备成功......"); |
| | | } else { |
| | | log.info("未触发加仓......,等待"); |
| | | } |
| | | }else{ |
| | | // 队列为空 |
| | | log.info("超出了网格设置..."); |
| | | } |
| | | } else if (avgPx.compareTo(markPx) < 0) { |
| | | log.info("开始卖出平多..."); |
| | | if (!queuePingCang.isEmpty()) { |
| | | AscBigDecimal pingCang = queuePingCang.peek(); |
| | | log.info("卖出平多队列价格:{}", pingCang.getValue()); |
| | | if (pingCang != null && avgPx.compareTo(pingCang.getValue()) < 0) { |
| | | log.info("开始卖出平多...卖出平多队列价格大于开仓价格{}>{}", pingCang.getValue(), avgPx); |
| | | // 手续费 |
| | | BigDecimal feeValue = PositionsWs.getAccountMap(positionAccountName).get("fee"); |
| | | //未实现收益 |
| | | BigDecimal uplValue = PositionsWs.getAccountMap(positionAccountName).get("upl"); |
| | | //已实现收益 |
| | | BigDecimal realizedPnlValue = PositionsWs.getAccountMap(positionAccountName).get("realizedPnl"); |
| | | realizedPnlValue = realizedPnlValue.add(feeValue); |
| | | |
| | | //持仓保证金 |
| | | BigDecimal imr = PositionsWs.getAccountMap(positionAccountName).get("imr"); |
| | | String pingCangImr = InstrumentsWs.getAccountMap(accountName).get(CoinEnums.PING_CANG_SHOUYI.name()); |
| | | BigDecimal imrValue = imr.multiply(new BigDecimal(pingCangImr)); |
| | | |
| | | 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.add(realizedPnlValueZheng)); |
| | | WsMapBuild.saveStringToMap(OrderInfoWs.getAccountMap(accountName), "orderPrice", String.valueOf(markPx)); |
| | | String side = CoinEnums.SIDE_SELL.getCode(); |
| | | tradeRequestParam.setSide(side); |
| | | String clOrdId = WsParamBuild.getOrderNum(side); |
| | | tradeRequestParam.setClOrdId(clOrdId); |
| | | BigDecimal sz = PositionsWs.getAccountMap(positionAccountName).get("pos"); |
| | | tradeRequestParam.setSz(String.valueOf( sz)); |
| | | log.info("卖出平多参数准备成功......"); |
| | | }else{ |
| | | log.info("当前未实现盈亏:{}没有大于预计收益>{},钱在路上了", uplValue, imrValue.add(realizedPnlValueZheng)); |
| | | } |
| | | }else { |
| | | if (uplValue.compareTo(imrValue.add(feeValue)) >= 0) { |
| | | log.info("当前未实现盈亏:{}大于预计收益>{},赚钱咯", uplValue, imrValue.add(feeValue)); |
| | | WsMapBuild.saveStringToMap(OrderInfoWs.getAccountMap(accountName), "orderPrice", String.valueOf(markPx)); |
| | | String side = CoinEnums.SIDE_SELL.getCode(); |
| | | tradeRequestParam.setSide(side); |
| | | String clOrdId = WsParamBuild.getOrderNum(side); |
| | | tradeRequestParam.setClOrdId(clOrdId); |
| | | BigDecimal sz = PositionsWs.getAccountMap(positionAccountName).get("pos"); |
| | | tradeRequestParam.setSz(String.valueOf( sz)); |
| | | log.info("卖出平多参数准备成功......"); |
| | | }else{ |
| | | log.info("当前未实现盈亏:{}没有大于预计收益>{},钱在路上了", uplValue, imrValue.add(feeValue)); |
| | | } |
| | | } |
| | | } else { |
| | | log.info("未触发减仓......,等待"); |
| | | } |
| | | }else{ |
| | | // 队列为空 |
| | | log.info("超出了网格设置..."); |
| | | } |
| | | } else { |
| | | log.info("价格波动较小......,等待"); |
| | | |
| | | // 根据技术指标策略获取交易信号 |
| | | TradeRequestParam strategySignal = technicalIndicatorStrategy.getSignal(accountName, markPxStr, posSide); |
| | | |
| | | // 如果策略返回无信号,则不进行操作 |
| | | if (strategySignal == null || "NO_SIGNAL".equals(strategySignal.getTradeType())) { |
| | | log.info("技术指标策略无信号,不进行操作"); |
| | | tradeRequestParam.setTradeType(OrderParamEnums.TRADE_NO.getValue()); |
| | | return tradeRequestParam; |
| | | } |
| | | |
| | | // 根据策略信号进行操作 |
| | | log.info("技术指标策略信号: {}, 执行相应操作", strategySignal.getTradeType()); |
| | | |
| | | // 处理平仓信号 |
| | | if (CoinEnums.SIDE_SELL.getCode().equals(strategySignal.getSide())) { |
| | | log.info("开始卖出平多..."); |
| | | // 手续费 |
| | | BigDecimal feeValue = PositionsWs.getAccountMap(positionAccountName).get("fee").multiply(new BigDecimal(2)); |
| | | //未实现收益 |
| | | BigDecimal uplValue = PositionsWs.getAccountMap(positionAccountName).get("upl"); |
| | | //已实现收益 |
| | | BigDecimal realizedPnlValue = PositionsWs.getAccountMap(positionAccountName).get("realizedPnl"); |
| | | realizedPnlValue = realizedPnlValue.add(feeValue); |
| | | |
| | | //持仓保证金 |
| | | BigDecimal imr = PositionsWs.getAccountMap(positionAccountName).get("imr"); |
| | | String pingCangImr = InstrumentsWs.getAccountMap(accountName).get(CoinEnums.PING_CANG_SHOUYI.name()); |
| | | BigDecimal imrValue = imr.multiply(new BigDecimal(pingCangImr)); |
| | | |
| | | 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.add(realizedPnlValueZheng)); |
| | | WsMapBuild.saveStringToMap(OrderInfoWs.getAccountMap(accountName), "orderPrice", String.valueOf(markPx)); |
| | | tradeRequestParam.setSide(CoinEnums.SIDE_SELL.getCode()); |
| | | String clOrdId = WsParamBuild.getOrderNum(CoinEnums.SIDE_SELL.getCode()); |
| | | tradeRequestParam.setClOrdId(clOrdId); |
| | | BigDecimal sz = PositionsWs.getAccountMap(positionAccountName).get("pos"); |
| | | tradeRequestParam.setSz(String.valueOf( sz)); |
| | | log.info("卖出平多参数准备成功......"); |
| | | }else{ |
| | | log.info("当前未实现盈亏:{}没有大于预计收益>{},钱在路上了", uplValue, imrValue.add(realizedPnlValueZheng)); |
| | | } |
| | | }else { |
| | | if (uplValue.compareTo(imrValue.add(feeValue)) >= 0) { |
| | | log.info("当前未实现盈亏:{}大于预计收益>{},赚钱咯", uplValue, imrValue.add(feeValue)); |
| | | WsMapBuild.saveStringToMap(OrderInfoWs.getAccountMap(accountName), "orderPrice", String.valueOf(markPx)); |
| | | tradeRequestParam.setSide(CoinEnums.SIDE_SELL.getCode()); |
| | | String clOrdId = WsParamBuild.getOrderNum(CoinEnums.SIDE_SELL.getCode()); |
| | | tradeRequestParam.setClOrdId(clOrdId); |
| | | BigDecimal sz = PositionsWs.getAccountMap(positionAccountName).get("pos"); |
| | | tradeRequestParam.setSz(String.valueOf( sz)); |
| | | log.info("卖出平多参数准备成功......"); |
| | | }else{ |
| | | log.info("当前未实现盈亏:{}没有大于预计收益>{},钱在路上了", uplValue, imrValue.add(feeValue)); |
| | | } |
| | | } |
| | | } |
| | | // 处理加仓信号 |
| | | else if (CoinEnums.SIDE_BUY.getCode().equals(strategySignal.getSide()) && avgPx.compareTo(markPx) > 0) { |
| | | log.info("开始买入加仓..."); |
| | | WsMapBuild.saveStringToMap(OrderInfoWs.getAccountMap(accountName), "orderPrice", String.valueOf(markPx)); |
| | | tradeRequestParam.setSide(CoinEnums.SIDE_BUY.getCode()); |
| | | String clOrdId = WsParamBuild.getOrderNum(CoinEnums.SIDE_BUY.getCode()); |
| | | tradeRequestParam.setClOrdId(clOrdId); |
| | | String sz = buyCntTimeLongEvent(accountName, avgPx, markPx); |
| | | tradeRequestParam.setSz(sz); |
| | | log.info("买入加仓参数准备成功......"); |
| | | } |
| | | else { |
| | | log.info("未触发操作......,等待"); |
| | | } |
| | | |
| | | return tradeRequestParam; |
| | | } catch (NumberFormatException e) { |
| | | log.error("开多方向异常", e); |
| | |
| | | BigDecimal markPx = new BigDecimal(markPxStr); |
| | | BigDecimal avgPx = PositionsWs.getAccountMap(positionAccountName).get("avgPx"); |
| | | log.info("持仓价格: {}, 当前价格:{},匹配队列中......", avgPx, markPx); |
| | | |
| | | // 初始化网格队列 |
| | | PriorityBlockingQueue<AscBigDecimal> queueAsc = WangGeListQueue.getQueueAsc(); |
| | | PriorityBlockingQueue<DescBigDecimal> queueKaiCang = wangGeListService.initKaiCang(avgPx, queueAsc); |
| | | PriorityBlockingQueue<AscBigDecimal> queuePingCang = wangGeListService.initPingCang(avgPx, queueAsc); |
| | | |
| | | // 处理订单价格在队列中的情况 |
| | | String orderPrice = OrderInfoWs.getAccountMap(accountName).get("orderPrice"); |
| | | log.info("上一次网格触发价格:{}", orderPrice); |
| | | handleOrderPriceInQueues(orderPrice, queueKaiCang, queuePingCang); |
| | | // 判断是加仓还是减仓 |
| | | if (avgPx.compareTo(markPx) > 0) { |
| | | log.info("开始买入平空..."); |
| | | if (!queueKaiCang.isEmpty()) { |
| | | DescBigDecimal kaiCang = queueKaiCang.peek(); |
| | | log.info("买入平空队列价格{}", kaiCang.getValue()); |
| | | if (kaiCang != null && avgPx.compareTo(kaiCang.getValue()) >= 0) { |
| | | log.info("开始买入平空...买入平空队列价格小于开仓价格{}<{}", kaiCang.getValue(), avgPx); |
| | | |
| | | // 手续费 |
| | | BigDecimal feeValue = PositionsWs.getAccountMap(positionAccountName).get("fee"); |
| | | //未实现收益 |
| | | BigDecimal uplValue = PositionsWs.getAccountMap(positionAccountName).get("upl"); |
| | | //已实现收益 |
| | | BigDecimal realizedPnlValue = PositionsWs.getAccountMap(positionAccountName).get("realizedPnl"); |
| | | realizedPnlValue = realizedPnlValue.add(feeValue); |
| | | |
| | | //持仓保证金 |
| | | BigDecimal imr = PositionsWs.getAccountMap(positionAccountName).get("imr"); |
| | | String pingCangImr = InstrumentsWs.getAccountMap(accountName).get(CoinEnums.PING_CANG_SHOUYI.name()); |
| | | BigDecimal imrValue = imr.multiply(new BigDecimal(pingCangImr)); |
| | | |
| | | 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.add(realizedPnlValueZheng)); |
| | | WsMapBuild.saveStringToMap(OrderInfoWs.getAccountMap(accountName), "orderPrice", String.valueOf(markPx)); |
| | | String side = CoinEnums.SIDE_BUY.getCode(); |
| | | tradeRequestParam.setSide(side); |
| | | String clOrdId = WsParamBuild.getOrderNum(side); |
| | | tradeRequestParam.setClOrdId(clOrdId); |
| | | BigDecimal sz = PositionsWs.getAccountMap(positionAccountName).get("pos"); |
| | | tradeRequestParam.setSz(String.valueOf( sz)); |
| | | log.info("买入平空参数准备成功......"); |
| | | }else{ |
| | | log.info("当前未实现盈亏:{}没有大于预计收益>{},钱在路上了", uplValue, imrValue.add(realizedPnlValueZheng)); |
| | | } |
| | | }else { |
| | | if (uplValue.compareTo(imrValue.add(feeValue)) >= 0) { |
| | | WsMapBuild.saveStringToMap(OrderInfoWs.getAccountMap(accountName), "orderPrice", String.valueOf(markPx)); |
| | | log.info("当前未实现盈亏:{}大于预计收益>{},赚钱咯", uplValue, imrValue.add(feeValue)); |
| | | String side = CoinEnums.SIDE_BUY.getCode(); |
| | | tradeRequestParam.setSide(side); |
| | | String clOrdId = WsParamBuild.getOrderNum(side); |
| | | tradeRequestParam.setClOrdId(clOrdId); |
| | | BigDecimal sz = PositionsWs.getAccountMap(positionAccountName).get("pos"); |
| | | tradeRequestParam.setSz(String.valueOf( sz)); |
| | | log.info("买入平空参数准备成功......"); |
| | | }else{ |
| | | log.info("当前未实现盈亏:{}没有大于预计收益>{},钱在路上了", uplValue, imrValue.add(feeValue)); |
| | | } |
| | | } |
| | | } else { |
| | | log.info("未触发减仓......,等待"); |
| | | } |
| | | }else{ |
| | | log.info("开始减仓,但是超出了网格设置..."); |
| | | } |
| | | } else if (avgPx.compareTo(markPx) < 0) { |
| | | log.info("开始卖出开空..."); |
| | | if (!queuePingCang.isEmpty()) { |
| | | 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)); |
| | | String side = CoinEnums.SIDE_SELL.getCode(); |
| | | tradeRequestParam.setSide(side); |
| | | String clOrdId = WsParamBuild.getOrderNum(side); |
| | | tradeRequestParam.setClOrdId(clOrdId); |
| | | String sz = buyCntTimeShortEvent(accountName, avgPx, markPx); |
| | | tradeRequestParam.setSz(sz); |
| | | log.info("卖出开空参数准备成功......"); |
| | | } else { |
| | | log.info("未触发加仓......,等待"); |
| | | } |
| | | }else{ |
| | | // 队列为空 |
| | | log.info("超出了网格设置..."); |
| | | } |
| | | } else { |
| | | log.info("价格波动较小......,等待"); |
| | | |
| | | // 根据技术指标策略获取交易信号 |
| | | TradeRequestParam strategySignal = technicalIndicatorStrategy.getSignal(accountName, markPxStr, posSide); |
| | | |
| | | // 如果策略返回无信号,则不进行操作 |
| | | if (strategySignal == null || "NO_SIGNAL".equals(strategySignal.getTradeType())) { |
| | | log.info("技术指标策略无信号,不进行操作"); |
| | | tradeRequestParam.setTradeType(OrderParamEnums.TRADE_NO.getValue()); |
| | | return tradeRequestParam; |
| | | } |
| | | |
| | | // 根据策略信号进行操作 |
| | | log.info("技术指标策略信号: {}, 执行相应操作", strategySignal.getTradeType()); |
| | | |
| | | // 处理平仓信号 |
| | | if (CoinEnums.SIDE_BUY.getCode().equals(strategySignal.getSide())) { |
| | | log.info("开始买入平空..."); |
| | | // 手续费 |
| | | BigDecimal feeValue = PositionsWs.getAccountMap(positionAccountName).get("fee"); |
| | | //未实现收益 |
| | | BigDecimal uplValue = PositionsWs.getAccountMap(positionAccountName).get("upl"); |
| | | //已实现收益 |
| | | BigDecimal realizedPnlValue = PositionsWs.getAccountMap(positionAccountName).get("realizedPnl"); |
| | | realizedPnlValue = realizedPnlValue.add(feeValue); |
| | | |
| | | //持仓保证金 |
| | | BigDecimal imr = PositionsWs.getAccountMap(positionAccountName).get("imr"); |
| | | String pingCangImr = InstrumentsWs.getAccountMap(accountName).get(CoinEnums.PING_CANG_SHOUYI.name()); |
| | | BigDecimal imrValue = imr.multiply(new BigDecimal(pingCangImr)); |
| | | |
| | | 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.add(realizedPnlValueZheng)); |
| | | WsMapBuild.saveStringToMap(OrderInfoWs.getAccountMap(accountName), "orderPrice", String.valueOf(markPx)); |
| | | tradeRequestParam.setSide(CoinEnums.SIDE_BUY.getCode()); |
| | | String clOrdId = WsParamBuild.getOrderNum(CoinEnums.SIDE_BUY.getCode()); |
| | | tradeRequestParam.setClOrdId(clOrdId); |
| | | BigDecimal sz = PositionsWs.getAccountMap(positionAccountName).get("pos"); |
| | | tradeRequestParam.setSz(String.valueOf( sz)); |
| | | log.info("买入平空参数准备成功......"); |
| | | }else{ |
| | | log.info("当前未实现盈亏:{}没有大于预计收益>{},钱在路上了", uplValue, imrValue.add(realizedPnlValueZheng)); |
| | | } |
| | | }else { |
| | | if (uplValue.compareTo(imrValue.add(feeValue)) >= 0) { |
| | | WsMapBuild.saveStringToMap(OrderInfoWs.getAccountMap(accountName), "orderPrice", String.valueOf(markPx)); |
| | | log.info("当前未实现盈亏:{}大于预计收益>{},赚钱咯", uplValue, imrValue.add(feeValue)); |
| | | tradeRequestParam.setSide(CoinEnums.SIDE_BUY.getCode()); |
| | | String clOrdId = WsParamBuild.getOrderNum(CoinEnums.SIDE_BUY.getCode()); |
| | | tradeRequestParam.setClOrdId(clOrdId); |
| | | BigDecimal sz = PositionsWs.getAccountMap(positionAccountName).get("pos"); |
| | | tradeRequestParam.setSz(String.valueOf( sz)); |
| | | log.info("买入平空参数准备成功......"); |
| | | }else{ |
| | | log.info("当前未实现盈亏:{}没有大于预计收益>{},钱在路上了", uplValue, imrValue.add(feeValue)); |
| | | } |
| | | } |
| | | } |
| | | // 处理加仓信号 |
| | | else if (CoinEnums.SIDE_SELL.getCode().equals(strategySignal.getSide()) && avgPx.compareTo(markPx) < 0) { |
| | | log.info("开始卖出加仓..."); |
| | | WsMapBuild.saveStringToMap(OrderInfoWs.getAccountMap(accountName), "orderPrice", String.valueOf(markPx)); |
| | | tradeRequestParam.setSide(CoinEnums.SIDE_SELL.getCode()); |
| | | String clOrdId = WsParamBuild.getOrderNum(CoinEnums.SIDE_SELL.getCode()); |
| | | tradeRequestParam.setClOrdId(clOrdId); |
| | | String sz = buyCntTimeShortEvent(accountName, avgPx, markPx); |
| | | tradeRequestParam.setSz(sz); |
| | | log.info("卖出加仓参数准备成功......"); |
| | | } |
| | | else { |
| | | log.info("未触发操作......,等待"); |
| | | } |
| | | |
| | | return tradeRequestParam; |
| | | } catch (NumberFormatException e) { |
| | | log.error("开空方向异常", e); |