dominiktraxl/pykrakenapi

Trading rate limiter

Closed this issue · 4 comments

Any plans to add a trading rate limiter, similar to the limiter that is implemented for the none-trades?

There's info on how it's implemented server side here.

Not at the moment, but thank you for the suggestion. It would be great to get that implemented. Want to give it a try? From a quick glance, it might be possible to implement it similarly to the "Trading rate limit calculator" (Google Sheet).

I've pushed a branch to my fork that implements a basic trade rate limiter.

I've added a new decorator:
https://github.com/jonnymaserati/pykrakenapi/blob/ec3f0b86cf3ccef4af27be3ec8e29fbce51370a1/pykrakenapi/pykrakenapi.py#L154-L213

A couple new functions:
https://github.com/jonnymaserati/pykrakenapi/blob/ec3f0b86cf3ccef4af27be3ec8e29fbce51370a1/pykrakenapi/pykrakenapi.py#L310-L331

And there's some additional rates and variables set in the main class.

I'm importing numpy for searching which given the limited size of the list could be written with basic Python, although since pandas is a requirement then numpy will already be installed since it's a requirement for pandas.

I should also write a cleanup function to periodically delete any stale orders (older than 300 seconds). And of course, I should add some docstrings and comments to explain what it happening. Also, I could initiate the api_trade_counter dict with some user account data - the current assumption is that when the API is initiated that there's not been any trade activity in the past 300 seconds.

https://github.com/jonnymaserati/pykrakenapi/blob/ec3f0b86cf3ccef4af27be3ec8e29fbce51370a1/pykrakenapi/pykrakenapi.py#L278

I've tested it and it seems to work, but I've not been able to get the counter high enough yet to actually start limiting. In principle it should work though.

Appreciate your feedback.

I'm not working on this anymore... it's better to use the websockets counter.