Reduce the number of requests in ccxt live feed?
-
I am using the ccxbt library to retrieve live-data from binance. The problem is that my strategy only uses 15 minute intervals, so there is no need to make requests for the OHCLV every second, which it appears to be doing. I want to later scale the project to run several strategies concurrently and I am worried this calls will exceed Binance's limit of 1200 per minute.
Is there any way to limit this calls, the strategy run only on full intervals anyway.
-
@borutf if all the strategies run off the same data you don't have to worry since the data will only be retrieved once and share to all your strategies. If you are trading multiple pairs, you can change the rateLimit parameter which will slow ccxt down and allow you to stay within the limit at the cost of latency to getting the data but a few seconds on a 15 minutes timeframe shouldn't be too critical.
I agree with you that it would be great if the backtrader could simply wait until the next datapoint should be available before polling.
Also I'm hoping the the websocket option in ccxt pro (which will become free in the coming months) will solve this problem.
-
@goloap Thank you very much.
How exactly does rateLimit function? As far as I understand it is in milliseconds and a bigger number brings a bigger gap in between the requests, but I don't understand the magnitude of the effect?
When I set it to 5000ms, I see it takes almost 25 seconds from one request to the other.
-
@goloap How would you the websocket with backtrader?
-
You can have a look at the throttle function in exchange.py (https://github.com/ccxt/ccxt/blob/master/python/ccxt/base/exchange.py) for the details. But basically the rateLimit is multiplied by a cost (which should be 1 most of the time). So with a 5000ms you should see a delay of 5 seconds. I'm not sure why you are seeing 25. Do you have multiple symbols?
Regarding the websocket. I expect that it will be handled by ccxt transparently to backtrader, but will have to wait and see once it becomes available.