joancaron/cryptocompare-api

Throttling HttpClient

monsieurleberre opened this issue ยท 2 comments

โœจ Feature request

Add a possibility to throttle request to CryptoCompare.com API

๐Ÿ“ Description

The aim of this new feature is to allow users to remain below the maximum number of requests per second imposed by CryptoCompare.com when using their API.
For instance the free key I am using restricts the user to less than 10 requests per second.

Describe the solution you'd like

Please look at this draft solution:
master...monsieurleberre:throttle

I am happy to add some unit tests showing that the queries are delayed, however that will require mocking the wrapped HttpClient and therefore the introduction of the IHttpClientFactory interface (cf https://gingter.org/2018/07/26/how-to-mock-httpclient-in-your-net-c-unit-tests/). I felt that was a bit too much for this proposal but let me know if this is required.

Describe alternatives you've considered

For a more re-usable solution, I think we could also introduce a generic type that would wrap the type containing the method being throttled and take a Function in its constructor (the call that needs to be throttled). I think this might be an overkill here though.

Hello @monsieurleberre!
That's a great proposal ๐Ÿ‘
I reviewed your draft and I think that it could be better to inherit from HttpClientHandler class instead of making an abstraction of the HttpClient. The SendAsync method could be overriden and the logic could be implemented here.
What's your feeling about that ?

Cool thanks for the feedback.

- "What's your feeling about that ?"
- It looks a hundred times better (cf. #37) :) thanks for the idea, I didn't realise I could override this SendAsync method :)

Please let me know in the PR if you require any more changes.
Cheers!