Administrator
4 days ago 04a1828f4cca58545725aef8fb6eb6312d3d1e83
src/main/java/com/xcong/excoin/modules/station/service/impl/StationServiceImpl.java
@@ -18,7 +18,10 @@
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
@@ -166,6 +169,51 @@
    }
    @Override
    public List<Map<String, Object>> getRoundStopLossCount(String apiKeyMd5) {
        // selectByApiKeyMd5 按 event_time DESC 返回(新→旧),反转为升序(旧→新)
        List<StrategyEventLog> events = strategyEventLogDao.selectByApiKeyMd5(apiKeyMd5);
        List<StrategyEventLog> asc = new ArrayList<>(events);
        Collections.reverse(asc);
        List<Map<String, Object>> rounds = new ArrayList<>();
        int longCount = 0;
        int shortCount = 0;
        for (StrategyEventLog e : asc) {
            String type = e.getEventType();
            if ("STOP_LOSS_TRIGGERED".equals(type)) {
                JSONObject p = JSON.parseObject(e.getPayloadJson());
                String direction = p.getString("direction");
                if ("long".equals(direction)) {
                    longCount++;
                } else if ("short".equals(direction)) {
                    shortCount++;
                }
            } else if ("ROUND_COMPLETE".equals(type)) {
                // 轮次结束(重置前):快照当前累计的止损次数,然后清零进入下一轮
                JSONObject p = JSON.parseObject(e.getPayloadJson());
                Map<String, Object> row = new LinkedHashMap<>();
                row.put("roundNum", p.getIntValue("roundNum"));
                row.put("longLossCount", longCount);
                row.put("shortLossCount", shortCount);
                rounds.add(row);
                longCount = 0;
                shortCount = 0;
            }
        }
        // 当前进行中的轮次(尚未 ROUND_COMPLETE):若已有止损则追加
        if (longCount > 0 || shortCount > 0) {
            Map<String, Object> row = new LinkedHashMap<>();
            row.put("roundNum", null);
            row.put("longLossCount", longCount);
            row.put("shortLossCount", shortCount);
            rounds.add(row);
        }
        return rounds;
    }
    @Override
    public StrategyStatus getStrategyStatus(String apiKeyMd5) {
        return strategyStatusDao.selectByApiKeyMd5(apiKeyMd5);
    }