coinbasepro-python icon indicating copy to clipboard operation
coinbasepro-python copied to clipboard

Coinbase rate limits impact calls for arbitrarily large number of pages

Open angelaponte opened this issue 5 years ago • 1 comments

I ran into what looks like a Coinbase API rate limit issue when calling AuthenticatedClient.get_account_history, read the source, and didn't see how API rate limits were being handled in PublicClient._send_paginated_message .

Here's the Coinbase Pro API rate limits page: https://docs.pro.coinbase.com/#rate-limits

It says: "PUBLIC ENDPOINTS We throttle public endpoints by IP: 3 requests per second, up to 6 requests per second in bursts.

PRIVATE ENDPOINTS We throttle private endpoints by profile ID: 5 requests per second, up to 10 requests per second in bursts."

This patch adds a time.sleep of .2 seconds to paginated calls in the AuthenticatedClient (to meet the 5 request per second limit) and sets a default time.sleep of .34 seconds for all other paginated calls (e.g. the PublicClient).

The changes are simple and easy to read, but I only tested them for performance. I have not tested all of the paginated calls. The changes necessarily make the pulling of multiple pages of data slower.

angelaponte avatar Feb 18 '20 15:02 angelaponte

Great consideration, but maybe we ought to pass the sleep_interval through kwargs in the functions that are paginated, so the defaults can easily be overridden by the application.

danpaquin avatar Apr 05 '20 14:04 danpaquin