I am creating a program that imports and stores Internet data with node.js.
Once a second, data is received in api and stored in csv.
When we receive the current data, we are experiencing a problem in which the data does not come in order as shown below and is shown below.
02:03:01 02:03:02 02:03:04 02:03:03 02:03:05 02:03:06 02:03:07 02:03:08 02:03:10 02:03:09
I use setInterval() and I want to know how to reload the function after the function that goes inside in setInterval, or how to code it so that it doesn't have that problem.
node.js data io
Source checked. In this case, we can subtract based on sequence
.
/* Strategy */
var isOn = false;
var lastSeq = 0; // Variable that stores the most recently checked sequence value
var getBTCData = function(){
if (isOn == false) {
isOn = true;
/* Skipping */
request({
url: "https://api.gopax.co.kr/trading-pairs/BTC-KRW/book?level=1",
method: 'GET',
json: true
}, }, (error, response, body) => {
console.timeEnd('requestTime:');
console.time('parsingTime:');
If (body.sequence > lastSeq) { // Check if it is more recent and only if it is the latest value
let date = newDate().toLocaleString(); // Perform the required logic
/* Skipping */
console.timeEnd('insertTime:');
isOn = false;
LastSeq = body.sequence; // Update this value to latest when logic is complete
}
});
}
}
setInterval(getBTCData, 1000);
© 2024 OneMinuteCode. All rights reserved.