ERR_INTERNET_DISCONNECTED

since it does not exist or at least I did not find a websocket to obtain the order book, I wrote the following code that returns the order book every 30 seconds the problem is that when the internet is disconnected the setTimeout is executed without respecting the interval of 30000 ms that I have configured by sending the error consecutively every second, what can I do so that the setTimeout is executed respecting the 30 seconds,

const burl = 'https://api.binance.com';

function loadRequest(url, callback) {
	'use strict';
	
	var xhttp = new XMLHttpRequest();
	
	xhttp.responseType = 'json';

	xhttp.onreadystatechange = function () {
		if (this.readyState == 4){
			if(this.status == 200) {
//				console.log('DONE')
				callback(this.response);
			}else{
//				console.log('ERROR')
				setTimeout(loadRequest(url, callback), 30000);
			}
		}
	};

function depth(symbol = 'BTCUSDT', limit = 1000, callback = () => {}) {	
	var endpoint = '/api/v3/depth',
	url = burl + endpoint + '?symbol=' + symbol + '&limit=' + limit;
	
	loadRequest(url, callback);
}

I could find the error, apparently the setInterval and setTimeout functions have a bug, I don’t know if it is a browser error or a function error, the problem is that the function that is passed as a parameter in any of the two functions must be passed as a string for example

WRONG: setTimeout(loadRequest(url, callback), 30000);
OK: setTimeout("loadRequest('" + url + "', " + callback + ")", 30000);

It is strange because in the documentation they do not mention this, in fact they pass the parameter as a function and not as a string, but everything does not end there, setTimeout works correctly however setInterval with each call begins to reduce the call time of the function what that after a while it causes the calls to run faster and faster until reaching the minimum allowed by setInterval of 10 milliseconds which if we are not careful can cause multiple calls to the api and they can ban us the IP, remember that only allow up to 1200 calls to the api per minute, the corrected code remains as follows

const burl = 'https://api.binance.com';

function loadRequest(url, callback) {
	'use strict';
	
	var xhttp = new XMLHttpRequest();
	
	xhttp.responseType = 'json';

	xhttp.onreadystatechange = function () {
		if (this.readyState == 4 && this.status == 200){
		}
	};
	
	xhttp.onload = function () {
		callback(this.response);
	};
	
	xhttp.onerror = function () {
		this.abort();
		setTimeout("loadRequest('" + url + "', " + callback + ")", 30000);
	};
	
	xhttp.open("GET", url, true);
	xhttp.send();
}

function depth(symbol = 'BTCUSDT', limit = 1000, callback = () => {}) {	
	var endpoint = '/api/v3/depth',
	url = burl + endpoint + '?symbol=' + symbol + '&limit=' + limit;
	
	loadRequest(url, callback);
}