rateLimits
See original GitHub issueI was wondering how you come up with rateLimit values for given exchanges. They are usually > 1000 (as I understand this is in ms), but on exchanges which publish their limits its more like 1000/min and 1,000,000/day which comes to about 87ms rateLimit instead.
I would also like to spark conversation about implementing rateLimit natively into all libs so that we do not have to care about ddos protection in our code.
This is what I use now in my code:
let _EXCHANGES_API_LAST_CALLED = {};
function APICallTimeLog(exchange_id){
_EXCHANGES_API_LAST_CALLED[exchange_id] = Date.now();
}
async function APISleep(exchange_id){
let sleep = (ms) => new Promise (resolve => setTimeout (resolve, ms));
let wait_time = APICallWait(exchange_id);
if(wait_time)
await sleep(wait_time);
APICallTimeLog(exchange_id);
}
function APICallWait(exchange_id){
if(!_EXCHANGES_API_LAST_CALLED[exchange_id])
return 0;
let last_called_time = parseInt(_EXCHANGES_API_LAST_CALLED[exchange_id]);
let wait = last_called_time + config.exchanges[exchange_id].rateLimit - Date.now();
if(wait < 0)
return 0;
return wait;
}
and then during API communications:
let promise = (async () => {
await APISleep(exchange_id);
return await exchange.fetchTickers();
})();
would be nice if all this were under the hood implemented. I am willing to look into this if there is interest, thanks for your opinion
Issue Analytics
- State:
- Created 6 years ago
- Comments:11 (10 by maintainers)
Top Results From Across the Web
Rate limiting - Wikipedia
In computer networks, rate limiting is used to control the rate of requests sent or received by a network interface controller.
Read more >Rate limits | Stripe Documentation
A rate limiter that limits the number of requests received by the API within any given second. For most APIs, Stripe allows up...
Read more >Rate Limits - Graph API - Meta for Developers - Facebook
A rate limit is the number of API calls an app or user can make within a given time period. If this limit...
Read more >Rate limits | Docs | Twitter Developer ... - Twitter Developers
These limits help us provide the reliable and scalable API that our developer community relies on. Each of our APIs use rate limits...
Read more >Rate Limits - Let's Encrypt
Let's Encrypt provides rate limits to ensure fair usage by as many people ... them so renewing a certificate almost never hits a...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@michnovka here’s the plan:
(we are working on the js/base and some files may be moving around in the meantime, don’t panic 😉)
you probably already know this: https://github.com/ccxt/ccxt/blob/master/CONTRIBUTING.md
ask questions if any )
your contributions and pull-requests are welcome 😉
Let me know if it answers your question )
@Codewyvern
Yep.
Nope. You should either do it manually, or enable and use the built-in rate-limiting in the library, but not both.
The code after
'enableRateLimit': true
is: