| | |
| | | longPriceQueue.clear(); |
| | | currentLongOrderIds.clear(); |
| | | currentShortOrderIds.clear(); |
| | | log.info("[OKX] 网格策略已启动"); |
| | | |
| | | // 每次重启重新获取当前本金,确保盈亏对比基准正确 |
| | | refreshInitialPrincipal(); |
| | | |
| | | log.info("[OKX] 网格策略已启动, 当前本金: {} USDT", initialPrincipal); |
| | | } |
| | | |
| | | /** |
| | | * 重新获取当前账户权益作为初始本金。 |
| | | */ |
| | | private void refreshInitialPrincipal() { |
| | | try { |
| | | String balanceResp = executor.getBalance(); |
| | | if (balanceResp != null) { |
| | | JSONObject json = JSON.parseObject(balanceResp); |
| | | if ("0".equals(json.getString("code"))) { |
| | | JSONArray data = json.getJSONArray("data"); |
| | | if (data != null && !data.isEmpty()) { |
| | | JSONObject detail = data.getJSONObject(0); |
| | | String totalEq = detail.getString("totalEq"); |
| | | if (totalEq != null) { |
| | | this.initialPrincipal = new BigDecimal(totalEq); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } catch (Exception e) { |
| | | log.warn("[OKX] 获取初始化本金失败,使用旧值: {}", initialPrincipal); |
| | | } |
| | | } |
| | | |
| | | public void stopGrid() { |