njmango / sales-bot

0 stars 2 forks source link

Rate limit issues #7

Open mcmcford opened 2 months ago

mcmcford commented 2 months ago

If calls to the https://www.simcompanies.com/api/v3/market/all// end point happen too quickly, you'll recieve the 429 status code, meaning the server is rate limiting the script. This rate limit is fairly harsh.

This error is logged and printed to console however the bot sends the discord message Failed to fetch the latest market price. Adding to list with 'MP' as price. seeming as if the order was a success. This should be avoided by caching prices every minute or so.

If findLowestPriceForItem is called, check if the item is in the cache, if it is, check when it was added to the cache. If the difference between the current epoch and the epoch at which the data was cached is less than 60 seconds, use the cached price, if it is greater than 60 seconds, update it by calling the API.

This avoids abusing the API and confusing users