| | |
| | | * @param closePrice K 线收盘价(即当前最新成交价) |
| | | */ |
| | | public void onKline(BigDecimal closePrice) { |
| | | |
| | | lastKlinePrice = closePrice; |
| | | |
| | | //初始化0位置的开仓,并且用空的开仓价格,作为价格基准来划分网格 |
| | |
| | | return; |
| | | } |
| | | |
| | | |
| | | // checkProfitAndReset(); |
| | | |
| | | checkProfitAndReset(); |
| | | |
| | | if (state == StrategyState.ACTIVE && |
| | | longActive == false && |
| | |
| | | BigDecimal target = initialPrincipal.add(config.getExpectedProfit()); |
| | | |
| | | FuturesAccount account = futuresApi.listFuturesAccounts(SETTLE); |
| | | BigDecimal unrealisedPnl = new BigDecimal(account.getCrossUnrealisedPnl()); |
| | | BigDecimal available = new BigDecimal(account.getCrossAvailable()); |
| | | BigDecimal totalEquity = unrealisedPnl.add(available); |
| | | BigDecimal totalEquity = new BigDecimal(account.getTotal()); |
| | | //加一个日志 |
| | | log.info("[Gate] 当前权益: {} USDT,目标:{} USDT", totalEquity, target); |
| | | |
| | | // 估算平仓手续费:(多仓张数+空仓张数) × 合约面值 × 当前价 × taker费率 |
| | | BigDecimal totalSize = longPositionSize.abs().add(shortPositionSize.abs()); |
| | | BigDecimal closeContractValue = |
| | | totalSize.multiply(config.getContractMultiplier()).multiply(lastKlinePrice != null ? lastKlinePrice : BigDecimal.ZERO); |
| | | BigDecimal estimatedFee = closeContractValue.multiply(TAKER_FEE_RATE); |
| | | BigDecimal netEquity = totalEquity.subtract(estimatedFee); |
| | | log.info("[Gate] 盈亏检查,总张数:{}, upl:{}, avail:{}, 合计:{}, 估手续费:{}, 净权益:{}, 目标:{}", |
| | | totalSize,unrealisedPnl, available, totalEquity, estimatedFee, netEquity, target); |
| | | if (netEquity.compareTo(target) > 0) { |
| | | log.info("[Gate] 盈亏达标(净权益{}>目标{}),重置策略", netEquity, target); |
| | | if (totalEquity.compareTo(target) > 0) { |
| | | log.info("[Gate] 盈亏达标(净权益{}>目标{}),重置策略", totalEquity, target); |
| | | state = StrategyState.STOPPED; |
| | | try { |
| | | futuresApi.cancelPriceTriggeredOrderList(SETTLE, config.getContract()); |