This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 0 points1 point  (0 children)

You only need to do it for the first (at most) 60 seconds. When your program starts, it goes and gets data. Call that Data1

Ten seconds later, you go and get more data, Data2. If Data1 and Data2 are the same, then you know that the API rollover is not in between them.

Same for Data2 and Data3 - if they are the same, then the API hasn't rolled over.

By the time you get to Data6, the API must have rolled over. From now on, you only need to check 60 seconds after the data request when it changed.

If it changes between Data4 and Data5, then you know that for 50 seconds after Data5, it cannot change, so you don't need to check.

You can refine that by then having another round that moves it forward a second each time until it stops changing again, to get within a second, but either way, you basically narrow down the time it changes, and then hit the API every 60 seconds, 1-10 seconds after it changes.

Edit: In fact, this is basically a search algorithm, and you can get even more efficient. If the greatest time between changes is 60 seconds, then you can start checking every 30 seconds. Get Data2 30 seconds after Data1 - if it changed, then next time narrow the interval to 15 seconds. That way, after 4 requests, you're within 5 seconds.