| | |
| | | public void init() { |
| | | try { |
| | | JSONObject account = executorGet("/api/v5/account/balance"); |
| | | JSONArray details = account.getJSONArray("data"); |
| | | if (details != null && !details.isEmpty()) { |
| | | JSONObject total = details.getJSONObject(0); |
| | | this.initialPrincipal = total.getBigDecimal("totalEq"); |
| | | log.info("[OKX] 初始本金: {} USDT", initialPrincipal); |
| | | JSONArray dataArr = account.getJSONArray("data"); |
| | | if (dataArr != null && !dataArr.isEmpty()) { |
| | | JSONArray details = dataArr.getJSONObject(0).getJSONArray("details"); |
| | | if (details != null) { |
| | | for (int i = 0; i < details.size(); i++) { |
| | | JSONObject currency = details.getJSONObject(i); |
| | | if ("USDT".equals(currency.getString("ccy"))) { |
| | | this.initialPrincipal = currency.getBigDecimal("eq"); |
| | | log.info("[OKX] 初始本金(USDT余额): {}", initialPrincipal); |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | // 设置双向持仓模式 |
| | |
| | | private void refreshInitialPrincipal() { |
| | | try { |
| | | JSONObject account = executorGet("/api/v5/account/balance"); |
| | | JSONArray details = account.getJSONArray("data"); |
| | | if (details != null && !details.isEmpty()) { |
| | | this.initialPrincipal = details.getJSONObject(0).getBigDecimal("totalEq"); |
| | | JSONArray dataArr = account.getJSONArray("data"); |
| | | if (dataArr != null && !dataArr.isEmpty()) { |
| | | JSONArray details = dataArr.getJSONObject(0).getJSONArray("details"); |
| | | if (details != null) { |
| | | for (int i = 0; i < details.size(); i++) { |
| | | JSONObject currency = details.getJSONObject(i); |
| | | if ("USDT".equals(currency.getString("ccy"))) { |
| | | this.initialPrincipal = currency.getBigDecimal("eq"); |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } catch (Exception e) { |
| | | log.warn("[OKX] 获取初始化本金失败,使用旧值: {}", initialPrincipal); |