최대 1 분 소요

  1. 새로고침하면 값이 N/A로 변하는 문제
  2. 몇몇 코인은 처음부터 N/A가 뜸

image-20241209121740035

image-20241209121750942

발생했던 오류는 429 Too Many Requests 에러였고, 이 에러는 업비트 쪽 서버에서 API 이용시, 요청횟수 제한을 걸어놓은 이유때문이었다.

public List<Map<String, Object>> getUpbitPrice(String markets) {
        try {
            String[] marketArray = markets.split(",");
            List<Map<String, Object>> results = new ArrayList<>();

            for (String market : marketArray) {
                try {
                    results.addAll(upbitFeignClient.getUpBitPriceList(market));
                    Thread.sleep(1000);
                } catch (Exception e) {
                    System.err.println("Error fetching price for market : " + ", Error : " + e.getMessage());
                }
            }
            return results;
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

sleep 메서드를 이용해 요청 횟수를 조절하니 해결되었다.

댓글남기기