1

I'm trying to parse JSON data from an external URL I have managed to print the data but I'm having difficulties looping it and printing the complete data

here's my code

<div class="coin"></div>

    <script>
    $.getJSON('https://www.binance.com/gateway-api/v1/public/indicator/abnormal-trading-notice/list', function(fetch) {
        
        var coin = `noticeType: ${fetch.data[0].noticeType}<br>
                    symbol: ${fetch.data[0].symbol}<br>
                    eventType: ${fetch.data[0].eventType}<br>
                    volume: ${fetch.data[0].volume}<br>
                    priceChange: ${fetch.data[0].priceChange}<br>
                    period: ${fetch.data[0].period}<br>
                    createTimestamp: ${fetch.data[0].createTimestamp}<br>
                    updateTimestamp: ${fetch.data[0].updateTimestamp}<br>
                    baseAsset: ${fetch.data[0].baseAsset}<br>
                    quotaAsset: ${fetch.data[0].quotaAsset}<br>`
        $(".coin").html(coin);
    });
    </script>
1
  • 1
    You printed fetch.data[0] into .coin, but it's not clear where you would like to print the other elements of the fetch.data array. Commented Feb 13, 2021 at 20:06

1 Answer 1

2

Try this:

<script>

$.getJSON('https://www.binance.com/gateway-api/v1/public/indicator/abnormal-trading-notice/list', function (fetch) {

    for (var i = 0; i < fetch.data.length; i++) {
        $(".coin").append(`noticeType: ${fetch.data[i].noticeType}<br>
                symbol: ${fetch.data[i].symbol}<br>
                eventType: ${fetch.data[i].eventType}<br>
                volume: ${fetch.data[i].volume}<br>
                priceChange: ${fetch.data[i].priceChange}<br>
                period: ${fetch.data[i].period}<br>
                createTimestamp: ${fetch.data[i].createTimestamp}<br>
                updateTimestamp: ${fetch.data[i].updateTimestamp}<br>
                baseAsset: ${fetch.data[i].baseAsset}<br>
                quotaAsset: ${fetch.data[i].quotaAsset}<br> <br/><br/>`);
    }
});
Sign up to request clarification or add additional context in comments.

4 Comments

Is there a way I can request this data every 1 second automatically?
@neo81040 yes, see setInterval w3schools.com/js/js_timing.asp
Yes, you can use the javascript "setInterval" function. Please follow the link. stackoverflow.com/questions/2170923/…
Fetching the data every second seems a bit too frequent... Please be careful not to overload the API with your requests...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.